Commit e81c9f6d authored by Thomas Heller's avatar Thomas Heller

[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur

with small modifications.
parent da587ab4
...@@ -789,7 +789,7 @@ static int ...@@ -789,7 +789,7 @@ static int
CharArray_set_value(CDataObject *self, PyObject *value) CharArray_set_value(CDataObject *self, PyObject *value)
{ {
char *ptr; char *ptr;
int size; Py_ssize_t size;
if (PyUnicode_Check(value)) { if (PyUnicode_Check(value)) {
value = PyUnicode_AsEncodedString(value, value = PyUnicode_AsEncodedString(value,
...@@ -844,7 +844,7 @@ WCharArray_get_value(CDataObject *self) ...@@ -844,7 +844,7 @@ WCharArray_get_value(CDataObject *self)
static int static int
WCharArray_set_value(CDataObject *self, PyObject *value) WCharArray_set_value(CDataObject *self, PyObject *value)
{ {
int result = 0; Py_ssize_t result = 0;
if (PyString_Check(value)) { if (PyString_Check(value)) {
value = PyUnicode_FromEncodedObject(value, value = PyUnicode_FromEncodedObject(value,
...@@ -868,14 +868,12 @@ WCharArray_set_value(CDataObject *self, PyObject *value) ...@@ -868,14 +868,12 @@ WCharArray_set_value(CDataObject *self, PyObject *value)
result = PyUnicode_AsWideChar((PyUnicodeObject *)value, result = PyUnicode_AsWideChar((PyUnicodeObject *)value,
(wchar_t *)self->b_ptr, (wchar_t *)self->b_ptr,
self->b_size/sizeof(wchar_t)); self->b_size/sizeof(wchar_t));
if (result >= 0 && (unsigned)result < self->b_size/sizeof(wchar_t)) if (result >= 0 && (size_t)result < self->b_size/sizeof(wchar_t))
((wchar_t *)self->b_ptr)[result] = (wchar_t)0; ((wchar_t *)self->b_ptr)[result] = (wchar_t)0;
if (result > 0)
result = 0;
done: done:
Py_DECREF(value); Py_DECREF(value);
return result; return result >= 0 ? 0 : -1;
} }
static PyGetSetDef WCharArray_getsets[] = { static PyGetSetDef WCharArray_getsets[] = {
...@@ -966,7 +964,7 @@ ArrayType_new(PyTypeObject *type, PyObject *args, PyObject *kwds) ...@@ -966,7 +964,7 @@ ArrayType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
PyObject *typedict; PyObject *typedict;
int length; int length;
int itemsize, itemalign; Py_ssize_t itemsize, itemalign;
typedict = PyTuple_GetItem(args, 2); typedict = PyTuple_GetItem(args, 2);
if (!typedict) if (!typedict)
...@@ -1737,8 +1735,8 @@ static PyObject * ...@@ -1737,8 +1735,8 @@ static PyObject *
converters_from_argtypes(PyObject *ob) converters_from_argtypes(PyObject *ob)
{ {
PyObject *converters; PyObject *converters;
int i; Py_ssize_t i;
int nArgs; Py_ssize_t nArgs;
ob = PySequence_Tuple(ob); /* new reference */ ob = PySequence_Tuple(ob); /* new reference */
if (!ob) { if (!ob) {
...@@ -2591,18 +2589,18 @@ static PyGetSetDef CFuncPtr_getsets[] = { ...@@ -2591,18 +2589,18 @@ static PyGetSetDef CFuncPtr_getsets[] = {
#ifdef MS_WIN32 #ifdef MS_WIN32
static PPROC FindAddress(void *handle, char *name, PyObject *type) static PPROC FindAddress(void *handle, char *name, PyObject *type)
{ {
#ifdef MS_WIN64
/* win64 has no stdcall calling conv, so it should
also not have the name mangling of it.
*/
return (PPROC)GetProcAddress(handle, name);
#else
PPROC address; PPROC address;
char *mangled_name; char *mangled_name;
int i; int i;
StgDictObject *dict; StgDictObject *dict;
address = (PPROC)GetProcAddress(handle, name); address = (PPROC)GetProcAddress(handle, name);
#ifdef _WIN64
/* win64 has no stdcall calling conv, so it should
also not have the name mangling of it.
*/
return address;
#else
if (address) if (address)
return address; return address;
if (((size_t)name & ~0xFFFF) == 0) { if (((size_t)name & ~0xFFFF) == 0) {
...@@ -2634,7 +2632,7 @@ static PPROC FindAddress(void *handle, char *name, PyObject *type) ...@@ -2634,7 +2632,7 @@ static PPROC FindAddress(void *handle, char *name, PyObject *type)
/* Return 1 if usable, 0 else and exception set. */ /* Return 1 if usable, 0 else and exception set. */
static int static int
_check_outarg_type(PyObject *arg, int index) _check_outarg_type(PyObject *arg, Py_ssize_t index)
{ {
StgDictObject *dict; StgDictObject *dict;
...@@ -2655,7 +2653,7 @@ _check_outarg_type(PyObject *arg, int index) ...@@ -2655,7 +2653,7 @@ _check_outarg_type(PyObject *arg, int index)
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"'out' parameter %d must be a pointer type, not %s", "'out' parameter %d must be a pointer type, not %s",
index, Py_SAFE_DOWNCAST(index, Py_ssize_t, int),
PyType_Check(arg) ? PyType_Check(arg) ?
((PyTypeObject *)arg)->tp_name : ((PyTypeObject *)arg)->tp_name :
arg->ob_type->tp_name); arg->ob_type->tp_name);
...@@ -2666,7 +2664,7 @@ _check_outarg_type(PyObject *arg, int index) ...@@ -2666,7 +2664,7 @@ _check_outarg_type(PyObject *arg, int index)
static int static int
_validate_paramflags(PyTypeObject *type, PyObject *paramflags) _validate_paramflags(PyTypeObject *type, PyObject *paramflags)
{ {
int i, len; Py_ssize_t i, len;
StgDictObject *dict; StgDictObject *dict;
PyObject *argtypes; PyObject *argtypes;
...@@ -3051,12 +3049,12 @@ _build_callargs(CFuncPtrObject *self, PyObject *argtypes, ...@@ -3051,12 +3049,12 @@ _build_callargs(CFuncPtrObject *self, PyObject *argtypes,
PyObject *paramflags = self->paramflags; PyObject *paramflags = self->paramflags;
PyObject *callargs; PyObject *callargs;
StgDictObject *dict; StgDictObject *dict;
int i, len; Py_ssize_t i, len;
int inargs_index = 0; int inargs_index = 0;
/* It's a little bit difficult to determine how many arguments the /* It's a little bit difficult to determine how many arguments the
function call requires/accepts. For simplicity, we count the consumed function call requires/accepts. For simplicity, we count the consumed
args and compare this to the number of supplied args. */ args and compare this to the number of supplied args. */
int actual_args; Py_ssize_t actual_args;
*poutmask = 0; *poutmask = 0;
*pinoutmask = 0; *pinoutmask = 0;
...@@ -3093,7 +3091,7 @@ _build_callargs(CFuncPtrObject *self, PyObject *argtypes, ...@@ -3093,7 +3091,7 @@ _build_callargs(CFuncPtrObject *self, PyObject *argtypes,
/* This way seems to be ~2 us faster than the PyArg_ParseTuple /* This way seems to be ~2 us faster than the PyArg_ParseTuple
calls below. */ calls below. */
/* We HAVE already checked that the tuple can be parsed with "i|zO", so... */ /* We HAVE already checked that the tuple can be parsed with "i|zO", so... */
int tsize = PyTuple_GET_SIZE(item); Py_ssize_t tsize = PyTuple_GET_SIZE(item);
flag = PyInt_AS_LONG(PyTuple_GET_ITEM(item, 0)); flag = PyInt_AS_LONG(PyTuple_GET_ITEM(item, 0));
name = tsize > 1 ? PyString_AS_STRING(PyTuple_GET_ITEM(item, 1)) : NULL; name = tsize > 1 ? PyString_AS_STRING(PyTuple_GET_ITEM(item, 1)) : NULL;
defval = tsize > 2 ? PyTuple_GET_ITEM(item, 2) : NULL; defval = tsize > 2 ? PyTuple_GET_ITEM(item, 2) : NULL;
...@@ -3339,8 +3337,10 @@ CFuncPtr_call(CFuncPtrObject *self, PyObject *inargs, PyObject *kwds) ...@@ -3339,8 +3337,10 @@ CFuncPtr_call(CFuncPtrObject *self, PyObject *inargs, PyObject *kwds)
return NULL; return NULL;
if (converters) { if (converters) {
int required = PyTuple_GET_SIZE(converters); int required = Py_SAFE_DOWNCAST(PyTuple_GET_SIZE(converters),
int actual = PyTuple_GET_SIZE(callargs); Py_ssize_t, int);
int actual = Py_SAFE_DOWNCAST(PyTuple_GET_SIZE(callargs),
Py_ssize_t, int);
if ((dict->flags & FUNCFLAG_CDECL) == FUNCFLAG_CDECL) { if ((dict->flags & FUNCFLAG_CDECL) == FUNCFLAG_CDECL) {
/* For cdecl functions, we allow more actual arguments /* For cdecl functions, we allow more actual arguments
...@@ -3679,8 +3679,8 @@ static PyTypeObject Union_Type = { ...@@ -3679,8 +3679,8 @@ static PyTypeObject Union_Type = {
static int static int
Array_init(CDataObject *self, PyObject *args, PyObject *kw) Array_init(CDataObject *self, PyObject *args, PyObject *kw)
{ {
int i; Py_ssize_t i;
int n; Py_ssize_t n;
if (!PyTuple_Check(args)) { if (!PyTuple_Check(args)) {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
...@@ -3701,7 +3701,7 @@ static PyObject * ...@@ -3701,7 +3701,7 @@ static PyObject *
Array_item(PyObject *_self, Py_ssize_t index) Array_item(PyObject *_self, Py_ssize_t index)
{ {
CDataObject *self = (CDataObject *)_self; CDataObject *self = (CDataObject *)_self;
int offset, size; Py_ssize_t offset, size;
StgDictObject *stgdict; StgDictObject *stgdict;
...@@ -3773,7 +3773,7 @@ static int ...@@ -3773,7 +3773,7 @@ static int
Array_ass_item(PyObject *_self, Py_ssize_t index, PyObject *value) Array_ass_item(PyObject *_self, Py_ssize_t index, PyObject *value)
{ {
CDataObject *self = (CDataObject *)_self; CDataObject *self = (CDataObject *)_self;
int size, offset; Py_ssize_t size, offset;
StgDictObject *stgdict; StgDictObject *stgdict;
char *ptr; char *ptr;
...@@ -3802,7 +3802,7 @@ static int ...@@ -3802,7 +3802,7 @@ static int
Array_ass_slice(PyObject *_self, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *value) Array_ass_slice(PyObject *_self, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *value)
{ {
CDataObject *self = (CDataObject *)_self; CDataObject *self = (CDataObject *)_self;
int i, len; Py_ssize_t i, len;
if (value == NULL) { if (value == NULL) {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
...@@ -4164,7 +4164,7 @@ static PyObject * ...@@ -4164,7 +4164,7 @@ static PyObject *
Pointer_item(PyObject *_self, Py_ssize_t index) Pointer_item(PyObject *_self, Py_ssize_t index)
{ {
CDataObject *self = (CDataObject *)_self; CDataObject *self = (CDataObject *)_self;
int size; Py_ssize_t size;
Py_ssize_t offset; Py_ssize_t offset;
StgDictObject *stgdict, *itemdict; StgDictObject *stgdict, *itemdict;
PyObject *proto; PyObject *proto;
...@@ -4195,7 +4195,7 @@ static int ...@@ -4195,7 +4195,7 @@ static int
Pointer_ass_item(PyObject *_self, Py_ssize_t index, PyObject *value) Pointer_ass_item(PyObject *_self, Py_ssize_t index, PyObject *value)
{ {
CDataObject *self = (CDataObject *)_self; CDataObject *self = (CDataObject *)_self;
int size; Py_ssize_t size;
Py_ssize_t offset; Py_ssize_t offset;
StgDictObject *stgdict, *itemdict; StgDictObject *stgdict, *itemdict;
PyObject *proto; PyObject *proto;
...@@ -4629,9 +4629,10 @@ cast(void *ptr, PyObject *src, PyObject *ctype) ...@@ -4629,9 +4629,10 @@ cast(void *ptr, PyObject *src, PyObject *ctype)
static PyObject * static PyObject *
wstring_at(const wchar_t *ptr, int size) wstring_at(const wchar_t *ptr, int size)
{ {
if (size == -1) Py_ssize_t ssize = size;
size = wcslen(ptr); if (ssize == -1)
return PyUnicode_FromWideChar(ptr, size); ssize = wcslen(ptr);
return PyUnicode_FromWideChar(ptr, ssize);
} }
#endif #endif
...@@ -4831,7 +4832,7 @@ PyObject *My_PyUnicode_FromWideChar(register const wchar_t *w, ...@@ -4831,7 +4832,7 @@ PyObject *My_PyUnicode_FromWideChar(register const wchar_t *w,
return (PyObject *)unicode; return (PyObject *)unicode;
} }
int My_PyUnicode_AsWideChar(PyUnicodeObject *unicode, Py_ssize_t My_PyUnicode_AsWideChar(PyUnicodeObject *unicode,
register wchar_t *w, register wchar_t *w,
Py_ssize_t size) Py_ssize_t size)
{ {
......
...@@ -123,10 +123,10 @@ static void _CallPythonObject(void *mem, ...@@ -123,10 +123,10 @@ static void _CallPythonObject(void *mem,
PyObject *converters, PyObject *converters,
void **pArgs) void **pArgs)
{ {
int i; Py_ssize_t i;
PyObject *result; PyObject *result;
PyObject *arglist = NULL; PyObject *arglist = NULL;
int nArgs; Py_ssize_t nArgs;
#ifdef WITH_THREAD #ifdef WITH_THREAD
PyGILState_STATE state = PyGILState_Ensure(); PyGILState_STATE state = PyGILState_Ensure();
#endif #endif
...@@ -264,7 +264,7 @@ ffi_info *AllocFunctionCallback(PyObject *callable, ...@@ -264,7 +264,7 @@ ffi_info *AllocFunctionCallback(PyObject *callable,
{ {
int result; int result;
ffi_info *p; ffi_info *p;
int nArgs, i; Py_ssize_t nArgs, i;
ffi_abi cc; ffi_abi cc;
nArgs = PySequence_Size(converters); nArgs = PySequence_Size(converters);
...@@ -307,7 +307,8 @@ ffi_info *AllocFunctionCallback(PyObject *callable, ...@@ -307,7 +307,8 @@ ffi_info *AllocFunctionCallback(PyObject *callable,
if (is_cdecl == 0) if (is_cdecl == 0)
cc = FFI_STDCALL; cc = FFI_STDCALL;
#endif #endif
result = ffi_prep_cif(&p->cif, cc, nArgs, result = ffi_prep_cif(&p->cif, cc,
Py_SAFE_DOWNCAST(nArgs, Py_ssize_t, int),
GetType(restype), GetType(restype),
&p->atypes[0]); &p->atypes[0]);
if (result != FFI_OK) { if (result != FFI_OK) {
......
...@@ -361,13 +361,13 @@ PyCArg_repr(PyCArgObject *self) ...@@ -361,13 +361,13 @@ PyCArg_repr(PyCArgObject *self)
case 'z': case 'z':
case 'Z': case 'Z':
case 'P': case 'P':
sprintf(buffer, "<cparam '%c' (%08lx)>", sprintf(buffer, "<cparam '%c' (%p)>",
self->tag, (long)self->value.p); self->tag, self->value.p);
break; break;
default: default:
sprintf(buffer, "<cparam '%c' at %08lx>", sprintf(buffer, "<cparam '%c' at %p>",
self->tag, (long)self); self->tag, self);
break; break;
} }
return PyString_FromString(buffer); return PyString_FromString(buffer);
...@@ -464,7 +464,7 @@ struct argument { ...@@ -464,7 +464,7 @@ struct argument {
/* /*
* Convert a single Python object into a PyCArgObject and return it. * Convert a single Python object into a PyCArgObject and return it.
*/ */
static int ConvParam(PyObject *obj, int index, struct argument *pa) static int ConvParam(PyObject *obj, Py_ssize_t index, struct argument *pa)
{ {
StgDictObject *dict; StgDictObject *dict;
pa->keep = NULL; /* so we cannot forget it later */ pa->keep = NULL; /* so we cannot forget it later */
...@@ -572,7 +572,8 @@ static int ConvParam(PyObject *obj, int index, struct argument *pa) ...@@ -572,7 +572,8 @@ static int ConvParam(PyObject *obj, int index, struct argument *pa)
return result; return result;
} }
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"Don't know how to convert parameter %d", index); "Don't know how to convert parameter %d",
Py_SAFE_DOWNCAST(index, Py_ssize_t, int));
return -1; return -1;
} }
} }
...@@ -912,7 +913,7 @@ PyObject *_CallProc(PPROC pProc, ...@@ -912,7 +913,7 @@ PyObject *_CallProc(PPROC pProc,
PyObject *restype, PyObject *restype,
PyObject *checker) PyObject *checker)
{ {
int i, n, argcount, argtype_count; Py_ssize_t i, n, argcount, argtype_count;
void *resbuf; void *resbuf;
struct argument *args, *pa; struct argument *args, *pa;
ffi_type **atypes; ffi_type **atypes;
...@@ -1002,7 +1003,10 @@ PyObject *_CallProc(PPROC pProc, ...@@ -1002,7 +1003,10 @@ PyObject *_CallProc(PPROC pProc,
} }
if (-1 == _call_function_pointer(flags, pProc, avalues, atypes, if (-1 == _call_function_pointer(flags, pProc, avalues, atypes,
rtype, resbuf, argcount)) rtype, resbuf,
Py_SAFE_DOWNCAST(argcount,
Py_ssize_t,
int)))
goto cleanup; goto cleanup;
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
...@@ -1358,10 +1362,10 @@ sizeof_func(PyObject *self, PyObject *obj) ...@@ -1358,10 +1362,10 @@ sizeof_func(PyObject *self, PyObject *obj)
dict = PyType_stgdict(obj); dict = PyType_stgdict(obj);
if (dict) if (dict)
return PyInt_FromLong(dict->size); return PyInt_FromSsize_t(dict->size);
if (CDataObject_Check(obj)) if (CDataObject_Check(obj))
return PyInt_FromLong(((CDataObject *)obj)->b_size); return PyInt_FromSsize_t(((CDataObject *)obj)->b_size);
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"this type has no size"); "this type has no size");
return NULL; return NULL;
...@@ -1379,11 +1383,11 @@ align_func(PyObject *self, PyObject *obj) ...@@ -1379,11 +1383,11 @@ align_func(PyObject *self, PyObject *obj)
dict = PyType_stgdict(obj); dict = PyType_stgdict(obj);
if (dict) if (dict)
return PyInt_FromLong(dict->align); return PyInt_FromSsize_t(dict->align);
dict = PyObject_stgdict(obj); dict = PyObject_stgdict(obj);
if (dict) if (dict)
return PyInt_FromLong(dict->align); return PyInt_FromSsize_t(dict->align);
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"no alignment info"); "no alignment info");
......
...@@ -35,14 +35,14 @@ CField_new(PyTypeObject *type, PyObject *args, PyObject *kwds) ...@@ -35,14 +35,14 @@ 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, int index, CField_FromDesc(PyObject *desc, Py_ssize_t index,
int *pfield_size, int bitsize, int *pbitofs, Py_ssize_t *pfield_size, int bitsize, int *pbitofs,
int *psize, int *poffset, int *palign, Py_ssize_t *psize, Py_ssize_t *poffset, Py_ssize_t *palign,
int pack, int big_endian) int pack, int big_endian)
{ {
CFieldObject *self; CFieldObject *self;
PyObject *proto; PyObject *proto;
int size, align, length; Py_ssize_t size, align, length;
SETFUNC setfunc = NULL; SETFUNC setfunc = NULL;
GETFUNC getfunc = NULL; GETFUNC getfunc = NULL;
StgDictObject *dict; StgDictObject *dict;
...@@ -147,7 +147,7 @@ CField_FromDesc(PyObject *desc, int index, ...@@ -147,7 +147,7 @@ CField_FromDesc(PyObject *desc, int index,
else else
align = dict->align; align = dict->align;
if (align && *poffset % align) { if (align && *poffset % align) {
int delta = align - (*poffset % align); Py_ssize_t delta = align - (*poffset % align);
*psize += delta; *psize += delta;
*poffset += delta; *poffset += delta;
} }
...@@ -268,8 +268,8 @@ static PyObject * ...@@ -268,8 +268,8 @@ static PyObject *
CField_repr(CFieldObject *self) CField_repr(CFieldObject *self)
{ {
PyObject *result; PyObject *result;
int bits = self->size >> 16; Py_ssize_t bits = self->size >> 16;
int size = self->size & 0xFFFF; Py_ssize_t size = self->size & 0xFFFF;
const char *name; const char *name;
name = ((PyTypeObject *)self->proto)->tp_name; name = ((PyTypeObject *)self->proto)->tp_name;
...@@ -519,7 +519,7 @@ get_ulonglong(PyObject *v, unsigned PY_LONG_LONG *p) ...@@ -519,7 +519,7 @@ get_ulonglong(PyObject *v, unsigned PY_LONG_LONG *p)
*/ */
static PyObject * static PyObject *
b_set(void *ptr, PyObject *value, unsigned size) b_set(void *ptr, PyObject *value, Py_ssize_t size)
{ {
long val; long val;
if (get_long(value, &val) < 0) if (get_long(value, &val) < 0)
...@@ -530,7 +530,7 @@ b_set(void *ptr, PyObject *value, unsigned size) ...@@ -530,7 +530,7 @@ b_set(void *ptr, PyObject *value, unsigned size)
static PyObject * static PyObject *
b_get(void *ptr, unsigned size) b_get(void *ptr, Py_ssize_t size)
{ {
signed char val = *(signed char *)ptr; signed char val = *(signed char *)ptr;
GET_BITFIELD(val, size); GET_BITFIELD(val, size);
...@@ -538,7 +538,7 @@ b_get(void *ptr, unsigned size) ...@@ -538,7 +538,7 @@ b_get(void *ptr, unsigned size)
} }
static PyObject * static PyObject *
B_set(void *ptr, PyObject *value, unsigned size) B_set(void *ptr, PyObject *value, Py_ssize_t size)
{ {
unsigned long val; unsigned long val;
if (get_ulong(value, &val) < 0) if (get_ulong(value, &val) < 0)
...@@ -550,7 +550,7 @@ B_set(void *ptr, PyObject *value, unsigned size) ...@@ -550,7 +550,7 @@ B_set(void *ptr, PyObject *value, unsigned size)
static PyObject * static PyObject *
B_get(void *ptr, unsigned size) B_get(void *ptr, Py_ssize_t size)
{ {
unsigned char val = *(unsigned char *)ptr; unsigned char val = *(unsigned char *)ptr;
GET_BITFIELD(val, size); GET_BITFIELD(val, size);
...@@ -558,7 +558,7 @@ B_get(void *ptr, unsigned size) ...@@ -558,7 +558,7 @@ B_get(void *ptr, unsigned size)
} }
static PyObject * static PyObject *
h_set(void *ptr, PyObject *value, unsigned size) h_set(void *ptr, PyObject *value, Py_ssize_t size)
{ {
long val; long val;
short x; short x;
...@@ -572,7 +572,7 @@ h_set(void *ptr, PyObject *value, unsigned size) ...@@ -572,7 +572,7 @@ h_set(void *ptr, PyObject *value, unsigned size)
static PyObject * static PyObject *
h_set_sw(void *ptr, PyObject *value, unsigned size) h_set_sw(void *ptr, PyObject *value, Py_ssize_t size)
{ {
long val; long val;
short field; short field;
...@@ -587,7 +587,7 @@ h_set_sw(void *ptr, PyObject *value, unsigned size) ...@@ -587,7 +587,7 @@ h_set_sw(void *ptr, PyObject *value, unsigned size)
} }
static PyObject * static PyObject *
h_get(void *ptr, unsigned size) h_get(void *ptr, Py_ssize_t size)
{ {
short val; short val;
memcpy(&val, ptr, sizeof(val)); memcpy(&val, ptr, sizeof(val));
...@@ -596,7 +596,7 @@ h_get(void *ptr, unsigned size) ...@@ -596,7 +596,7 @@ h_get(void *ptr, unsigned size)
} }
static PyObject * static PyObject *
h_get_sw(void *ptr, unsigned size) h_get_sw(void *ptr, Py_ssize_t size)
{ {
short val; short val;
memcpy(&val, ptr, sizeof(val)); memcpy(&val, ptr, sizeof(val));
...@@ -606,7 +606,7 @@ h_get_sw(void *ptr, unsigned size) ...@@ -606,7 +606,7 @@ h_get_sw(void *ptr, unsigned size)
} }
static PyObject * static PyObject *
H_set(void *ptr, PyObject *value, unsigned size) H_set(void *ptr, PyObject *value, Py_ssize_t size)
{ {
unsigned long val; unsigned long val;
unsigned short x; unsigned short x;
...@@ -619,7 +619,7 @@ H_set(void *ptr, PyObject *value, unsigned size) ...@@ -619,7 +619,7 @@ H_set(void *ptr, PyObject *value, unsigned size)
} }
static PyObject * static PyObject *
H_set_sw(void *ptr, PyObject *value, unsigned size) H_set_sw(void *ptr, PyObject *value, Py_ssize_t size)
{ {
unsigned long val; unsigned long val;
unsigned short field; unsigned short field;
...@@ -635,7 +635,7 @@ H_set_sw(void *ptr, PyObject *value, unsigned size) ...@@ -635,7 +635,7 @@ H_set_sw(void *ptr, PyObject *value, unsigned size)
static PyObject * static PyObject *
H_get(void *ptr, unsigned size) H_get(void *ptr, Py_ssize_t size)
{ {
unsigned short val; unsigned short val;
memcpy(&val, ptr, sizeof(val)); memcpy(&val, ptr, sizeof(val));
...@@ -644,7 +644,7 @@ H_get(void *ptr, unsigned size) ...@@ -644,7 +644,7 @@ H_get(void *ptr, unsigned size)
} }
static PyObject * static PyObject *
H_get_sw(void *ptr, unsigned size) H_get_sw(void *ptr, Py_ssize_t size)
{ {
unsigned short val; unsigned short val;
memcpy(&val, ptr, sizeof(val)); memcpy(&val, ptr, sizeof(val));
...@@ -654,7 +654,7 @@ H_get_sw(void *ptr, unsigned size) ...@@ -654,7 +654,7 @@ H_get_sw(void *ptr, unsigned size)
} }
static PyObject * static PyObject *
i_set(void *ptr, PyObject *value, unsigned size) i_set(void *ptr, PyObject *value, Py_ssize_t size)
{ {
long val; long val;
int x; int x;
...@@ -667,7 +667,7 @@ i_set(void *ptr, PyObject *value, unsigned size) ...@@ -667,7 +667,7 @@ i_set(void *ptr, PyObject *value, unsigned size)
} }
static PyObject * static PyObject *
i_set_sw(void *ptr, PyObject *value, unsigned size) i_set_sw(void *ptr, PyObject *value, Py_ssize_t size)
{ {
long val; long val;
int field; int field;
...@@ -683,7 +683,7 @@ i_set_sw(void *ptr, PyObject *value, unsigned size) ...@@ -683,7 +683,7 @@ i_set_sw(void *ptr, PyObject *value, unsigned size)
static PyObject * static PyObject *
i_get(void *ptr, unsigned size) i_get(void *ptr, Py_ssize_t size)
{ {
int val; int val;
memcpy(&val, ptr, sizeof(val)); memcpy(&val, ptr, sizeof(val));
...@@ -692,7 +692,7 @@ i_get(void *ptr, unsigned size) ...@@ -692,7 +692,7 @@ i_get(void *ptr, unsigned size)
} }
static PyObject * static PyObject *
i_get_sw(void *ptr, unsigned size) i_get_sw(void *ptr, Py_ssize_t size)
{ {
int val; int val;
memcpy(&val, ptr, sizeof(val)); memcpy(&val, ptr, sizeof(val));
...@@ -704,7 +704,7 @@ i_get_sw(void *ptr, unsigned size) ...@@ -704,7 +704,7 @@ i_get_sw(void *ptr, unsigned size)
#ifdef MS_WIN32 #ifdef MS_WIN32
/* short BOOL - VARIANT_BOOL */ /* short BOOL - VARIANT_BOOL */
static PyObject * static PyObject *
vBOOL_set(void *ptr, PyObject *value, unsigned size) vBOOL_set(void *ptr, PyObject *value, Py_ssize_t size)
{ {
switch (PyObject_IsTrue(value)) { switch (PyObject_IsTrue(value)) {
case -1: case -1:
...@@ -719,7 +719,7 @@ vBOOL_set(void *ptr, PyObject *value, unsigned size) ...@@ -719,7 +719,7 @@ vBOOL_set(void *ptr, PyObject *value, unsigned size)
} }
static PyObject * static PyObject *
vBOOL_get(void *ptr, unsigned size) vBOOL_get(void *ptr, Py_ssize_t size)
{ {
return PyBool_FromLong((long)*(short int *)ptr); return PyBool_FromLong((long)*(short int *)ptr);
} }
...@@ -734,7 +734,7 @@ vBOOL_get(void *ptr, unsigned size) ...@@ -734,7 +734,7 @@ vBOOL_get(void *ptr, unsigned size)
#endif #endif
static PyObject * static PyObject *
t_set(void *ptr, PyObject *value, unsigned size) t_set(void *ptr, PyObject *value, Py_ssize_t size)
{ {
switch (PyObject_IsTrue(value)) { switch (PyObject_IsTrue(value)) {
case -1: case -1:
...@@ -749,13 +749,13 @@ t_set(void *ptr, PyObject *value, unsigned size) ...@@ -749,13 +749,13 @@ t_set(void *ptr, PyObject *value, unsigned size)
} }
static PyObject * static PyObject *
t_get(void *ptr, unsigned size) t_get(void *ptr, Py_ssize_t size)
{ {
return PyBool_FromLong((long)*(BOOL_TYPE *)ptr); return PyBool_FromLong((long)*(BOOL_TYPE *)ptr);
} }
static PyObject * static PyObject *
I_set(void *ptr, PyObject *value, unsigned size) I_set(void *ptr, PyObject *value, Py_ssize_t size)
{ {
unsigned long val; unsigned long val;
unsigned int x; unsigned int x;
...@@ -768,7 +768,7 @@ I_set(void *ptr, PyObject *value, unsigned size) ...@@ -768,7 +768,7 @@ I_set(void *ptr, PyObject *value, unsigned size)
} }
static PyObject * static PyObject *
I_set_sw(void *ptr, PyObject *value, unsigned size) I_set_sw(void *ptr, PyObject *value, Py_ssize_t size)
{ {
unsigned long val; unsigned long val;
unsigned int field; unsigned int field;
...@@ -783,7 +783,7 @@ I_set_sw(void *ptr, PyObject *value, unsigned size) ...@@ -783,7 +783,7 @@ I_set_sw(void *ptr, PyObject *value, unsigned size)
static PyObject * static PyObject *
I_get(void *ptr, unsigned size) I_get(void *ptr, Py_ssize_t size)
{ {
unsigned int val; unsigned int val;
memcpy(&val, ptr, sizeof(val)); memcpy(&val, ptr, sizeof(val));
...@@ -792,7 +792,7 @@ I_get(void *ptr, unsigned size) ...@@ -792,7 +792,7 @@ I_get(void *ptr, unsigned size)
} }
static PyObject * static PyObject *
I_get_sw(void *ptr, unsigned size) I_get_sw(void *ptr, Py_ssize_t size)
{ {
unsigned int val; unsigned int val;
memcpy(&val, ptr, sizeof(val)); memcpy(&val, ptr, sizeof(val));
...@@ -802,7 +802,7 @@ I_get_sw(void *ptr, unsigned size) ...@@ -802,7 +802,7 @@ I_get_sw(void *ptr, unsigned size)
} }
static PyObject * static PyObject *
l_set(void *ptr, PyObject *value, unsigned size) l_set(void *ptr, PyObject *value, Py_ssize_t size)
{ {
long val; long val;
long x; long x;
...@@ -815,7 +815,7 @@ l_set(void *ptr, PyObject *value, unsigned size) ...@@ -815,7 +815,7 @@ l_set(void *ptr, PyObject *value, unsigned size)
} }
static PyObject * static PyObject *
l_set_sw(void *ptr, PyObject *value, unsigned size) l_set_sw(void *ptr, PyObject *value, Py_ssize_t size)
{ {
long val; long val;
long field; long field;
...@@ -831,7 +831,7 @@ l_set_sw(void *ptr, PyObject *value, unsigned size) ...@@ -831,7 +831,7 @@ l_set_sw(void *ptr, PyObject *value, unsigned size)
static PyObject * static PyObject *
l_get(void *ptr, unsigned size) l_get(void *ptr, Py_ssize_t size)
{ {
long val; long val;
memcpy(&val, ptr, sizeof(val)); memcpy(&val, ptr, sizeof(val));
...@@ -840,7 +840,7 @@ l_get(void *ptr, unsigned size) ...@@ -840,7 +840,7 @@ l_get(void *ptr, unsigned size)
} }
static PyObject * static PyObject *
l_get_sw(void *ptr, unsigned size) l_get_sw(void *ptr, Py_ssize_t size)
{ {
long val; long val;
memcpy(&val, ptr, sizeof(val)); memcpy(&val, ptr, sizeof(val));
...@@ -850,7 +850,7 @@ l_get_sw(void *ptr, unsigned size) ...@@ -850,7 +850,7 @@ l_get_sw(void *ptr, unsigned size)
} }
static PyObject * static PyObject *
L_set(void *ptr, PyObject *value, unsigned size) L_set(void *ptr, PyObject *value, Py_ssize_t size)
{ {
unsigned long val; unsigned long val;
unsigned long x; unsigned long x;
...@@ -863,7 +863,7 @@ L_set(void *ptr, PyObject *value, unsigned size) ...@@ -863,7 +863,7 @@ L_set(void *ptr, PyObject *value, unsigned size)
} }
static PyObject * static PyObject *
L_set_sw(void *ptr, PyObject *value, unsigned size) L_set_sw(void *ptr, PyObject *value, Py_ssize_t size)
{ {
unsigned long val; unsigned long val;
unsigned long field; unsigned long field;
...@@ -879,7 +879,7 @@ L_set_sw(void *ptr, PyObject *value, unsigned size) ...@@ -879,7 +879,7 @@ L_set_sw(void *ptr, PyObject *value, unsigned size)
static PyObject * static PyObject *
L_get(void *ptr, unsigned size) L_get(void *ptr, Py_ssize_t size)
{ {
unsigned long val; unsigned long val;
memcpy(&val, ptr, sizeof(val)); memcpy(&val, ptr, sizeof(val));
...@@ -888,7 +888,7 @@ L_get(void *ptr, unsigned size) ...@@ -888,7 +888,7 @@ L_get(void *ptr, unsigned size)
} }
static PyObject * static PyObject *
L_get_sw(void *ptr, unsigned size) L_get_sw(void *ptr, Py_ssize_t size)
{ {
unsigned long val; unsigned long val;
memcpy(&val, ptr, sizeof(val)); memcpy(&val, ptr, sizeof(val));
...@@ -899,7 +899,7 @@ L_get_sw(void *ptr, unsigned size) ...@@ -899,7 +899,7 @@ L_get_sw(void *ptr, unsigned size)
#ifdef HAVE_LONG_LONG #ifdef HAVE_LONG_LONG
static PyObject * static PyObject *
q_set(void *ptr, PyObject *value, unsigned size) q_set(void *ptr, PyObject *value, Py_ssize_t size)
{ {
PY_LONG_LONG val; PY_LONG_LONG val;
PY_LONG_LONG x; PY_LONG_LONG x;
...@@ -912,7 +912,7 @@ q_set(void *ptr, PyObject *value, unsigned size) ...@@ -912,7 +912,7 @@ q_set(void *ptr, PyObject *value, unsigned size)
} }
static PyObject * static PyObject *
q_set_sw(void *ptr, PyObject *value, unsigned size) q_set_sw(void *ptr, PyObject *value, Py_ssize_t size)
{ {
PY_LONG_LONG val; PY_LONG_LONG val;
PY_LONG_LONG field; PY_LONG_LONG field;
...@@ -927,7 +927,7 @@ q_set_sw(void *ptr, PyObject *value, unsigned size) ...@@ -927,7 +927,7 @@ q_set_sw(void *ptr, PyObject *value, unsigned size)
} }
static PyObject * static PyObject *
q_get(void *ptr, unsigned size) q_get(void *ptr, Py_ssize_t size)
{ {
PY_LONG_LONG val; PY_LONG_LONG val;
memcpy(&val, ptr, sizeof(val)); memcpy(&val, ptr, sizeof(val));
...@@ -936,7 +936,7 @@ q_get(void *ptr, unsigned size) ...@@ -936,7 +936,7 @@ q_get(void *ptr, unsigned size)
} }
static PyObject * static PyObject *
q_get_sw(void *ptr, unsigned size) q_get_sw(void *ptr, Py_ssize_t size)
{ {
PY_LONG_LONG val; PY_LONG_LONG val;
memcpy(&val, ptr, sizeof(val)); memcpy(&val, ptr, sizeof(val));
...@@ -946,7 +946,7 @@ q_get_sw(void *ptr, unsigned size) ...@@ -946,7 +946,7 @@ q_get_sw(void *ptr, unsigned size)
} }
static PyObject * static PyObject *
Q_set(void *ptr, PyObject *value, unsigned size) Q_set(void *ptr, PyObject *value, Py_ssize_t size)
{ {
unsigned PY_LONG_LONG val; unsigned PY_LONG_LONG val;
unsigned PY_LONG_LONG x; unsigned PY_LONG_LONG x;
...@@ -959,7 +959,7 @@ Q_set(void *ptr, PyObject *value, unsigned size) ...@@ -959,7 +959,7 @@ Q_set(void *ptr, PyObject *value, unsigned size)
} }
static PyObject * static PyObject *
Q_set_sw(void *ptr, PyObject *value, unsigned size) Q_set_sw(void *ptr, PyObject *value, Py_ssize_t size)
{ {
unsigned PY_LONG_LONG val; unsigned PY_LONG_LONG val;
unsigned PY_LONG_LONG field; unsigned PY_LONG_LONG field;
...@@ -974,7 +974,7 @@ Q_set_sw(void *ptr, PyObject *value, unsigned size) ...@@ -974,7 +974,7 @@ Q_set_sw(void *ptr, PyObject *value, unsigned size)
} }
static PyObject * static PyObject *
Q_get(void *ptr, unsigned size) Q_get(void *ptr, Py_ssize_t size)
{ {
unsigned PY_LONG_LONG val; unsigned PY_LONG_LONG val;
memcpy(&val, ptr, sizeof(val)); memcpy(&val, ptr, sizeof(val));
...@@ -983,7 +983,7 @@ Q_get(void *ptr, unsigned size) ...@@ -983,7 +983,7 @@ Q_get(void *ptr, unsigned size)
} }
static PyObject * static PyObject *
Q_get_sw(void *ptr, unsigned size) Q_get_sw(void *ptr, Py_ssize_t size)
{ {
unsigned PY_LONG_LONG val; unsigned PY_LONG_LONG val;
memcpy(&val, ptr, sizeof(val)); memcpy(&val, ptr, sizeof(val));
...@@ -1000,7 +1000,7 @@ Q_get_sw(void *ptr, unsigned size) ...@@ -1000,7 +1000,7 @@ Q_get_sw(void *ptr, unsigned size)
static PyObject * static PyObject *
d_set(void *ptr, PyObject *value, unsigned size) d_set(void *ptr, PyObject *value, Py_ssize_t size)
{ {
double x; double x;
...@@ -1016,7 +1016,7 @@ d_set(void *ptr, PyObject *value, unsigned size) ...@@ -1016,7 +1016,7 @@ d_set(void *ptr, PyObject *value, unsigned size)
} }
static PyObject * static PyObject *
d_get(void *ptr, unsigned size) d_get(void *ptr, Py_ssize_t size)
{ {
double val; double val;
memcpy(&val, ptr, sizeof(val)); memcpy(&val, ptr, sizeof(val));
...@@ -1024,7 +1024,7 @@ d_get(void *ptr, unsigned size) ...@@ -1024,7 +1024,7 @@ d_get(void *ptr, unsigned size)
} }
static PyObject * static PyObject *
d_set_sw(void *ptr, PyObject *value, unsigned size) d_set_sw(void *ptr, PyObject *value, Py_ssize_t size)
{ {
double x; double x;
...@@ -1046,7 +1046,7 @@ d_set_sw(void *ptr, PyObject *value, unsigned size) ...@@ -1046,7 +1046,7 @@ d_set_sw(void *ptr, PyObject *value, unsigned size)
} }
static PyObject * static PyObject *
d_get_sw(void *ptr, unsigned size) d_get_sw(void *ptr, Py_ssize_t size)
{ {
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
return PyFloat_FromDouble(_PyFloat_Unpack8(ptr, 1)); return PyFloat_FromDouble(_PyFloat_Unpack8(ptr, 1));
...@@ -1056,7 +1056,7 @@ d_get_sw(void *ptr, unsigned size) ...@@ -1056,7 +1056,7 @@ d_get_sw(void *ptr, unsigned size)
} }
static PyObject * static PyObject *
f_set(void *ptr, PyObject *value, unsigned size) f_set(void *ptr, PyObject *value, Py_ssize_t size)
{ {
float x; float x;
...@@ -1072,7 +1072,7 @@ f_set(void *ptr, PyObject *value, unsigned size) ...@@ -1072,7 +1072,7 @@ f_set(void *ptr, PyObject *value, unsigned size)
} }
static PyObject * static PyObject *
f_get(void *ptr, unsigned size) f_get(void *ptr, Py_ssize_t size)
{ {
float val; float val;
memcpy(&val, ptr, sizeof(val)); memcpy(&val, ptr, sizeof(val));
...@@ -1080,7 +1080,7 @@ f_get(void *ptr, unsigned size) ...@@ -1080,7 +1080,7 @@ f_get(void *ptr, unsigned size)
} }
static PyObject * static PyObject *
f_set_sw(void *ptr, PyObject *value, unsigned size) f_set_sw(void *ptr, PyObject *value, Py_ssize_t size)
{ {
float x; float x;
...@@ -1102,7 +1102,7 @@ f_set_sw(void *ptr, PyObject *value, unsigned size) ...@@ -1102,7 +1102,7 @@ f_set_sw(void *ptr, PyObject *value, unsigned size)
} }
static PyObject * static PyObject *
f_get_sw(void *ptr, unsigned size) f_get_sw(void *ptr, Py_ssize_t size)
{ {
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
return PyFloat_FromDouble(_PyFloat_Unpack4(ptr, 1)); return PyFloat_FromDouble(_PyFloat_Unpack4(ptr, 1));
...@@ -1122,7 +1122,7 @@ f_get_sw(void *ptr, unsigned size) ...@@ -1122,7 +1122,7 @@ f_get_sw(void *ptr, unsigned size)
Py_DECREF on destruction. Maybe only when b_needsfree is non-zero. Py_DECREF on destruction. Maybe only when b_needsfree is non-zero.
*/ */
static PyObject * static PyObject *
O_get(void *ptr, unsigned size) O_get(void *ptr, Py_ssize_t size)
{ {
PyObject *ob = *(PyObject **)ptr; PyObject *ob = *(PyObject **)ptr;
if (ob == NULL) { if (ob == NULL) {
...@@ -1137,7 +1137,7 @@ O_get(void *ptr, unsigned size) ...@@ -1137,7 +1137,7 @@ O_get(void *ptr, unsigned size)
} }
static PyObject * static PyObject *
O_set(void *ptr, PyObject *value, unsigned size) O_set(void *ptr, PyObject *value, Py_ssize_t size)
{ {
/* Hm, does the memory block need it's own refcount or not? */ /* Hm, does the memory block need it's own refcount or not? */
*(PyObject **)ptr = value; *(PyObject **)ptr = value;
...@@ -1147,7 +1147,7 @@ O_set(void *ptr, PyObject *value, unsigned size) ...@@ -1147,7 +1147,7 @@ O_set(void *ptr, PyObject *value, unsigned size)
static PyObject * static PyObject *
c_set(void *ptr, PyObject *value, unsigned size) c_set(void *ptr, PyObject *value, Py_ssize_t size)
{ {
if (!PyString_Check(value) || (1 != PyString_Size(value))) { if (!PyString_Check(value) || (1 != PyString_Size(value))) {
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
...@@ -1160,7 +1160,7 @@ c_set(void *ptr, PyObject *value, unsigned size) ...@@ -1160,7 +1160,7 @@ c_set(void *ptr, PyObject *value, unsigned size)
static PyObject * static PyObject *
c_get(void *ptr, unsigned size) c_get(void *ptr, Py_ssize_t size)
{ {
return PyString_FromStringAndSize((char *)ptr, 1); return PyString_FromStringAndSize((char *)ptr, 1);
} }
...@@ -1168,9 +1168,9 @@ c_get(void *ptr, unsigned size) ...@@ -1168,9 +1168,9 @@ c_get(void *ptr, unsigned size)
#ifdef CTYPES_UNICODE #ifdef CTYPES_UNICODE
/* u - a single wchar_t character */ /* u - a single wchar_t character */
static PyObject * static PyObject *
u_set(void *ptr, PyObject *value, unsigned size) u_set(void *ptr, PyObject *value, Py_ssize_t size)
{ {
int len; Py_ssize_t len;
if (PyString_Check(value)) { if (PyString_Check(value)) {
value = PyUnicode_FromEncodedObject(value, value = PyUnicode_FromEncodedObject(value,
...@@ -1202,17 +1202,17 @@ u_set(void *ptr, PyObject *value, unsigned size) ...@@ -1202,17 +1202,17 @@ u_set(void *ptr, PyObject *value, unsigned size)
static PyObject * static PyObject *
u_get(void *ptr, unsigned size) u_get(void *ptr, Py_ssize_t size)
{ {
return PyUnicode_FromWideChar((wchar_t *)ptr, 1); return PyUnicode_FromWideChar((wchar_t *)ptr, 1);
} }
/* U - a unicode string */ /* U - a unicode string */
static PyObject * static PyObject *
U_get(void *ptr, unsigned size) U_get(void *ptr, Py_ssize_t size)
{ {
PyObject *result; PyObject *result;
unsigned int len; Py_ssize_t len;
Py_UNICODE *p; Py_UNICODE *p;
size /= sizeof(wchar_t); /* we count character units here, not bytes */ size /= sizeof(wchar_t); /* we count character units here, not bytes */
...@@ -1240,9 +1240,9 @@ U_get(void *ptr, unsigned size) ...@@ -1240,9 +1240,9 @@ U_get(void *ptr, unsigned size)
} }
static PyObject * static PyObject *
U_set(void *ptr, PyObject *value, unsigned length) U_set(void *ptr, PyObject *value, Py_ssize_t length)
{ {
unsigned int size; Py_ssize_t size;
/* It's easier to calculate in characters than in bytes */ /* It's easier to calculate in characters than in bytes */
length /= sizeof(wchar_t); length /= sizeof(wchar_t);
...@@ -1277,9 +1277,10 @@ U_set(void *ptr, PyObject *value, unsigned length) ...@@ -1277,9 +1277,10 @@ U_set(void *ptr, PyObject *value, unsigned length)
#endif #endif
static PyObject * static PyObject *
s_get(void *ptr, unsigned size) s_get(void *ptr, Py_ssize_t size)
{ {
PyObject *result; PyObject *result;
size_t slen;
result = PyString_FromString((char *)ptr); result = PyString_FromString((char *)ptr);
if (!result) if (!result)
...@@ -1287,7 +1288,8 @@ s_get(void *ptr, unsigned size) ...@@ -1287,7 +1288,8 @@ s_get(void *ptr, unsigned size)
/* chop off at the first NUL character, if any. /* chop off at the first NUL character, if any.
* On error, result will be deallocated and set to NULL. * On error, result will be deallocated and set to NULL.
*/ */
size = min(size, strlen(PyString_AS_STRING(result))); slen = strlen(PyString_AS_STRING(result));
size = min(size, (Py_ssize_t)slen);
if (result->ob_refcnt == 1) { if (result->ob_refcnt == 1) {
/* shorten the result */ /* shorten the result */
_PyString_Resize(&result, size); _PyString_Resize(&result, size);
...@@ -1298,10 +1300,10 @@ s_get(void *ptr, unsigned size) ...@@ -1298,10 +1300,10 @@ s_get(void *ptr, unsigned size)
} }
static PyObject * static PyObject *
s_set(void *ptr, PyObject *value, unsigned length) s_set(void *ptr, PyObject *value, Py_ssize_t length)
{ {
char *data; char *data;
unsigned size; Py_ssize_t size;
data = PyString_AsString(value); data = PyString_AsString(value);
if (!data) if (!data)
...@@ -1324,7 +1326,7 @@ s_set(void *ptr, PyObject *value, unsigned length) ...@@ -1324,7 +1326,7 @@ s_set(void *ptr, PyObject *value, unsigned length)
} }
static PyObject * static PyObject *
z_set(void *ptr, PyObject *value, unsigned size) z_set(void *ptr, PyObject *value, Py_ssize_t size)
{ {
if (value == Py_None) { if (value == Py_None) {
*(char **)ptr = NULL; *(char **)ptr = NULL;
...@@ -1358,7 +1360,7 @@ z_set(void *ptr, PyObject *value, unsigned size) ...@@ -1358,7 +1360,7 @@ z_set(void *ptr, PyObject *value, unsigned size)
} }
static PyObject * static PyObject *
z_get(void *ptr, unsigned size) z_get(void *ptr, Py_ssize_t size)
{ {
/* XXX What about invalid pointers ??? */ /* XXX What about invalid pointers ??? */
if (*(void **)ptr) { if (*(void **)ptr) {
...@@ -1379,7 +1381,7 @@ z_get(void *ptr, unsigned size) ...@@ -1379,7 +1381,7 @@ z_get(void *ptr, unsigned size)
#ifdef CTYPES_UNICODE #ifdef CTYPES_UNICODE
static PyObject * static PyObject *
Z_set(void *ptr, PyObject *value, unsigned size) Z_set(void *ptr, PyObject *value, Py_ssize_t size)
{ {
if (value == Py_None) { if (value == Py_None) {
*(wchar_t **)ptr = NULL; *(wchar_t **)ptr = NULL;
...@@ -1447,7 +1449,7 @@ Z_set(void *ptr, PyObject *value, unsigned size) ...@@ -1447,7 +1449,7 @@ Z_set(void *ptr, PyObject *value, unsigned size)
} }
static PyObject * static PyObject *
Z_get(void *ptr, unsigned size) Z_get(void *ptr, Py_ssize_t size)
{ {
wchar_t *p; wchar_t *p;
p = *(wchar_t **)ptr; p = *(wchar_t **)ptr;
...@@ -1470,7 +1472,7 @@ Z_get(void *ptr, unsigned size) ...@@ -1470,7 +1472,7 @@ Z_get(void *ptr, unsigned size)
#ifdef MS_WIN32 #ifdef MS_WIN32
static PyObject * static PyObject *
BSTR_set(void *ptr, PyObject *value, unsigned size) BSTR_set(void *ptr, PyObject *value, Py_ssize_t size)
{ {
BSTR bstr; BSTR bstr;
...@@ -1494,8 +1496,13 @@ BSTR_set(void *ptr, PyObject *value, unsigned size) ...@@ -1494,8 +1496,13 @@ BSTR_set(void *ptr, PyObject *value, unsigned size)
/* create a BSTR from value */ /* create a BSTR from value */
if (value) { if (value) {
Py_ssize_t size = PyUnicode_GET_SIZE(value);
if ((unsigned) size != size) {
PyErr_SetString(PyExc_ValueError, "String too long for BSTR");
return NULL;
}
bstr = SysAllocStringLen(PyUnicode_AS_UNICODE(value), bstr = SysAllocStringLen(PyUnicode_AS_UNICODE(value),
PyUnicode_GET_SIZE(value)); (unsigned)size);
Py_DECREF(value); Py_DECREF(value);
} else } else
bstr = NULL; bstr = NULL;
...@@ -1513,7 +1520,7 @@ BSTR_set(void *ptr, PyObject *value, unsigned size) ...@@ -1513,7 +1520,7 @@ BSTR_set(void *ptr, PyObject *value, unsigned size)
static PyObject * static PyObject *
BSTR_get(void *ptr, unsigned size) BSTR_get(void *ptr, Py_ssize_t size)
{ {
BSTR p; BSTR p;
p = *(BSTR *)ptr; p = *(BSTR *)ptr;
...@@ -1530,7 +1537,7 @@ BSTR_get(void *ptr, unsigned size) ...@@ -1530,7 +1537,7 @@ BSTR_get(void *ptr, unsigned size)
#endif #endif
static PyObject * static PyObject *
P_set(void *ptr, PyObject *value, unsigned size) P_set(void *ptr, PyObject *value, Py_ssize_t size)
{ {
void *v; void *v;
if (value == Py_None) { if (value == Py_None) {
...@@ -1563,7 +1570,7 @@ P_set(void *ptr, PyObject *value, unsigned size) ...@@ -1563,7 +1570,7 @@ P_set(void *ptr, PyObject *value, unsigned size)
} }
static PyObject * static PyObject *
P_get(void *ptr, unsigned size) P_get(void *ptr, Py_ssize_t size)
{ {
if (*(void **)ptr == NULL) { if (*(void **)ptr == NULL) {
Py_INCREF(Py_None); Py_INCREF(Py_None);
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#if (PY_VERSION_HEX < 0x02050000) #if (PY_VERSION_HEX < 0x02050000)
typedef int Py_ssize_t; typedef int Py_ssize_t;
#define PyInt_FromSsize_t PyInt_FromLong
#endif #endif
#ifndef MS_WIN32 #ifndef MS_WIN32
...@@ -31,8 +32,8 @@ typedef int Py_ssize_t; ...@@ -31,8 +32,8 @@ typedef int Py_ssize_t;
typedef struct tagPyCArgObject PyCArgObject; typedef struct tagPyCArgObject PyCArgObject;
typedef struct tagCDataObject CDataObject; typedef struct tagCDataObject CDataObject;
typedef PyObject *(* GETFUNC)(void *, unsigned size); typedef PyObject *(* GETFUNC)(void *, Py_ssize_t size);
typedef PyObject *(* SETFUNC)(void *, PyObject *value, unsigned size); typedef PyObject *(* SETFUNC)(void *, PyObject *value, Py_ssize_t size);
typedef PyCArgObject *(* PARAMFUNC)(CDataObject *obj); typedef PyCArgObject *(* PARAMFUNC)(CDataObject *obj);
/* A default buffer in CDataObject, which can be used for small C types. If /* A default buffer in CDataObject, which can be used for small C types. If
...@@ -137,9 +138,9 @@ extern struct fielddesc *getentry(char *fmt); ...@@ -137,9 +138,9 @@ extern struct fielddesc *getentry(char *fmt);
extern PyObject * extern PyObject *
CField_FromDesc(PyObject *desc, int index, CField_FromDesc(PyObject *desc, Py_ssize_t index,
int *pfield_size, int bitsize, int *pbitofs, Py_ssize_t *pfield_size, int bitsize, int *pbitofs,
int *psize, int *poffset, int *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 *CData_AtAddress(PyObject *type, void *buf);
...@@ -310,7 +311,7 @@ struct tagPyCArgObject { ...@@ -310,7 +311,7 @@ struct tagPyCArgObject {
void *p; void *p;
} value; } value;
PyObject *obj; PyObject *obj;
int size; /* for the 'V' tag */ Py_ssize_t size; /* for the 'V' tag */
}; };
extern PyTypeObject PyCArg_Type; extern PyTypeObject PyCArg_Type;
...@@ -387,7 +388,7 @@ extern char *conversion_mode_errors; ...@@ -387,7 +388,7 @@ extern char *conversion_mode_errors;
# define PyUnicode_AsWideChar My_PyUnicode_AsWideChar # define PyUnicode_AsWideChar My_PyUnicode_AsWideChar
extern PyObject *My_PyUnicode_FromWideChar(const wchar_t *, Py_ssize_t); extern PyObject *My_PyUnicode_FromWideChar(const wchar_t *, Py_ssize_t);
extern int My_PyUnicode_AsWideChar(PyUnicodeObject *, wchar_t *, Py_ssize_t); extern Py_ssize_t My_PyUnicode_AsWideChar(PyUnicodeObject *, wchar_t *, Py_ssize_t);
#endif #endif
......
...@@ -50,7 +50,7 @@ int ...@@ -50,7 +50,7 @@ int
StgDict_clone(StgDictObject *dst, StgDictObject *src) StgDict_clone(StgDictObject *dst, StgDictObject *src)
{ {
char *d, *s; char *d, *s;
int size; Py_ssize_t size;
StgDict_clear(dst); StgDict_clear(dst);
PyMem_Free(dst->ffi_type_pointer.elements); PyMem_Free(dst->ffi_type_pointer.elements);
...@@ -289,13 +289,13 @@ int ...@@ -289,13 +289,13 @@ int
StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct) StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct)
{ {
StgDictObject *stgdict, *basedict; StgDictObject *stgdict, *basedict;
int len, offset, size, align, i; Py_ssize_t len, offset, size, align, i;
int union_size, total_align; Py_ssize_t union_size, total_align;
int field_size = 0; Py_ssize_t field_size = 0;
int bitofs; int bitofs;
PyObject *isPacked; PyObject *isPacked;
int pack = 0; int pack = 0;
int ffi_ofs; Py_ssize_t ffi_ofs;
int big_endian; int big_endian;
/* HACK Alert: I cannot be bothered to fix ctypes.com, so there has to /* HACK Alert: I cannot be bothered to fix ctypes.com, so there has to
...@@ -484,7 +484,9 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct) ...@@ -484,7 +484,9 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct)
/* Adjust the size according to the alignment requirements */ /* Adjust the size according to the alignment requirements */
size = ((size + total_align - 1) / total_align) * total_align; size = ((size + total_align - 1) / total_align) * total_align;
stgdict->ffi_type_pointer.alignment = total_align; stgdict->ffi_type_pointer.alignment = Py_SAFE_DOWNCAST(total_align,
Py_ssize_t,
unsigned short);
stgdict->ffi_type_pointer.size = size; stgdict->ffi_type_pointer.size = size;
stgdict->size = size; stgdict->size = size;
......
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