Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4b52ae8

Browse files
committed
Clean up references to the no longer existing PyString_ APIs in our docs.
1 parent 3f885b5 commit 4b52ae8

4 files changed

Lines changed: 23 additions & 22 deletions

File tree

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: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -287,14 +287,14 @@ strings, so we provide a new method::
287287

288288
self = (Noddy *)type->tp_alloc(type, 0);
289289
if (self != NULL) {
290-
self->first = PyString_FromString("");
290+
self->first = PyUnicode_FromString("");
291291
if (self->first == NULL)
292292
{
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
{
300300
Py_DECREF(self);
@@ -449,7 +449,7 @@ concatenation of the first and last names. ::
449449
PyObject *args, *result;
450450

451451
if (format == NULL) {
452-
format = PyString_FromString("%s %s");
452+
format = PyUnicode_FromString("%s %s");
453453
if (format == NULL)
454454
return NULL;
455455
}
@@ -468,7 +468,7 @@ concatenation of the first and last names. ::
468468
if (args == NULL)
469469
return NULL;
470470

471-
result = PyString_Format(format, args);
471+
result = PyUnicode_Format(format, args);
472472
Py_DECREF(args);
473473

474474
return result;
@@ -557,9 +557,9 @@ getting and setting the :attr:`first` attribute::
557557
return -1;
558558
}
559559

560-
if (! PyString_Check(value)) {
560+
if (! PyUnicode_Check(value)) {
561561
PyErr_SetString(PyExc_TypeError,
562-
"The first attribute value must be a string");
562+
"The first attribute value must be a str");
563563
return -1;
564564
}
565565

@@ -1022,8 +1022,8 @@ example::
10221022
static PyObject *
10231023
newdatatype_repr(newdatatypeobject * obj)
10241024
{
1025-
return PyString_FromFormat("Repr-ified_newdatatype{{size:\%d}}",
1026-
obj->obj_UnderlyingDatatypePtr->size);
1025+
return PyUnicode_FromFormat("Repr-ified_newdatatype{{size:\%d}}",
1026+
obj->obj_UnderlyingDatatypePtr->size);
10271027
}
10281028

10291029
If no :attr:`tp_repr` handler is specified, the interpreter will supply a
@@ -1042,8 +1042,8 @@ Here is a simple example::
10421042
static PyObject *
10431043
newdatatype_str(newdatatypeobject * obj)
10441044
{
1045-
return PyString_FromFormat("Stringified_newdatatype{{size:\%d}}",
1046-
obj->obj_UnderlyingDatatypePtr->size);
1045+
return PyUnicode_FromFormat("Stringified_newdatatype{{size:\%d}}",
1046+
obj->obj_UnderlyingDatatypePtr->size);
10471047
}
10481048

10491049

@@ -1364,11 +1364,10 @@ Here is a desultory example of the implementation of the call function. ::
13641364
if (!PyArg_ParseTuple(args, "sss:call", &arg1, &arg2, &arg3)) {
13651365
return NULL;
13661366
}
1367-
result = PyString_FromFormat(
1367+
result = PyUnicode_FromFormat(
13681368
"Returning -- value: [\%d] arg1: [\%s] arg2: [\%s] arg3: [\%s]\n",
13691369
obj->obj_UnderlyingDatatypePtr->size,
13701370
arg1, arg2, arg3);
1371-
printf("\%s", PyString_AS_STRING(result));
13721371
return result;
13731372
}
13741373

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)