diff options
author | Thomas Heller <theller@ctypes.org> | 2008-06-10 15:08:51 (GMT) |
---|---|---|
committer | Thomas Heller <theller@ctypes.org> | 2008-06-10 15:08:51 (GMT) |
commit | c5d012694b7a357f7e6a7b5ce445f8147efbd3c2 (patch) | |
tree | 9924cdc39a9a4e16888e9b507394c8b015b7906f /Modules | |
parent | 12f8a0538b7e0964d82ddda86c63df97129f0c99 (diff) | |
download | cpython-c5d012694b7a357f7e6a7b5ce445f8147efbd3c2.zip cpython-c5d012694b7a357f7e6a7b5ce445f8147efbd3c2.tar.gz cpython-c5d012694b7a357f7e6a7b5ce445f8147efbd3c2.tar.bz2 |
Merged revisions 64070 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r64070 | thomas.heller | 2008-06-10 16:02:46 +0200 (Di, 10 Jun 2008) | 2 lines
Add an optional 'offset' parameter to byref, defaultingto zero.
........
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_ctypes/callproc.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c index ffdc3bb..5fa6336 100644 --- a/Modules/_ctypes/callproc.c +++ b/Modules/_ctypes/callproc.c @@ -1528,7 +1528,7 @@ align_func(PyObject *self, PyObject *obj) } static char byref_doc[] = -"byref(C instance) -> byref-object\n" +"byref(C instance[, offset=0]) -> byref-object\n" "Return a pointer lookalike to a C instance, only usable\n" "as function argument"; @@ -1537,9 +1537,21 @@ static char byref_doc[] = * but still has a reference to self. */ static PyObject * -byref(PyObject *self, PyObject *obj) +byref(PyObject *self, PyObject *args) { PyCArgObject *parg; + PyObject *obj; + PyObject *pyoffset = NULL; + Py_ssize_t offset = 0; + + if (!PyArg_UnpackTuple(args, "byref", 1, 2, + &obj, &pyoffset)) + return NULL; + if (pyoffset) { + offset = PyNumber_AsSsize_t(pyoffset, NULL); + if (offset == -1 && PyErr_Occurred()) + return NULL; + } if (!CDataObject_Check(obj)) { PyErr_Format(PyExc_TypeError, "byref() argument must be a ctypes instance, not '%s'", @@ -1555,7 +1567,7 @@ byref(PyObject *self, PyObject *obj) parg->pffi_type = &ffi_type_pointer; Py_INCREF(obj); parg->obj = obj; - parg->value.p = ((CDataObject *)obj)->b_ptr; + parg->value.p = (char *)((CDataObject *)obj)->b_ptr + offset; return (PyObject *)parg; } @@ -1835,7 +1847,7 @@ PyMethodDef module_methods[] = { #endif {"alignment", align_func, METH_O, alignment_doc}, {"sizeof", sizeof_func, METH_O, sizeof_doc}, - {"byref", byref, METH_O, byref_doc}, + {"byref", byref, METH_VARARGS, byref_doc}, {"addressof", addressof, METH_O, addressof_doc}, {"call_function", call_function, METH_VARARGS }, {"call_cdeclfunction", call_cdeclfunction, METH_VARARGS }, |