Commit c877a7c2 authored by Georg Brandl's avatar Georg Brandl

Use PyLong_FromLong where appropriate.

parent 84499323
...@@ -209,7 +209,7 @@ Python extension. For example:: ...@@ -209,7 +209,7 @@ Python extension. For example::
{ {
if(!PyArg_ParseTuple(args, ":numargs")) if(!PyArg_ParseTuple(args, ":numargs"))
return NULL; return NULL;
return Py_BuildValue("i", numargs); return PyLong_FromLong(numargs);
} }
static PyMethodDef EmbMethods[] = { static PyMethodDef EmbMethods[] = {
......
...@@ -81,7 +81,7 @@ shortly how it ends up being called):: ...@@ -81,7 +81,7 @@ shortly how it ends up being called)::
if (!PyArg_ParseTuple(args, "s", &command)) if (!PyArg_ParseTuple(args, "s", &command))
return NULL; return NULL;
sts = system(command); sts = system(command);
return Py_BuildValue("i", sts); return PyLong_FromLong(sts);
} }
There is a straightforward translation from the argument list in Python (for 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`:: ...@@ -274,12 +274,9 @@ the string we just got from :c:func:`PyArg_ParseTuple`::
sts = system(command); sts = system(command);
Our :func:`spam.system` function must return the value of :c:data:`sts` as a Our :func:`spam.system` function must return the value of :c:data:`sts` as a
Python object. This is done using the function :c:func:`Py_BuildValue`, which is Python object. This is done using the function :c:func:`PyLong_FromLong`. ::
something like the inverse of :c:func:`PyArg_ParseTuple`: it takes a format
string and an arbitrary number of C values, and returns a new Python object.
More info on :c:func:`Py_BuildValue` is given later. ::
return Py_BuildValue("i", sts); return PyLong_FromLong(sts);
In this case, it will return an integer object. (Yes, even integers are objects In this case, it will return an integer object. (Yes, even integers are objects
on the heap in Python!) on the heap in Python!)
...@@ -1195,7 +1192,7 @@ The function :c:func:`spam_system` is modified in a trivial way:: ...@@ -1195,7 +1192,7 @@ The function :c:func:`spam_system` is modified in a trivial way::
if (!PyArg_ParseTuple(args, "s", &command)) if (!PyArg_ParseTuple(args, "s", &command))
return NULL; return NULL;
sts = PySpam_System(command); sts = PySpam_System(command);
return Py_BuildValue("i", sts); return PyLong_FromLong(sts);
} }
In the beginning of the module, right after the line :: In the beginning of the module, right after the line ::
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment