Commit 34596a90 authored by Thomas Heller's avatar Thomas Heller

Merged revisions 71853 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/trunk

........
  r71853 | thomas.heller | 2009-04-24 22:31:47 +0200 (Fr, 24 Apr 2009) | 3 lines

  Issue #3102: All global symbols that the _ctypes extension defines are
  now prefixed with 'Py' or '_ctypes'.
........
parent d3cfe99b
...@@ -77,6 +77,11 @@ Core and Builtins ...@@ -77,6 +77,11 @@ Core and Builtins
Library Library
------- -------
- Issue #3102: All global symbols that the _ctypes extension defines
are now prefixed with 'Py' or '_ctypes'.
- Issue #5041: ctypes does now allow pickling wide character.
- Issue #5812: For the two-argument form of the Fraction constructor, - Issue #5812: For the two-argument form of the Fraction constructor,
Fraction(m, n), m and n are permitted to be arbitrary Rational Fraction(m, n), m and n are permitted to be arbitrary Rational
instances. instances.
...@@ -430,8 +435,6 @@ Core and Builtins ...@@ -430,8 +435,6 @@ Core and Builtins
Library Library
------- -------
- Issue #5041: ctypes does now allow pickling wide character.
- Issue #5795: Fixed test_distutils failure on Debian ppc. - Issue #5795: Fixed test_distutils failure on Debian ppc.
- Issue #5607: fixed Distutils test_get_platform for Mac OS X fat binaries. - Issue #5607: fixed Distutils test_get_platform for Mac OS X fat binaries.
......
This diff is collapsed.
...@@ -17,7 +17,7 @@ CThunkObject_dealloc(PyObject *_self) ...@@ -17,7 +17,7 @@ CThunkObject_dealloc(PyObject *_self)
Py_XDECREF(self->callable); Py_XDECREF(self->callable);
Py_XDECREF(self->restype); Py_XDECREF(self->restype);
if (self->pcl) if (self->pcl)
FreeClosure(self->pcl); _ctypes_free_closure(self->pcl);
PyObject_Del(self); PyObject_Del(self);
} }
...@@ -41,7 +41,7 @@ CThunkObject_clear(PyObject *_self) ...@@ -41,7 +41,7 @@ CThunkObject_clear(PyObject *_self)
return 0; return 0;
} }
PyTypeObject CThunk_Type = { PyTypeObject PyCThunk_Type = {
PyVarObject_HEAD_INIT(NULL, 0) PyVarObject_HEAD_INIT(NULL, 0)
"_ctypes.CThunkObject", "_ctypes.CThunkObject",
sizeof(CThunkObject), /* tp_basicsize */ sizeof(CThunkObject), /* tp_basicsize */
...@@ -92,7 +92,7 @@ PrintError(char *msg, ...) ...@@ -92,7 +92,7 @@ PrintError(char *msg, ...)
/* after code that pyrex generates */ /* after code that pyrex generates */
void _AddTraceback(char *funcname, char *filename, int lineno) void _ctypes_add_traceback(char *funcname, char *filename, int lineno)
{ {
PyObject *py_srcfile = 0; PyObject *py_srcfile = 0;
PyObject *py_funcname = 0; PyObject *py_funcname = 0;
...@@ -223,7 +223,7 @@ static void _CallPythonObject(void *mem, ...@@ -223,7 +223,7 @@ static void _CallPythonObject(void *mem,
goto Done; goto Done;
} }
if (dict && dict->getfunc && !IsSimpleSubType(cnv)) { if (dict && dict->getfunc && !_ctypes_simple_instance(cnv)) {
PyObject *v = dict->getfunc(*pArgs, dict->size); PyObject *v = dict->getfunc(*pArgs, dict->size);
if (!v) { if (!v) {
PrintError("create argument %d:\n", i); PrintError("create argument %d:\n", i);
...@@ -237,7 +237,7 @@ static void _CallPythonObject(void *mem, ...@@ -237,7 +237,7 @@ static void _CallPythonObject(void *mem,
BTW, the same problem occurrs when they are pushed as parameters BTW, the same problem occurrs when they are pushed as parameters
*/ */
} else if (dict) { } else if (dict) {
/* Hm, shouldn't we use CData_AtAddress() or something like that instead? */ /* Hm, shouldn't we use PyCData_AtAddress() or something like that instead? */
CDataObject *obj = (CDataObject *)PyObject_CallFunctionObjArgs(cnv, NULL); CDataObject *obj = (CDataObject *)PyObject_CallFunctionObjArgs(cnv, NULL);
if (!obj) { if (!obj) {
PrintError("create argument %d:\n", i); PrintError("create argument %d:\n", i);
...@@ -268,10 +268,10 @@ static void _CallPythonObject(void *mem, ...@@ -268,10 +268,10 @@ static void _CallPythonObject(void *mem,
} }
#define CHECK(what, x) \ #define CHECK(what, x) \
if (x == NULL) _AddTraceback(what, "_ctypes/callbacks.c", __LINE__ - 1), PyErr_Print() if (x == NULL) _ctypes_add_traceback(what, "_ctypes/callbacks.c", __LINE__ - 1), PyErr_Print()
if (flags & (FUNCFLAG_USE_ERRNO | FUNCFLAG_USE_LASTERROR)) { if (flags & (FUNCFLAG_USE_ERRNO | FUNCFLAG_USE_LASTERROR)) {
error_object = get_error_object(&space); error_object = _ctypes_get_errobj(&space);
if (error_object == NULL) if (error_object == NULL)
goto Done; goto Done;
if (flags & FUNCFLAG_USE_ERRNO) { if (flags & FUNCFLAG_USE_ERRNO) {
...@@ -328,7 +328,7 @@ if (x == NULL) _AddTraceback(what, "_ctypes/callbacks.c", __LINE__ - 1), PyErr_P ...@@ -328,7 +328,7 @@ if (x == NULL) _AddTraceback(what, "_ctypes/callbacks.c", __LINE__ - 1), PyErr_P
PyErr_WriteUnraisable(callable); PyErr_WriteUnraisable(callable);
else if (keep == Py_None) /* Nothing to keep */ else if (keep == Py_None) /* Nothing to keep */
Py_DECREF(keep); Py_DECREF(keep);
else if (setfunc != getentry("O")->setfunc) { else if (setfunc != _ctypes_get_fielddesc("O")->setfunc) {
if (-1 == PyErr_WarnEx(PyExc_RuntimeWarning, if (-1 == PyErr_WarnEx(PyExc_RuntimeWarning,
"memory leak in callback function.", "memory leak in callback function.",
1)) 1))
...@@ -364,7 +364,7 @@ static CThunkObject* CThunkObject_new(Py_ssize_t nArgs) ...@@ -364,7 +364,7 @@ static CThunkObject* CThunkObject_new(Py_ssize_t nArgs)
CThunkObject *p; CThunkObject *p;
int i; int i;
p = PyObject_NewVar(CThunkObject, &CThunk_Type, nArgs); p = PyObject_NewVar(CThunkObject, &PyCThunk_Type, nArgs);
if (p == NULL) { if (p == NULL) {
PyErr_NoMemory(); PyErr_NoMemory();
return NULL; return NULL;
...@@ -382,7 +382,7 @@ static CThunkObject* CThunkObject_new(Py_ssize_t nArgs) ...@@ -382,7 +382,7 @@ static CThunkObject* CThunkObject_new(Py_ssize_t nArgs)
return p; return p;
} }
CThunkObject *AllocFunctionCallback(PyObject *callable, CThunkObject *_ctypes_alloc_callback(PyObject *callable,
PyObject *converters, PyObject *converters,
PyObject *restype, PyObject *restype,
int flags) int flags)
...@@ -399,7 +399,7 @@ CThunkObject *AllocFunctionCallback(PyObject *callable, ...@@ -399,7 +399,7 @@ CThunkObject *AllocFunctionCallback(PyObject *callable,
assert(CThunk_CheckExact((PyObject *)p)); assert(CThunk_CheckExact((PyObject *)p));
p->pcl = MallocClosure(); p->pcl = _ctypes_alloc_closure();
if (p->pcl == NULL) { if (p->pcl == NULL) {
PyErr_NoMemory(); PyErr_NoMemory();
goto error; goto error;
...@@ -410,7 +410,7 @@ CThunkObject *AllocFunctionCallback(PyObject *callable, ...@@ -410,7 +410,7 @@ CThunkObject *AllocFunctionCallback(PyObject *callable,
PyObject *cnv = PySequence_GetItem(converters, i); PyObject *cnv = PySequence_GetItem(converters, i);
if (cnv == NULL) if (cnv == NULL)
goto error; goto error;
p->atypes[i] = GetType(cnv); p->atypes[i] = _ctypes_get_ffi_type(cnv);
Py_DECREF(cnv); Py_DECREF(cnv);
} }
p->atypes[i] = NULL; p->atypes[i] = NULL;
...@@ -438,7 +438,7 @@ CThunkObject *AllocFunctionCallback(PyObject *callable, ...@@ -438,7 +438,7 @@ CThunkObject *AllocFunctionCallback(PyObject *callable,
#endif #endif
result = ffi_prep_cif(&p->cif, cc, result = ffi_prep_cif(&p->cif, cc,
Py_SAFE_DOWNCAST(nArgs, Py_ssize_t, int), Py_SAFE_DOWNCAST(nArgs, Py_ssize_t, int),
GetType(restype), _ctypes_get_ffi_type(restype),
&p->atypes[0]); &p->atypes[0]);
if (result != FFI_OK) { if (result != FFI_OK) {
PyErr_Format(PyExc_RuntimeError, PyErr_Format(PyExc_RuntimeError,
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
/* /*
How are functions called, and how are parameters converted to C ? How are functions called, and how are parameters converted to C ?
1. _ctypes.c::CFuncPtr_call receives an argument tuple 'inargs' and a 1. _ctypes.c::PyCFuncPtr_call receives an argument tuple 'inargs' and a
keyword dictionary 'kwds'. keyword dictionary 'kwds'.
2. After several checks, _build_callargs() is called which returns another 2. After several checks, _build_callargs() is called which returns another
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
the callargs tuple, specifying how to build the return value(s) of the callargs tuple, specifying how to build the return value(s) of
the function. the function.
4. _CallProc is then called with the 'callargs' tuple. _CallProc first 4. _ctypes_callproc is then called with the 'callargs' tuple. _ctypes_callproc first
allocates two arrays. The first is an array of 'struct argument' items, the allocates two arrays. The first is an array of 'struct argument' items, the
second array has 'void *' entried. second array has 'void *' entried.
...@@ -47,8 +47,8 @@ ...@@ -47,8 +47,8 @@
libffi specific stuff, then it calls ffi_call. libffi specific stuff, then it calls ffi_call.
So, there are 4 data structures holding processed arguments: So, there are 4 data structures holding processed arguments:
- the inargs tuple (in CFuncPtr_call) - the inargs tuple (in PyCFuncPtr_call)
- the callargs tuple (in CFuncPtr_call) - the callargs tuple (in PyCFuncPtr_call)
- the 'struct argguments' array - the 'struct argguments' array
- the 'void *' array - the 'void *' array
...@@ -113,7 +113,7 @@ ...@@ -113,7 +113,7 @@
kept alive in the thread state dictionary as long as the thread itself. kept alive in the thread state dictionary as long as the thread itself.
*/ */
PyObject * PyObject *
get_error_object(int **pspace) _ctypes_get_errobj(int **pspace)
{ {
PyObject *dict = PyThreadState_GetDict(); PyObject *dict = PyThreadState_GetDict();
PyObject *errobj; PyObject *errobj;
...@@ -153,7 +153,7 @@ static PyObject * ...@@ -153,7 +153,7 @@ static PyObject *
get_error_internal(PyObject *self, PyObject *args, int index) get_error_internal(PyObject *self, PyObject *args, int index)
{ {
int *space; int *space;
PyObject *errobj = get_error_object(&space); PyObject *errobj = _ctypes_get_errobj(&space);
PyObject *result; PyObject *result;
if (errobj == NULL) if (errobj == NULL)
...@@ -172,7 +172,7 @@ set_error_internal(PyObject *self, PyObject *args, int index) ...@@ -172,7 +172,7 @@ set_error_internal(PyObject *self, PyObject *args, int index)
if (!PyArg_ParseTuple(args, "i", &new_errno)) if (!PyArg_ParseTuple(args, "i", &new_errno))
return NULL; return NULL;
errobj = get_error_object(&space); errobj = _ctypes_get_errobj(&space);
if (errobj == NULL) if (errobj == NULL)
return NULL; return NULL;
old_errno = space[index]; old_errno = space[index];
...@@ -405,7 +405,7 @@ check_hresult(PyObject *self, PyObject *args) ...@@ -405,7 +405,7 @@ check_hresult(PyObject *self, PyObject *args)
/**************************************************************/ /**************************************************************/
PyCArgObject * PyCArgObject *
new_CArgObject(void) PyCArgObject_new(void)
{ {
PyCArgObject *p; PyCArgObject *p;
p = PyObject_New(PyCArgObject, &PyCArg_Type); p = PyObject_New(PyCArgObject, &PyCArg_Type);
...@@ -697,7 +697,7 @@ static int ConvParam(PyObject *obj, Py_ssize_t index, struct argument *pa) ...@@ -697,7 +697,7 @@ static int ConvParam(PyObject *obj, Py_ssize_t index, struct argument *pa)
} }
ffi_type *GetType(PyObject *obj) ffi_type *_ctypes_get_ffi_type(PyObject *obj)
{ {
StgDictObject *dict; StgDictObject *dict;
if (obj == NULL) if (obj == NULL)
...@@ -777,7 +777,7 @@ static int _call_function_pointer(int flags, ...@@ -777,7 +777,7 @@ static int _call_function_pointer(int flags,
} }
if (flags & (FUNCFLAG_USE_ERRNO | FUNCFLAG_USE_LASTERROR)) { if (flags & (FUNCFLAG_USE_ERRNO | FUNCFLAG_USE_LASTERROR)) {
error_object = get_error_object(&space); error_object = _ctypes_get_errobj(&space);
if (error_object == NULL) if (error_object == NULL)
return -1; return -1;
} }
...@@ -895,24 +895,24 @@ static PyObject *GetResult(PyObject *restype, void *result, PyObject *checker) ...@@ -895,24 +895,24 @@ static PyObject *GetResult(PyObject *restype, void *result, PyObject *checker)
if (dict == NULL) if (dict == NULL)
return PyObject_CallFunction(restype, "i", *(int *)result); return PyObject_CallFunction(restype, "i", *(int *)result);
if (dict->getfunc && !IsSimpleSubType(restype)) { if (dict->getfunc && !_ctypes_simple_instance(restype)) {
retval = dict->getfunc(result, dict->size); retval = dict->getfunc(result, dict->size);
/* If restype is py_object (detected by comparing getfunc with /* If restype is py_object (detected by comparing getfunc with
O_get), we have to call Py_DECREF because O_get has already O_get), we have to call Py_DECREF because O_get has already
called Py_INCREF. called Py_INCREF.
*/ */
if (dict->getfunc == getentry("O")->getfunc) { if (dict->getfunc == _ctypes_get_fielddesc("O")->getfunc) {
Py_DECREF(retval); Py_DECREF(retval);
} }
} else } else
retval = CData_FromBaseObj(restype, NULL, 0, result); retval = PyCData_FromBaseObj(restype, NULL, 0, result);
if (!checker || !retval) if (!checker || !retval)
return retval; return retval;
v = PyObject_CallFunctionObjArgs(checker, retval, NULL); v = PyObject_CallFunctionObjArgs(checker, retval, NULL);
if (v == NULL) if (v == NULL)
_AddTraceback("GetResult", "_ctypes/callproc.c", __LINE__-2); _ctypes_add_traceback("GetResult", "_ctypes/callproc.c", __LINE__-2);
Py_DECREF(retval); Py_DECREF(retval);
return v; return v;
} }
...@@ -921,7 +921,7 @@ static PyObject *GetResult(PyObject *restype, void *result, PyObject *checker) ...@@ -921,7 +921,7 @@ static PyObject *GetResult(PyObject *restype, void *result, PyObject *checker)
* Raise a new exception 'exc_class', adding additional text to the original * Raise a new exception 'exc_class', adding additional text to the original
* exception string. * exception string.
*/ */
void Extend_Error_Info(PyObject *exc_class, char *fmt, ...) void _ctypes_extend_error(PyObject *exc_class, char *fmt, ...)
{ {
va_list vargs; va_list vargs;
PyObject *tp, *v, *tb, *s, *cls_str, *msg_str; PyObject *tp, *v, *tb, *s, *cls_str, *msg_str;
...@@ -1042,7 +1042,7 @@ GetComError(HRESULT errcode, GUID *riid, IUnknown *pIunk) ...@@ -1042,7 +1042,7 @@ GetComError(HRESULT errcode, GUID *riid, IUnknown *pIunk)
* *
* - XXX various requirements for restype, not yet collected * - XXX various requirements for restype, not yet collected
*/ */
PyObject *_CallProc(PPROC pProc, PyObject *_ctypes_callproc(PPROC pProc,
PyObject *argtuple, PyObject *argtuple,
#ifdef MS_WIN32 #ifdef MS_WIN32
IUnknown *pIunk, IUnknown *pIunk,
...@@ -1095,7 +1095,7 @@ PyObject *_CallProc(PPROC pProc, ...@@ -1095,7 +1095,7 @@ PyObject *_CallProc(PPROC pProc,
arg = PyTuple_GET_ITEM(argtuple, i); /* borrowed ref */ arg = PyTuple_GET_ITEM(argtuple, i); /* borrowed ref */
/* For cdecl functions, we allow more actual arguments /* For cdecl functions, we allow more actual arguments
than the length of the argtypes tuple. than the length of the argtypes tuple.
This is checked in _ctypes::CFuncPtr_Call This is checked in _ctypes::PyCFuncPtr_Call
*/ */
if (argtypes && argtype_count > i) { if (argtypes && argtype_count > i) {
PyObject *v; PyObject *v;
...@@ -1104,26 +1104,26 @@ PyObject *_CallProc(PPROC pProc, ...@@ -1104,26 +1104,26 @@ PyObject *_CallProc(PPROC pProc,
arg, arg,
NULL); NULL);
if (v == NULL) { if (v == NULL) {
Extend_Error_Info(PyExc_ArgError, "argument %d: ", i+1); _ctypes_extend_error(PyExc_ArgError, "argument %d: ", i+1);
goto cleanup; goto cleanup;
} }
err = ConvParam(v, i+1, pa); err = ConvParam(v, i+1, pa);
Py_DECREF(v); Py_DECREF(v);
if (-1 == err) { if (-1 == err) {
Extend_Error_Info(PyExc_ArgError, "argument %d: ", i+1); _ctypes_extend_error(PyExc_ArgError, "argument %d: ", i+1);
goto cleanup; goto cleanup;
} }
} else { } else {
err = ConvParam(arg, i+1, pa); err = ConvParam(arg, i+1, pa);
if (-1 == err) { if (-1 == err) {
Extend_Error_Info(PyExc_ArgError, "argument %d: ", i+1); _ctypes_extend_error(PyExc_ArgError, "argument %d: ", i+1);
goto cleanup; /* leaking ? */ goto cleanup; /* leaking ? */
} }
} }
} }
rtype = GetType(restype); rtype = _ctypes_get_ffi_type(restype);
resbuf = alloca(max(rtype->size, sizeof(ffi_arg))); resbuf = alloca(max(rtype->size, sizeof(ffi_arg)));
avalues = (void **)alloca(sizeof(void *) * argcount); avalues = (void **)alloca(sizeof(void *) * argcount);
...@@ -1310,7 +1310,7 @@ call_commethod(PyObject *self, PyObject *args) ...@@ -1310,7 +1310,7 @@ call_commethod(PyObject *self, PyObject *args)
pIunk = (IUnknown *)(*(void **)(pcom->b_ptr)); pIunk = (IUnknown *)(*(void **)(pcom->b_ptr));
lpVtbl = (PPROC *)(pIunk->lpVtbl); lpVtbl = (PPROC *)(pIunk->lpVtbl);
result = _CallProc(lpVtbl[index], result = _ctypes_callproc(lpVtbl[index],
arguments, arguments,
#ifdef MS_WIN32 #ifdef MS_WIN32
pIunk, pIunk,
...@@ -1433,7 +1433,7 @@ call_function(PyObject *self, PyObject *args) ...@@ -1433,7 +1433,7 @@ call_function(PyObject *self, PyObject *args)
&PyTuple_Type, &arguments)) &PyTuple_Type, &arguments))
return NULL; return NULL;
result = _CallProc((PPROC)func, result = _ctypes_callproc((PPROC)func,
arguments, arguments,
#ifdef MS_WIN32 #ifdef MS_WIN32
NULL, NULL,
...@@ -1464,7 +1464,7 @@ call_cdeclfunction(PyObject *self, PyObject *args) ...@@ -1464,7 +1464,7 @@ call_cdeclfunction(PyObject *self, PyObject *args)
&PyTuple_Type, &arguments)) &PyTuple_Type, &arguments))
return NULL; return NULL;
result = _CallProc((PPROC)func, result = _ctypes_callproc((PPROC)func,
arguments, arguments,
#ifdef MS_WIN32 #ifdef MS_WIN32
NULL, NULL,
...@@ -1556,7 +1556,7 @@ byref(PyObject *self, PyObject *args) ...@@ -1556,7 +1556,7 @@ byref(PyObject *self, PyObject *args)
return NULL; return NULL;
} }
parg = new_CArgObject(); parg = PyCArgObject_new();
if (parg == NULL) if (parg == NULL)
return NULL; return NULL;
...@@ -1631,17 +1631,17 @@ set_conversion_mode(PyObject *self, PyObject *args) ...@@ -1631,17 +1631,17 @@ set_conversion_mode(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "zs:set_conversion_mode", &coding, &mode)) if (!PyArg_ParseTuple(args, "zs:set_conversion_mode", &coding, &mode))
return NULL; return NULL;
result = Py_BuildValue("(zz)", conversion_mode_encoding, conversion_mode_errors); result = Py_BuildValue("(zz)", _ctypes_conversion_encoding, _ctypes_conversion_errors);
if (coding) { if (coding) {
PyMem_Free(conversion_mode_encoding); PyMem_Free(_ctypes_conversion_encoding);
conversion_mode_encoding = PyMem_Malloc(strlen(coding) + 1); _ctypes_conversion_encoding = PyMem_Malloc(strlen(coding) + 1);
strcpy(conversion_mode_encoding, coding); strcpy(_ctypes_conversion_encoding, coding);
} else { } else {
conversion_mode_encoding = NULL; _ctypes_conversion_encoding = NULL;
} }
PyMem_Free(conversion_mode_errors); PyMem_Free(_ctypes_conversion_errors);
conversion_mode_errors = PyMem_Malloc(strlen(mode) + 1); _ctypes_conversion_errors = PyMem_Malloc(strlen(mode) + 1);
strcpy(conversion_mode_errors, mode); strcpy(_ctypes_conversion_errors, mode);
return result; return result;
} }
#endif #endif
...@@ -1732,7 +1732,7 @@ POINTER(PyObject *self, PyObject *cls) ...@@ -1732,7 +1732,7 @@ POINTER(PyObject *self, PyObject *cls)
PyObject *key; PyObject *key;
char *buf; char *buf;
result = PyDict_GetItem(_pointer_type_cache, cls); result = PyDict_GetItem(_ctypes_ptrtype_cache, cls);
if (result) { if (result) {
Py_INCREF(result); Py_INCREF(result);
return result; return result;
...@@ -1741,10 +1741,10 @@ POINTER(PyObject *self, PyObject *cls) ...@@ -1741,10 +1741,10 @@ POINTER(PyObject *self, PyObject *cls)
char *name = _PyUnicode_AsString(cls); char *name = _PyUnicode_AsString(cls);
buf = alloca(strlen(name) + 3 + 1); buf = alloca(strlen(name) + 3 + 1);
sprintf(buf, "LP_%s", name); sprintf(buf, "LP_%s", name);
result = PyObject_CallFunction((PyObject *)Py_TYPE(&Pointer_Type), result = PyObject_CallFunction((PyObject *)Py_TYPE(&PyCPointer_Type),
"s(O){}", "s(O){}",
buf, buf,
&Pointer_Type); &PyCPointer_Type);
if (result == NULL) if (result == NULL)
return result; return result;
key = PyLong_FromVoidPtr(result); key = PyLong_FromVoidPtr(result);
...@@ -1752,10 +1752,10 @@ POINTER(PyObject *self, PyObject *cls) ...@@ -1752,10 +1752,10 @@ POINTER(PyObject *self, PyObject *cls)
typ = (PyTypeObject *)cls; typ = (PyTypeObject *)cls;
buf = alloca(strlen(typ->tp_name) + 3 + 1); buf = alloca(strlen(typ->tp_name) + 3 + 1);
sprintf(buf, "LP_%s", typ->tp_name); sprintf(buf, "LP_%s", typ->tp_name);
result = PyObject_CallFunction((PyObject *)Py_TYPE(&Pointer_Type), result = PyObject_CallFunction((PyObject *)Py_TYPE(&PyCPointer_Type),
"s(O){sO}", "s(O){sO}",
buf, buf,
&Pointer_Type, &PyCPointer_Type,
"_type_", cls); "_type_", cls);
if (result == NULL) if (result == NULL)
return result; return result;
...@@ -1765,7 +1765,7 @@ POINTER(PyObject *self, PyObject *cls) ...@@ -1765,7 +1765,7 @@ POINTER(PyObject *self, PyObject *cls)
PyErr_SetString(PyExc_TypeError, "must be a ctypes type"); PyErr_SetString(PyExc_TypeError, "must be a ctypes type");
return NULL; return NULL;
} }
if (-1 == PyDict_SetItem(_pointer_type_cache, key, result)) { if (-1 == PyDict_SetItem(_ctypes_ptrtype_cache, key, result)) {
Py_DECREF(result); Py_DECREF(result);
Py_DECREF(key); Py_DECREF(key);
return NULL; return NULL;
...@@ -1780,7 +1780,7 @@ pointer(PyObject *self, PyObject *arg) ...@@ -1780,7 +1780,7 @@ pointer(PyObject *self, PyObject *arg)
PyObject *result; PyObject *result;
PyObject *typ; PyObject *typ;
typ = PyDict_GetItem(_pointer_type_cache, (PyObject *)Py_TYPE(arg)); typ = PyDict_GetItem(_ctypes_ptrtype_cache, (PyObject *)Py_TYPE(arg));
if (typ) if (typ)
return PyObject_CallFunctionObjArgs(typ, arg, NULL); return PyObject_CallFunctionObjArgs(typ, arg, NULL);
typ = POINTER(NULL, (PyObject *)Py_TYPE(arg)); typ = POINTER(NULL, (PyObject *)Py_TYPE(arg));
...@@ -1818,7 +1818,7 @@ buffer_info(PyObject *self, PyObject *arg) ...@@ -1818,7 +1818,7 @@ buffer_info(PyObject *self, PyObject *arg)
return Py_BuildValue("siN", dict->format, dict->ndim, shape); return Py_BuildValue("siN", dict->format, dict->ndim, shape);
} }
PyMethodDef module_methods[] = { PyMethodDef _ctypes_module_methods[] = {
{"get_errno", get_errno, METH_NOARGS}, {"get_errno", get_errno, METH_NOARGS},
{"set_errno", set_errno, METH_VARARGS}, {"set_errno", set_errno, METH_VARARGS},
{"POINTER", POINTER, METH_O }, {"POINTER", POINTER, METH_O },
......
...@@ -8,10 +8,10 @@ ...@@ -8,10 +8,10 @@
/******************************************************************/ /******************************************************************/
/* /*
CField_Type PyCField_Type
*/ */
static PyObject * static PyObject *
CField_new(PyTypeObject *type, PyObject *args, PyObject *kwds) PyCField_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{ {
CFieldObject *obj; CFieldObject *obj;
obj = (CFieldObject *)type->tp_alloc(type, 0); obj = (CFieldObject *)type->tp_alloc(type, 0);
...@@ -31,7 +31,7 @@ CField_new(PyTypeObject *type, PyObject *args, PyObject *kwds) ...@@ -31,7 +31,7 @@ CField_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
* prev_desc points to the type of the previous bitfield, if any. * prev_desc points to the type of the previous bitfield, if any.
*/ */
PyObject * PyObject *
CField_FromDesc(PyObject *desc, Py_ssize_t index, PyCField_FromDesc(PyObject *desc, Py_ssize_t index,
Py_ssize_t *pfield_size, int bitsize, int *pbitofs, Py_ssize_t *pfield_size, int bitsize, int *pbitofs,
Py_ssize_t *psize, Py_ssize_t *poffset, Py_ssize_t *palign, Py_ssize_t *psize, Py_ssize_t *poffset, Py_ssize_t *palign,
int pack, int big_endian) int pack, int big_endian)
...@@ -48,7 +48,7 @@ CField_FromDesc(PyObject *desc, Py_ssize_t index, ...@@ -48,7 +48,7 @@ CField_FromDesc(PyObject *desc, Py_ssize_t index,
#define CONT_BITFIELD 2 #define CONT_BITFIELD 2
#define EXPAND_BITFIELD 3 #define EXPAND_BITFIELD 3
self = (CFieldObject *)PyObject_CallObject((PyObject *)&CField_Type, self = (CFieldObject *)PyObject_CallObject((PyObject *)&PyCField_Type,
NULL); NULL);
if (self == NULL) if (self == NULL)
return NULL; return NULL;
...@@ -98,7 +98,7 @@ CField_FromDesc(PyObject *desc, Py_ssize_t index, ...@@ -98,7 +98,7 @@ CField_FromDesc(PyObject *desc, Py_ssize_t index,
/* Field descriptors for 'c_char * n' are be scpecial cased to /* Field descriptors for 'c_char * n' are be scpecial cased to
return a Python string instead of an Array object instance... return a Python string instead of an Array object instance...
*/ */
if (ArrayTypeObject_Check(proto)) { if (PyCArrayTypeObject_Check(proto)) {
StgDictObject *adict = PyType_stgdict(proto); StgDictObject *adict = PyType_stgdict(proto);
StgDictObject *idict; StgDictObject *idict;
if (adict && adict->proto) { if (adict && adict->proto) {
...@@ -109,14 +109,14 @@ CField_FromDesc(PyObject *desc, Py_ssize_t index, ...@@ -109,14 +109,14 @@ CField_FromDesc(PyObject *desc, Py_ssize_t index,
Py_DECREF(self); Py_DECREF(self);
return NULL; return NULL;
} }
if (idict->getfunc == getentry("c")->getfunc) { if (idict->getfunc == _ctypes_get_fielddesc("c")->getfunc) {
struct fielddesc *fd = getentry("s"); struct fielddesc *fd = _ctypes_get_fielddesc("s");
getfunc = fd->getfunc; getfunc = fd->getfunc;
setfunc = fd->setfunc; setfunc = fd->setfunc;
} }
#ifdef CTYPES_UNICODE #ifdef CTYPES_UNICODE
if (idict->getfunc == getentry("u")->getfunc) { if (idict->getfunc == _ctypes_get_fielddesc("u")->getfunc) {
struct fielddesc *fd = getentry("U"); struct fielddesc *fd = _ctypes_get_fielddesc("U");
getfunc = fd->getfunc; getfunc = fd->getfunc;
setfunc = fd->setfunc; setfunc = fd->setfunc;
} }
...@@ -190,7 +190,7 @@ CField_FromDesc(PyObject *desc, Py_ssize_t index, ...@@ -190,7 +190,7 @@ CField_FromDesc(PyObject *desc, Py_ssize_t index,
} }
static int static int
CField_set(CFieldObject *self, PyObject *inst, PyObject *value) PyCField_set(CFieldObject *self, PyObject *inst, PyObject *value)
{ {
CDataObject *dst; CDataObject *dst;
char *ptr; char *ptr;
...@@ -202,12 +202,12 @@ CField_set(CFieldObject *self, PyObject *inst, PyObject *value) ...@@ -202,12 +202,12 @@ CField_set(CFieldObject *self, PyObject *inst, PyObject *value)
"can't delete attribute"); "can't delete attribute");
return -1; return -1;
} }
return CData_set(inst, self->proto, self->setfunc, value, return PyCData_set(inst, self->proto, self->setfunc, value,
self->index, self->size, ptr); self->index, self->size, ptr);
} }
static PyObject * static PyObject *
CField_get(CFieldObject *self, PyObject *inst, PyTypeObject *type) PyCField_get(CFieldObject *self, PyObject *inst, PyTypeObject *type)
{ {
CDataObject *src; CDataObject *src;
if (inst == NULL) { if (inst == NULL) {
...@@ -216,51 +216,51 @@ CField_get(CFieldObject *self, PyObject *inst, PyTypeObject *type) ...@@ -216,51 +216,51 @@ CField_get(CFieldObject *self, PyObject *inst, PyTypeObject *type)
} }
assert(CDataObject_Check(inst)); assert(CDataObject_Check(inst));
src = (CDataObject *)inst; src = (CDataObject *)inst;
return CData_get(self->proto, self->getfunc, inst, return PyCData_get(self->proto, self->getfunc, inst,
self->index, self->size, src->b_ptr + self->offset); self->index, self->size, src->b_ptr + self->offset);
} }
static PyObject * static PyObject *
CField_get_offset(PyObject *self, void *data) PyCField_get_offset(PyObject *self, void *data)
{ {
return PyLong_FromSsize_t(((CFieldObject *)self)->offset); return PyLong_FromSsize_t(((CFieldObject *)self)->offset);
} }
static PyObject * static PyObject *
CField_get_size(PyObject *self, void *data) PyCField_get_size(PyObject *self, void *data)
{ {
return PyLong_FromSsize_t(((CFieldObject *)self)->size); return PyLong_FromSsize_t(((CFieldObject *)self)->size);
} }
static PyGetSetDef CField_getset[] = { static PyGetSetDef PyCField_getset[] = {
{ "offset", CField_get_offset, NULL, "offset in bytes of this field" }, { "offset", PyCField_get_offset, NULL, "offset in bytes of this field" },
{ "size", CField_get_size, NULL, "size in bytes of this field" }, { "size", PyCField_get_size, NULL, "size in bytes of this field" },
{ NULL, NULL, NULL, NULL }, { NULL, NULL, NULL, NULL },
}; };
static int static int
CField_traverse(CFieldObject *self, visitproc visit, void *arg) PyCField_traverse(CFieldObject *self, visitproc visit, void *arg)
{ {
Py_VISIT(self->proto); Py_VISIT(self->proto);
return 0; return 0;
} }
static int static int
CField_clear(CFieldObject *self) PyCField_clear(CFieldObject *self)
{ {
Py_CLEAR(self->proto); Py_CLEAR(self->proto);
return 0; return 0;
} }
static void static void
CField_dealloc(PyObject *self) PyCField_dealloc(PyObject *self)
{ {
CField_clear((CFieldObject *)self); PyCField_clear((CFieldObject *)self);
self->ob_type->tp_free((PyObject *)self); self->ob_type->tp_free((PyObject *)self);
} }
static PyObject * static PyObject *
CField_repr(CFieldObject *self) PyCField_repr(CFieldObject *self)
{ {
PyObject *result; PyObject *result;
Py_ssize_t bits = self->size >> 16; Py_ssize_t bits = self->size >> 16;
...@@ -280,17 +280,17 @@ CField_repr(CFieldObject *self) ...@@ -280,17 +280,17 @@ CField_repr(CFieldObject *self)
return result; return result;
} }
PyTypeObject CField_Type = { PyTypeObject PyCField_Type = {
PyVarObject_HEAD_INIT(NULL, 0) PyVarObject_HEAD_INIT(NULL, 0)
"_ctypes.CField", /* tp_name */ "_ctypes.CField", /* tp_name */
sizeof(CFieldObject), /* tp_basicsize */ sizeof(CFieldObject), /* tp_basicsize */
0, /* tp_itemsize */ 0, /* tp_itemsize */
CField_dealloc, /* tp_dealloc */ PyCField_dealloc, /* tp_dealloc */
0, /* tp_print */ 0, /* tp_print */
0, /* tp_getattr */ 0, /* tp_getattr */
0, /* tp_setattr */ 0, /* tp_setattr */
0, /* tp_reserved */ 0, /* tp_reserved */
(reprfunc)CField_repr, /* tp_repr */ (reprfunc)PyCField_repr, /* tp_repr */
0, /* tp_as_number */ 0, /* tp_as_number */
0, /* tp_as_sequence */ 0, /* tp_as_sequence */
0, /* tp_as_mapping */ 0, /* tp_as_mapping */
...@@ -302,23 +302,23 @@ PyTypeObject CField_Type = { ...@@ -302,23 +302,23 @@ PyTypeObject CField_Type = {
0, /* tp_as_buffer */ 0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */
"Structure/Union member", /* tp_doc */ "Structure/Union member", /* tp_doc */
(traverseproc)CField_traverse, /* tp_traverse */ (traverseproc)PyCField_traverse, /* tp_traverse */
(inquiry)CField_clear, /* tp_clear */ (inquiry)PyCField_clear, /* tp_clear */
0, /* tp_richcompare */ 0, /* tp_richcompare */
0, /* tp_weaklistoffset */ 0, /* tp_weaklistoffset */
0, /* tp_iter */ 0, /* tp_iter */
0, /* tp_iternext */ 0, /* tp_iternext */
0, /* tp_methods */ 0, /* tp_methods */
0, /* tp_members */ 0, /* tp_members */
CField_getset, /* tp_getset */ PyCField_getset, /* tp_getset */
0, /* tp_base */ 0, /* tp_base */
0, /* tp_dict */ 0, /* tp_dict */
(descrgetfunc)CField_get, /* tp_descr_get */ (descrgetfunc)PyCField_get, /* tp_descr_get */
(descrsetfunc)CField_set, /* tp_descr_set */ (descrsetfunc)PyCField_set, /* tp_descr_set */
0, /* tp_dictoffset */ 0, /* tp_dictoffset */
0, /* tp_init */ 0, /* tp_init */
0, /* tp_alloc */ 0, /* tp_alloc */
CField_new, /* tp_new */ PyCField_new, /* tp_new */
0, /* tp_free */ 0, /* tp_free */
}; };
...@@ -1158,8 +1158,8 @@ c_set(void *ptr, PyObject *value, Py_ssize_t size) ...@@ -1158,8 +1158,8 @@ c_set(void *ptr, PyObject *value, Py_ssize_t size)
{ {
if (PyUnicode_Check(value)) { if (PyUnicode_Check(value)) {
value = PyUnicode_AsEncodedString(value, value = PyUnicode_AsEncodedString(value,
conversion_mode_encoding, _ctypes_conversion_encoding,
conversion_mode_errors); _ctypes_conversion_errors);
if (value == NULL) if (value == NULL)
return NULL; return NULL;
if (PyBytes_GET_SIZE(value) != 1) { if (PyBytes_GET_SIZE(value) != 1) {
...@@ -1207,8 +1207,8 @@ u_set(void *ptr, PyObject *value, Py_ssize_t size) ...@@ -1207,8 +1207,8 @@ u_set(void *ptr, PyObject *value, Py_ssize_t size)
Py_ssize_t len; Py_ssize_t len;
if (PyBytes_Check(value)) { if (PyBytes_Check(value)) {
value = PyUnicode_FromEncodedObject(value, value = PyUnicode_FromEncodedObject(value,
conversion_mode_encoding, _ctypes_conversion_encoding,
conversion_mode_errors); _ctypes_conversion_errors);
if (!value) if (!value)
return NULL; return NULL;
} else if (!PyUnicode_Check(value)) { } else if (!PyUnicode_Check(value)) {
...@@ -1282,8 +1282,8 @@ U_set(void *ptr, PyObject *value, Py_ssize_t length) ...@@ -1282,8 +1282,8 @@ U_set(void *ptr, PyObject *value, Py_ssize_t length)
if (PyBytes_Check(value)) { if (PyBytes_Check(value)) {
value = PyUnicode_FromEncodedObject(value, value = PyUnicode_FromEncodedObject(value,
conversion_mode_encoding, _ctypes_conversion_encoding,
conversion_mode_errors); _ctypes_conversion_errors);
if (!value) if (!value)
return NULL; return NULL;
} else if (!PyUnicode_Check(value)) { } else if (!PyUnicode_Check(value)) {
...@@ -1332,8 +1332,8 @@ s_set(void *ptr, PyObject *value, Py_ssize_t length) ...@@ -1332,8 +1332,8 @@ s_set(void *ptr, PyObject *value, Py_ssize_t length)
if (PyUnicode_Check(value)) { if (PyUnicode_Check(value)) {
value = PyUnicode_AsEncodedString(value, value = PyUnicode_AsEncodedString(value,
conversion_mode_encoding, _ctypes_conversion_encoding,
conversion_mode_errors); _ctypes_conversion_errors);
if (value == NULL) if (value == NULL)
return NULL; return NULL;
assert(PyBytes_Check(value)); assert(PyBytes_Check(value));
...@@ -1383,8 +1383,8 @@ z_set(void *ptr, PyObject *value, Py_ssize_t size) ...@@ -1383,8 +1383,8 @@ z_set(void *ptr, PyObject *value, Py_ssize_t size)
return value; return value;
} else if (PyUnicode_Check(value)) { } else if (PyUnicode_Check(value)) {
PyObject *str = PyUnicode_AsEncodedString(value, PyObject *str = PyUnicode_AsEncodedString(value,
conversion_mode_encoding, _ctypes_conversion_encoding,
conversion_mode_errors); _ctypes_conversion_errors);
if (str == NULL) if (str == NULL)
return NULL; return NULL;
*(char **)ptr = PyBytes_AS_STRING(str); *(char **)ptr = PyBytes_AS_STRING(str);
...@@ -1443,8 +1443,8 @@ Z_set(void *ptr, PyObject *value, Py_ssize_t size) ...@@ -1443,8 +1443,8 @@ Z_set(void *ptr, PyObject *value, Py_ssize_t size)
} }
if (PyBytes_Check(value)) { if (PyBytes_Check(value)) {
value = PyUnicode_FromEncodedObject(value, value = PyUnicode_FromEncodedObject(value,
conversion_mode_encoding, _ctypes_conversion_encoding,
conversion_mode_errors); _ctypes_conversion_errors);
if (!value) if (!value)
return NULL; return NULL;
} else if (!PyUnicode_Check(value)) { } else if (!PyUnicode_Check(value)) {
...@@ -1529,8 +1529,8 @@ BSTR_set(void *ptr, PyObject *value, Py_ssize_t size) ...@@ -1529,8 +1529,8 @@ BSTR_set(void *ptr, PyObject *value, Py_ssize_t size)
value = NULL; value = NULL;
} else if (PyBytes_Check(value)) { } else if (PyBytes_Check(value)) {
value = PyUnicode_FromEncodedObject(value, value = PyUnicode_FromEncodedObject(value,
conversion_mode_encoding, _ctypes_conversion_encoding,
conversion_mode_errors); _ctypes_conversion_errors);
if (!value) if (!value)
return NULL; return NULL;
} else if (PyUnicode_Check(value)) { } else if (PyUnicode_Check(value)) {
...@@ -1690,7 +1690,7 @@ static struct fielddesc formattable[] = { ...@@ -1690,7 +1690,7 @@ static struct fielddesc formattable[] = {
*/ */
struct fielddesc * struct fielddesc *
getentry(const char *fmt) _ctypes_get_fielddesc(const char *fmt)
{ {
static int initialized = 0; static int initialized = 0;
struct fielddesc *table = formattable; struct fielddesc *table = formattable;
...@@ -1699,11 +1699,11 @@ getentry(const char *fmt) ...@@ -1699,11 +1699,11 @@ getentry(const char *fmt)
initialized = 1; initialized = 1;
#ifdef CTYPES_UNICODE #ifdef CTYPES_UNICODE
if (sizeof(wchar_t) == sizeof(short)) if (sizeof(wchar_t) == sizeof(short))
getentry("u")->pffi_type = &ffi_type_sshort; _ctypes_get_fielddesc("u")->pffi_type = &ffi_type_sshort;
else if (sizeof(wchar_t) == sizeof(int)) else if (sizeof(wchar_t) == sizeof(int))
getentry("u")->pffi_type = &ffi_type_sint; _ctypes_get_fielddesc("u")->pffi_type = &ffi_type_sint;
else if (sizeof(wchar_t) == sizeof(long)) else if (sizeof(wchar_t) == sizeof(long))
getentry("u")->pffi_type = &ffi_type_slong; _ctypes_get_fielddesc("u")->pffi_type = &ffi_type_slong;
#endif #endif
} }
......
...@@ -18,7 +18,7 @@ this buffer is too small, PyMem_Malloc will be called to create a larger one, ...@@ -18,7 +18,7 @@ this buffer is too small, PyMem_Malloc will be called to create a larger one,
and this one is not used. and this one is not used.
Making CDataObject a variable size object would be a better solution, but more Making CDataObject a variable size object would be a better solution, but more
difficult in the presence of CFuncPtrObject. Maybe later. difficult in the presence of PyCFuncPtrObject. Maybe later.
*/ */
union value { union value {
char c[16]; char c[16];
...@@ -64,8 +64,8 @@ typedef struct { ...@@ -64,8 +64,8 @@ typedef struct {
ffi_type *ffi_restype; ffi_type *ffi_restype;
ffi_type *atypes[1]; ffi_type *atypes[1];
} CThunkObject; } CThunkObject;
extern PyTypeObject CThunk_Type; extern PyTypeObject PyCThunk_Type;
#define CThunk_CheckExact(v) ((v)->ob_type == &CThunk_Type) #define CThunk_CheckExact(v) ((v)->ob_type == &PyCThunk_Type)
typedef struct { typedef struct {
/* First part identical to tagCDataObject */ /* First part identical to tagCDataObject */
...@@ -96,61 +96,61 @@ typedef struct { ...@@ -96,61 +96,61 @@ typedef struct {
GUID *iid; GUID *iid;
#endif #endif
PyObject *paramflags; PyObject *paramflags;
} CFuncPtrObject; } PyCFuncPtrObject;
extern PyTypeObject StgDict_Type; extern PyTypeObject PyCStgDict_Type;
#define StgDict_CheckExact(v) ((v)->ob_type == &StgDict_Type) #define PyCStgDict_CheckExact(v) ((v)->ob_type == &PyCStgDict_Type)
#define StgDict_Check(v) PyObject_TypeCheck(v, &StgDict_Type) #define PyCStgDict_Check(v) PyObject_TypeCheck(v, &PyCStgDict_Type)
extern int StructUnionType_update_stgdict(PyObject *fields, PyObject *type, int isStruct); extern int PyCStructUnionType_update_stgdict(PyObject *fields, PyObject *type, int isStruct);
extern int PyType_stginfo(PyTypeObject *self, Py_ssize_t *psize, Py_ssize_t *palign, Py_ssize_t *plength); extern int PyType_stginfo(PyTypeObject *self, Py_ssize_t *psize, Py_ssize_t *palign, Py_ssize_t *plength);
extern int PyObject_stginfo(PyObject *self, Py_ssize_t *psize, Py_ssize_t *palign, Py_ssize_t *plength); extern int PyObject_stginfo(PyObject *self, Py_ssize_t *psize, Py_ssize_t *palign, Py_ssize_t *plength);
extern PyTypeObject CData_Type; extern PyTypeObject PyCData_Type;
#define CDataObject_CheckExact(v) ((v)->ob_type == &CData_Type) #define CDataObject_CheckExact(v) ((v)->ob_type == &PyCData_Type)
#define CDataObject_Check(v) PyObject_TypeCheck(v, &CData_Type) #define CDataObject_Check(v) PyObject_TypeCheck(v, &PyCData_Type)
extern PyTypeObject SimpleType_Type; extern PyTypeObject PyCSimpleType_Type;
#define SimpleTypeObject_CheckExact(v) ((v)->ob_type == &SimpleType_Type) #define PyCSimpleTypeObject_CheckExact(v) ((v)->ob_type == &PyCSimpleType_Type)
#define SimpleTypeObject_Check(v) PyObject_TypeCheck(v, &SimpleType_Type) #define PyCSimpleTypeObject_Check(v) PyObject_TypeCheck(v, &PyCSimpleType_Type)
extern PyTypeObject CField_Type; extern PyTypeObject PyCField_Type;
extern struct fielddesc *getentry(const char *fmt); extern struct fielddesc *_ctypes_get_fielddesc(const char *fmt);
extern PyObject * extern PyObject *
CField_FromDesc(PyObject *desc, Py_ssize_t index, PyCField_FromDesc(PyObject *desc, Py_ssize_t index,
Py_ssize_t *pfield_size, int bitsize, int *pbitofs, Py_ssize_t *pfield_size, int bitsize, int *pbitofs,
Py_ssize_t *psize, Py_ssize_t *poffset, Py_ssize_t *palign, Py_ssize_t *psize, Py_ssize_t *poffset, Py_ssize_t *palign,
int pack, int is_big_endian); int pack, int is_big_endian);
extern PyObject *CData_AtAddress(PyObject *type, void *buf); extern PyObject *PyCData_AtAddress(PyObject *type, void *buf);
extern PyObject *CData_FromBytes(PyObject *type, char *data, Py_ssize_t length); extern PyObject *PyCData_FromBytes(PyObject *type, char *data, Py_ssize_t length);
extern PyTypeObject ArrayType_Type; extern PyTypeObject PyCArrayType_Type;
extern PyTypeObject Array_Type; extern PyTypeObject PyCArray_Type;
extern PyTypeObject PointerType_Type; extern PyTypeObject PyCPointerType_Type;
extern PyTypeObject Pointer_Type; extern PyTypeObject PyCPointer_Type;
extern PyTypeObject CFuncPtr_Type; extern PyTypeObject PyCFuncPtr_Type;
extern PyTypeObject CFuncPtrType_Type; extern PyTypeObject PyCFuncPtrType_Type;
extern PyTypeObject StructType_Type; extern PyTypeObject PyCStructType_Type;
#define ArrayTypeObject_Check(v) PyObject_TypeCheck(v, &ArrayType_Type) #define PyCArrayTypeObject_Check(v) PyObject_TypeCheck(v, &PyCArrayType_Type)
#define ArrayObject_Check(v) PyObject_TypeCheck(v, &Array_Type) #define ArrayObject_Check(v) PyObject_TypeCheck(v, &PyCArray_Type)
#define PointerObject_Check(v) PyObject_TypeCheck(v, &Pointer_Type) #define PointerObject_Check(v) PyObject_TypeCheck(v, &PyCPointer_Type)
#define PointerTypeObject_Check(v) PyObject_TypeCheck(v, &PointerType_Type) #define PyCPointerTypeObject_Check(v) PyObject_TypeCheck(v, &PyCPointerType_Type)
#define CFuncPtrObject_Check(v) PyObject_TypeCheck(v, &CFuncPtr_Type) #define PyCFuncPtrObject_Check(v) PyObject_TypeCheck(v, &PyCFuncPtr_Type)
#define CFuncPtrTypeObject_Check(v) PyObject_TypeCheck(v, &CFuncPtrType_Type) #define PyCFuncPtrTypeObject_Check(v) PyObject_TypeCheck(v, &PyCFuncPtrType_Type)
#define StructTypeObject_Check(v) PyObject_TypeCheck(v, &StructType_Type) #define PyCStructTypeObject_Check(v) PyObject_TypeCheck(v, &PyCStructType_Type)
extern PyObject * extern PyObject *
CreateArrayType(PyObject *itemtype, Py_ssize_t length); PyCArrayType_from_ctype(PyObject *itemtype, Py_ssize_t length);
extern PyMethodDef module_methods[]; extern PyMethodDef _ctypes_module_methods[];
extern CThunkObject *AllocFunctionCallback(PyObject *callable, extern CThunkObject *_ctypes_alloc_callback(PyObject *callable,
PyObject *converters, PyObject *converters,
PyObject *restype, PyObject *restype,
int flags); int flags);
...@@ -182,7 +182,7 @@ typedef struct { ...@@ -182,7 +182,7 @@ typedef struct {
PyDictObject dict; /* first part identical to PyDictObject */ PyDictObject dict; /* first part identical to PyDictObject */
/* The size and align fields are unneeded, they are in ffi_type as well. As /* The size and align fields are unneeded, they are in ffi_type as well. As
an experiment shows, it's trivial to get rid of them, the only thing to an experiment shows, it's trivial to get rid of them, the only thing to
remember is that in ArrayType_new the ffi_type fields must be filled in - remember is that in PyCArrayType_new the ffi_type fields must be filled in -
so far it was unneeded because libffi doesn't support arrays at all so far it was unneeded because libffi doesn't support arrays at all
(because they are passed as pointers to function calls anyway). But it's (because they are passed as pointers to function calls anyway). But it's
too much risk to change that now, and there are other fields which doen't too much risk to change that now, and there are other fields which doen't
...@@ -197,7 +197,7 @@ typedef struct { ...@@ -197,7 +197,7 @@ typedef struct {
GETFUNC getfunc; /* Only for simple objects */ GETFUNC getfunc; /* Only for simple objects */
PARAMFUNC paramfunc; PARAMFUNC paramfunc;
/* Following fields only used by CFuncPtrType_Type instances */ /* Following fields only used by PyCFuncPtrType_Type instances */
PyObject *argtypes; /* tuple of CDataObjects */ PyObject *argtypes; /* tuple of CDataObjects */
PyObject *converters; /* tuple([t.from_param for t in argtypes]) */ PyObject *converters; /* tuple([t.from_param for t in argtypes]) */
PyObject *restype; /* CDataObject or NULL */ PyObject *restype; /* CDataObject or NULL */
...@@ -231,7 +231,7 @@ typedef struct { ...@@ -231,7 +231,7 @@ typedef struct {
construction time, or assigns to it later, tp_setattro should update the construction time, or assigns to it later, tp_setattro should update the
StgDictObject function to a generic one. StgDictObject function to a generic one.
Currently, CFuncPtr types have 'converters' and 'checker' entries in their Currently, PyCFuncPtr types have 'converters' and 'checker' entries in their
type dict. They are only used to cache attributes from other entries, whihc type dict. They are only used to cache attributes from other entries, whihc
is wrong. is wrong.
...@@ -259,11 +259,11 @@ extern StgDictObject *PyType_stgdict(PyObject *obj); ...@@ -259,11 +259,11 @@ extern StgDictObject *PyType_stgdict(PyObject *obj);
/* May return NULL, but does not set an exception! */ /* May return NULL, but does not set an exception! */
extern StgDictObject *PyObject_stgdict(PyObject *self); extern StgDictObject *PyObject_stgdict(PyObject *self);
extern int StgDict_clone(StgDictObject *src, StgDictObject *dst); extern int PyCStgDict_clone(StgDictObject *src, StgDictObject *dst);
typedef int(* PPROC)(void); typedef int(* PPROC)(void);
PyObject *_CallProc(PPROC pProc, PyObject *_ctypes_callproc(PPROC pProc,
PyObject *arguments, PyObject *arguments,
#ifdef MS_WIN32 #ifdef MS_WIN32
IUnknown *pIUnk, IUnknown *pIUnk,
...@@ -311,17 +311,17 @@ struct tagPyCArgObject { ...@@ -311,17 +311,17 @@ struct tagPyCArgObject {
extern PyTypeObject PyCArg_Type; extern PyTypeObject PyCArg_Type;
#define PyCArg_CheckExact(v) ((v)->ob_type == &PyCArg_Type) #define PyCArg_CheckExact(v) ((v)->ob_type == &PyCArg_Type)
extern PyCArgObject *new_CArgObject(void); extern PyCArgObject *PyCArgObject_new(void);
extern PyObject * extern PyObject *
CData_get(PyObject *type, GETFUNC getfunc, PyObject *src, PyCData_get(PyObject *type, GETFUNC getfunc, PyObject *src,
Py_ssize_t index, Py_ssize_t size, char *ptr); Py_ssize_t index, Py_ssize_t size, char *ptr);
extern int extern int
CData_set(PyObject *dst, PyObject *type, SETFUNC setfunc, PyObject *value, PyCData_set(PyObject *dst, PyObject *type, SETFUNC setfunc, PyObject *value,
Py_ssize_t index, Py_ssize_t size, char *ptr); Py_ssize_t index, Py_ssize_t size, char *ptr);
extern void Extend_Error_Info(PyObject *exc_class, char *fmt, ...); extern void _ctypes_extend_error(PyObject *exc_class, char *fmt, ...);
struct basespec { struct basespec {
CDataObject *base; CDataObject *base;
...@@ -331,32 +331,31 @@ struct basespec { ...@@ -331,32 +331,31 @@ struct basespec {
extern char basespec_string[]; extern char basespec_string[];
extern ffi_type *GetType(PyObject *obj); extern ffi_type *_ctypes_get_ffi_type(PyObject *obj);
/* exception classes */ /* exception classes */
extern PyObject *PyExc_ArgError; extern PyObject *PyExc_ArgError;
extern char *conversion_mode_encoding; extern char *_ctypes_conversion_encoding;
extern char *conversion_mode_errors; extern char *_ctypes_conversion_errors;
#if defined(HAVE_WCHAR_H) #if defined(HAVE_WCHAR_H)
# define CTYPES_UNICODE # define CTYPES_UNICODE
#endif #endif
extern void FreeClosure(void *); extern void _ctypes_free_closure(void *);
extern void *MallocClosure(void); extern void *_ctypes_alloc_closure(void);
extern void _AddTraceback(char *, char *, int); extern void _ctypes_add_traceback(char *, char *, int);
extern PyObject *CData_FromBaseObj(PyObject *type, PyObject *base, Py_ssize_t index, char *adr); extern PyObject *PyCData_FromBaseObj(PyObject *type, PyObject *base, Py_ssize_t index, char *adr);
extern char *alloc_format_string(const char *prefix, const char *suffix); extern char *_ctypes_alloc_format_string(const char *prefix, const char *suffix);
/* XXX better name needed! */ extern int _ctypes_simple_instance(PyObject *obj);
extern int IsSimpleSubType(PyObject *obj);
extern PyObject *_pointer_type_cache; extern PyObject *_ctypes_ptrtype_cache;
PyObject *get_error_object(int **pspace); PyObject *_ctypes_get_errobj(int **pspace);
#ifdef MS_WIN32 #ifdef MS_WIN32
extern PyObject *ComError; extern PyObject *ComError;
......
...@@ -89,7 +89,7 @@ static void more_core(void) ...@@ -89,7 +89,7 @@ static void more_core(void)
/******************************************************************/ /******************************************************************/
/* put the item back into the free list */ /* put the item back into the free list */
void FreeClosure(void *p) void _ctypes_free_closure(void *p)
{ {
ITEM *item = (ITEM *)p; ITEM *item = (ITEM *)p;
item->next = free_list; item->next = free_list;
...@@ -97,7 +97,7 @@ void FreeClosure(void *p) ...@@ -97,7 +97,7 @@ void FreeClosure(void *p)
} }
/* return one item from the free list, allocating more if needed */ /* return one item from the free list, allocating more if needed */
void *MallocClosure(void) void *_ctypes_alloc_closure(void)
{ {
ITEM *item; ITEM *item;
if (!free_list) if (!free_list)
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
* PyDict_SetItem() (ma_lookup is NULL) * PyDict_SetItem() (ma_lookup is NULL)
*/ */
static int static int
StgDict_init(StgDictObject *self, PyObject *args, PyObject *kwds) PyCStgDict_init(StgDictObject *self, PyObject *args, PyObject *kwds)
{ {
if (PyDict_Type.tp_init((PyObject *)self, args, kwds) < 0) if (PyDict_Type.tp_init((PyObject *)self, args, kwds) < 0)
return -1; return -1;
...@@ -28,7 +28,7 @@ StgDict_init(StgDictObject *self, PyObject *args, PyObject *kwds) ...@@ -28,7 +28,7 @@ StgDict_init(StgDictObject *self, PyObject *args, PyObject *kwds)
} }
static int static int
StgDict_clear(StgDictObject *self) PyCStgDict_clear(StgDictObject *self)
{ {
Py_CLEAR(self->proto); Py_CLEAR(self->proto);
Py_CLEAR(self->argtypes); Py_CLEAR(self->argtypes);
...@@ -39,9 +39,9 @@ StgDict_clear(StgDictObject *self) ...@@ -39,9 +39,9 @@ StgDict_clear(StgDictObject *self)
} }
static void static void
StgDict_dealloc(StgDictObject *self) PyCStgDict_dealloc(StgDictObject *self)
{ {
StgDict_clear(self); PyCStgDict_clear(self);
PyMem_Free(self->format); PyMem_Free(self->format);
PyMem_Free(self->shape); PyMem_Free(self->shape);
PyMem_Free(self->ffi_type_pointer.elements); PyMem_Free(self->ffi_type_pointer.elements);
...@@ -49,12 +49,12 @@ StgDict_dealloc(StgDictObject *self) ...@@ -49,12 +49,12 @@ StgDict_dealloc(StgDictObject *self)
} }
int int
StgDict_clone(StgDictObject *dst, StgDictObject *src) PyCStgDict_clone(StgDictObject *dst, StgDictObject *src)
{ {
char *d, *s; char *d, *s;
Py_ssize_t size; Py_ssize_t size;
StgDict_clear(dst); PyCStgDict_clear(dst);
PyMem_Free(dst->ffi_type_pointer.elements); PyMem_Free(dst->ffi_type_pointer.elements);
PyMem_Free(dst->format); PyMem_Free(dst->format);
dst->format = NULL; dst->format = NULL;
...@@ -102,12 +102,12 @@ StgDict_clone(StgDictObject *dst, StgDictObject *src) ...@@ -102,12 +102,12 @@ StgDict_clone(StgDictObject *dst, StgDictObject *src)
return 0; return 0;
} }
PyTypeObject StgDict_Type = { PyTypeObject PyCStgDict_Type = {
PyVarObject_HEAD_INIT(NULL, 0) PyVarObject_HEAD_INIT(NULL, 0)
"StgDict", "StgDict",
sizeof(StgDictObject), sizeof(StgDictObject),
0, 0,
(destructor)StgDict_dealloc, /* tp_dealloc */ (destructor)PyCStgDict_dealloc, /* tp_dealloc */
0, /* tp_print */ 0, /* tp_print */
0, /* tp_getattr */ 0, /* tp_getattr */
0, /* tp_setattr */ 0, /* tp_setattr */
...@@ -138,7 +138,7 @@ PyTypeObject StgDict_Type = { ...@@ -138,7 +138,7 @@ PyTypeObject StgDict_Type = {
0, /* tp_descr_get */ 0, /* tp_descr_get */
0, /* tp_descr_set */ 0, /* tp_descr_set */
0, /* tp_dictoffset */ 0, /* tp_dictoffset */
(initproc)StgDict_init, /* tp_init */ (initproc)PyCStgDict_init, /* tp_init */
0, /* tp_alloc */ 0, /* tp_alloc */
0, /* tp_new */ 0, /* tp_new */
0, /* tp_free */ 0, /* tp_free */
...@@ -153,7 +153,7 @@ PyType_stgdict(PyObject *obj) ...@@ -153,7 +153,7 @@ PyType_stgdict(PyObject *obj)
if (!PyType_Check(obj)) if (!PyType_Check(obj))
return NULL; return NULL;
type = (PyTypeObject *)obj; type = (PyTypeObject *)obj;
if (!type->tp_dict || !StgDict_CheckExact(type->tp_dict)) if (!type->tp_dict || !PyCStgDict_CheckExact(type->tp_dict))
return NULL; return NULL;
return (StgDictObject *)type->tp_dict; return (StgDictObject *)type->tp_dict;
} }
...@@ -167,7 +167,7 @@ StgDictObject * ...@@ -167,7 +167,7 @@ StgDictObject *
PyObject_stgdict(PyObject *self) PyObject_stgdict(PyObject *self)
{ {
PyTypeObject *type = self->ob_type; PyTypeObject *type = self->ob_type;
if (!type->tp_dict || !StgDict_CheckExact(type->tp_dict)) if (!type->tp_dict || !PyCStgDict_CheckExact(type->tp_dict))
return NULL; return NULL;
return (StgDictObject *)type->tp_dict; return (StgDictObject *)type->tp_dict;
} }
...@@ -207,7 +207,7 @@ MakeFields(PyObject *type, CFieldObject *descr, ...@@ -207,7 +207,7 @@ MakeFields(PyObject *type, CFieldObject *descr,
Py_DECREF(fieldlist); Py_DECREF(fieldlist);
return -1; return -1;
} }
if (Py_TYPE(fdescr) != &CField_Type) { if (Py_TYPE(fdescr) != &PyCField_Type) {
PyErr_SetString(PyExc_TypeError, "unexpected type"); PyErr_SetString(PyExc_TypeError, "unexpected type");
Py_DECREF(fdescr); Py_DECREF(fdescr);
Py_DECREF(fieldlist); Py_DECREF(fieldlist);
...@@ -224,13 +224,13 @@ MakeFields(PyObject *type, CFieldObject *descr, ...@@ -224,13 +224,13 @@ MakeFields(PyObject *type, CFieldObject *descr,
} }
continue; continue;
} }
new_descr = (CFieldObject *)PyObject_CallObject((PyObject *)&CField_Type, NULL); new_descr = (CFieldObject *)PyObject_CallObject((PyObject *)&PyCField_Type, NULL);
if (new_descr == NULL) { if (new_descr == NULL) {
Py_DECREF(fdescr); Py_DECREF(fdescr);
Py_DECREF(fieldlist); Py_DECREF(fieldlist);
return -1; return -1;
} }
assert(Py_TYPE(new_descr) == &CField_Type); assert(Py_TYPE(new_descr) == &PyCField_Type);
new_descr->size = fdescr->size; new_descr->size = fdescr->size;
new_descr->offset = fdescr->offset + offset; new_descr->offset = fdescr->offset + offset;
new_descr->index = fdescr->index + index; new_descr->index = fdescr->index + index;
...@@ -278,7 +278,7 @@ MakeAnonFields(PyObject *type) ...@@ -278,7 +278,7 @@ MakeAnonFields(PyObject *type)
Py_DECREF(anon_names); Py_DECREF(anon_names);
return -1; return -1;
} }
assert(Py_TYPE(descr) == &CField_Type); assert(Py_TYPE(descr) == &PyCField_Type);
descr->anonymous = 1; descr->anonymous = 1;
/* descr is in the field descriptor. */ /* descr is in the field descriptor. */
...@@ -301,7 +301,7 @@ MakeAnonFields(PyObject *type) ...@@ -301,7 +301,7 @@ MakeAnonFields(PyObject *type)
and create an StgDictObject. Used for Structure and Union subclasses. and create an StgDictObject. Used for Structure and Union subclasses.
*/ */
int int
StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct) PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct)
{ {
StgDictObject *stgdict, *basedict; StgDictObject *stgdict, *basedict;
Py_ssize_t len, offset, size, align, i; Py_ssize_t len, offset, size, align, i;
...@@ -410,12 +410,12 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct) ...@@ -410,12 +410,12 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct)
assert(stgdict->format == NULL); assert(stgdict->format == NULL);
if (isStruct && !isPacked) { if (isStruct && !isPacked) {
stgdict->format = alloc_format_string(NULL, "T{"); stgdict->format = _ctypes_alloc_format_string(NULL, "T{");
} else { } else {
/* PEP3118 doesn't support union, or packed structures (well, /* PEP3118 doesn't support union, or packed structures (well,
only standard packing, but we dont support the pep for only standard packing, but we dont support the pep for
that). Use 'B' for bytes. */ that). Use 'B' for bytes. */
stgdict->format = alloc_format_string(NULL, "B"); stgdict->format = _ctypes_alloc_format_string(NULL, "B");
} }
#define realdict ((PyObject *)&stgdict->dict) #define realdict ((PyObject *)&stgdict->dict)
...@@ -456,9 +456,9 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct) ...@@ -456,9 +456,9 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct)
case FFI_TYPE_SINT8: case FFI_TYPE_SINT8:
case FFI_TYPE_SINT16: case FFI_TYPE_SINT16:
case FFI_TYPE_SINT32: case FFI_TYPE_SINT32:
if (dict->getfunc != getentry("c")->getfunc if (dict->getfunc != _ctypes_get_fielddesc("c")->getfunc
#ifdef CTYPES_UNICODE #ifdef CTYPES_UNICODE
&& dict->getfunc != getentry("u")->getfunc && dict->getfunc != _ctypes_get_fielddesc("u")->getfunc
#endif #endif
) )
break; break;
...@@ -488,7 +488,7 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct) ...@@ -488,7 +488,7 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct)
sprintf(buf, "%s:%s:", fieldfmt, fieldname); sprintf(buf, "%s:%s:", fieldfmt, fieldname);
ptr = stgdict->format; ptr = stgdict->format;
stgdict->format = alloc_format_string(stgdict->format, buf); stgdict->format = _ctypes_alloc_format_string(stgdict->format, buf);
PyMem_Free(ptr); PyMem_Free(ptr);
if (stgdict->format == NULL) { if (stgdict->format == NULL) {
...@@ -497,7 +497,7 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct) ...@@ -497,7 +497,7 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct)
} }
} }
if (isStruct) { if (isStruct) {
prop = CField_FromDesc(desc, i, prop = PyCField_FromDesc(desc, i,
&field_size, bitsize, &bitofs, &field_size, bitsize, &bitofs,
&size, &offset, &align, &size, &offset, &align,
pack, big_endian); pack, big_endian);
...@@ -505,7 +505,7 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct) ...@@ -505,7 +505,7 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct)
size = 0; size = 0;
offset = 0; offset = 0;
align = 0; align = 0;
prop = CField_FromDesc(desc, i, prop = PyCField_FromDesc(desc, i,
&field_size, bitsize, &bitofs, &field_size, bitsize, &bitofs,
&size, &offset, &align, &size, &offset, &align,
pack, big_endian); pack, big_endian);
...@@ -529,7 +529,7 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct) ...@@ -529,7 +529,7 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct)
if (isStruct && !isPacked) { if (isStruct && !isPacked) {
char *ptr = stgdict->format; char *ptr = stgdict->format;
stgdict->format = alloc_format_string(stgdict->format, "}"); stgdict->format = _ctypes_alloc_format_string(stgdict->format, "}");
PyMem_Free(ptr); PyMem_Free(ptr);
if (stgdict->format == NULL) if (stgdict->format == NULL)
return -1; return -1;
......
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