[ctypes-commit] ctypes/source callproc.c,1.109,1.110
Brought to you by:
theller
From: Thomas H. <th...@us...> - 2004-10-15 14:37:13
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5863 Modified Files: callproc.c Log Message: Added memmove and get_string functions. Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.109 retrieving revision 1.110 diff -C2 -d -r1.109 -r1.110 *** callproc.c 13 Oct 2004 15:24:12 -0000 1.109 --- callproc.c 15 Oct 2004 14:36:24 -0000 1.110 *************** *** 1303,1307 **** --- 1303,1357 ---- } + static char memmove_doc[] = + "memmove(dst, src, size) -> adress\n\ + \n\ + Copy size bytes from src to dst, return the destination address as integer.\n"; + + static PyObject * + c_memmove(PyObject *self, PyObject *args) + { + struct argument a_dst, a_src; + int size; + void *c_result; + PyObject *result = NULL; + PyObject *dst, *src; + + memset(&a_dst, 0, sizeof(struct argument)); + memset(&a_src, 0, sizeof(struct argument)); + if (!PyArg_ParseTuple(args, "OOi", &dst, &src, &size)) + return NULL; + if (-1 == ConvParam(dst, 0, &a_dst)) + goto done; + if (-1 == ConvParam(src, 1, &a_src)) + goto done; + c_result = memmove(a_dst.value.p, a_src.value.p, size); + result = PyLong_FromVoidPtr(c_result); + done: + Py_XDECREF(a_dst.keep); + Py_XDECREF(a_src.keep); + return result; + } + + static char get_string_doc[] = + "get_string(addr) -> string\n\ + \n\ + Return the string at addr.\n"; + + static PyObject * + get_string(PyObject *self, PyObject *arg) + { + PyObject *result = NULL; + struct argument a_arg; + if (-1 == ConvParam(arg, 0, &a_arg)) + goto done; + result = PyString_FromString(a_arg.value.p); + done: + Py_XDECREF(a_arg.keep); + return result; + } + PyMethodDef module_methods[] = { + {"get_string", get_string, METH_O, get_string_doc}, + {"memmove", c_memmove, METH_VARARGS, memmove_doc}, {"cast", cast, METH_VARARGS, cast_doc}, #ifdef Py_USING_UNICODE |