Skip to content

Commit c877a7c

Browse files
committed
Use PyLong_FromLong where appropriate.
1 parent 8449932 commit c877a7c

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

Doc/extending/embedding.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ Python extension. For example::
209209
{
210210
if(!PyArg_ParseTuple(args, ":numargs"))
211211
return NULL;
212-
return Py_BuildValue("i", numargs);
212+
return PyLong_FromLong(numargs);
213213
}
214214

215215
static PyMethodDef EmbMethods[] = {

Doc/extending/extending.rst

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ shortly how it ends up being called)::
8181
if (!PyArg_ParseTuple(args, "s", &command))
8282
return NULL;
8383
sts = system(command);
84-
return Py_BuildValue("i", sts);
84+
return PyLong_FromLong(sts);
8585
}
8686

8787
There is a straightforward translation from the argument list in Python (for
@@ -274,12 +274,9 @@ the string we just got from :c:func:`PyArg_ParseTuple`::
274274
sts = system(command);
275275

276276
Our :func:`spam.system` function must return the value of :c:data:`sts` as a
277-
Python object. This is done using the function :c:func:`Py_BuildValue`, which is
278-
something like the inverse of :c:func:`PyArg_ParseTuple`: it takes a format
279-
string and an arbitrary number of C values, and returns a new Python object.
280-
More info on :c:func:`Py_BuildValue` is given later. ::
277+
Python object. This is done using the function :c:func:`PyLong_FromLong`. ::
281278

282-
return Py_BuildValue("i", sts);
279+
return PyLong_FromLong(sts);
283280

284281
In this case, it will return an integer object. (Yes, even integers are objects
285282
on the heap in Python!)
@@ -1195,7 +1192,7 @@ The function :c:func:`spam_system` is modified in a trivial way::
11951192
if (!PyArg_ParseTuple(args, "s", &command))
11961193
return NULL;
11971194
sts = PySpam_System(command);
1198-
return Py_BuildValue("i", sts);
1195+
return PyLong_FromLong(sts);
11991196
}
12001197

12011198
In the beginning of the module, right after the line ::

0 commit comments

Comments
 (0)