Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
4b52ae8f
Commit
4b52ae8f
authored
Mar 22, 2013
by
Gregory P. Smith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up references to the no longer existing PyString_ APIs in our docs.
parent
3f885b54
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
22 deletions
+23
-22
Doc/c-api/intro.rst
Doc/c-api/intro.rst
+1
-1
Doc/c-api/memory.rst
Doc/c-api/memory.rst
+3
-3
Doc/extending/newtypes.rst
Doc/extending/newtypes.rst
+11
-12
Doc/faq/extending.rst
Doc/faq/extending.rst
+8
-6
No files found.
Doc/c-api/intro.rst
View file @
4b52ae8f
...
...
@@ -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
View file @
4b52ae8f
...
...
@@ -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
View file @
4b52ae8f
...
...
@@ -287,14 +287,14 @@ 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);
...
...
@@ -449,7 +449,7 @@ concatenation of the first and last names. ::
PyObject *args, *result;
if (format == NULL) {
format = Py
String
_FromString("%s %s");
format = Py
Unicode
_FromString("%s %s");
if (format == NULL)
return NULL;
}
...
...
@@ -468,7 +468,7 @@ concatenation of the first and last names. ::
if (args == NULL)
return NULL;
result = Py
String
_Format(format, args);
result = Py
Unicode
_Format(format, args);
Py_DECREF(args);
return result;
...
...
@@ -557,9 +557,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;
}
...
...
@@ -1022,8 +1022,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
...
...
@@ -1042,8 +1042,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);
}
...
...
@@ -1364,11 +1364,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
View file @
4b52ae8f
...
...
@@ -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