Skip to content

Commit d4296fc

Browse files
committed
cleanup references to PyString_ APIs in the 3.x docs.
2 parents 5a63fe6 + bcd2aa6 commit d4296fc

File tree

4 files changed

+21
-20
lines changed

4 files changed

+21
-20
lines changed

Doc/c-api/intro.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ error handling for the moment; a better way to code this is shown below)::
210210
t = PyTuple_New(3);
211211
PyTuple_SetItem(t, 0, PyLong_FromLong(1L));
212212
PyTuple_SetItem(t, 1, PyLong_FromLong(2L));
213-
PyTuple_SetItem(t, 2, PyString_FromString("three"));
213+
PyTuple_SetItem(t, 2, PyUnicode_FromString("three"));
214214

215215
Here, :c:func:`PyLong_FromLong` returns a new reference which is immediately
216216
stolen by :c:func:`PyTuple_SetItem`. When you want to keep using an object

Doc/c-api/memory.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ example::
6161
if (buf == NULL)
6262
return PyErr_NoMemory();
6363
...Do some I/O operation involving buf...
64-
res = PyString_FromString(buf);
64+
res = PyBytes_FromString(buf);
6565
free(buf); /* malloc'ed */
6666
return res;
6767

@@ -169,7 +169,7 @@ I/O buffer is allocated from the Python heap by using the first function set::
169169
if (buf == NULL)
170170
return PyErr_NoMemory();
171171
/* ...Do some I/O operation involving buf... */
172-
res = PyString_FromString(buf);
172+
res = PyBytes_FromString(buf);
173173
PyMem_Free(buf); /* allocated with PyMem_Malloc */
174174
return res;
175175
@@ -181,7 +181,7 @@ The same code using the type-oriented function set::
181181
if (buf == NULL)
182182
return PyErr_NoMemory();
183183
/* ...Do some I/O operation involving buf... */
184-
res = PyString_FromString(buf);
184+
res = PyBytes_FromString(buf);
185185
PyMem_Del(buf); /* allocated with PyMem_New */
186186
return res;
187187

Doc/extending/newtypes.rst

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -288,13 +288,13 @@ strings, so we provide a new method::
288288

289289
self = (Noddy *)type->tp_alloc(type, 0);
290290
if (self != NULL) {
291-
self->first = PyString_FromString("");
291+
self->first = PyUnicode_FromString("");
292292
if (self->first == NULL) {
293293
Py_DECREF(self);
294294
return NULL;
295295
}
296296

297-
self->last = PyString_FromString("");
297+
self->last = PyUnicode_FromString("");
298298
if (self->last == NULL) {
299299
Py_DECREF(self);
300300
return NULL;
@@ -540,9 +540,9 @@ getting and setting the :attr:`first` attribute::
540540
return -1;
541541
}
542542

543-
if (! PyString_Check(value)) {
543+
if (! PyUnicode_Check(value)) {
544544
PyErr_SetString(PyExc_TypeError,
545-
"The first attribute value must be a string");
545+
"The first attribute value must be a str");
546546
return -1;
547547
}
548548

@@ -1005,8 +1005,8 @@ example::
10051005
static PyObject *
10061006
newdatatype_repr(newdatatypeobject * obj)
10071007
{
1008-
return PyString_FromFormat("Repr-ified_newdatatype{{size:\%d}}",
1009-
obj->obj_UnderlyingDatatypePtr->size);
1008+
return PyUnicode_FromFormat("Repr-ified_newdatatype{{size:\%d}}",
1009+
obj->obj_UnderlyingDatatypePtr->size);
10101010
}
10111011

10121012
If no :attr:`tp_repr` handler is specified, the interpreter will supply a
@@ -1025,8 +1025,8 @@ Here is a simple example::
10251025
static PyObject *
10261026
newdatatype_str(newdatatypeobject * obj)
10271027
{
1028-
return PyString_FromFormat("Stringified_newdatatype{{size:\%d}}",
1029-
obj->obj_UnderlyingDatatypePtr->size);
1028+
return PyUnicode_FromFormat("Stringified_newdatatype{{size:\%d}}",
1029+
obj->obj_UnderlyingDatatypePtr->size);
10301030
}
10311031

10321032

@@ -1342,11 +1342,10 @@ Here is a desultory example of the implementation of the call function. ::
13421342
if (!PyArg_ParseTuple(args, "sss:call", &arg1, &arg2, &arg3)) {
13431343
return NULL;
13441344
}
1345-
result = PyString_FromFormat(
1345+
result = PyUnicode_FromFormat(
13461346
"Returning -- value: [\%d] arg1: [\%s] arg2: [\%s] arg3: [\%s]\n",
13471347
obj->obj_UnderlyingDatatypePtr->size,
13481348
arg1, arg2, arg3);
1349-
printf("\%s", PyString_AS_STRING(result));
13501349
return result;
13511350
}
13521351

Doc/faq/extending.rst

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,20 @@ returns its length and :c:func:`PyTuple_GetItem` returns the item at a specified
8282
index. Lists have similar functions, :c:func:`PyListSize` and
8383
:c:func:`PyList_GetItem`.
8484

85-
For strings, :c:func:`PyString_Size` returns its length and
86-
:c:func:`PyString_AsString` a pointer to its value. Note that Python strings may
87-
contain null bytes so C's :c:func:`strlen` should not be used.
85+
For bytes, :c:func:`PyBytes_Size` returns its length and
86+
:c:func:`PyBytes_AsStringAndSize` provides a pointer to its value and its
87+
length. Note that Python bytes objects may contain null bytes so C's
88+
:c:func:`strlen` should not be used.
8889

8990
To test the type of an object, first make sure it isn't *NULL*, and then use
90-
:c:func:`PyString_Check`, :c:func:`PyTuple_Check`, :c:func:`PyList_Check`, etc.
91+
:c:func:`PyBytes_Check`, :c:func:`PyTuple_Check`, :c:func:`PyList_Check`, etc.
9192

9293
There is also a high-level API to Python objects which is provided by the
9394
so-called 'abstract' interface -- read ``Include/abstract.h`` for further
9495
details. It allows interfacing with any kind of Python sequence using calls
95-
like :c:func:`PySequence_Length`, :c:func:`PySequence_GetItem`, etc.) as well as
96-
many other useful protocols.
96+
like :c:func:`PySequence_Length`, :c:func:`PySequence_GetItem`, etc.) as well
97+
as many other useful protocols such as numbers (:c:func:`PyNumber_Index` et.
98+
al.) and mappings in the PyMapping APIs.
9799

98100

99101
How do I use Py_BuildValue() to create a tuple of arbitrary length?

0 commit comments

Comments
 (0)