[Pyobjc-dev] Stricter checks
Brought to you by:
ronaldoussoren
From: Ronald O. <ous...@ci...> - 2003-03-01 20:26:37
|
This checkin also involves some user-visible semantic changes: 1) The conversion to native C types no longer cuts of the most significant bits if they wouldn't fit into the C type. 2) At the same time the bridge tries harder to convert the argument to a proper type, the bridge now calls int() when it wants to convert to a C integer type and float() when it wants to convert to a C floating point type. The conversion to integer types now always accept python longs as well as Python ints. This should make us more consistent with the rest of python. The conversion code could do with some refactoring, there is too much code duplication at the moment. Ronald On Saturday, Mar 1, 2003, at 21:07 Europe/Amsterdam, Ronald Oussoren wrote: > Update of /cvsroot/pyobjc/pyobjc/Modules/objc > In directory sc8-pr-cvs1:/tmp/cvs-serv5997/Modules/objc > > Modified Files: > OC_PythonObject.m informal-protocol.m libffi_support.m > module.m objc_support.m pyobjc-api.h pyobjc.h selector.m > Log Message: > - PyObjC_HAVE_PYTHON_BOOL was defined when we didn't have a Python > bool type > - Fix for BOOL return types of Python methods, Examples/TableModel > contains > a NSTableView where every other row is disabled. > - informal_protocols can be inspected from python (__name__ and > selectors) > - removed some compile-time warnings (the only ones left are caused by > libffi, > not under our control) > - Expanded unittests for basic message passing from Python to > Objective-C, > and fixed the bugs that were uncovered by this. The unittests are > not yet > complete, and the route from Objective-C to Python is not yet > tested, but > were getting closer. > - INSTALL mentions you have to install libffi first > > > Index: OC_PythonObject.m > =================================================================== > RCS file: /cvsroot/pyobjc/pyobjc/Modules/objc/OC_PythonObject.m,v > retrieving revision 1.10 > retrieving revision 1.11 > diff -C2 -d -r1.10 -r1.11 > *** OC_PythonObject.m 23 Feb 2003 08:58:42 -0000 1.10 > --- OC_PythonObject.m 1 Mar 2003 20:06:58 -0000 1.11 > *************** > *** 222,226 **** > unsigned int i; > unsigned int argcount; > - PyCodeObject* func_code; > int retsize = objc_sizeof_type (rettype); > char* retbuffer; > --- 222,225 ---- > > Index: informal-protocol.m > =================================================================== > RCS file: /cvsroot/pyobjc/pyobjc/Modules/objc/informal-protocol.m,v > retrieving revision 1.3 > retrieving revision 1.4 > diff -C2 -d -r1.3 -r1.4 > *** informal-protocol.m 6 Jan 2003 21:15:18 -0000 1.3 > --- informal-protocol.m 1 Mar 2003 20:06:59 -0000 1.4 > *************** > *** 5,8 **** > --- 5,9 ---- > */ > #include <Python.h> > + #include "structmember.h" /* needed for PyMemberDef */ > #include "pyobjc.h" > #include "objc_support.h" > *************** > *** 72,75 **** > --- 73,81 ---- > } > > + selectors = PySequence_Tuple(selectors); > + if (selectors == NULL) { > + return NULL; > + } > + > result = (ObjCInformalProtocol*)PyObject_New( > ObjCInformalProtocol, &ObjCInformalProtocol_Type); > *************** > *** 79,83 **** > > Py_XINCREF(name); > - Py_XINCREF(selectors); > > return (PyObject*)result; > --- 85,88 ---- > *************** > *** 96,99 **** > --- 101,122 ---- > } > > + static PyMemberDef proto_members[] = { > + { > + "__name__", > + T_OBJECT, > + offsetof(ObjCInformalProtocol, name), > + READONLY, > + NULL > + }, > + { > + "selectors", > + T_OBJECT, > + offsetof(ObjCInformalProtocol, selectors), > + READONLY, > + NULL > + }, > + > + { 0, 0, 0, 0, 0 } > + }; > > PyTypeObject ObjCInformalProtocol_Type = { > *************** > *** 128,132 **** > 0, /* tp_iternext */ > 0, /* tp_methods */ > ! 0, /* tp_members */ > 0, /* proto_getset , */ /* tp_getset */ > 0, /* tp_base */ > --- 151,155 ---- > 0, /* tp_iternext */ > 0, /* tp_methods */ > ! proto_members, /* tp_members */ > 0, /* proto_getset , */ /* tp_getset */ > 0, /* tp_base */ > > Index: libffi_support.m > =================================================================== > RCS file: /cvsroot/pyobjc/pyobjc/Modules/objc/libffi_support.m,v > retrieving revision 1.15 > retrieving revision 1.16 > diff -C2 -d -r1.15 -r1.16 > *** libffi_support.m 23 Feb 2003 16:15:32 -0000 1.15 > --- libffi_support.m 1 Mar 2003 20:06:59 -0000 1.16 > *************** > *** 72,75 **** > --- 72,141 ---- > > static ffi_type* > + array_to_ffi_type(const char* argtype) > + { > + static PyObject* array_types = NULL; > + PyObject* v; > + ffi_type* type; > + int field_count; > + int i; > + > + if (array_types == NULL) { > + array_types = PyDict_New(); > + if (array_types == NULL) return NULL; > + } > + > + v = PyDict_GetItemString(array_types, (char*)argtype); > + if (v != NULL) { > + return (ffi_type*)PyCObject_AsVoidPtr(v); > + } > + > + /* We don't have a type description yet, dynamicly > + * create it. > + */ > + field_count = atoi(argtype+1); > + > + type = malloc(sizeof(*type)); > + if (type == NULL) { > + PyErr_NoMemory(); > + return NULL; > + } > + type->size = 0; > + type->alignment = 0; > + > + /* Libffi doesn't really know about arrays as part of larger > + * data-structres (e.g. struct foo { int field[3]; };). We fake it > + * by treating the nested array as a struct. These seems to work > + * fine on MacOS X. > + */ > + type->type = FFI_TYPE_STRUCT; > + type->elements = malloc((1+field_count) * sizeof(*type->elements)); > + if (type->elements == NULL) { > + free(type); > + PyErr_NoMemory(); > + return NULL; > + } > + > + while (isdigit(*++argtype)); > + type->elements[0] = signature_to_ffi_type(argtype); > + for (i = 1; i < field_count; i++) { > + type->elements[i] = type->elements[0]; > + } > + type->elements[field_count] = 0; > + > + v = PyCObject_FromVoidPtr(type, free_type); > + if (v == NULL) { > + free_type(type); > + return NULL; > + } > + > + PyDict_SetItemString(array_types, (char*)argtype, v); > + if (PyErr_Occurred()) { > + Py_DECREF(v); > + return NULL; > + } > + return type; > + } > + > + static ffi_type* > struct_to_ffi_type(const char* argtype) > { > *************** > *** 150,153 **** > --- 216,220 ---- > return type; > } > + > static ffi_type* > signature_to_ffi_return_type(const char* argtype) > *************** > *** 185,189 **** > case _C_CHARPTR: return &ffi_type_pointer; > case _C_PTR: return &ffi_type_pointer; > ! case _C_ARY_B: return &ffi_type_pointer; > case _C_IN: case _C_OUT: case _C_INOUT: case _C_CONST: > return signature_to_ffi_type(argtype+1); > --- 252,257 ---- > case _C_CHARPTR: return &ffi_type_pointer; > case _C_PTR: return &ffi_type_pointer; > ! case _C_ARY_B: > ! return array_to_ffi_type(argtype); > case _C_IN: case _C_OUT: case _C_INOUT: case _C_CONST: > return signature_to_ffi_type(argtype+1); > *************** > *** 370,374 **** > int i; > const char* rettype; > - char buf[2]; > > methinfo = [NSMethodSignature signatureWithObjCTypes:signature]; > --- 438,441 ---- > *************** > *** 514,518 **** > int itemSize; > int itemAlign; > - char tpBuf[2]; > > if (meth->sel_oc_signature) { > --- 581,584 ---- > *************** > *** 782,786 **** > case _C_CONST: > > ! if (argbuf[1] == _C_PTR) { > /* Allocate space and encode */ > argbuf_cur = align(argbuf_cur, objc_alignof_type(argtype+2)); > --- 848,852 ---- > case _C_CONST: > > ! if (argtype[1] == _C_PTR) { > /* Allocate space and encode */ > argbuf_cur = align(argbuf_cur, objc_alignof_type(argtype+2)); > *************** > *** 794,798 **** > > arglist[arglistOffset + i] = &ffi_type_pointer; > ! values[arglistOffset + i] = arg; > > } else { > --- 860,864 ---- > > arglist[arglistOffset + i] = &ffi_type_pointer; > ! values[arglistOffset + i] = byref + i; > > } else { > > Index: module.m > =================================================================== > RCS file: /cvsroot/pyobjc/pyobjc/Modules/objc/module.m,v > retrieving revision 1.20 > retrieving revision 1.21 > diff -C2 -d -r1.20 -r1.21 > *** module.m 23 Feb 2003 08:58:43 -0000 1.20 > --- module.m 1 Mar 2003 20:06:59 -0000 1.21 > *************** > *** 431,468 **** > } > > ! PyObject* func_setArgv0(PyObject* self, PyObject* args, PyObject* > kwds) > { > ! typedef struct { > ! @defs(NSProcessInfo) > ! } NSProcessInfoStruct; > ! > ! static char* keywords[] = { "argv0", NULL }; > ! char* argv0; > ! NSProcessInfo *processInfo = [NSProcessInfo processInfo]; > ! NSMutableArray *argv = [NSMutableArray arrayWithArray: > ! ((NSProcessInfoStruct *)processInfo)->arguments]; > ! [argv retain]; > > if (!PyArg_ParseTupleAndKeywords(args, kwds, > ! "s:setArgv0", > ! keywords, &argv0)) { > return NULL; > } > > ! > ! //[argv replaceObjectAtIndex:0 withObject: [NSString > stringWithUTF8String:argv0]]; > ! [argv insertObject: [NSString stringWithUTF8String:argv0] > atIndex:0]; > ! ((NSProcessInfoStruct *)processInfo)->arguments = argv; > > ! Py_INCREF(Py_None); > ! return Py_None; > } > > static PyMethodDef meta_methods[] = { > { > ! "setArgv0", > ! (PyCFunction)func_setArgv0, > METH_VARARGS|METH_KEYWORDS, > ! NULL > }, > { > --- 431,488 ---- > } > > ! PyDoc_STRVAR(objc_splitSignature_doc, > ! "splitSignature(signature) -> list\n" > ! "\n" > ! "Split a signature string into a list of items." > ! ); > ! PyObject* > ! objc_splitSignature(PyObject* self, PyObject* args, PyObject* kwds) > { > ! static char* keywords[] = { "signature", NULL }; > ! const char* signature; > ! const char* end; > ! PyObject* result; > > if (!PyArg_ParseTupleAndKeywords(args, kwds, > ! "s:splitSignature", > ! keywords, &signature)) { > return NULL; > } > > ! result = PyList_New(0); > ! if (result == NULL) return NULL; > ! > ! while (*signature != 0) { > ! PyObject* str; > > ! end = objc_skip_typespec(signature); > ! if (end == NULL) { > ! Py_DECREF(result); > ! return NULL; > ! } > ! > ! str = PyString_FromStringAndSize(signature, end - signature); > ! if (str == NULL) { > ! Py_DECREF(result); > ! return NULL; > ! } > ! > ! if (PyList_Append(result, str) == -1) { > ! Py_DECREF(result); > ! return NULL; > ! } > ! > ! signature = end; > ! } > ! return result; > } > > + > static PyMethodDef meta_methods[] = { > { > ! "splitSignature", > ! (PyCFunction)objc_splitSignature, > METH_VARARGS|METH_KEYWORDS, > ! objc_splitSignature_doc > }, > { > > Index: objc_support.m > =================================================================== > RCS file: /cvsroot/pyobjc/pyobjc/Modules/objc/objc_support.m,v > retrieving revision 1.29 > retrieving revision 1.30 > diff -C2 -d -r1.29 -r1.30 > *** objc_support.m 28 Feb 2003 10:20:40 -0000 1.29 > --- objc_support.m 1 Mar 2003 20:06:59 -0000 1.30 > *************** > *** 415,419 **** > { > PyObject *ret; > ! unsigned int nitems, offset, itemidx, sizeofitem; > > nitems = atoi (type+1); > --- 415,420 ---- > { > PyObject *ret; > ! unsigned int nitems, itemidx, sizeofitem; > ! unsigned char* curdatum; > > nitems = atoi (type+1); > *************** > *** 426,433 **** > if (!ret) return NULL; > > ! for (offset=itemidx=0; itemidx < nitems; itemidx++) { > PyObject *pyitem = NULL; > > ! pyitem = pythonify_c_value (type, datum+offset); > > if (pyitem) { > --- 427,435 ---- > if (!ret) return NULL; > > ! curdatum = datum; > ! for (itemidx=0; itemidx < nitems; itemidx++) { > PyObject *pyitem = NULL; > > ! pyitem = pythonify_c_value (type, curdatum); > > if (pyitem) { > *************** > *** 438,442 **** > } > > ! offset += sizeofitem; > } > > --- 440,444 ---- > } > > ! curdatum += sizeofitem; > } > > *************** > *** 488,497 **** > depythonify_c_array (const char *type, PyObject *arg, void *datum) > { > ! unsigned int nitems, offset, itemidx, sizeofitem; > > nitems = atoi (type+1); > while (isdigit (*++type)) > ; > ! sizeofitem = objc_sizeof_type (type); > if (sizeofitem == -1) { > ObjCErr_Set(ObjCExc_error, > --- 490,500 ---- > depythonify_c_array (const char *type, PyObject *arg, void *datum) > { > ! unsigned int nitems, itemidx, sizeofitem; > ! unsigned char* curdatum; > > nitems = atoi (type+1); > while (isdigit (*++type)) > ; > ! sizeofitem = objc_aligned_size (type); > if (sizeofitem == -1) { > ObjCErr_Set(ObjCExc_error, > *************** > *** 507,518 **** > } > > ! for (offset=itemidx=0; itemidx < nitems; itemidx++) { > PyObject *pyarg = PyTuple_GetItem (arg, itemidx); > int err; > > ! err = depythonify_c_value (type, pyarg, datum+offset); > if (err == -1) return err; > > ! offset += sizeofitem; > } > > --- 510,522 ---- > } > > ! curdatum = datum; > ! for (itemidx=0; itemidx < nitems; itemidx++) { > PyObject *pyarg = PyTuple_GetItem (arg, itemidx); > int err; > > ! err = depythonify_c_value (type, pyarg, curdatum); > if (err == -1) return err; > > ! curdatum += sizeofitem; > } > > *************** > *** 564,577 **** > > switch (*type) { > - case _C_ULNGLNG: > - retobject = (PyObject*)PyLong_FromUnsignedLongLong(*(unsigned long > long*)datum); > - break; > - > - case _C_LNGLNG: > - retobject = (PyObject*)PyLong_FromLongLong(*(long long*)datum); > - break; > - > case _C_CHR: > ! /* XXX: Why not return a string of length 1 */ > retobject = (PyObject*)PyInt_FromLong ((int)(*(char*)datum)); > break; > --- 568,574 ---- > > switch (*type) { > case _C_CHR: > ! // We don't return a string because BOOL is an alias for > ! // char (at least on MacOS X) > retobject = (PyObject*)PyInt_FromLong ((int)(*(char*)datum)); > break; > *************** > *** 631,634 **** > --- 628,639 ---- > break; > > + case _C_ULNGLNG: > + retobject = (PyObject*)PyLong_FromUnsignedLongLong(*(unsigned long > long*)datum); > + break; > + > + case _C_LNGLNG: > + retobject = (PyObject*)PyLong_FromLongLong(*(long long*)datum); > + break; > + > case _C_FLT: > retobject = (PyObject *) PyFloat_FromDouble (*(float*) datum); > *************** > *** 757,761 **** > > switch(*type) { > ! case _C_CHR: case _C_SHT: > return pythonify_c_value(intType, datum); > case _C_UCHR: case _C_USHT: > --- 762,767 ---- > > switch(*type) { > ! case _C_CHR: > ! case _C_SHT: > return pythonify_c_value(intType, datum); > case _C_UCHR: case _C_USHT: > *************** > *** 772,775 **** > --- 778,783 ---- > /* TODO: Examine whether using PyArg_Parse would be usefull to > translate > * basic types (range checking for free!) > + * > + * This function is way too large! > */ > int > *************** > *** 784,837 **** > > switch (*type) { > - case _C_ULNGLNG: > - if (PyInt_Check(argument)) { > - long value = PyInt_AsLong(argument); > - if (value < 0) { > - ObjCErr_Set(ObjCExc_error, > - "depythonifying 'unsigned long long'," > - "got negative %s", > - argument->ob_type->tp_name); > - return -1; > - } > - *(unsigned long long*)datum = (unsigned long long)value; > - } else if (PyLong_Check(argument)) { > - *(unsigned long long*)datum = > - PyLong_AsUnsignedLongLong(argument); > - if (PyErr_Occurred()) { > - ObjCErr_Set(ObjCExc_error, > - "depythonifying 'unsigned long long'," > - "got %s of wrong magnitude", > - argument->ob_type->tp_name); > - return -1; > - } > - } else { > - ObjCErr_Set(ObjCExc_error, > - "depythonifying 'unsigned long long', got %s", > - argument->ob_type->tp_name); > - return -1; > - } > - break; > - > - case _C_LNGLNG: > - if (PyInt_Check(argument)) { > - *(long long*)datum = PyInt_AsLong(argument); > - } else if (PyLong_Check(argument)) { > - *(long long*)datum = > - PyLong_AsLongLong(argument); > - if (PyErr_Occurred()) { > - ObjCErr_Set(ObjCExc_error, > - "depythonifying 'long long'," > - "got %s of wrong magnitude", > - argument->ob_type->tp_name); > - return -1; > - } > - } else { > - ObjCErr_Set(ObjCExc_error, > - "depythonifying 'long long', got %s", > - argument->ob_type->tp_name); > - return -1; > - } > - break; > - > case _C_CHR: > if (PyInt_Check (argument)) { > --- 792,795 ---- > *************** > *** 839,843 **** > if (temp < CHAR_MIN || temp > CHAR_MAX) { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'char', got %s of " > "wrong magnitude", > argument->ob_type->tp_name); > --- 797,801 ---- > if (temp < CHAR_MIN || temp > CHAR_MAX) { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'char', got '%s' of " > "wrong magnitude", > argument->ob_type->tp_name); > *************** > *** 849,853 **** > if (PyErr_Occurred()) { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'char', got %s of " > "wrong magnitude", > argument->ob_type->tp_name); > --- 807,811 ---- > if (PyErr_Occurred()) { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'char', got '%s' of " > "wrong magnitude", > argument->ob_type->tp_name); > *************** > *** 857,861 **** > if (temp < CHAR_MIN || temp > CHAR_MAX) { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'char', got %s of " > "wrong magnitude", > argument->ob_type->tp_name); > --- 815,819 ---- > if (temp < CHAR_MIN || temp > CHAR_MAX) { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'char', got '%s' of " > "wrong magnitude", > argument->ob_type->tp_name); > *************** > *** 867,872 **** > *(char *) datum = PyString_AsString (argument)[0]; > } else { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'char', got %s of %d", > argument->ob_type->tp_name, > PyString_Size(argument)); > --- 825,841 ---- > *(char *) datum = PyString_AsString (argument)[0]; > } else { > + PyObject* tmp = PyNumber_Int(argument); > + if (tmp != NULL) { > + long temp = PyInt_AsLong(tmp); > + Py_DECREF(tmp); > + > + if (temp >= CHAR_MIN && temp <= CHAR_MAX) { > + *(char *) datum = temp; > + return 0; > + } > + } > + > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'char', got '%s' of %d", > argument->ob_type->tp_name, > PyString_Size(argument)); > *************** > *** 881,885 **** > if (temp < 0 || temp > UCHAR_MAX) { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'char', got %s of " > "wrong magnitude", > argument->ob_type->tp_name); > --- 850,854 ---- > if (temp < 0 || temp > UCHAR_MAX) { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'char', got '%s' of " > "wrong magnitude", > argument->ob_type->tp_name); > *************** > *** 893,897 **** > if (PyErr_Occurred()) { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'char', got %s of " > "wrong magnitude", > argument->ob_type->tp_name); > --- 862,866 ---- > if (PyErr_Occurred()) { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'char', got '%s' of " > "wrong magnitude", > argument->ob_type->tp_name); > *************** > *** 901,905 **** > if (temp < 0 || temp > UCHAR_MAX) { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'char', got %s of " > "wrong magnitude", > argument->ob_type->tp_name); > --- 870,874 ---- > if (temp < 0 || temp > UCHAR_MAX) { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'char', got '%s' of " > "wrong magnitude", > argument->ob_type->tp_name); > *************** > *** 912,917 **** > PyString_AsString (argument)[0]; > } else { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'unsigned char', got %s of %d", > argument->ob_type->tp_name, > PyString_Size(argument)); > --- 881,900 ---- > PyString_AsString (argument)[0]; > } else { > + PyObject* tmp = PyNumber_Int(argument); > + if (tmp != NULL) { > + > + if (PyInt_Check(tmp)) { > + long temp = PyInt_AsLong(tmp); > + Py_DECREF(tmp); > + if (temp >= 0 && temp <= UCHAR_MAX) { > + *(unsigned char *) datum = temp; > + return 0; > + } > + } else { > + Py_DECREF(tmp); > + } > + } > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'unsigned char', got '%s' of %d", > argument->ob_type->tp_name, > PyString_Size(argument)); > *************** > *** 923,927 **** > if (!PyString_Check (argument) && argument != Py_None) { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'charptr', got %s", > argument->ob_type->tp_name); > return -1; > --- 906,910 ---- > if (!PyString_Check (argument) && argument != Py_None) { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'charptr', got '%s'", > argument->ob_type->tp_name); > return -1; > *************** > *** 944,948 **** > if (PyErr_Occurred()) { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'int', got %s of " > "wrong magnitude", > argument->ob_type->tp_name); > --- 927,931 ---- > if (PyErr_Occurred()) { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'int', got '%s' of " > "wrong magnitude", > argument->ob_type->tp_name); > *************** > *** 952,956 **** > if (temp < INT_MIN || temp > INT_MAX) { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'int', got %s of " > "wrong magnitude", > argument->ob_type->tp_name); > --- 935,939 ---- > if (temp < INT_MIN || temp > INT_MAX) { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'int', got '%s' of " > "wrong magnitude", > argument->ob_type->tp_name); > *************** > *** 960,965 **** > *(long*) datum = temp; > } else { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'int', got %s", > argument->ob_type->tp_name); > return -1; > --- 943,958 ---- > *(long*) datum = temp; > } else { > + PyObject* tmp = PyNumber_Int(argument); > + if (tmp != NULL) { > + if (PyInt_Check(tmp)) { > + *(int*) datum = PyInt_AsLong(tmp); > + Py_DECREF(tmp); > + return 0; > + } else { > + Py_DECREF(tmp); > + } > + } > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'int', got '%s'", > argument->ob_type->tp_name); > return -1; > *************** > *** 973,977 **** > if (temp < SHRT_MIN || temp > SHRT_MAX) { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'short', got %s of " > "wrong magnitude", > argument->ob_type->tp_name); > --- 966,970 ---- > if (temp < SHRT_MIN || temp > SHRT_MAX) { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'short', got '%s' of " > "wrong magnitude", > argument->ob_type->tp_name); > *************** > *** 985,989 **** > if (PyErr_Occurred()) { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'short', got %s of " > "wrong magnitude", > argument->ob_type->tp_name); > --- 978,982 ---- > if (PyErr_Occurred()) { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'short', got '%s' of " > "wrong magnitude", > argument->ob_type->tp_name); > *************** > *** 993,997 **** > if (temp < SHRT_MIN || temp > SHRT_MAX) { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'short', got %s of " > "wrong magnitude", > argument->ob_type->tp_name); > --- 986,990 ---- > if (temp < SHRT_MIN || temp > SHRT_MAX) { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'short', got '%s' of " > "wrong magnitude", > argument->ob_type->tp_name); > *************** > *** 1001,1006 **** > *(short*) datum = temp; > } else { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'short', got %s", > argument->ob_type->tp_name); > return -1; > --- 994,1013 ---- > *(short*) datum = temp; > } else { > + PyObject* tmp = PyNumber_Int(argument); > + if (tmp != NULL) { > + if (PyInt_Check(tmp)) { > + long temp = PyInt_AsLong(tmp); > + Py_DECREF(tmp); > + if (temp >= SHRT_MIN && > + temp <= SHRT_MAX) { > + *(short*) datum = temp; > + return 0; > + } > + } else { > + Py_DECREF(tmp); > + } > + } > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'short', got '%s'", > argument->ob_type->tp_name); > return -1; > *************** > *** 1014,1018 **** > if (temp < 0) { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'unsigned int', got %s " > "of wrong magnitude", > argument->ob_type->tp_name); > --- 1021,1025 ---- > if (temp < 0) { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'unsigned int', got '%s' " > "of wrong magnitude", > argument->ob_type->tp_name); > *************** > *** 1026,1030 **** > if (PyErr_Occurred()) { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'unsigned int', got %s " > "of wrong magnitude", > argument->ob_type->tp_name); > --- 1033,1037 ---- > if (PyErr_Occurred()) { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'unsigned int', got '%s' " > "of wrong magnitude", > argument->ob_type->tp_name); > *************** > *** 1034,1038 **** > if (temp > UINT_MAX) { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'unsigned int', got %s " > "of wrong magnitude", > argument->ob_type->tp_name); > --- 1041,1045 ---- > if (temp > UINT_MAX) { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'unsigned int', got '%s' " > "of wrong magnitude", > argument->ob_type->tp_name); > *************** > *** 1042,1047 **** > *(unsigned int*) datum = temp; > } else { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'unsigned int', got %s", > argument->ob_type->tp_name); > return -1; > --- 1049,1084 ---- > *(unsigned int*) datum = temp; > } else { > + PyObject* tmp = PyNumber_Int(argument); > + if (tmp != NULL) { > + if (PyInt_Check(tmp)) { > + long temp = PyInt_AsLong(tmp); > + Py_DECREF(tmp); > + if (temp >= 0) { > + *(unsigned int *) datum = temp; > + return 0; > + } > + } else if (PyLong_Check(tmp)) { > + long long temp = PyLong_AsLongLong(tmp); > + Py_DECREF(tmp); > + if (temp >= 0 && temp <= ULONG_MAX) { > + *(unsigned int*) datum = temp; > + return 0; > + } > + } else { > + Py_DECREF(tmp); > + } > + } > + tmp = PyNumber_Long(argument); > + if (tmp != NULL) { > + long long temp = PyLong_AsLongLong(tmp); > + Py_DECREF(tmp); > + if (!PyErr_Occurred() && temp >= 0) { > + *(unsigned int*) datum = temp; > + return 0; > + } > + } > + > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'unsigned int', got '%s'", > argument->ob_type->tp_name); > return -1; > *************** > *** 1056,1060 **** > ObjCErr_Set(ObjCExc_error, > "depythonifying 'unsigned short', " > ! "got %s of wrong magnitude", > argument->ob_type->tp_name); > return -1; > --- 1093,1097 ---- > ObjCErr_Set(ObjCExc_error, > "depythonifying 'unsigned short', " > ! "got '%s' of wrong magnitude", > argument->ob_type->tp_name); > return -1; > *************** > *** 1068,1072 **** > ObjCErr_Set(ObjCExc_error, > "depythonifying 'unsigned short', " > ! "got %s of wrong magnitude", > argument->ob_type->tp_name); > return -1; > --- 1105,1109 ---- > ObjCErr_Set(ObjCExc_error, > "depythonifying 'unsigned short', " > ! "got '%s' of wrong magnitude", > argument->ob_type->tp_name); > return -1; > *************** > *** 1076,1080 **** > ObjCErr_Set(ObjCExc_error, > "depythonifying 'unsigned short', " > ! "got %s of wrong magnitude", > argument->ob_type->tp_name); > return -1; > --- 1113,1117 ---- > ObjCErr_Set(ObjCExc_error, > "depythonifying 'unsigned short', " > ! "got '%s' of wrong magnitude", > argument->ob_type->tp_name); > return -1; > *************** > *** 1083,1088 **** > *(unsigned short*) datum = temp; > } else { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'unsigned short', got %s", > argument->ob_type->tp_name); > return -1; > --- 1120,1139 ---- > *(unsigned short*) datum = temp; > } else { > + PyObject* tmp = PyNumber_Int(argument); > + if (tmp != NULL) { > + if (PyInt_Check(tmp)) { > + long temp = PyInt_AsLong(tmp); > + Py_DECREF(tmp); > + if (temp >= 0 && temp <= USHRT_MAX) { > + *(unsigned short *) datum = temp; > + return 0; > + } > + } else { > + Py_DECREF(tmp); > + } > + } > + > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'unsigned short', got '%s'", > argument->ob_type->tp_name); > return -1; > *************** > *** 1099,1103 **** > if (PyErr_Occurred()) { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'long', got %s of " > "wrong magnitude", > argument->ob_type->tp_name); > --- 1150,1154 ---- > if (PyErr_Occurred()) { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'long', got '%s' of " > "wrong magnitude", > argument->ob_type->tp_name); > *************** > *** 1107,1111 **** > if (temp < LONG_MIN || temp > LONG_MAX) { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'long', got %s of " > "wrong magnitude", > argument->ob_type->tp_name); > --- 1158,1162 ---- > if (temp < LONG_MIN || temp > LONG_MAX) { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'long', got '%s' of " > "wrong magnitude", > argument->ob_type->tp_name); > *************** > *** 1115,1120 **** > *(long*) datum = temp; > } else { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'long', got %s", > argument->ob_type->tp_name); > return -1; > --- 1166,1181 ---- > *(long*) datum = temp; > } else { > + PyObject* tmp = PyNumber_Int(argument); > + if (tmp != NULL) { > + if (PyInt_Check(tmp)) { > + *(long*) datum = PyInt_AsLong(tmp); > + Py_DECREF(tmp); > + return 0; > + } else { > + Py_DECREF(tmp); > + } > + } > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'long', got '%s'", > argument->ob_type->tp_name); > return -1; > *************** > *** 1132,1136 **** > ObjCErr_Set(ObjCExc_error, > "depythonifying 'unsigned long', " > ! "got %s of wrong magnitude", > argument->ob_type->tp_name); > return -1; > --- 1193,1197 ---- > ObjCErr_Set(ObjCExc_error, > "depythonifying 'unsigned long', " > ! "got '%s' of wrong magnitude", > argument->ob_type->tp_name); > return -1; > *************** > *** 1140,1144 **** > ObjCErr_Set(ObjCExc_error, > "depythonifying 'unsigned long', " > ! "got %s of wrong magnitude", > argument->ob_type->tp_name); > return -1; > --- 1201,1205 ---- > ObjCErr_Set(ObjCExc_error, > "depythonifying 'unsigned long', " > ! "got '%s' of wrong magnitude", > argument->ob_type->tp_name); > return -1; > *************** > *** 1147,1152 **** > *(unsigned long*) datum = temp; > } else { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'unsigned long', got %s", > argument->ob_type->tp_name); > return -1; > --- 1208,1283 ---- > *(unsigned long*) datum = temp; > } else { > + PyObject* tmp = PyNumber_Int(argument); > + if (tmp != NULL) { > + if (PyInt_Check(tmp)) { > + long temp = PyInt_AsLong(tmp); > + Py_DECREF(tmp); > + if (temp >= 0) { > + *(unsigned long *) datum = temp; > + return 0; > + } > + } else if (PyLong_Check(tmp)) { > + unsigned long long temp = > + PyLong_AsUnsignedLongLong(tmp); > + Py_DECREF(tmp); > + if (!PyErr_Occurred() && temp <= ULONG_MAX) { > + *(unsigned long*) datum = temp; > + return 0; > + } > + } else { > + Py_DECREF(tmp); > + } > + } > + tmp = PyNumber_Long(argument); > + if (tmp != NULL) { > + unsigned long long temp = > + PyLong_AsUnsignedLongLong(tmp); > + Py_DECREF(tmp); > + if (!PyErr_Occurred() && temp <= ULONG_MAX) { > + *(unsigned long*) datum = temp; > + return 0; > + } > + } > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'unsigned long', got '%s'", > ! argument->ob_type->tp_name); > ! return -1; > ! } > ! break; > ! > ! case _C_ULNGLNG: > ! if (PyInt_Check(argument)) { > ! long value = PyInt_AsLong(argument); > ! if (value < 0) { > ! ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'unsigned long long'," > ! "got negative '%s'", > ! argument->ob_type->tp_name); > ! return -1; > ! } > ! *(unsigned long long*)datum = (unsigned long long)value; > ! } else if (PyLong_Check(argument)) { > ! *(unsigned long long*)datum = > ! PyLong_AsUnsignedLongLong(argument); > ! if (PyErr_Occurred()) { > ! ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'unsigned long long'," > ! "got '%s' of wrong magnitude", > ! argument->ob_type->tp_name); > ! return -1; > ! } > ! } else { > ! PyObject* tmp = PyNumber_Long(argument); > ! if (tmp != NULL) { > ! unsigned long long temp = > ! PyLong_AsUnsignedLongLong(tmp); > ! Py_DECREF(tmp); > ! if (!PyErr_Occurred()) { > ! *(unsigned long long *) datum = temp; > ! return 0; > ! } > ! } > ! ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'unsigned long long', got '%s'", > argument->ob_type->tp_name); > return -1; > *************** > *** 1154,1157 **** > --- 1285,1319 ---- > break; > > + case _C_LNGLNG: > + if (PyInt_Check(argument)) { > + *(long long*)datum = PyInt_AsLong(argument); > + } else if (PyLong_Check(argument)) { > + *(long long*)datum = > + PyLong_AsLongLong(argument); > + if (PyErr_Occurred()) { > + ObjCErr_Set(ObjCExc_error, > + "depythonifying 'long long'," > + "got '%s' of wrong magnitude", > + argument->ob_type->tp_name); > + return -1; > + } > + } else { > + PyObject* tmp = PyNumber_Long(argument); > + if (tmp != NULL) { > + long long temp = PyLong_AsLongLong(tmp); > + Py_DECREF(tmp); > + if (!PyErr_Occurred()) { > + *(long long*) datum = temp; > + return 0; > + } > + } > + ObjCErr_Set(ObjCExc_error, > + "depythonifying 'long long', got '%s'", > + argument->ob_type->tp_name); > + return -1; > + } > + break; > + > + > case _C_ID: > if (argument == Py_None) { > *************** > *** 1179,1183 **** > "strict"); > if (as_unicode == NULL) { > ! ObjCErr_Set(ObjCExc_error, > "depythonifying 'id', got " > "a string with a non-default " > --- 1341,1345 ---- > "strict"); > if (as_unicode == NULL) { > ! ObjCErr_Set(PyExc_UnicodeError, > "depythonifying 'id', got " > "a string with a non-default " > *************** > *** 1257,1261 **** > } else { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'Class', got %s", > argument->ob_type->tp_name); > return -1; > --- 1419,1423 ---- > } else { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'Class', got '%s'", > argument->ob_type->tp_name); > return -1; > *************** > *** 1276,1280 **** > } else { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'SEL', got cannot " > "register string with runtime"); > return -1; > --- 1438,1442 ---- > } else { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'SEL', cannot " > "register string with runtime"); > return -1; > *************** > *** 1282,1286 **** > } else { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'SEL', got %s", > argument->ob_type->tp_name); > return -1; > --- 1444,1448 ---- > } else { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'SEL', got '%s'", > argument->ob_type->tp_name); > return -1; > *************** > *** 1302,1307 **** > } else { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'pointer', got %s", > argument->ob_type->tp_name); > return -1; > } > --- 1464,1470 ---- > } else { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'pointer', got '%s'", > argument->ob_type->tp_name); > + abort(); > return -1; > } > *************** > *** 1314,1319 **** > *(float *) datum = (float) PyInt_AsLong (argument); > } else { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'float', got %s", > argument->ob_type->tp_name); > return -1; > --- 1477,1490 ---- > *(float *) datum = (float) PyInt_AsLong (argument); > } else { > + PyObject* tmp = PyNumber_Float(argument); > + if (tmp != NULL) { > + double temp = PyFloat_AsDouble(tmp); > + Py_DECREF(tmp); > + *(float*) datum = temp; > + return 0; > + } > + > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'float', got '%s'", > argument->ob_type->tp_name); > return -1; > *************** > *** 1327,1332 **** > *(double *) datum = (double) PyInt_AsLong (argument); > } else { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'double', got %s", > argument->ob_type->tp_name); > return -1; > --- 1498,1511 ---- > *(double *) datum = (double) PyInt_AsLong (argument); > } else { > + PyObject* tmp = PyNumber_Float(argument); > + if (tmp != NULL) { > + double temp = PyFloat_AsDouble(tmp); > + Py_DECREF(tmp); > + *(double*) datum = temp; > + return 0; > + } > + > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'double', got '%s'", > argument->ob_type->tp_name); > return -1; > *************** > *** 1357,1361 **** > } else { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'union', got %s", > argument->ob_type->tp_name); > return -1; > --- 1536,1540 ---- > } else { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'union', got '%s'", > argument->ob_type->tp_name); > return -1; > *************** > *** 1366,1370 **** > if (! PyTuple_Check (argument)) { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'struct', got %s", > argument->ob_type->tp_name); > return -1; > --- 1545,1549 ---- > if (! PyTuple_Check (argument)) { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'struct', got '%s'", > argument->ob_type->tp_name); > return -1; > *************** > *** 1377,1381 **** > if (! PyTuple_Check (argument)) { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'array', got %s", > argument->ob_type->tp_name); > return -1; > --- 1556,1560 ---- > if (! PyTuple_Check (argument)) { > ObjCErr_Set(ObjCExc_error, > ! "depythonifying 'array', got '%s'", > argument->ob_type->tp_name); > return -1; > > Index: pyobjc-api.h > =================================================================== > RCS file: /cvsroot/pyobjc/pyobjc/Modules/objc/pyobjc-api.h,v > retrieving revision 1.8 > retrieving revision 1.9 > diff -C2 -d -r1.8 -r1.9 > *** pyobjc-api.h 26 Feb 2003 14:26:36 -0000 1.8 > --- pyobjc-api.h 1 Mar 2003 20:07:00 -0000 1.9 > *************** > *** 32,38 **** > /* PyBool_Type was introduced in Python 2.3 */ > > - #define PyObjC_HAVE_PYTHON_BOOL > #define PyBool_Check(_x_) (0) > #define PyBool_FromLong(_x_) PyInt_FromLong(_x_) > > #endif /* Python < 2.3.0a */ > --- 32,41 ---- > /* PyBool_Type was introduced in Python 2.3 */ > > #define PyBool_Check(_x_) (0) > #define PyBool_FromLong(_x_) PyInt_FromLong(_x_) > + > + #else > + > + #define PyObjC_HAVE_PYTHON_BOOL > > #endif /* Python < 2.3.0a */ > > Index: pyobjc.h > =================================================================== > RCS file: /cvsroot/pyobjc/pyobjc/Modules/objc/pyobjc.h,v > retrieving revision 1.22 > retrieving revision 1.23 > diff -C2 -d -r1.22 -r1.23 > *** pyobjc.h 26 Feb 2003 14:26:37 -0000 1.22 > --- pyobjc.h 1 Mar 2003 20:07:00 -0000 1.23 > *************** > *** 32,35 **** > --- 32,38 ---- > #define PyBool_Check(_x_) (0) > #define PyBool_FromLong(_x_) PyInt_FromLong(_x_) > + > + #else > + > #define PyObjC_HAVE_PYTHON_BOOL > > > Index: selector.m > =================================================================== > RCS file: /cvsroot/pyobjc/pyobjc/Modules/objc/selector.m,v > retrieving revision 1.18 > retrieving revision 1.19 > diff -C2 -d -r1.18 -r1.19 > *** selector.m 23 Feb 2003 08:58:44 -0000 1.18 > --- selector.m 1 Mar 2003 20:07:00 -0000 1.19 > *************** > *** 490,496 **** > { > PyObject* pyself = self->sel_self; > - Class pyself_class; > ObjC_CallFunc_t execute = NULL; > int is_super_call = 0; > PyObject* res; > > --- 490,498 ---- > { > PyObject* pyself = self->sel_self; > ObjC_CallFunc_t execute = NULL; > + #if !(defined(OC_WITH_LIBFFI) && defined(OC_USE_FFI_SHORTCUTS)) > + Class pyself_class; > int is_super_call = 0; > + #endif > PyObject* res; > > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > pyobjc-checkins mailing list > pyo...@li... > https://lists.sourceforge.net/lists/listinfo/pyobjc-checkins > |