[Python-checkins] r45547 - python/trunk/Modules/_ctypes/_ctypes.c python/trunk/Modules/_ctypes/_ctypes_test.c python/trunk/Modules/_ctypes/callbacks.c python/trunk/Modules/_ctypes/callproc.c python/trunk/Modules/_ctypes/ctypes.h python/trunk/Modules/_ctypes/stgdict.c
skip.montanaro
python-checkins at python.org
Tue Apr 18 21:45:19 CEST 2006
Author: skip.montanaro
Date: Tue Apr 18 21:45:17 2006
New Revision: 45547
Modified:
python/trunk/Modules/_ctypes/_ctypes.c
python/trunk/Modules/_ctypes/_ctypes_test.c
python/trunk/Modules/_ctypes/callbacks.c
python/trunk/Modules/_ctypes/callproc.c
python/trunk/Modules/_ctypes/ctypes.h
python/trunk/Modules/_ctypes/stgdict.c
Log:
C++ compiler cleanup: the typical few casts, and ... C++ didn't like that
the StgDictObject's ffi_type member had the same name as its type. I
changed that to ffi_type_pointer. Feel free to change it to something else
more meaningful, just not ffi_type.
Modified: python/trunk/Modules/_ctypes/_ctypes.c
==============================================================================
--- python/trunk/Modules/_ctypes/_ctypes.c (original)
+++ python/trunk/Modules/_ctypes/_ctypes.c Tue Apr 18 21:45:17 2006
@@ -549,7 +549,7 @@
stgdict->size = sizeof(void *);
stgdict->align = getentry("P")->pffi_type->alignment;
stgdict->length = 1;
- stgdict->ffi_type = ffi_type_pointer;
+ stgdict->ffi_type_pointer = ffi_type_pointer;
proto = PyDict_GetItemString(typedict, "_type_"); /* Borrowed ref */
if (proto && -1 == PointerType_SetProto(stgdict, proto)) {
@@ -949,7 +949,7 @@
stgdict->proto = proto;
/* Arrays are passed as pointers to function calls. */
- stgdict->ffi_type = ffi_type_pointer;
+ stgdict->ffi_type_pointer = ffi_type_pointer;
/* create the new instance (which is a class,
since we are a metatype!) */
@@ -1307,7 +1307,7 @@
if (!stgdict) /* XXX leaks result! */
return NULL;
- stgdict->ffi_type = *fmt->pffi_type;
+ stgdict->ffi_type_pointer = *fmt->pffi_type;
stgdict->align = fmt->pffi_type->alignment;
stgdict->length = 0;
stgdict->size = fmt->pffi_type->size;
@@ -1365,7 +1365,7 @@
fmt = getentry(PyString_AS_STRING(proto));
- stgdict->ffi_type = *fmt->pffi_type;
+ stgdict->ffi_type_pointer = *fmt->pffi_type;
stgdict->align = fmt->pffi_type->alignment;
stgdict->length = 0;
stgdict->size = fmt->pffi_type->size;
@@ -1635,7 +1635,7 @@
stgdict->size = sizeof(void *);
stgdict->setfunc = NULL;
stgdict->getfunc = NULL;
- stgdict->ffi_type = ffi_type_pointer;
+ stgdict->ffi_type_pointer = ffi_type_pointer;
ob = PyDict_GetItemString((PyObject *)stgdict, "_flags_");
if (!ob || !PyInt_Check(ob)) {
@@ -1857,7 +1857,7 @@
StgDictObject *dict = PyObject_stgdict((PyObject *)self);
Py_CLEAR(self->b_objects);
if ((self->b_needsfree)
- && (dict->size > sizeof(self->b_value)))
+ && ((size_t)dict->size > sizeof(self->b_value)))
PyMem_Free(self->b_ptr);
self->b_ptr = NULL;
Py_CLEAR(self->b_base);
@@ -1979,7 +1979,7 @@
static void CData_MallocBuffer(CDataObject *obj, StgDictObject *dict)
{
- if (dict->size <= sizeof(obj->b_value)) {
+ if ((size_t)dict->size <= sizeof(obj->b_value)) {
/* No need to call malloc, can use the default buffer */
obj->b_ptr = (char *)&obj->b_value;
obj->b_needsfree = 1;
@@ -1987,7 +1987,7 @@
/* In python 2.4, and ctypes 0.9.6, the malloc call took about
33% of the creation time for c_int().
*/
- obj->b_ptr = PyMem_Malloc(dict->size);
+ obj->b_ptr = (char *)PyMem_Malloc(dict->size);
obj->b_needsfree = 1;
memset(obj->b_ptr, 0, dict->size);
}
@@ -2052,7 +2052,7 @@
if (!pd)
return NULL;
assert(CDataObject_Check(pd));
- pd->b_ptr = buf;
+ pd->b_ptr = (char *)buf;
pd->b_length = dict->length;
pd->b_size = dict->size;
return (PyObject *)pd;
@@ -3295,7 +3295,7 @@
parg->tag = 'V';
stgdict = PyObject_stgdict((PyObject *)self);
- parg->pffi_type = &stgdict->ffi_type;
+ parg->pffi_type = &stgdict->ffi_type_pointer;
/* For structure parameters (by value), parg->value doesn't contain the structure
data itself, instead parg->value.p *points* to the structure's data
See also _ctypes.c, function _call_function_pointer().
Modified: python/trunk/Modules/_ctypes/_ctypes_test.c
==============================================================================
--- python/trunk/Modules/_ctypes/_ctypes_test.c (original)
+++ python/trunk/Modules/_ctypes/_ctypes_test.c Tue Apr 18 21:45:17 2006
@@ -74,7 +74,7 @@
EXPORT(char *) _testfunc_p_p(void *s)
{
- return s;
+ return (char *)s;
}
EXPORT(void *) _testfunc_c_p_p(int *argcp, char **argv)
@@ -89,7 +89,7 @@
EXPORT(char *) my_strdup(char *src)
{
- char *dst = malloc(strlen(src)+1);
+ char *dst = (char *)malloc(strlen(src)+1);
if (!dst)
return NULL;
strcpy(dst, src);
@@ -100,7 +100,7 @@
EXPORT(wchar_t *) my_wcsdup(wchar_t *src)
{
size_t len = wcslen(src);
- wchar_t *ptr = malloc((len + 1) * sizeof(wchar_t));
+ wchar_t *ptr = (wchar_t *)malloc((len + 1) * sizeof(wchar_t));
if (ptr == NULL)
return NULL;
memcpy(ptr, src, (len+1) * sizeof(wchar_t));
@@ -191,7 +191,7 @@
{
static char message[] = "Hello, World";
if (p) {
- *p = malloc(sizeof(char *));
+ *p = (char **)malloc(sizeof(char *));
printf("malloc returned %p\n", *p);
**p = message;
return 1;
Modified: python/trunk/Modules/_ctypes/callbacks.c
==============================================================================
--- python/trunk/Modules/_ctypes/callbacks.c (original)
+++ python/trunk/Modules/_ctypes/callbacks.c Tue Apr 18 21:45:17 2006
@@ -318,7 +318,7 @@
if (dict == NULL)
goto error;
p->setfunc = dict->setfunc;
- p->restype = &dict->ffi_type;
+ p->restype = &dict->ffi_type_pointer;
}
cc = FFI_DEFAULT_ABI;
Modified: python/trunk/Modules/_ctypes/callproc.c
==============================================================================
--- python/trunk/Modules/_ctypes/callproc.c (original)
+++ python/trunk/Modules/_ctypes/callproc.c Tue Apr 18 21:45:17 2006
@@ -588,7 +588,7 @@
return &ffi_type_sint64;
}
#endif
- return &dict->ffi_type;
+ return &dict->ffi_type_pointer;
}
Modified: python/trunk/Modules/_ctypes/ctypes.h
==============================================================================
--- python/trunk/Modules/_ctypes/ctypes.h (original)
+++ python/trunk/Modules/_ctypes/ctypes.h Tue Apr 18 21:45:17 2006
@@ -198,7 +198,7 @@
Py_ssize_t size; /* number of bytes */
Py_ssize_t align; /* alignment requirements */
Py_ssize_t length; /* number of fields */
- ffi_type ffi_type;
+ ffi_type ffi_type_pointer;
PyObject *proto; /* Only for Pointer/ArrayObject */
SETFUNC setfunc; /* Only for simple objects */
GETFUNC getfunc; /* Only for simple objects */
Modified: python/trunk/Modules/_ctypes/stgdict.c
==============================================================================
--- python/trunk/Modules/_ctypes/stgdict.c (original)
+++ python/trunk/Modules/_ctypes/stgdict.c Tue Apr 18 21:45:17 2006
@@ -38,7 +38,7 @@
StgDict_dealloc(StgDictObject *self)
{
StgDict_clear(self);
- PyMem_Free(self->ffi_type.elements);
+ PyMem_Free(self->ffi_type_pointer.elements);
PyDict_Type.tp_dealloc((PyObject *)self);
}
@@ -49,8 +49,8 @@
int size;
StgDict_clear(dst);
- PyMem_Free(dst->ffi_type.elements);
- dst->ffi_type.elements = NULL;
+ PyMem_Free(dst->ffi_type_pointer.elements);
+ dst->ffi_type_pointer.elements = NULL;
d = (char *)dst;
s = (char *)src;
@@ -64,13 +64,15 @@
Py_XINCREF(dst->restype);
Py_XINCREF(dst->checker);
- if (src->ffi_type.elements == NULL)
+ if (src->ffi_type_pointer.elements == NULL)
return 0;
size = sizeof(ffi_type *) * (src->length + 1);
- dst->ffi_type.elements = PyMem_Malloc(size);
- if (dst->ffi_type.elements == NULL)
+ dst->ffi_type_pointer.elements = PyMem_Malloc(size);
+ if (dst->ffi_type_pointer.elements == NULL)
return -1;
- memcpy(dst->ffi_type.elements, src->ffi_type.elements, size);
+ memcpy(dst->ffi_type_pointer.elements,
+ src->ffi_type_pointer.elements,
+ size);
return 0;
}
@@ -234,8 +236,8 @@
stuff is sucessfully finished. */
stgdict->flags |= DICTFLAG_FINAL; /* set final */
- if (stgdict->ffi_type.elements)
- PyMem_Free(stgdict->ffi_type.elements);
+ if (stgdict->ffi_type_pointer.elements)
+ PyMem_Free(stgdict->ffi_type_pointer.elements);
basedict = PyType_stgdict((PyObject *)((PyTypeObject *)type)->tp_base);
if (basedict && !use_broken_old_ctypes_semantics) {
@@ -243,10 +245,12 @@
align = basedict->align;
union_size = 0;
total_align = align ? align : 1;
- stgdict->ffi_type.type = FFI_TYPE_STRUCT;
- stgdict->ffi_type.elements = PyMem_Malloc(sizeof(ffi_type *) * (basedict->length + len + 1));
- memset(stgdict->ffi_type.elements, 0, sizeof(ffi_type *) * (basedict->length + len + 1));
- memcpy(stgdict->ffi_type.elements, basedict->ffi_type.elements,
+ stgdict->ffi_type_pointer.type = FFI_TYPE_STRUCT;
+ stgdict->ffi_type_pointer.elements = PyMem_Malloc(sizeof(ffi_type *) * (basedict->length + len + 1));
+ memset(stgdict->ffi_type_pointer.elements, 0,
+ sizeof(ffi_type *) * (basedict->length + len + 1));
+ memcpy(stgdict->ffi_type_pointer.elements,
+ basedict->ffi_type_pointer.elements,
sizeof(ffi_type *) * (basedict->length));
ffi_ofs = basedict->length;
} else {
@@ -255,9 +259,10 @@
align = 0;
union_size = 0;
total_align = 1;
- stgdict->ffi_type.type = FFI_TYPE_STRUCT;
- stgdict->ffi_type.elements = PyMem_Malloc(sizeof(ffi_type *) * (len + 1));
- memset(stgdict->ffi_type.elements, 0, sizeof(ffi_type *) * (len + 1));
+ stgdict->ffi_type_pointer.type = FFI_TYPE_STRUCT;
+ stgdict->ffi_type_pointer.elements = PyMem_Malloc(sizeof(ffi_type *) * (len + 1));
+ memset(stgdict->ffi_type_pointer.elements, 0,
+ sizeof(ffi_type *) * (len + 1));
ffi_ofs = 0;
}
@@ -283,10 +288,10 @@
i);
return -1;
}
- stgdict->ffi_type.elements[ffi_ofs + i] = &dict->ffi_type;
+ stgdict->ffi_type_pointer.elements[ffi_ofs + i] = &dict->ffi_type_pointer;
dict->flags |= DICTFLAG_FINAL; /* mark field type final */
if (PyTuple_Size(pair) == 3) { /* bits specified */
- switch(dict->ffi_type.type) {
+ switch(dict->ffi_type_pointer.type) {
case FFI_TYPE_UINT8:
case FFI_TYPE_UINT16:
case FFI_TYPE_UINT32:
@@ -357,8 +362,8 @@
/* Adjust the size according to the alignment requirements */
size = ((size + total_align - 1) / total_align) * total_align;
- stgdict->ffi_type.alignment = total_align;
- stgdict->ffi_type.size = size;
+ stgdict->ffi_type_pointer.alignment = total_align;
+ stgdict->ffi_type_pointer.size = size;
stgdict->size = size;
stgdict->align = total_align;
More information about the Python-checkins
mailing list