[ctypes-commit] ctypes/source callproc.c,1.112,1.113
Brought to you by:
theller
From: Thomas H. <th...@us...> - 2004-10-27 19:59:12
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32600 Modified Files: callproc.c Log Message: Refactor some code, and implement a get_wstring function. Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.112 retrieving revision 1.113 diff -C2 -d -r1.112 -r1.113 *** callproc.c 18 Oct 2004 08:07:05 -0000 1.112 --- callproc.c 27 Oct 2004 19:58:56 -0000 1.113 *************** *** 768,771 **** --- 768,772 ---- Is there another way? */ + PyObject *retval; char c; short s; *************** *** 777,794 **** case 1: c = (char)result->value.l; ! return dict->getfunc(&c, dict->size); case SIZEOF_SHORT: s = (short)result->value.l; ! return dict->getfunc(&s, dict->size); case SIZEOF_INT: i = (int)result->value.l; ! return dict->getfunc(&i, dict->size); #if (SIZEOF_LONG != SIZEOF_INT) case SIZEOF_LONG: l = (long)result->value.l; ! return dict->getfunc(&l, dict->size); #endif } ! return dict->getfunc(&result->value, dict->size); } if (PyCallable_Check(restype)) --- 778,802 ---- case 1: c = (char)result->value.l; ! retval = dict->getfunc(&c, dict->size); ! break; case SIZEOF_SHORT: s = (short)result->value.l; ! retval = dict->getfunc(&s, dict->size); ! break; case SIZEOF_INT: i = (int)result->value.l; ! retval = dict->getfunc(&i, dict->size); ! break; #if (SIZEOF_LONG != SIZEOF_INT) case SIZEOF_LONG: l = (long)result->value.l; ! retval = dict->getfunc(&l, dict->size); ! break; #endif + default: + retval = dict->getfunc(&result->value, dict->size); + break; } ! return retval; } if (PyCallable_Check(restype)) *************** *** 1382,1385 **** --- 1390,1421 ---- } + #ifdef CTYPES_UNICODE + static char get_wstring_doc[] = + "get_wstring(addr[, size]) -> unicode string\n\ + \n\ + Return the wide string at addr.\n"; + + static PyObject * + get_wstring(PyObject *self, PyObject *args) + { + PyObject *result = NULL; + PyObject *src; + struct argument a_arg; + int size; + + if (!PyArg_ParseTuple(args, "O|i", &src, &size)) + return NULL; + memset(&a_arg, 0, sizeof(struct argument)); + if (-1 == ConvParam(src, 1, &a_arg)) + return NULL; + if (PyTuple_GET_SIZE(args) == 1) + result = PyUnicode_FromWideChar(a_arg.value.p, wcslen(a_arg.value.p)); + else + result = PyUnicode_FromWideChar(a_arg.value.p, size); + Py_XDECREF(a_arg.keep); + return result; + } + #endif + PyMethodDef module_methods[] = { {"get_string", get_string, METH_VARARGS, get_string_doc}, *************** *** 1388,1391 **** --- 1424,1428 ---- {"cast", cast, METH_VARARGS, cast_doc}, #ifdef CTYPES_UNICODE + {"get_wstring", get_wstring, METH_VARARGS, get_wstring_doc}, {"set_conversion_mode", set_conversion_mode, METH_VARARGS, set_conversion_mode_doc}, #endif |