[ctypes-commit] ctypes/source ctypes.h,1.65,1.66 callproc.c,1.122,1.123 _ctypes.c,1.192,1.193
Brought to you by:
theller
From: Thomas H. <th...@us...> - 2004-12-17 13:08:39
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31484 Modified Files: ctypes.h callproc.c _ctypes.c Log Message: Move some functions from _ctypes.c into callbacks.c so that they can be static. Index: ctypes.h =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/ctypes.h,v retrieving revision 1.65 retrieving revision 1.66 diff -C2 -d -r1.65 -r1.66 *** ctypes.h 2 Dec 2004 19:51:32 -0000 1.65 --- ctypes.h 17 Dec 2004 13:08:23 -0000 1.66 *************** *** 123,131 **** extern PyMethodDef module_methods[]; - extern PyObject *sizeof_func(PyObject *self, PyObject *obj); - extern PyObject *align_func(PyObject *self, PyObject *obj); - extern PyObject *byref(PyObject *self, PyObject *obj); - extern PyObject *addressof(PyObject *self, PyObject *obj); - typedef PyObject *(* GETFUNC)(void *, unsigned size); typedef PyObject *(* SETFUNC)(void *, PyObject *value, unsigned size); --- 123,126 ---- Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.122 retrieving revision 1.123 diff -C2 -d -r1.122 -r1.123 *** callproc.c 2 Dec 2004 20:57:29 -0000 1.122 --- callproc.c 17 Dec 2004 13:08:23 -0000 1.123 *************** *** 1219,1226 **** } ! static char alignment_doc[] = ! "alignment(C type) -> integer\n" ! "alignment(C instance) -> integer\n" ! "Return the alignment requirements of a C instance"; static char sizeof_doc[] = "sizeof(C type) -> integer\n" --- 1219,1225 ---- } ! /***************************************************************** ! * functions ! */ static char sizeof_doc[] = "sizeof(C type) -> integer\n" *************** *** 1228,1239 **** --- 1227,1313 ---- "Return the size in bytes of a C instance"; + static PyObject * + sizeof_func(PyObject *self, PyObject *obj) + { + StgDictObject *dict; + + dict = PyType_stgdict(obj); + if (dict) + return PyInt_FromLong(dict->size); + + if (CDataObject_Check(obj)) + return PyInt_FromLong(((CDataObject *)obj)->b_size); + PyErr_SetString(PyExc_TypeError, + "this type has no size"); + return NULL; + } + + static char alignment_doc[] = + "alignment(C type) -> integer\n" + "alignment(C instance) -> integer\n" + "Return the alignment requirements of a C instance"; + + static PyObject * + align_func(PyObject *self, PyObject *obj) + { + StgDictObject *dict; + + dict = PyType_stgdict(obj); + if (dict) + return PyInt_FromLong(dict->align); + + dict = PyObject_stgdict(obj); + if (dict) + return PyInt_FromLong(dict->align); + + PyErr_SetString(PyExc_TypeError, + "no alignment info"); + return NULL; + } + static char byref_doc[] = "byref(C instance) -> byref-object\n" "Return a pointer lookalike to a C instance, only usable\n" "as function argument"; + + /* + * We must return something which can be converted to a parameter, + * but still has a reference to self. + */ + static PyObject * + byref(PyObject *self, PyObject *obj) + { + PyCArgObject *parg; + if (!CDataObject_Check(obj)) { + PyErr_SetString(PyExc_TypeError, + "expected CData instance"); + return NULL; + } + + parg = new_CArgObject(); + if (parg == NULL) + return NULL; + + parg->tag = 'P'; + parg->pffi_type = &ffi_type_pointer; + Py_INCREF(obj); + parg->obj = obj; + parg->value.p = ((CDataObject *)obj)->b_ptr; + return (PyObject *)parg; + } + static char addressof_doc[] = "addressof(C instance) -> integer\n" "Return the address of the C instance internal buffer"; + static PyObject * + addressof(PyObject *self, PyObject *obj) + { + if (CDataObject_Check(obj)) + return PyInt_FromLong((long)((CDataObject *)obj)->b_ptr); + PyErr_SetString(PyExc_TypeError, + "invalid type"); + return NULL; + } static PyObject * *************** *** 1267,1270 **** --- 1341,1350 ---- #ifdef CTYPES_UNICODE + static char set_conversion_mode_doc[] = + "FormatError(encoding, errors) -> (previous-encoding, previous-errors)\n\ + \n\ + Set the encoding and error handling ctypes uses when converting\n\ + between unicode and strings. Returns the previous values.\n"; + static PyObject * set_conversion_mode(PyObject *self, PyObject *args) *************** *** 1288,1297 **** return result; } - - static char set_conversion_mode_doc[] = - "FormatError(encoding, errors) -> (previous-encoding, previous-errors)\n\ - \n\ - Set the encoding and error handling ctypes uses when converting\n\ - between unicode and strings. Returns the previous values.\n"; #endif --- 1368,1371 ---- Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.192 retrieving revision 1.193 diff -C2 -d -r1.192 -r1.193 *** _ctypes.c 2 Dec 2004 19:51:32 -0000 1.192 --- _ctypes.c 17 Dec 2004 13:08:23 -0000 1.193 *************** *** 3480,3557 **** */ - PyObject * - sizeof_func(PyObject *self, PyObject *obj) - { - StgDictObject *dict; - - dict = PyType_stgdict(obj); - if (dict) - return PyInt_FromLong(dict->size); - - if (CDataObject_Check(obj)) - return PyInt_FromLong(((CDataObject *)obj)->b_size); - PyErr_SetString(PyExc_TypeError, - "this type has no size"); - return NULL; - } - - PyObject * - align_func(PyObject *self, PyObject *obj) - { - StgDictObject *dict; - - dict = PyType_stgdict(obj); - if (dict) - return PyInt_FromLong(dict->align); - - dict = PyObject_stgdict(obj); - if (dict) - return PyInt_FromLong(dict->align); - - PyErr_SetString(PyExc_TypeError, - "no alignment info"); - return NULL; - } - - /* - * We must return something which can be converted to a parameter, - * but still has a reference to self. - */ - PyObject * - byref(PyObject *self, PyObject *obj) - { - PyCArgObject *parg; - if (!CDataObject_Check(obj)) { - PyErr_SetString(PyExc_TypeError, - "expected CData instance"); - return NULL; - } - - parg = new_CArgObject(); - if (parg == NULL) - return NULL; - - parg->tag = 'P'; - parg->pffi_type = &ffi_type_pointer; - Py_INCREF(obj); - parg->obj = obj; - parg->value.p = ((CDataObject *)obj)->b_ptr; - return (PyObject *)parg; - } - - /* - * Better to implement addressof here, than to do it in ctypes.py, - * and have to know about the exact format returned by byref(). - */ - PyObject * - addressof(PyObject *self, PyObject *obj) - { - if (CDataObject_Check(obj)) - return PyInt_FromLong((long)((CDataObject *)obj)->b_ptr); - PyErr_SetString(PyExc_TypeError, - "invalid type"); - return NULL; - } - static char *module_docs = "Create and manipulate C compatible data types in Python."; --- 3480,3483 ---- |