summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Heller <theller@ctypes.org>2008-01-24 18:54:12 (GMT)
committerThomas Heller <theller@ctypes.org>2008-01-24 18:54:12 (GMT)
commit71dba4ccee4d90c7dfb970ab77fcba113c9aec5c (patch)
treef7363261e3449bc32fc59e3459605a246e82c98a
parente4c03e4520cdf0959cb2b0e0cc289cb1e3a0ceb4 (diff)
downloadcpython-71dba4ccee4d90c7dfb970ab77fcba113c9aec5c.zip
cpython-71dba4ccee4d90c7dfb970ab77fcba113c9aec5c.tar.gz
cpython-71dba4ccee4d90c7dfb970ab77fcba113c9aec5c.tar.bz2
Replace Py_BuildValue with PyTuple_Pack because it is faster.
Also add a missing DECREF.
-rw-r--r--Modules/_ctypes/_ctypes.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
index 3b749ec..fd043d6 100644
--- a/Modules/_ctypes/_ctypes.c
+++ b/Modules/_ctypes/_ctypes.c
@@ -2523,7 +2523,7 @@ _CData_set(CDataObject *dst, PyObject *type, SETFUNC setfunc, PyObject *value,
only it's object list. So we create a tuple, containing
b_objects list PLUS the array itself, and return that!
*/
- return Py_BuildValue("(OO)", keep, value);
+ return PyTuple_Pack(2, keep, value);
}
PyErr_Format(PyExc_TypeError,
"incompatible types, %s instance instead of %s instance",
@@ -4228,17 +4228,18 @@ CreateArrayType(PyObject *itemtype, Py_ssize_t length)
PyObject *key;
PyObject *result;
char name[256];
+ PyObject *len;
if (cache == NULL) {
cache = PyDict_New();
if (cache == NULL)
return NULL;
}
-#if (PY_VERSION_HEX < 0x02050000)
- key = Py_BuildValue("(Oi)", itemtype, length);
-#else
- key = Py_BuildValue("(On)", itemtype, length);
-#endif
+ len = PyInt_FromSsize_t(length);
+ if (len == NULL)
+ return NULL;
+ key = PyTuple_Pack(2, itemtype, len);
+ Py_DECREF(len);
if (!key)
return NULL;
result = PyDict_GetItemProxy(cache, key);
@@ -4274,8 +4275,10 @@ CreateArrayType(PyObject *itemtype, Py_ssize_t length)
"_type_",
itemtype
);
- if (!result)
+ if (result == NULL) {
+ Py_DECREF(key);
return NULL;
+ }
if (-1 == PyDict_SetItemProxy(cache, key, result)) {
Py_DECREF(key);
Py_DECREF(result);