Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
d4296fc1
Kaydet (Commit)
d4296fc1
authored
Mar 22, 2013
tarafından
Gregory P. Smith
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
cleanup references to PyString_ APIs in the 3.x docs.
üst
5a63fe68
bcd2aa6d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
20 deletions
+21
-20
intro.rst
Doc/c-api/intro.rst
+1
-1
memory.rst
Doc/c-api/memory.rst
+3
-3
newtypes.rst
Doc/extending/newtypes.rst
+9
-10
extending.rst
Doc/faq/extending.rst
+8
-6
No files found.
Doc/c-api/intro.rst
Dosyayı görüntüle @
d4296fc1
...
...
@@ -210,7 +210,7 @@ error handling for the moment; a better way to code this is shown below)::
t = PyTuple_New(3);
PyTuple_SetItem(t, 0, PyLong_FromLong(1L));
PyTuple_SetItem(t, 1, PyLong_FromLong(2L));
PyTuple_SetItem(t, 2, Py
String
_FromString("three"));
PyTuple_SetItem(t, 2, Py
Unicode
_FromString("three"));
Here, :c:func:`PyLong_FromLong` returns a new reference which is immediately
stolen by :c:func:`PyTuple_SetItem`. When you want to keep using an object
...
...
Doc/c-api/memory.rst
Dosyayı görüntüle @
d4296fc1
...
...
@@ -61,7 +61,7 @@ example::
if (buf == NULL)
return PyErr_NoMemory();
...Do some I/O operation involving buf...
res = Py
String
_FromString(buf);
res = Py
Bytes
_FromString(buf);
free(buf); /* malloc'ed */
return res;
...
...
@@ -169,7 +169,7 @@ I/O buffer is allocated from the Python heap by using the first function set::
if (buf == NULL)
return PyErr_NoMemory();
/* ...Do some I/O operation involving buf... */
res = Py
String
_FromString(buf);
res = Py
Bytes
_FromString(buf);
PyMem_Free(buf); /* allocated with PyMem_Malloc */
return res;
...
...
@@ -181,7 +181,7 @@ The same code using the type-oriented function set::
if (buf == NULL)
return PyErr_NoMemory();
/* ...Do some I/O operation involving buf... */
res = Py
String
_FromString(buf);
res = Py
Bytes
_FromString(buf);
PyMem_Del(buf); /* allocated with PyMem_New */
return res;
...
...
Doc/extending/newtypes.rst
Dosyayı görüntüle @
d4296fc1
...
...
@@ -288,13 +288,13 @@ strings, so we provide a new method::
self = (Noddy *)type->tp_alloc(type, 0);
if (self != NULL) {
self->first = Py
String
_FromString("");
self->first = Py
Unicode
_FromString("");
if (self->first == NULL) {
Py_DECREF(self);
return NULL;
}
self->last = Py
String
_FromString("");
self->last = Py
Unicode
_FromString("");
if (self->last == NULL) {
Py_DECREF(self);
return NULL;
...
...
@@ -540,9 +540,9 @@ getting and setting the :attr:`first` attribute::
return -1;
}
if (! Py
String
_Check(value)) {
if (! Py
Unicode
_Check(value)) {
PyErr_SetString(PyExc_TypeError,
"The first attribute value must be a str
ing
");
"The first attribute value must be a str");
return -1;
}
...
...
@@ -1005,8 +1005,8 @@ example::
static PyObject *
newdatatype_repr(newdatatypeobject * obj)
{
return Py
String
_FromFormat("Repr-ified_newdatatype{{size:\%d}}",
obj->obj_UnderlyingDatatypePtr->size);
return Py
Unicode
_FromFormat("Repr-ified_newdatatype{{size:\%d}}",
obj->obj_UnderlyingDatatypePtr->size);
}
If no :attr:`tp_repr` handler is specified, the interpreter will supply a
...
...
@@ -1025,8 +1025,8 @@ Here is a simple example::
static PyObject *
newdatatype_str(newdatatypeobject * obj)
{
return Py
String
_FromFormat("Stringified_newdatatype{{size:\%d}}",
obj->obj_UnderlyingDatatypePtr->size);
return Py
Unicode
_FromFormat("Stringified_newdatatype{{size:\%d}}",
obj->obj_UnderlyingDatatypePtr->size);
}
...
...
@@ -1342,11 +1342,10 @@ Here is a desultory example of the implementation of the call function. ::
if (!PyArg_ParseTuple(args, "sss:call", &arg1, &arg2, &arg3)) {
return NULL;
}
result = Py
String
_FromFormat(
result = Py
Unicode
_FromFormat(
"Returning -- value: [\%d] arg1: [\%s] arg2: [\%s] arg3: [\%s]\n",
obj->obj_UnderlyingDatatypePtr->size,
arg1, arg2, arg3);
printf("\%s", PyString_AS_STRING(result));
return result;
}
...
...
Doc/faq/extending.rst
Dosyayı görüntüle @
d4296fc1
...
...
@@ -82,18 +82,20 @@ returns its length and :c:func:`PyTuple_GetItem` returns the item at a specified
index. Lists have similar functions, :c:func:`PyListSize` and
:c:func:`PyList_GetItem`.
For strings, :c:func:`PyString_Size` returns its length and
:c:func:`PyString_AsString` a pointer to its value. Note that Python strings may
contain null bytes so C's :c:func:`strlen` should not be used.
For bytes, :c:func:`PyBytes_Size` returns its length and
:c:func:`PyBytes_AsStringAndSize` provides a pointer to its value and its
length. Note that Python bytes objects may contain null bytes so C's
:c:func:`strlen` should not be used.
To test the type of an object, first make sure it isn't *NULL*, and then use
:c:func:`Py
String
_Check`, :c:func:`PyTuple_Check`, :c:func:`PyList_Check`, etc.
:c:func:`Py
Bytes
_Check`, :c:func:`PyTuple_Check`, :c:func:`PyList_Check`, etc.
There is also a high-level API to Python objects which is provided by the
so-called 'abstract' interface -- read ``Include/abstract.h`` for further
details. It allows interfacing with any kind of Python sequence using calls
like :c:func:`PySequence_Length`, :c:func:`PySequence_GetItem`, etc.) as well as
many other useful protocols.
like :c:func:`PySequence_Length`, :c:func:`PySequence_GetItem`, etc.) as well
as many other useful protocols such as numbers (:c:func:`PyNumber_Index` et.
al.) and mappings in the PyMapping APIs.
How do I use Py_BuildValue() to create a tuple of arbitrary length?
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment