[Python-checkins] cpython (merge 3.3 -> default): cleanup references to PyString_ APIs in the 3.x docs.
gregory.p.smith
python-checkins at python.org
Fri Mar 22 21:50:01 CET 2013
http://hg.python.org/cpython/rev/81083f8841fe
changeset: 82887:81083f8841fe
parent: 82884:b916efe30d77
parent: 82886:6bdf64a5f4d7
user: Gregory P. Smith <greg at krypto.org>
date: Fri Mar 22 13:49:53 2013 -0700
summary:
cleanup references to PyString_ APIs in the 3.x docs.
files:
Doc/c-api/intro.rst | 2 +-
Doc/c-api/memory.rst | 6 +++---
Doc/extending/newtypes.rst | 19 +++++++++----------
Doc/faq/extending.rst | 14 ++++++++------
4 files changed, 21 insertions(+), 20 deletions(-)
diff --git a/Doc/c-api/intro.rst b/Doc/c-api/intro.rst
--- a/Doc/c-api/intro.rst
+++ b/Doc/c-api/intro.rst
@@ -210,7 +210,7 @@
t = PyTuple_New(3);
PyTuple_SetItem(t, 0, PyLong_FromLong(1L));
PyTuple_SetItem(t, 1, PyLong_FromLong(2L));
- PyTuple_SetItem(t, 2, PyString_FromString("three"));
+ PyTuple_SetItem(t, 2, PyUnicode_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
diff --git a/Doc/c-api/memory.rst b/Doc/c-api/memory.rst
--- a/Doc/c-api/memory.rst
+++ b/Doc/c-api/memory.rst
@@ -61,7 +61,7 @@
if (buf == NULL)
return PyErr_NoMemory();
...Do some I/O operation involving buf...
- res = PyString_FromString(buf);
+ res = PyBytes_FromString(buf);
free(buf); /* malloc'ed */
return res;
@@ -169,7 +169,7 @@
if (buf == NULL)
return PyErr_NoMemory();
/* ...Do some I/O operation involving buf... */
- res = PyString_FromString(buf);
+ res = PyBytes_FromString(buf);
PyMem_Free(buf); /* allocated with PyMem_Malloc */
return res;
@@ -181,7 +181,7 @@
if (buf == NULL)
return PyErr_NoMemory();
/* ...Do some I/O operation involving buf... */
- res = PyString_FromString(buf);
+ res = PyBytes_FromString(buf);
PyMem_Del(buf); /* allocated with PyMem_New */
return res;
diff --git a/Doc/extending/newtypes.rst b/Doc/extending/newtypes.rst
--- a/Doc/extending/newtypes.rst
+++ b/Doc/extending/newtypes.rst
@@ -288,13 +288,13 @@
self = (Noddy *)type->tp_alloc(type, 0);
if (self != NULL) {
- self->first = PyString_FromString("");
+ self->first = PyUnicode_FromString("");
if (self->first == NULL) {
Py_DECREF(self);
return NULL;
}
- self->last = PyString_FromString("");
+ self->last = PyUnicode_FromString("");
if (self->last == NULL) {
Py_DECREF(self);
return NULL;
@@ -540,9 +540,9 @@
return -1;
}
- if (! PyString_Check(value)) {
+ if (! PyUnicode_Check(value)) {
PyErr_SetString(PyExc_TypeError,
- "The first attribute value must be a string");
+ "The first attribute value must be a str");
return -1;
}
@@ -1005,8 +1005,8 @@
static PyObject *
newdatatype_repr(newdatatypeobject * obj)
{
- return PyString_FromFormat("Repr-ified_newdatatype{{size:\%d}}",
- obj->obj_UnderlyingDatatypePtr->size);
+ return PyUnicode_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 @@
static PyObject *
newdatatype_str(newdatatypeobject * obj)
{
- return PyString_FromFormat("Stringified_newdatatype{{size:\%d}}",
- obj->obj_UnderlyingDatatypePtr->size);
+ return PyUnicode_FromFormat("Stringified_newdatatype{{size:\%d}}",
+ obj->obj_UnderlyingDatatypePtr->size);
}
@@ -1342,11 +1342,10 @@
if (!PyArg_ParseTuple(args, "sss:call", &arg1, &arg2, &arg3)) {
return NULL;
}
- result = PyString_FromFormat(
+ result = PyUnicode_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;
}
diff --git a/Doc/faq/extending.rst b/Doc/faq/extending.rst
--- a/Doc/faq/extending.rst
+++ b/Doc/faq/extending.rst
@@ -82,18 +82,20 @@
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:`PyString_Check`, :c:func:`PyTuple_Check`, :c:func:`PyList_Check`, etc.
+:c:func:`PyBytes_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?
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list