ctypes-commit Mailing List for ctypes (Page 96)
Brought to you by:
theller
You can subscribe to this list here.
2004 |
Jan
|
Feb
|
Mar
|
Apr
(8) |
May
(90) |
Jun
(143) |
Jul
(106) |
Aug
(94) |
Sep
(84) |
Oct
(163) |
Nov
(60) |
Dec
(58) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2005 |
Jan
(128) |
Feb
(79) |
Mar
(227) |
Apr
(192) |
May
(179) |
Jun
(41) |
Jul
(53) |
Aug
(103) |
Sep
(28) |
Oct
(38) |
Nov
(81) |
Dec
(17) |
2006 |
Jan
(184) |
Feb
(111) |
Mar
(188) |
Apr
(67) |
May
(58) |
Jun
(123) |
Jul
(73) |
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
From: Thomas H. <th...@us...> - 2004-08-27 18:41:47
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4635 Modified Files: test_cfuncs.py Log Message: Check if this is the value we actually passed. Index: test_cfuncs.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_cfuncs.py,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** test_cfuncs.py 27 Aug 2004 18:03:35 -0000 1.12 --- test_cfuncs.py 27 Aug 2004 18:41:36 -0000 1.13 *************** *** 13,16 **** --- 13,23 ---- return f + # These two functions report the argument in the last call to one of + # the tf_? functions. + + from _ctypes_test import \ + get_last_tf_arg_s as S, \ + get_last_tf_arg_u as U + class CFunctions(unittest.TestCase): def __init__(self, *args): *************** *** 22,28 **** --- 29,37 ---- self.dll.tf_b.argtypes = (c_byte,) self.failUnlessEqual(self.dll.tf_b(-126), -42) + self.failUnlessEqual(S(), -126) self.dll.tf_bb.restype = c_byte self.dll.tf_bb.argtypes = (c_byte, c_byte) self.failUnlessEqual(self.dll.tf_bb(0, -126), -42) + self.failUnlessEqual(S(), -126) def test_ubyte(self): *************** *** 30,60 **** --- 39,79 ---- self.dll.tf_B.argtypes = (c_ubyte,) self.failUnlessEqual(self.dll.tf_B(255), 85) + self.failUnlessEqual(U(), 255) self.dll.tf_bB.restype = c_ubyte self.dll.tf_bB.argtypes = (c_byte, c_ubyte) self.failUnlessEqual(self.dll.tf_bB(0, 255), 85) + self.failUnlessEqual(U(), 255) def test_short(self): self.dll.tf_h.restype = c_short self.failUnlessEqual(self.dll.tf_h(-32766), -10922) + self.failUnlessEqual(S(), -32766) self.dll.tf_bh.restype = c_short self.failUnlessEqual(self.dll.tf_bh(0, -32766), -10922) + self.failUnlessEqual(S(), -32766) def test_ushort(self): self.dll.tf_H.restype = c_ushort self.failUnlessEqual(self.dll.tf_H(65535), 21845) + self.failUnlessEqual(U(), 65535) self.dll.tf_bH.restype = c_ushort self.failUnlessEqual(self.dll.tf_bH(0, 65535), 21845) + self.failUnlessEqual(U(), 65535) def test_int(self): self.dll.tf_i.restype = c_int self.failUnlessEqual(self.dll.tf_i(-2147483646), -715827882) + self.failUnlessEqual(S(), -2147483646) self.dll.tf_bi.restype = c_int self.failUnlessEqual(self.dll.tf_bi(0, -2147483646), -715827882) + self.failUnlessEqual(S(), -2147483646) def test_uint(self): self.dll.tf_I.restype = c_uint self.failUnlessEqual(self.dll.tf_I(4294967295), 1431655765) + self.failUnlessEqual(U(), 4294967295) self.dll.tf_bI.restype = c_uint self.failUnlessEqual(self.dll.tf_bI(0, 4294967295), 1431655765) + self.failUnlessEqual(U(), 4294967295) def test_long(self): *************** *** 62,74 **** --- 81,97 ---- self.dll.tf_l.argtypes = (c_long,) self.failUnlessEqual(self.dll.tf_l(-2147483646), -715827882) + self.failUnlessEqual(S(), -2147483646) self.dll.tf_bl.restype = c_long self.dll.tf_bl.argtypes = (c_byte, c_long) self.failUnlessEqual(self.dll.tf_bl(0, -2147483646), -715827882) + self.failUnlessEqual(S(), -2147483646) def test_ulong(self): self.dll.tf_L.restype = c_ulong self.failUnlessEqual(self.dll.tf_L(4294967295), 1431655765) + self.failUnlessEqual(U(), 4294967295) self.dll.tf_bL.restype = c_ulong self.failUnlessEqual(self.dll.tf_bL(0, 4294967295), 1431655765) + self.failUnlessEqual(U(), 4294967295) def test_longlong(self): *************** *** 76,90 **** self.dll.tf_q.argtypes = (c_longlong, ) self.failUnlessEqual(self.dll.tf_q(-9223372036854775806), -3074457345618258602) self.dll.tf_bq.restype = c_longlong self.dll.tf_bq.argtypes = (c_byte, c_longlong) self.failUnlessEqual(self.dll.tf_bq(0, -9223372036854775806), -3074457345618258602) def test_ulonglong(self): self.dll.tf_Q.restype = c_ulonglong ! self.dll.tf_Q.argtypes = (c_longlong, ) self.failUnlessEqual(self.dll.tf_Q(18446744073709551615), 6148914691236517205) self.dll.tf_bQ.restype = c_ulonglong self.dll.tf_bQ.argtypes = (c_byte, c_ulonglong) self.failUnlessEqual(self.dll.tf_bQ(0, 18446744073709551615), 6148914691236517205) def test_float(self): --- 99,117 ---- self.dll.tf_q.argtypes = (c_longlong, ) self.failUnlessEqual(self.dll.tf_q(-9223372036854775806), -3074457345618258602) + self.failUnlessEqual(S(), -9223372036854775806) self.dll.tf_bq.restype = c_longlong self.dll.tf_bq.argtypes = (c_byte, c_longlong) self.failUnlessEqual(self.dll.tf_bq(0, -9223372036854775806), -3074457345618258602) + self.failUnlessEqual(S(), -9223372036854775806) def test_ulonglong(self): self.dll.tf_Q.restype = c_ulonglong ! self.dll.tf_Q.argtypes = (c_ulonglong, ) self.failUnlessEqual(self.dll.tf_Q(18446744073709551615), 6148914691236517205) + self.failUnlessEqual(U(), 18446744073709551615) self.dll.tf_bQ.restype = c_ulonglong self.dll.tf_bQ.argtypes = (c_byte, c_ulonglong) self.failUnlessEqual(self.dll.tf_bQ(0, 18446744073709551615), 6148914691236517205) + self.failUnlessEqual(U(), 18446744073709551615) def test_float(self): *************** *** 92,98 **** --- 119,127 ---- self.dll.tf_f.argtypes = (c_float,) self.failUnlessEqual(self.dll.tf_f(-42.), -14.) + self.failUnlessEqual(S(), -42) self.dll.tf_bf.restype = c_float self.dll.tf_bf.argtypes = (c_byte, c_float) self.failUnlessEqual(self.dll.tf_bf(0, -42.), -14.) + self.failUnlessEqual(S(), -42) def test_double(self): *************** *** 100,106 **** --- 129,137 ---- self.dll.tf_d.argtypes = (c_double,) self.failUnlessEqual(self.dll.tf_d(42.), 14.) + self.failUnlessEqual(S(), 42) self.dll.tf_bd.restype = c_double self.dll.tf_bd.argtypes = (c_byte, c_double) self.failUnlessEqual(self.dll.tf_bd(0, 42.), 14.) + self.failUnlessEqual(S(), 42) def test_callwithresult(self): *************** *** 110,114 **** --- 141,147 ---- self.dll.tf_i.argtypes = (c_int,) self.failUnlessEqual(self.dll.tf_i(42), 28) + self.failUnlessEqual(S(), 42) self.failUnlessEqual(self.dll.tf_i(-42), -28) + self.failUnlessEqual(S(), -42) def test_void(self): *************** *** 116,120 **** --- 149,155 ---- self.dll.tv_i.argtypes = (c_int,) self.failUnlessEqual(self.dll.tv_i(42), None) + self.failUnlessEqual(S(), 42) self.failUnlessEqual(self.dll.tv_i(-42), None) + self.failUnlessEqual(S(), -42) # The following repeates the above tests with stdcall functions (where |
From: Thomas H. <th...@us...> - 2004-08-27 18:41:32
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4608 Modified Files: _ctypes_test.c Log Message: Check if this is the value we actually passed. Index: _ctypes_test.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes_test.c,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** _ctypes_test.c 27 Aug 2004 18:17:35 -0000 1.25 --- _ctypes_test.c 27 Aug 2004 18:41:21 -0000 1.26 *************** *** 279,283 **** --- 279,300 ---- } + PY_LONG_LONG last_tf_arg_s; + unsigned PY_LONG_LONG last_tf_arg_u; + + PyObject * + get_last_tf_arg_s(PyObject *self, PyObject *arg) + { + return PyLong_FromLongLong(last_tf_arg_s); + } + + PyObject * + get_last_tf_arg_u(PyObject *self, PyObject *arg) + { + return PyLong_FromUnsignedLongLong(last_tf_arg_u); + } + PyMethodDef module_methods[] = { + {"get_last_tf_arg_s", get_last_tf_arg_s, METH_NOARGS}, + {"get_last_tf_arg_u", get_last_tf_arg_u, METH_NOARGS}, {"func_si", py_func_si, METH_VARARGS}, {"func", py_func, METH_NOARGS}, *************** *** 285,345 **** }; ! EXPORT(char) tf_b(char c) { return c/3; } ! EXPORT(unsigned char) tf_B(unsigned char c) { return c/3; } ! EXPORT(short) tf_h(short c) { return c/3; } ! EXPORT(unsigned short) tf_H(unsigned short c) { return c/3; } ! EXPORT(int) tf_i(int c) { return c/3; } ! EXPORT(unsigned int) tf_I(unsigned int c) { return c/3; } ! EXPORT(long) tf_l(long c) { return c/3; } ! EXPORT(unsigned long) tf_L(unsigned long c) { return c/3; } ! EXPORT(PY_LONG_LONG) tf_q(PY_LONG_LONG c) { return c/3; } ! EXPORT(unsigned PY_LONG_LONG) tf_Q(unsigned PY_LONG_LONG c) { return c/3; } ! EXPORT(float) tf_f(float c) { return c/3; } ! EXPORT(double) tf_d(double c) { return c/3; } #ifdef MS_WIN32 ! EXPORT(char) __stdcall s_tf_b(char c) { return c/3; } ! EXPORT(unsigned char) __stdcall s_tf_B(unsigned char c) { return c/3; } ! EXPORT(short) __stdcall s_tf_h(short c) { return c/3; } ! EXPORT(unsigned short) __stdcall s_tf_H(unsigned short c) { return c/3; } ! EXPORT(int) __stdcall s_tf_i(int c) { return c/3; } ! EXPORT(unsigned int) __stdcall s_tf_I(unsigned int c) { return c/3; } ! EXPORT(long) __stdcall s_tf_l(long c) { return c/3; } ! EXPORT(unsigned long) __stdcall s_tf_L(unsigned long c) { return c/3; } ! EXPORT(PY_LONG_LONG) __stdcall s_tf_q(PY_LONG_LONG c) { return c/3; } ! EXPORT(unsigned PY_LONG_LONG) __stdcall s_tf_Q(unsigned PY_LONG_LONG c) { return c/3; } ! EXPORT(float) __stdcall s_tf_f(float c) { return c/3; } ! EXPORT(double) __stdcall s_tf_d(double c) { return c/3; } #endif /*******/ ! EXPORT(char) tf_bb(char x, char c) { return c/3; } ! EXPORT(unsigned char) tf_bB(char x, unsigned char c) { return c/3; } ! EXPORT(short) tf_bh(char x, short c) { return c/3; } ! EXPORT(unsigned short) tf_bH(char x, unsigned short c) { return c/3; } ! EXPORT(int) tf_bi(char x, int c) { return c/3; } ! EXPORT(unsigned int) tf_bI(char x, unsigned int c) { return c/3; } ! EXPORT(long) tf_bl(char x, long c) { return c/3; } ! EXPORT(unsigned long) tf_bL(char x, unsigned long c) { return c/3; } ! EXPORT(PY_LONG_LONG) tf_bq(char x, PY_LONG_LONG c) { return c/3; } ! EXPORT(unsigned PY_LONG_LONG) tf_bQ(char x, unsigned PY_LONG_LONG c) { return c/3; } ! EXPORT(float) tf_bf(char x, float c) { return c/3; } ! EXPORT(double) tf_bd(char x, double c) { return c/3; } ! EXPORT(void) tv_i(int i) { return; } #ifdef MS_WIN32 ! EXPORT(char) __stdcall s_tf_bb(char x, char c) { return c/3; } ! EXPORT(unsigned char) __stdcall s_tf_bB(char x, unsigned char c) { return c/3; } ! EXPORT(short) __stdcall s_tf_bh(char x, short c) { return c/3; } ! EXPORT(unsigned short) __stdcall s_tf_bH(char x, unsigned short c) { return c/3; } ! EXPORT(int) __stdcall s_tf_bi(char x, int c) { return c/3; } ! EXPORT(unsigned int) __stdcall s_tf_bI(char x, unsigned int c) { return c/3; } ! EXPORT(long) __stdcall s_tf_bl(char x, long c) { return c/3; } ! EXPORT(unsigned long) __stdcall s_tf_bL(char x, unsigned long c) { return c/3; } ! EXPORT(PY_LONG_LONG) __stdcall s_tf_bq(char x, PY_LONG_LONG c) { return c/3; } ! EXPORT(unsigned PY_LONG_LONG) __stdcall s_tf_bQ(char x, unsigned PY_LONG_LONG c) { return c/3; } ! EXPORT(float) __stdcall s_tf_bf(char x, float c) { return c/3; } ! EXPORT(double) __stdcall s_tf_bd(char x, double c) { return c/3; } ! EXPORT(void) __stdcall s_tv_i(int i) { return; } #endif --- 302,365 ---- }; ! #define S last_tf_arg_s = (PY_LONG_LONG)c ! #define U last_tf_arg_u = (unsigned PY_LONG_LONG)c ! ! EXPORT(char) tf_b(char c) { S; return c/3; } ! EXPORT(unsigned char) tf_B(unsigned char c) { U; return c/3; } ! EXPORT(short) tf_h(short c) { S; return c/3; } ! EXPORT(unsigned short) tf_H(unsigned short c) { U; return c/3; } ! EXPORT(int) tf_i(int c) { S; return c/3; } ! EXPORT(unsigned int) tf_I(unsigned int c) { U; return c/3; } ! EXPORT(long) tf_l(long c) { S; return c/3; } ! EXPORT(unsigned long) tf_L(unsigned long c) { U; return c/3; } ! EXPORT(PY_LONG_LONG) tf_q(PY_LONG_LONG c) { S; return c/3; } ! EXPORT(unsigned PY_LONG_LONG) tf_Q(unsigned PY_LONG_LONG c) { U; return c/3; } ! EXPORT(float) tf_f(float c) { S; return c/3; } ! EXPORT(double) tf_d(double c) { S; return c/3; } #ifdef MS_WIN32 ! EXPORT(char) __stdcall s_tf_b(char c) { S; return c/3; } ! EXPORT(unsigned char) __stdcall s_tf_B(unsigned char c) { U; return c/3; } ! EXPORT(short) __stdcall s_tf_h(short c) { S; return c/3; } ! EXPORT(unsigned short) __stdcall s_tf_H(unsigned short c) { U; return c/3; } ! EXPORT(int) __stdcall s_tf_i(int c) { S; return c/3; } ! EXPORT(unsigned int) __stdcall s_tf_I(unsigned int c) { U; return c/3; } ! EXPORT(long) __stdcall s_tf_l(long c) { S; return c/3; } ! EXPORT(unsigned long) __stdcall s_tf_L(unsigned long c) { U; return c/3; } ! EXPORT(PY_LONG_LONG) __stdcall s_tf_q(PY_LONG_LONG c) { S; return c/3; } ! EXPORT(unsigned PY_LONG_LONG) __stdcall s_tf_Q(unsigned PY_LONG_LONG c) { U; return c/3; } ! EXPORT(float) __stdcall s_tf_f(float c) { S; return c/3; } ! EXPORT(double) __stdcall s_tf_d(double c) { S; return c/3; } #endif /*******/ ! EXPORT(char) tf_bb(char x, char c) { S; return c/3; } ! EXPORT(unsigned char) tf_bB(char x, unsigned char c) { U; return c/3; } ! EXPORT(short) tf_bh(char x, short c) { S; return c/3; } ! EXPORT(unsigned short) tf_bH(char x, unsigned short c) { U; return c/3; } ! EXPORT(int) tf_bi(char x, int c) { S; return c/3; } ! EXPORT(unsigned int) tf_bI(char x, unsigned int c) { U; return c/3; } ! EXPORT(long) tf_bl(char x, long c) { S; return c/3; } ! EXPORT(unsigned long) tf_bL(char x, unsigned long c) { U; return c/3; } ! EXPORT(PY_LONG_LONG) tf_bq(char x, PY_LONG_LONG c) { S; return c/3; } ! EXPORT(unsigned PY_LONG_LONG) tf_bQ(char x, unsigned PY_LONG_LONG c) { U; return c/3; } ! EXPORT(float) tf_bf(char x, float c) { S; return c/3; } ! EXPORT(double) tf_bd(char x, double c) { S; return c/3; } ! EXPORT(void) tv_i(int c) { S; return; } #ifdef MS_WIN32 ! EXPORT(char) __stdcall s_tf_bb(char x, char c) { S; return c/3; } ! EXPORT(unsigned char) __stdcall s_tf_bB(char x, unsigned char c) { U; return c/3; } ! EXPORT(short) __stdcall s_tf_bh(char x, short c) { S; return c/3; } ! EXPORT(unsigned short) __stdcall s_tf_bH(char x, unsigned short c) { U; return c/3; } ! EXPORT(int) __stdcall s_tf_bi(char x, int c) { S; return c/3; } ! EXPORT(unsigned int) __stdcall s_tf_bI(char x, unsigned int c) { U; return c/3; } ! EXPORT(long) __stdcall s_tf_bl(char x, long c) { S; return c/3; } ! EXPORT(unsigned long) __stdcall s_tf_bL(char x, unsigned long c) { U; return c/3; } ! EXPORT(PY_LONG_LONG) __stdcall s_tf_bq(char x, PY_LONG_LONG c) { S; return c/3; } ! EXPORT(unsigned PY_LONG_LONG) __stdcall s_tf_bQ(char x, unsigned PY_LONG_LONG c) { U; return c/3; } ! EXPORT(float) __stdcall s_tf_bf(char x, float c) { S; return c/3; } ! EXPORT(double) __stdcall s_tf_bd(char x, double c) { S; return c/3; } ! EXPORT(void) __stdcall s_tv_i(int c) { S; return; } #endif |
From: Thomas H. <th...@us...> - 2004-08-27 18:17:50
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32749 Modified Files: _ctypes_test.c Log Message: The test functions now return their argument divided by 3, for better error detection. Index: _ctypes_test.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes_test.c,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** _ctypes_test.c 18 Aug 2004 12:57:45 -0000 1.24 --- _ctypes_test.c 27 Aug 2004 18:17:35 -0000 1.25 *************** *** 285,344 **** }; ! EXPORT(char) tf_b(char c) { return c; } ! EXPORT(unsigned char) tf_B(unsigned char c) { return c; } ! EXPORT(short) tf_h(short c) { return c; } ! EXPORT(unsigned short) tf_H(unsigned short c) { return c; } ! EXPORT(int) tf_i(int c) { return c; } ! EXPORT(unsigned int) tf_I(unsigned int c) { return c; } ! EXPORT(long) tf_l(long c) { return c; } ! EXPORT(unsigned long) tf_L(unsigned long c) { return c; } ! EXPORT(PY_LONG_LONG) tf_q(PY_LONG_LONG c) { return c; } ! EXPORT(unsigned PY_LONG_LONG) tf_Q(unsigned PY_LONG_LONG c) { return c; } ! EXPORT(float) tf_f(float c) { return c; } ! EXPORT(double) tf_d(double c) { return c; } #ifdef MS_WIN32 ! EXPORT(char) __stdcall s_tf_b(char c) { return c; } ! EXPORT(unsigned char) __stdcall s_tf_B(unsigned char c) { return c; } ! EXPORT(short) __stdcall s_tf_h(short c) { return c; } ! EXPORT(unsigned short) __stdcall s_tf_H(unsigned short c) { return c; } ! EXPORT(int) __stdcall s_tf_i(int c) { return c; } ! EXPORT(unsigned int) __stdcall s_tf_I(unsigned int c) { return c; } ! EXPORT(long) __stdcall s_tf_l(long c) { return c; } ! EXPORT(unsigned long) __stdcall s_tf_L(unsigned long c) { return c; } ! EXPORT(PY_LONG_LONG) __stdcall s_tf_q(PY_LONG_LONG c) { return c; } ! EXPORT(unsigned PY_LONG_LONG) __stdcall s_tf_Q(unsigned PY_LONG_LONG c) { return c; } ! EXPORT(float) __stdcall s_tf_f(float c) { return c; } ! EXPORT(double) __stdcall s_tf_d(double c) { return c; } #endif /*******/ ! EXPORT(char) tf_bb(char x, char c) { return c; } ! EXPORT(unsigned char) tf_bB(char x, unsigned char c) { return c; } ! EXPORT(short) tf_bh(char x, short c) { return c; } ! EXPORT(unsigned short) tf_bH(char x, unsigned short c) { return c; } ! EXPORT(int) tf_bi(char x, int c) { return c; } ! EXPORT(unsigned int) tf_bI(char x, unsigned int c) { return c; } ! EXPORT(long) tf_bl(char x, long c) { return c; } ! EXPORT(unsigned long) tf_bL(char x, unsigned long c) { return c; } ! EXPORT(PY_LONG_LONG) tf_bq(char x, PY_LONG_LONG c) { return c; } ! EXPORT(unsigned PY_LONG_LONG) tf_bQ(char x, unsigned PY_LONG_LONG c) { return c; } ! EXPORT(float) tf_bf(char x, float c) { return c; } ! EXPORT(double) tf_bd(char x, double c) { return c; } EXPORT(void) tv_i(int i) { return; } #ifdef MS_WIN32 ! EXPORT(char) __stdcall s_tf_bb(char x, char c) { return c; } ! EXPORT(unsigned char) __stdcall s_tf_bB(char x, unsigned char c) { return c; } ! EXPORT(short) __stdcall s_tf_bh(char x, short c) { return c; } ! EXPORT(unsigned short) __stdcall s_tf_bH(char x, unsigned short c) { return c; } ! EXPORT(int) __stdcall s_tf_bi(char x, int c) { return c; } ! EXPORT(unsigned int) __stdcall s_tf_bI(char x, unsigned int c) { return c; } ! EXPORT(long) __stdcall s_tf_bl(char x, long c) { return c; } ! EXPORT(unsigned long) __stdcall s_tf_bL(char x, unsigned long c) { return c; } ! EXPORT(PY_LONG_LONG) __stdcall s_tf_bq(char x, PY_LONG_LONG c) { return c; } ! EXPORT(unsigned PY_LONG_LONG) __stdcall s_tf_bQ(char x, unsigned PY_LONG_LONG c) { return c; } ! EXPORT(float) __stdcall s_tf_bf(char x, float c) { return c; } ! EXPORT(double) __stdcall s_tf_bd(char x, double c) { return c; } EXPORT(void) __stdcall s_tv_i(int i) { return; } #endif --- 285,344 ---- }; ! EXPORT(char) tf_b(char c) { return c/3; } ! EXPORT(unsigned char) tf_B(unsigned char c) { return c/3; } ! EXPORT(short) tf_h(short c) { return c/3; } ! EXPORT(unsigned short) tf_H(unsigned short c) { return c/3; } ! EXPORT(int) tf_i(int c) { return c/3; } ! EXPORT(unsigned int) tf_I(unsigned int c) { return c/3; } ! EXPORT(long) tf_l(long c) { return c/3; } ! EXPORT(unsigned long) tf_L(unsigned long c) { return c/3; } ! EXPORT(PY_LONG_LONG) tf_q(PY_LONG_LONG c) { return c/3; } ! EXPORT(unsigned PY_LONG_LONG) tf_Q(unsigned PY_LONG_LONG c) { return c/3; } ! EXPORT(float) tf_f(float c) { return c/3; } ! EXPORT(double) tf_d(double c) { return c/3; } #ifdef MS_WIN32 ! EXPORT(char) __stdcall s_tf_b(char c) { return c/3; } ! EXPORT(unsigned char) __stdcall s_tf_B(unsigned char c) { return c/3; } ! EXPORT(short) __stdcall s_tf_h(short c) { return c/3; } ! EXPORT(unsigned short) __stdcall s_tf_H(unsigned short c) { return c/3; } ! EXPORT(int) __stdcall s_tf_i(int c) { return c/3; } ! EXPORT(unsigned int) __stdcall s_tf_I(unsigned int c) { return c/3; } ! EXPORT(long) __stdcall s_tf_l(long c) { return c/3; } ! EXPORT(unsigned long) __stdcall s_tf_L(unsigned long c) { return c/3; } ! EXPORT(PY_LONG_LONG) __stdcall s_tf_q(PY_LONG_LONG c) { return c/3; } ! EXPORT(unsigned PY_LONG_LONG) __stdcall s_tf_Q(unsigned PY_LONG_LONG c) { return c/3; } ! EXPORT(float) __stdcall s_tf_f(float c) { return c/3; } ! EXPORT(double) __stdcall s_tf_d(double c) { return c/3; } #endif /*******/ ! EXPORT(char) tf_bb(char x, char c) { return c/3; } ! EXPORT(unsigned char) tf_bB(char x, unsigned char c) { return c/3; } ! EXPORT(short) tf_bh(char x, short c) { return c/3; } ! EXPORT(unsigned short) tf_bH(char x, unsigned short c) { return c/3; } ! EXPORT(int) tf_bi(char x, int c) { return c/3; } ! EXPORT(unsigned int) tf_bI(char x, unsigned int c) { return c/3; } ! EXPORT(long) tf_bl(char x, long c) { return c/3; } ! EXPORT(unsigned long) tf_bL(char x, unsigned long c) { return c/3; } ! EXPORT(PY_LONG_LONG) tf_bq(char x, PY_LONG_LONG c) { return c/3; } ! EXPORT(unsigned PY_LONG_LONG) tf_bQ(char x, unsigned PY_LONG_LONG c) { return c/3; } ! EXPORT(float) tf_bf(char x, float c) { return c/3; } ! EXPORT(double) tf_bd(char x, double c) { return c/3; } EXPORT(void) tv_i(int i) { return; } #ifdef MS_WIN32 ! EXPORT(char) __stdcall s_tf_bb(char x, char c) { return c/3; } ! EXPORT(unsigned char) __stdcall s_tf_bB(char x, unsigned char c) { return c/3; } ! EXPORT(short) __stdcall s_tf_bh(char x, short c) { return c/3; } ! EXPORT(unsigned short) __stdcall s_tf_bH(char x, unsigned short c) { return c/3; } ! EXPORT(int) __stdcall s_tf_bi(char x, int c) { return c/3; } ! EXPORT(unsigned int) __stdcall s_tf_bI(char x, unsigned int c) { return c/3; } ! EXPORT(long) __stdcall s_tf_bl(char x, long c) { return c/3; } ! EXPORT(unsigned long) __stdcall s_tf_bL(char x, unsigned long c) { return c/3; } ! EXPORT(PY_LONG_LONG) __stdcall s_tf_bq(char x, PY_LONG_LONG c) { return c/3; } ! EXPORT(unsigned PY_LONG_LONG) __stdcall s_tf_bQ(char x, unsigned PY_LONG_LONG c) { return c/3; } ! EXPORT(float) __stdcall s_tf_bf(char x, float c) { return c/3; } ! EXPORT(double) __stdcall s_tf_bd(char x, double c) { return c/3; } EXPORT(void) __stdcall s_tv_i(int i) { return; } #endif |
From: Thomas H. <th...@us...> - 2004-08-27 18:03:45
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29897 Modified Files: test_cfuncs.py Log Message: Enlarge the numbers the tests use, for better error detection. Index: test_cfuncs.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_cfuncs.py,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** test_cfuncs.py 28 Jul 2004 12:56:55 -0000 1.11 --- test_cfuncs.py 27 Aug 2004 18:03:35 -0000 1.12 *************** *** 21,106 **** self.dll.tf_b.restype = c_byte self.dll.tf_b.argtypes = (c_byte,) ! self.failUnlessEqual(self.dll.tf_b(-42), -42) self.dll.tf_bb.restype = c_byte self.dll.tf_bb.argtypes = (c_byte, c_byte) ! self.failUnlessEqual(self.dll.tf_bb(0, -42), -42) def test_ubyte(self): self.dll.tf_B.restype = c_ubyte self.dll.tf_B.argtypes = (c_ubyte,) ! self.failUnlessEqual(self.dll.tf_B(42), 42) self.dll.tf_bB.restype = c_ubyte self.dll.tf_bB.argtypes = (c_byte, c_ubyte) ! self.failUnlessEqual(self.dll.tf_bB(0, 42), 42) def test_short(self): self.dll.tf_h.restype = c_short ! self.failUnlessEqual(self.dll.tf_h(-42), -42) self.dll.tf_bh.restype = c_short ! self.failUnlessEqual(self.dll.tf_bh(0, -42), -42) def test_ushort(self): self.dll.tf_H.restype = c_ushort ! self.failUnlessEqual(self.dll.tf_H(42), 42) self.dll.tf_bH.restype = c_ushort ! self.failUnlessEqual(self.dll.tf_bH(0, 42), 42) def test_int(self): self.dll.tf_i.restype = c_int ! self.failUnlessEqual(self.dll.tf_i(-42), -42) self.dll.tf_bi.restype = c_int ! self.failUnlessEqual(self.dll.tf_bi(0, -42), -42) def test_uint(self): self.dll.tf_I.restype = c_uint ! self.failUnlessEqual(self.dll.tf_I(42), 42) self.dll.tf_bI.restype = c_uint ! self.failUnlessEqual(self.dll.tf_bI(0, 42), 42) def test_long(self): self.dll.tf_l.restype = c_long self.dll.tf_l.argtypes = (c_long,) ! self.failUnlessEqual(self.dll.tf_l(-42), -42) self.dll.tf_bl.restype = c_long self.dll.tf_bl.argtypes = (c_byte, c_long) ! self.failUnlessEqual(self.dll.tf_bl(0, -42), -42) def test_ulong(self): self.dll.tf_L.restype = c_ulong ! self.failUnlessEqual(self.dll.tf_L(42), 42) self.dll.tf_bL.restype = c_ulong ! self.failUnlessEqual(self.dll.tf_bL(0, 42), 42) def test_longlong(self): self.dll.tf_q.restype = c_longlong self.dll.tf_q.argtypes = (c_longlong, ) ! self.failUnlessEqual(self.dll.tf_q(-42L), -42L) self.dll.tf_bq.restype = c_longlong self.dll.tf_bq.argtypes = (c_byte, c_longlong) ! self.failUnlessEqual(self.dll.tf_bq(0, -42), -42) def test_ulonglong(self): self.dll.tf_Q.restype = c_ulonglong self.dll.tf_Q.argtypes = (c_longlong, ) ! self.failUnlessEqual(self.dll.tf_Q(42), 42) self.dll.tf_bQ.restype = c_ulonglong self.dll.tf_bQ.argtypes = (c_byte, c_ulonglong) ! self.failUnlessEqual(self.dll.tf_bQ(0, 42), 42) def test_float(self): self.dll.tf_f.restype = c_float self.dll.tf_f.argtypes = (c_float,) ! self.failUnlessEqual(self.dll.tf_f(-42.), -42.) self.dll.tf_bf.restype = c_float self.dll.tf_bf.argtypes = (c_byte, c_float) ! self.failUnlessEqual(self.dll.tf_bf(0, -42.), -42.) def test_double(self): self.dll.tf_d.restype = c_double self.dll.tf_d.argtypes = (c_double,) ! self.failUnlessEqual(self.dll.tf_d(42), 42) self.dll.tf_bd.restype = c_double self.dll.tf_bd.argtypes = (c_byte, c_double) ! self.failUnlessEqual(self.dll.tf_bd(0, 42), 42) def test_callwithresult(self): --- 21,106 ---- self.dll.tf_b.restype = c_byte self.dll.tf_b.argtypes = (c_byte,) ! self.failUnlessEqual(self.dll.tf_b(-126), -42) self.dll.tf_bb.restype = c_byte self.dll.tf_bb.argtypes = (c_byte, c_byte) ! self.failUnlessEqual(self.dll.tf_bb(0, -126), -42) def test_ubyte(self): self.dll.tf_B.restype = c_ubyte self.dll.tf_B.argtypes = (c_ubyte,) ! self.failUnlessEqual(self.dll.tf_B(255), 85) self.dll.tf_bB.restype = c_ubyte self.dll.tf_bB.argtypes = (c_byte, c_ubyte) ! self.failUnlessEqual(self.dll.tf_bB(0, 255), 85) def test_short(self): self.dll.tf_h.restype = c_short ! self.failUnlessEqual(self.dll.tf_h(-32766), -10922) self.dll.tf_bh.restype = c_short ! self.failUnlessEqual(self.dll.tf_bh(0, -32766), -10922) def test_ushort(self): self.dll.tf_H.restype = c_ushort ! self.failUnlessEqual(self.dll.tf_H(65535), 21845) self.dll.tf_bH.restype = c_ushort ! self.failUnlessEqual(self.dll.tf_bH(0, 65535), 21845) def test_int(self): self.dll.tf_i.restype = c_int ! self.failUnlessEqual(self.dll.tf_i(-2147483646), -715827882) self.dll.tf_bi.restype = c_int ! self.failUnlessEqual(self.dll.tf_bi(0, -2147483646), -715827882) def test_uint(self): self.dll.tf_I.restype = c_uint ! self.failUnlessEqual(self.dll.tf_I(4294967295), 1431655765) self.dll.tf_bI.restype = c_uint ! self.failUnlessEqual(self.dll.tf_bI(0, 4294967295), 1431655765) def test_long(self): self.dll.tf_l.restype = c_long self.dll.tf_l.argtypes = (c_long,) ! self.failUnlessEqual(self.dll.tf_l(-2147483646), -715827882) self.dll.tf_bl.restype = c_long self.dll.tf_bl.argtypes = (c_byte, c_long) ! self.failUnlessEqual(self.dll.tf_bl(0, -2147483646), -715827882) def test_ulong(self): self.dll.tf_L.restype = c_ulong ! self.failUnlessEqual(self.dll.tf_L(4294967295), 1431655765) self.dll.tf_bL.restype = c_ulong ! self.failUnlessEqual(self.dll.tf_bL(0, 4294967295), 1431655765) def test_longlong(self): self.dll.tf_q.restype = c_longlong self.dll.tf_q.argtypes = (c_longlong, ) ! self.failUnlessEqual(self.dll.tf_q(-9223372036854775806), -3074457345618258602) self.dll.tf_bq.restype = c_longlong self.dll.tf_bq.argtypes = (c_byte, c_longlong) ! self.failUnlessEqual(self.dll.tf_bq(0, -9223372036854775806), -3074457345618258602) def test_ulonglong(self): self.dll.tf_Q.restype = c_ulonglong self.dll.tf_Q.argtypes = (c_longlong, ) ! self.failUnlessEqual(self.dll.tf_Q(18446744073709551615), 6148914691236517205) self.dll.tf_bQ.restype = c_ulonglong self.dll.tf_bQ.argtypes = (c_byte, c_ulonglong) ! self.failUnlessEqual(self.dll.tf_bQ(0, 18446744073709551615), 6148914691236517205) def test_float(self): self.dll.tf_f.restype = c_float self.dll.tf_f.argtypes = (c_float,) ! self.failUnlessEqual(self.dll.tf_f(-42.), -14.) self.dll.tf_bf.restype = c_float self.dll.tf_bf.argtypes = (c_byte, c_float) ! self.failUnlessEqual(self.dll.tf_bf(0, -42.), -14.) def test_double(self): self.dll.tf_d.restype = c_double self.dll.tf_d.argtypes = (c_double,) ! self.failUnlessEqual(self.dll.tf_d(42.), 14.) self.dll.tf_bd.restype = c_double self.dll.tf_bd.argtypes = (c_byte, c_double) ! self.failUnlessEqual(self.dll.tf_bd(0, 42.), 14.) def test_callwithresult(self): *************** *** 109,114 **** self.dll.tf_i.restype = process_result self.dll.tf_i.argtypes = (c_int,) ! self.failUnlessEqual(self.dll.tf_i(42), 84) ! self.failUnlessEqual(self.dll.tf_i(-42), -84) def test_void(self): --- 109,114 ---- self.dll.tf_i.restype = process_result self.dll.tf_i.argtypes = (c_int,) ! self.failUnlessEqual(self.dll.tf_i(42), 28) ! self.failUnlessEqual(self.dll.tf_i(-42), -28) def test_void(self): |
From: Thomas H. <th...@us...> - 2004-08-27 17:10:43
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19051 Modified Files: ChangeLog ANNOUNCE Log Message: Changes. Index: ANNOUNCE =================================================================== RCS file: /cvsroot/ctypes/ctypes/ANNOUNCE,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** ANNOUNCE 27 Aug 2004 11:52:17 -0000 1.9 --- ANNOUNCE 27 Aug 2004 17:10:22 -0000 1.10 *************** *** 23,28 **** --- 23,40 ---- Changes in 0.9.1 + ctypes 0.9.1 should be fully compatible again with Gary Bishop's + readline module which is also used by IPython. + ctypes changes + It is now possible to create strings or unicode strings if you + have the integer address by calling c_char_p(address) or + c_wchar_p(address). Integers can also be assigned to structure + fields of type c_char_p and c_wchar_p. + + c_char_p and c_wchar_p both accept strings and unicode strings - + if needed they are encoded or decoded using 'strict' error + handling. + The _ctypes.call_function function, although private and deprecated, has been put back in - it is used by Gary Bishop's *************** *** 51,57 **** ctypes now caches the types that WINFUNCTYPE and CFUNCTYPE ! creates, to avoid creation of a lot of similar classes. This makes ! importing files containing a lot of COM interfaces (like the ones ! that the readtlb tool generates) a lot (10 x) faster. COM servers now print a short usage message when they are run --- 63,69 ---- ctypes now caches the types that WINFUNCTYPE and CFUNCTYPE ! creates, to avoid unneeeded creation of classes. This ! makes importing files containing a lot of COM interfaces (like the ! ones that the readtlb tool generates) a lot (10 x) faster. COM servers now print a short usage message when they are run *************** *** 61,71 **** datetime. ! VARIANT now handles integers and longs - if longs are too large ! they are stored as doubles (VT_R8). Integers are now stored as ! VT_I4 instead of VT_INT. ! ! Detailed changelogs are in CVS (well, sometimes I forget to update ! them): <http://cvs.sourceforge.net/viewcvs.py/ctypes/ctypes/ChangeLog?rev=HEAD> --- 73,81 ---- datetime. ! VARIANT now handles integers and longs correctly - if longs are ! too large they are stored as doubles (VT_R8). Integers are now ! stored as VT_I4 instead of VT_INT. ! Detailed changelogs are in CVS: <http://cvs.sourceforge.net/viewcvs.py/ctypes/ctypes/ChangeLog?rev=HEAD> Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/ChangeLog,v retrieving revision 1.53 retrieving revision 1.54 diff -C2 -d -r1.53 -r1.54 *** ChangeLog 27 Aug 2004 11:52:17 -0000 1.53 --- ChangeLog 27 Aug 2004 17:10:22 -0000 1.54 *************** *** 1,2 **** --- 1,14 ---- + 2004-08-27 Thomas Heller <th...@py...> + + * ctypes: Accept integer addresses, uncode strings, and strings in + the c_char_p and c_wchar_p constructor and as c_char_p and + c_wchar_p fields in Structures. strings are automatically decoded + to unicode, and unicode is automatically encoded in strings if + needed. + + Integer addresses are *not* accepted in function parameter lists, + they must before be converted to c_char_p or c_wchar_p. + + 2004-08-26 Thomas Heller <th...@py...> |
From: Thomas H. <th...@us...> - 2004-08-27 17:06:24
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18289 Modified Files: setup.py Log Message: Reorder the code, and clean up a bit. The ctypes.com samples are now handled as data_files instead of packages - this removes the warning that the __init__.py files are missing. Index: setup.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/setup.py,v retrieving revision 1.102 retrieving revision 1.103 diff -C2 -d -r1.102 -r1.103 *** setup.py 18 Aug 2004 13:29:12 -0000 1.102 --- setup.py 27 Aug 2004 17:06:14 -0000 1.103 *************** *** 29,94 **** from distutils.util import get_platform - kw = {} - kw["sources"] = ["source/_ctypes.c", - "source/callbacks.c", - "source/callproc.c", - "source/stgdict.c", - "source/cfield.c"] - - # Support the distutils 'depends' option, if available - if hasattr(distutils.core, 'get_distutil_options'): - # Python 2.3a1 - kw["depends"] = ["source/ctypes.h"] - elif (hasattr(distutils.core, 'extension_keywords') and - 'depends' in distutils.core.extension_keywords): - # Python current CVS - kw["depends"] = ["source/ctypes.h"] - - - if os.name == "nt": - kw["sources"].extend([ - # types.c is no longer needed, ffi_type defs are in cfield.c - "source/libffi_msvc/ffi.c", - "source/libffi_msvc/prep_cif.c", - "source/libffi_msvc/win32.c", - ]) - extensions = [Extension("_ctypes", - export_symbols=["DllGetClassObject,PRIVATE", - "DllCanUnloadNow,PRIVATE"], - libraries=["ole32", "user32", "oleaut32"], - include_dirs=["source/libffi_msvc"], - **kw), - Extension("_ctypes_test", - libraries=["oleaut32"], - sources=["source/_ctypes_test.c"], - include_dirs=["source/libffi_msvc"], - ) - ] - if kw.has_key("depends"): - kw["depends"].extend(["source/libffi_msvc/ffi.h", - "source/libffi_msvc/fficonfig.h", - "source/libffi_msvc/ffitarget.h", - "source/libffi_msvc/ffi_common.h"]) - else: - include_dirs = [] - library_dirs = [] - extra_link_args = [] - if sys.platform == "darwin": - kw["sources"].append("source/darwin/dlfcn_simple.c") - extra_link_args.extend(['-read_only_relocs', 'warning']) - include_dirs.append("source/darwin") - - extensions = [Extension("_ctypes", - libraries=["ffi"], - include_dirs=include_dirs, - library_dirs=library_dirs, - extra_link_args=extra_link_args, - **kw), - Extension("_ctypes_test", - sources=["source/_ctypes_test.c"]) - ] ################################################################ ! # Parts of this section copied from the PyObjC project if sys.platform == 'darwin': # Apple has used build options that don't work with a 'normal' system. # Remove '-arch i386' from the LDFLAGS. --- 29,37 ---- from distutils.util import get_platform ################################################################ ! # Manipulate the environment for the build process. ! # if sys.platform == 'darwin': + # This section copied from the PyObjC project # Apple has used build options that don't work with a 'normal' system. # Remove '-arch i386' from the LDFLAGS. *************** *** 101,141 **** distutils.sysconfig._config_vars['LDSHARED'] = y ! ##if sys.platform != 'darwin' and os.path.exists('/usr/include/ffi.h') \ ! ## or os.path.exists('/usr/local/include/ffi.h'): ! ## # A system with a pre-existing libffi. ! ## LIBFFI_SOURCES=None ! ! if sys.platform == 'win32': ! LIBFFI_SOURCES=None ! ! platform = get_platform() ! ! if platform in ["solaris-2.9-sun4u", "linux-x86_64"]: os.environ["CFLAGS"] = "-fPIC" ################################################################ ! ! packages = ["ctypes"] ! package_dir = {} ! ! if sys.platform == "win32": ! packages.append("ctypes.com") ! package_dir["ctypes.com"] = "win32/com" ! packages.append("ctypes.com.samples") ! package_dir["ctypes.com.samples"] = "win32/com/samples" ! packages.append("ctypes.com.tools") ! package_dir["ctypes.com.tools"] = "win32/com/tools" ! ! packages.append("ctypes.com.samples.server") ! package_dir["ctypes.com.samples.server"] = "win32/com/samples/server" ! ! packages.append("ctypes.com.samples.server.control") ! package_dir["ctypes.com.samples.server.control"] = "win32/com/samples/server/control" ! ! packages.append("ctypes.com.samples.server.IExplorer") ! package_dir["ctypes.com.samples.server.IExplorer"] = "win32/com/samples/server/IExplorer" ! ! ################################################################ ! class test(Command): # Original version of this class posted --- 44,53 ---- distutils.sysconfig._config_vars['LDSHARED'] = y ! if get_platform() in ["solaris-2.9-sun4u", "linux-x86_64"]: os.environ["CFLAGS"] = "-fPIC" ################################################################ ! # Additional and overridden distutils commands ! # class test(Command): # Original version of this class posted *************** *** 232,236 **** print >> sys.stderr, "-" * 70 ! print >> sys.stderr, "Ran %d tests in %.3fs" % (len(self.testcases), stop_time - start_time) print >> sys.stderr if self.fail + self.errors == 0: --- 144,149 ---- print >> sys.stderr, "-" * 70 ! print >> sys.stderr, "Ran %d tests in %.3fs" % (len(self.testcases), ! stop_time - start_time) print >> sys.stderr if self.fail + self.errors == 0: *************** *** 238,242 **** else: if self.errors: ! print >> sys.stderr, "FAILED (failures=%d, errors=%d)" % (self.fail, self.errors) else: print >> sys.stderr, "FAILED (failures=%d)" % self.fail --- 151,156 ---- else: if self.errors: ! print >> sys.stderr, "FAILED (failures=%d, errors=%d)" % (self.fail, ! self.errors) else: print >> sys.stderr, "FAILED (failures=%d)" % self.fail *************** *** 292,307 **** # class test - if (hasattr(distutils.core, 'setup_keywords') and - 'classifiers' in distutils.core.setup_keywords): - kw['classifiers'] = \ - ['Topic :: Software Development', - 'Operating System :: MacOS :: MacOS X', - 'Operating System :: Microsoft :: Windows', - 'Operating System :: POSIX', - 'Intended Audience :: Developers', - 'Development Status :: 3 - Alpha', - 'Development Status :: 4 - Beta', - ] - class my_build_py(build_py.build_py): def find_package_modules (self, package, package_dir): --- 206,209 ---- *************** *** 317,322 **** return result - ################################################################ - def find_file_in_subdir(dirname, filename): # if <filename> is in <dirname> or any subdirectory thereof, --- 219,222 ---- *************** *** 328,331 **** --- 228,232 ---- class my_build_ext(build_ext.build_ext): + # First build a static libffi library, then build the _ctypes extension. def run(self): self.build_libffi_static() *************** *** 351,354 **** --- 252,257 ---- def build_libffi_static(self): + if sys.platform == "win32": + return if LIBFFI_SOURCES == None: return *************** *** 389,406 **** clean.clean.run(self) - # Use different MANIFEST templates, to minimize the distribution size. - # Also, the MANIFEST templates behave differently on Windows and Linux (distutils bug?) - options = {} - - if sys.platform == 'win32': - options["sdist"] = {"template": "MANIFEST.windows.in", "force_manifest": 1} - data_files = [("ctypes/com/samples/server/control", - ["win32/com/samples/server/control/test.html"]) - ] - - else: - options["sdist"] = {"template": "MANIFEST.other.in", "force_manifest": 1} - data_files = [] - class my_install_data(install_data.install_data): """A custom install_data command, which will install it's files --- 292,295 ---- *************** *** 414,417 **** --- 303,434 ---- install_data.install_data.finalize_options(self) + ################################################################ + # Specify the _ctypes extension + # + kw = {} + # common source files + kw["sources"] = ["source/_ctypes.c", + "source/callbacks.c", + "source/callproc.c", + "source/stgdict.c", + "source/cfield.c"] + + # common header file + kw["depends"] = ["source/ctypes.h"] + + if sys.platform == "win32": + kw["sources"].extend([ + # types.c is no longer needed, ffi_type defs are in cfield.c + "source/libffi_msvc/ffi.c", + "source/libffi_msvc/prep_cif.c", + "source/libffi_msvc/win32.c", + ]) + extensions = [Extension("_ctypes", + export_symbols=["DllGetClassObject,PRIVATE", + "DllCanUnloadNow,PRIVATE"], + libraries=["ole32", "user32", "oleaut32"], + include_dirs=["source/libffi_msvc"], + **kw), + Extension("_ctypes_test", + libraries=["oleaut32"], + sources=["source/_ctypes_test.c"], + include_dirs=["source/libffi_msvc"], + ) + ] + if kw.has_key("depends"): + kw["depends"].extend(["source/libffi_msvc/ffi.h", + "source/libffi_msvc/fficonfig.h", + "source/libffi_msvc/ffitarget.h", + "source/libffi_msvc/ffi_common.h"]) + else: + include_dirs = [] + library_dirs = [] + extra_link_args = [] + if sys.platform == "darwin": + kw["sources"].append("source/darwin/dlfcn_simple.c") + extra_link_args.extend(['-read_only_relocs', 'warning']) + include_dirs.append("source/darwin") + + extensions = [Extension("_ctypes", + libraries=["ffi"], + include_dirs=include_dirs, + library_dirs=library_dirs, + extra_link_args=extra_link_args, + **kw), + Extension("_ctypes_test", + sources=["source/_ctypes_test.c"]) + ] + ################################################################ + # the ctypes package + # + packages = ["ctypes"] + package_dir = {} + + ################################################################ + # the ctypes.com package + # + if sys.platform == "win32": + packages.append("ctypes.com") + package_dir["ctypes.com"] = "win32/com" + + packages.append("ctypes.com.tools") + package_dir["ctypes.com.tools"] = "win32/com/tools" + + ################################################################ + # options for distutils, and ctypes.com samples + # + setup_options = {} + + if sys.platform == 'win32': + # Use different MANIFEST templates, to minimize the distribution + # size. Also, the MANIFEST templates behave differently on + # Windows and Linux (distutils bug?). + # Finally, force rebuilding the MANIFEST file + + setup_options["sdist"] = {"template": "MANIFEST.windows.in", "force_manifest": 1} + + import glob + data_files = [("ctypes/com/samples", + glob.glob("win32/com/samples/*.py") + + glob.glob("win32/com/samples/*.txt")), + + ("ctypes/com/samples/server", + glob.glob("win32/com/samples/server/*.py") + + glob.glob("win32/com/samples/server/*.txt")), + + ("ctypes/com/samples/server/control", + glob.glob("win32/com/samples/server/control/*.py") + + glob.glob("win32/com/samples/server/control/*.txt") + + glob.glob("win32/com/samples/server/control/*.html")), + + ("ctypes/com/samples/server/IExplorer", + glob.glob("win32/com/samples/server/IExplorer/*.py") + + glob.glob("win32/com/samples/server/IExplorer/*.txt") + + glob.glob("win32/com/samples/server/IExplorer/*.html")), + ] + + else: + setup_options["sdist"] = {"template": "MANIFEST.other.in", "force_manifest": 1} + data_files = [] + + ################################################################ + # pypi classifiers + # + classifiers = [ + 'Development Status :: 4 - Beta', + 'Development Status :: 5 - Production/Stable', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: MIT License', + 'Operating System :: MacOS :: MacOS X', + 'Operating System :: Microsoft :: Windows', + 'Operating System :: POSIX', + 'Programming Language :: C', + 'Programming Language :: Python', + 'Topic :: Software Development :: Libraries :: Python Modules', + ] + + ################################################################ + # main section + # if __name__ == '__main__': setup(name="ctypes", *************** *** 421,424 **** --- 438,443 ---- data_files = data_files, + classifiers = classifiers, + version=__version__, description="create and manipulate C data types in Python", *************** *** 432,436 **** cmdclass = {'test': test, 'build_py': my_build_py, 'build_ext': my_build_ext, 'clean': my_clean, 'install_data': my_install_data}, ! options = options ) --- 451,455 ---- cmdclass = {'test': test, 'build_py': my_build_py, 'build_ext': my_build_ext, 'clean': my_clean, 'install_data': my_install_data}, ! options = setup_options ) |
From: Thomas H. <th...@us...> - 2004-08-27 16:14:45
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8811 Modified Files: MANIFEST.windows.in Log Message: Replace / with \. Complete the list of files to be included. Index: MANIFEST.windows.in =================================================================== RCS file: /cvsroot/ctypes/ctypes/MANIFEST.windows.in,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** MANIFEST.windows.in 18 Aug 2004 13:47:35 -0000 1.4 --- MANIFEST.windows.in 27 Aug 2004 16:14:23 -0000 1.5 *************** *** 2,15 **** include run_remote_test.py ! include ctypes/.CTYPES_DEVEL ! include source/ctypes.h source/libffi_msvc/*.h recursive-include unittests *.py ! include docs/*.html ! include docs/*.css ! include docs/*.stx - include samples/rt recursive-include samples *.py ! include win32/com/samples/server/control/test.html --- 2,16 ---- include run_remote_test.py ! include ctypes\.CTYPES_DEVEL ! include source\ctypes.h source\libffi_msvc\*.h recursive-include unittests *.py ! include docs\*.html ! include docs\*.css ! include docs\*.stx ! ! include samples\rt samples\rt.bat recursive-include samples *.py ! recursive-include win32\com\samples *.py *.txt *.html |
From: Thomas H. <th...@us...> - 2004-08-27 12:04:59
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17929 Modified Files: test_parameters.py Log Message: Accept integer addresses, uncode strings, and strings in the c_char_p and c_wchar_p constructor and as c_char_p and c_wchar_p fields in Structures. strings are automatically decoded to unicode, and unicode is automatically encoded in strings if needed. Integer addresses are *not* accepted in function parameter lists, they must before be converted to c_char_p or c_wchar_p. Index: test_parameters.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_parameters.py,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** test_parameters.py 4 May 2004 09:15:19 -0000 1.23 --- test_parameters.py 27 Aug 2004 12:04:50 -0000 1.24 *************** *** 12,16 **** self.failUnless(c_char_p.from_param(s)._obj is s) ! self.assertRaises(TypeError, c_char_p.from_param, u"123") self.assertRaises(TypeError, c_char_p.from_param, 42) --- 12,19 ---- self.failUnless(c_char_p.from_param(s)._obj is s) ! # new in 0.9.1: convert (encode) unicode to ascii ! self.failUnlessEqual(c_char_p.from_param(u"123")._obj, "123") ! self.assertRaises(UnicodeEncodeError, c_char_p.from_param, u"123\377") ! self.assertRaises(TypeError, c_char_p.from_param, 42) *************** *** 30,36 **** self.failUnless(c_wchar_p.from_param(s)._obj is s) - ## self.assertRaises(TypeError, c_wchar_p.from_param, "123") self.assertRaises(TypeError, c_wchar_p.from_param, 42) pa = c_wchar_p.from_param(c_wchar_p(u"123")) self.failUnlessEqual(type(pa), c_wchar_p) --- 33,42 ---- self.failUnless(c_wchar_p.from_param(s)._obj is s) self.assertRaises(TypeError, c_wchar_p.from_param, 42) + # new in 0.9.1: convert (decode) ascii to unicode + self.failUnlessEqual(c_wchar_p.from_param("123")._obj, u"123") + self.assertRaises(UnicodeDecodeError, c_wchar_p.from_param, "123\377") + pa = c_wchar_p.from_param(c_wchar_p(u"123")) self.failUnlessEqual(type(pa), c_wchar_p) |
From: Thomas H. <th...@us...> - 2004-08-27 12:04:32
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17820 Modified Files: _ctypes.c Log Message: Accept integer addresses, uncode strings, and strings in the c_char_p and c_wchar_p constructor and as c_char_p and c_wchar_p fields in Structures. strings are automatically decoded to unicode, and unicode is automatically encoded in strings if needed. Integer addresses are *not* accepted in function parameter lists, they must before be converted to c_char_p or c_wchar_p. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.153 retrieving revision 1.154 diff -C2 -d -r1.153 -r1.154 *** _ctypes.c 20 Aug 2004 14:20:10 -0000 1.153 --- _ctypes.c 27 Aug 2004 12:04:14 -0000 1.154 *************** *** 936,940 **** return Py_None; } ! if (PyUnicode_Check(value)) { PyCArgObject *parg; struct fielddesc *fd = getentry("Z"); --- 936,940 ---- return Py_None; } ! if (PyUnicode_Check(value) || PyString_Check(value)) { PyCArgObject *parg; struct fielddesc *fd = getentry("Z"); *************** *** 989,993 **** return Py_None; } ! if (PyString_Check(value)) { PyCArgObject *parg; struct fielddesc *fd = getentry("z"); --- 989,993 ---- return Py_None; } ! if (PyString_Check(value) || PyUnicode_Check(value)) { PyCArgObject *parg; struct fielddesc *fd = getentry("z"); |
From: Thomas H. <th...@us...> - 2004-08-27 12:03:04
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17484 Modified Files: cfield.c Log Message: Accept integer addresses, uncode strings, and strings in the c_char_p and c_wchar_p constructor and as c_char_p and c_wchar_p fields in Structures. strings are automatically decoded to unicode, and unicode is automatically encoded in strings if needed. Integer addresses are *not* accepted in function parameter lists, they must before be converted to c_char_p or c_wchar_p. Index: cfield.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/cfield.c,v retrieving revision 1.40 retrieving revision 1.41 diff -C2 -d -r1.40 -r1.41 *** cfield.c 20 Aug 2004 14:51:50 -0000 1.40 --- cfield.c 27 Aug 2004 12:02:54 -0000 1.41 *************** *** 705,717 **** return value; } ! if (!PyString_Check(value)) { ! PyErr_Format(PyExc_TypeError, ! "string expected instead of %s instance", ! value->ob_type->tp_name); ! return NULL; } ! *(char **)ptr = PyString_AS_STRING(value); ! Py_INCREF(value); ! return value; } --- 705,728 ---- return value; } ! if (PyString_Check(value)) { ! *(char **)ptr = PyString_AS_STRING(value); ! Py_INCREF(value); ! return value; ! } else if (PyUnicode_Check(value)) { ! PyObject *str = PyUnicode_AsASCIIString(value); ! if (str == NULL) ! return NULL; ! *(char **)ptr = PyString_AS_STRING(str); ! Py_INCREF(str); ! return str; ! } else if (PyInt_Check(value) || PyLong_Check(value)) { ! *(char **)ptr = PyInt_AsUnsignedLongMask(value); ! Py_INCREF(Py_None); ! return Py_None; } ! PyErr_Format(PyExc_TypeError, ! "string or integer address expected instead of %s instance", ! value->ob_type->tp_name); ! return NULL; } *************** *** 740,747 **** if (!value) return NULL; } else if (!PyUnicode_Check(value)) { PyErr_Format(PyExc_TypeError, ! "unicode string expected instead of %s instance", ! value->ob_type->tp_name); return NULL; } else --- 751,762 ---- if (!value) return NULL; + } else if (PyInt_Check(value) || PyLong_Check(value)) { + *(wchar_t **)ptr = PyInt_AsUnsignedLongMask(value); + Py_INCREF(Py_None); + return Py_None; } else if (!PyUnicode_Check(value)) { PyErr_Format(PyExc_TypeError, ! "unicode string or integer address expected instead of %s instance", ! value->ob_type->tp_name); return NULL; } else |
From: Thomas H. <th...@us...> - 2004-08-27 11:52:43
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15440 Modified Files: NEWS.txt ChangeLog ANNOUNCE Log Message: Record changes. Index: ANNOUNCE =================================================================== RCS file: /cvsroot/ctypes/ctypes/ANNOUNCE,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** ANNOUNCE 20 Aug 2004 15:33:28 -0000 1.8 --- ANNOUNCE 27 Aug 2004 11:52:17 -0000 1.9 *************** *** 18,22 **** On windows, ctypes contains a ctypes.com package which allows to ! descrive, call, and implement custom com interfaces. --- 18,22 ---- On windows, ctypes contains a ctypes.com package which allows to ! call and implement custom COM interfaces. *************** *** 41,44 **** --- 41,46 ---- returns the alignment requirements in bytes of a type or instance. + experimental changes + It is now possible to call Python API functions with ctypes. This is an experimental feature and will probably change. Please don't *************** *** 48,51 **** --- 50,58 ---- ctypes.com changes + ctypes now caches the types that WINFUNCTYPE and CFUNCTYPE + creates, to avoid creation of a lot of similar classes. This makes + importing files containing a lot of COM interfaces (like the ones + that the readtlb tool generates) a lot (10 x) faster. + COM servers now print a short usage message when they are run without the /regserver or /unregserver flag. Index: NEWS.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/NEWS.txt,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** NEWS.txt 26 Aug 2004 18:19:09 -0000 1.5 --- NEWS.txt 27 Aug 2004 11:52:17 -0000 1.6 *************** *** 19,22 **** --- 19,33 ---- strings resp. unicode strings are used - much more convenient. + Experimatal change: + + It is now possibile to safely call Python C Api functions. + Before, this was dangerous because ctypes releases and reaquires + the threadstate before resp. after the call of C functions. Most + Python API functions require a valid threadstate, especially in + combination with the native windows handling this could lead to + very strange effects. This functionality is experimental and will + probably change in future releases, if you want to try it out you + should ask on the ctypes-users mailing list. + Other Versions: no news recorded in this file! Please see the CVS commit messages. Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/ChangeLog,v retrieving revision 1.52 retrieving revision 1.53 diff -C2 -d -r1.52 -r1.53 *** ChangeLog 26 Aug 2004 18:19:09 -0000 1.52 --- ChangeLog 27 Aug 2004 11:52:17 -0000 1.53 *************** *** 1,4 **** --- 1,7 ---- 2004-08-26 Thomas Heller <th...@py...> + * source\callproc.c: Implemented Py_INCREF and Py_DECREF as + functions. + * ctypes\__init__.py: Cache the types that WINFUNCTYPE and CFUNCTYPE creates, to avoid creation of a lot of similar classes. |
From: Thomas H. <th...@us...> - 2004-08-26 19:59:31
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16588 Modified Files: callproc.c Log Message: Add a comment about a variable which looks unused, but is not. Let dlopen accept None in addition to a string. Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.99 retrieving revision 1.100 diff -C2 -d -r1.99 -r1.100 *** callproc.c 26 Aug 2004 19:38:27 -0000 1.99 --- callproc.c 26 Aug 2004 19:59:21 -0000 1.100 *************** *** 585,589 **** int argcount) { ! PyThreadState *_save; ffi_cif cif; int cc; --- 585,589 ---- int argcount) { ! PyThreadState *_save; /* For Py_BLOCK_THREADS and Py_UNBLOCK_THREADS */ ffi_cif cif; int cc; *************** *** 1057,1061 **** int mode = RTLD_NOW; #endif ! if (!PyArg_ParseTuple(args, "s:dlopen", &name)) return NULL; handle = dlopen(name, mode); --- 1057,1061 ---- int mode = RTLD_NOW; #endif ! if (!PyArg_ParseTuple(args, "z:dlopen", &name)) return NULL; handle = dlopen(name, mode); |
From: Thomas H. <th...@us...> - 2004-08-26 19:48:59
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14518 Modified Files: test_python_api.py Log Message: Make the test work on Linux. Index: test_python_api.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_python_api.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** test_python_api.py 26 Aug 2004 19:33:15 -0000 1.1 --- test_python_api.py 26 Aug 2004 19:48:50 -0000 1.2 *************** *** 1,4 **** from ctypes import * ! import unittest ################################################################ --- 1,4 ---- from ctypes import * ! import unittest, sys ################################################################ *************** *** 11,15 **** _type_ = "O" ! python = getattr(pydll, "python%s%s" % sys.version_info[:2]) ################################################################ --- 11,18 ---- _type_ = "O" ! if sys.platform == "win32": ! python = getattr(pydll, "python%s%s" % sys.version_info[:2]) ! else: ! python = PyDLL(None) ################################################################ |
From: Thomas H. <th...@us...> - 2004-08-26 19:38:38
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12805 Modified Files: callproc.c Log Message: Implemented Py_INCREF and Py_DECREF functions. Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.98 retrieving revision 1.99 diff -C2 -d -r1.98 -r1.99 *** callproc.c 20 Aug 2004 14:50:13 -0000 1.98 --- callproc.c 26 Aug 2004 19:38:27 -0000 1.99 *************** *** 1185,1188 **** --- 1185,1204 ---- } + static PyObject * + My_Py_INCREF(PyObject *self, PyObject *arg) + { + Py_INCREF(arg); /* that's what this function is for */ + Py_INCREF(arg); /* that for returning it */ + return arg; + } + + static PyObject * + My_Py_DECREF(PyObject *self, PyObject *arg) + { + Py_DECREF(arg); /* that's what this function is for */ + Py_INCREF(arg); /* that's for returning it */ + return arg; + } + PyMethodDef module_methods[] = { #ifdef MS_WIN32 *************** *** 1205,1208 **** --- 1221,1226 ---- {"call_cdeclfunction", call_cdeclfunction, METH_VARARGS }, {"PyObj_FromPtr", My_PyObj_FromPtr, METH_VARARGS }, + {"Py_INCREF", My_Py_INCREF, METH_O }, + {"Py_DECREF", My_Py_DECREF, METH_O }, {NULL, NULL} /* Sentinel */ }; |
From: Thomas H. <th...@us...> - 2004-08-26 19:33:27
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11770 Added Files: test_python_api.py Log Message: Unittests for calling Python api functions. --- NEW FILE: test_python_api.py --- from ctypes import * import unittest ################################################################ # This section should be moved into ctypes\__init__.py, when it's ready. from _ctypes import PyObj_FromPtr from _ctypes import _SimpleCData class PyObject(_SimpleCData): _type_ = "O" python = getattr(pydll, "python%s%s" % sys.version_info[:2]) ################################################################ from sys import getrefcount as grc class PythonAPITestCase(unittest.TestCase): def test_PyString_FromString(self): python.PyString_FromString.restype = PyObject python.PyString_FromString.argtypes = (c_char_p,) s = "abc" refcnt = grc(s) pyob = python.PyString_FromString(s) self.failUnlessEqual(grc(s), refcnt) self.failUnlessEqual(s, pyob) del pyob self.failUnlessEqual(grc(s), refcnt) def test_PyInt_Long(self): ref42 = grc(42) python.PyInt_FromLong.restype = PyObject self.failUnlessEqual(python.PyInt_FromLong(42), 42) self.failUnlessEqual(grc(42), ref42) python.PyInt_AsLong.argtypes = (PyObject,) python.PyInt_AsLong.restype = c_int res = python.PyInt_AsLong(42) self.failUnlessEqual(grc(res), ref42 + 1) del res self.failUnlessEqual(grc(42), ref42) def test_PyObj_FromPtr(self): s = "abc def ghi jkl" ref = grc(s) # id(python-object) is the address pyobj = PyObj_FromPtr(id(s)) self.failUnless(s is pyobj) self.failUnlessEqual(grc(s), ref + 1) del pyobj self.failUnlessEqual(grc(s), ref) if __name__ == "__main__": unittest.main() |
From: Thomas H. <th...@us...> - 2004-08-26 18:19:19
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29059 Modified Files: NEWS.txt ChangeLog Log Message: Changes. Index: NEWS.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/NEWS.txt,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** NEWS.txt 18 Aug 2004 12:34:33 -0000 1.4 --- NEWS.txt 26 Aug 2004 18:19:09 -0000 1.5 *************** *** 3,6 **** --- 3,16 ---- Version 0.9.1 + Cache the types that WINFUNCTYPE and CFUNCTYPE creates, to avoid + creation of a lot of similar classes. Rearrange the code to use + try:except: instead of dict.get(xxx, None), the former is faster + if lookup mostly succeeds - as is the case for POINTER imo. + + This makes importing large COM files created by readtlb a lot + faster, since WINFUNCTYPE is called for every COM method. The + python wrapper for mshtml.tlb, which contains nearly 600 + interfaces, now imports in 3 seconds instead of 40! + Array and POINTER instance now support slicing, for POINTER only getslice is implemented (setslice is too dangerous, probably). *************** *** 9,13 **** strings resp. unicode strings are used - much more convenient. ! Other Versions: no news recorded in this file! Version 0.4.0, 2003-02-07: --- 19,24 ---- strings resp. unicode strings are used - much more convenient. ! Other Versions: no news recorded in this file! Please see the CVS ! commit messages. Version 0.4.0, 2003-02-07: Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/ChangeLog,v retrieving revision 1.51 retrieving revision 1.52 diff -C2 -d -r1.51 -r1.52 *** ChangeLog 20 Aug 2004 15:33:28 -0000 1.51 --- ChangeLog 26 Aug 2004 18:19:09 -0000 1.52 *************** *** 1,2 **** --- 1,16 ---- + 2004-08-26 Thomas Heller <th...@py...> + + * ctypes\__init__.py: Cache the types that WINFUNCTYPE and + CFUNCTYPE creates, to avoid creation of a lot of similar classes. + Rearrange the code to use try:except: instead of dict.get(xxx, + None), the former is faster if lookup mostly succeeds - as is the + case for POINTER imo. + + This makes importing large COM files created by readtlb a lot + faster, since WINFUNCTYPE is called for every COM method. The + python wrapper for mshtml.tlb, which contains nearly 600 + interfaces, now imports in 3 seconds instead of 40! + + 2004-08-20 Thomas Heller <th...@py...> |
From: Thomas H. <th...@us...> - 2004-08-26 18:18:07
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28687 Modified Files: test_funcptr.py Log Message: Cache the types that WINFUNCTYPE and CFUNCTYPE creates, to avoid creation of a lot of similar classes. Rearrange the code to use try:except: instead of dict.get(xxx, None), the former is faster if lookup mostly succeeds - as is the case for POINTER imo. This makes importing large COM files created by readtlb a lot faster, since WINFUNCTYPE is called for every COM method. The python wrapper for mshtml.tlb, which contains nearly 600 interfaces, now imports in 3 seconds instead of 40! Index: test_funcptr.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_funcptr.py,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** test_funcptr.py 22 Jul 2004 12:37:32 -0000 1.15 --- test_funcptr.py 26 Aug 2004 18:17:56 -0000 1.16 *************** *** 83,91 **** WNDPROC_2 = WINFUNCTYPE(c_long, c_int, c_int, c_int, c_int) ! # CFuncPtr subclasses are compared by identity, so this raises a TypeError: ! ## wndclass.lpfnWndProc = WNDPROC_2(wndproc) ! self.assertRaises(TypeError, setattr, wndclass, ! "lpfnWndProc", WNDPROC_2(wndproc)) self.failUnlessEqual(wndclass.lpfnWndProc(1, 2, 3, 4), 10) --- 83,93 ---- WNDPROC_2 = WINFUNCTYPE(c_long, c_int, c_int, c_int, c_int) ! # This is no longer true, now that WINFUNCTYPE caches created types internally. ! ## # CFuncPtr subclasses are compared by identity, so this raises a TypeError: ! ## self.assertRaises(TypeError, setattr, wndclass, ! ## "lpfnWndProc", WNDPROC_2(wndproc)) ! # instead: + self.failUnless(WNDPROC is WNDPROC_2) self.failUnlessEqual(wndclass.lpfnWndProc(1, 2, 3, 4), 10) |
From: Thomas H. <th...@us...> - 2004-08-26 18:14:52
|
Update of /cvsroot/ctypes/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27839 Modified Files: __init__.py Log Message: Cache the types that WINFUNCTYPE and CFUNCTYPE creates, to avoid creation of a lot of similar classes. Rearrange the code to use try:except: instead of dict.get(xxx, None), the former is faster if lookup mostly succeeds - as is the case for POINTER imo. This makes importing large COM files created by readtlb a lot faster, since WINFUNCTYPE is called for every COM method. The python wrapper for mshtml.tlb, which contains nearly 600 interfaces, now imports in 3 seconds instead of 40! Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/__init__.py,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** __init__.py 20 Aug 2004 15:31:50 -0000 1.29 --- __init__.py 26 Aug 2004 18:14:41 -0000 1.30 *************** *** 83,92 **** return create_string_buffer(init, size) def CFUNCTYPE(restype, *argtypes): ! class CFunctionType(_CFuncPtr): ! _argtypes_ = argtypes ! _restype_ = restype ! _flags_ = _FUNCFLAG_CDECL ! return CFunctionType if _os.name == "nt": --- 83,97 ---- return create_string_buffer(init, size) + _c_functype_cache = {} def CFUNCTYPE(restype, *argtypes): ! try: ! return _c_functype_cache[(restype, argtypes)] ! except KeyError: ! class CFunctionType(_CFuncPtr): ! _argtypes_ = argtypes ! _restype_ = restype ! _flags_ = _FUNCFLAG_CDECL ! _c_functype_cache[(restype, argtypes)] = CFunctionType ! return CFunctionType if _os.name == "nt": *************** *** 96,105 **** FUNCFLAG_STDCALL as _FUNCFLAG_STDCALL def WINFUNCTYPE(restype, *argtypes): ! class WinFunctionType(_CFuncPtr): ! _argtypes_ = argtypes ! _restype_ = restype ! _flags_ = _FUNCFLAG_STDCALL ! return WinFunctionType elif _os.name == "posix": --- 101,115 ---- FUNCFLAG_STDCALL as _FUNCFLAG_STDCALL + _win_functype_cache = {} def WINFUNCTYPE(restype, *argtypes): ! try: ! return _win_functype_cache[(restype, argtypes)] ! except KeyError: ! class WinFunctionType(_CFuncPtr): ! _argtypes_ = argtypes ! _restype_ = restype ! _flags_ = _FUNCFLAG_STDCALL ! _win_functype_cache[(restype, argtypes)] = WinFunctionType ! return WinFunctionType elif _os.name == "posix": *************** *** 206,209 **** --- 216,223 ---- def POINTER(cls): + try: + return _pointer_type_cache[cls] + except KeyError: + pass if type(cls) is str: klass = type(_Pointer)("LP_%s" % cls, *************** *** 212,217 **** _pointer_type_cache[id(klass)] = klass return klass ! klass = _pointer_type_cache.get(cls, None) ! if klass is None: name = "LP_%s" % cls.__name__ klass = type(_Pointer)(name, --- 226,230 ---- _pointer_type_cache[id(klass)] = klass return klass ! else: name = "LP_%s" % cls.__name__ klass = type(_Pointer)(name, *************** *** 340,341 **** --- 353,355 ---- descr = FormatError(code).strip() return WindowsError(code, descr) + |
From: Thomas H. <th...@us...> - 2004-08-20 15:33:56
|
Update of /cvsroot/ctypes/ctypes/win32/com In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25169 Modified Files: ChangeLog Log Message: Record changes. Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/win32/com/ChangeLog,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ChangeLog 19 Aug 2004 10:22:33 -0000 1.6 --- ChangeLog 20 Aug 2004 15:33:41 -0000 1.7 *************** *** 1,2 **** --- 1,9 ---- + 2004-08-20 Thomas Heller <th...@py...> + + * com/server.py: In UseCommandLine, print a short explanation that + the regserver or unregserver flag is required. Don't mention the + /automation flag, it is only used by windows (that's my + impression, at least). + 2004-08-19 Thomas Heller <th...@py...> |
From: Thomas H. <th...@us...> - 2004-08-20 15:33:41
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25085 Modified Files: ChangeLog ANNOUNCE Log Message: Record changes. Index: ANNOUNCE =================================================================== RCS file: /cvsroot/ctypes/ctypes/ANNOUNCE,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** ANNOUNCE 19 Aug 2004 13:49:36 -0000 1.7 --- ANNOUNCE 20 Aug 2004 15:33:28 -0000 1.8 *************** *** 41,46 **** --- 41,54 ---- returns the alignment requirements in bytes of a type or instance. + It is now possible to call Python API functions with ctypes. This + is an experimental feature and will probably change. Please don't + use it yet in production code, and watch the ctypes-users mailing + list. + ctypes.com changes + COM servers now print a short usage message when they are run + without the /regserver or /unregserver flag. + VARIANT does now handle the COM DATE type (VT_DATE) as Python datetime. Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/ChangeLog,v retrieving revision 1.50 retrieving revision 1.51 diff -C2 -d -r1.50 -r1.51 *** ChangeLog 19 Aug 2004 13:49:36 -0000 1.50 --- ChangeLog 20 Aug 2004 15:33:28 -0000 1.51 *************** *** 1,2 **** --- 1,16 ---- + 2004-08-20 Thomas Heller <th...@py...> + + * (Message): Add the PyDLL class and pydll object to ctypes, they + will expose functions using FUNCFLAG_PYTHONAPI allowing to call + Python api functions. + + * source/cfield.c: Add accessors for 'O' typecode (which converts + to/from python objects). + + * (Message): Implement the FUNCFLAG_PYTHONAPI flag which allows to + call Python API functions with ctypes. Somewhat tricky - we have + to keep the thread state during the call, and we have to make sure + to return failure if the Python error flag has been set. + 2004-08-19 Thomas Heller <th...@py...> |
From: Thomas H. <th...@us...> - 2004-08-20 15:32:00
|
Update of /cvsroot/ctypes/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24636 Modified Files: __init__.py Log Message: Add the PyDLL class and the pydll object, they do expose functions using FUNCFLAG_PYTHONAPI. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/__init__.py,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** __init__.py 19 Aug 2004 11:34:44 -0000 1.28 --- __init__.py 20 Aug 2004 15:31:50 -0000 1.29 *************** *** 24,28 **** from _ctypes import FormatError ! from _ctypes import FUNCFLAG_CDECL as _FUNCFLAG_CDECL """ --- 24,29 ---- from _ctypes import FormatError ! from _ctypes import FUNCFLAG_CDECL as _FUNCFLAG_CDECL, \ ! FUNCFLAG_PYTHONAPI as _FUNCFLAG_PYTHONAPI """ *************** *** 277,280 **** --- 278,286 ---- self._handle = 0 + class PyDLL(CDLL): + class _CdeclFuncPtr(_CFuncPtr): + _flags_ = _FUNCFLAG_CDECL | _FUNCFLAG_PYTHONAPI + _restype_ = c_int # default, can be overridden in instances + if _os.name == "nt": *************** *** 321,324 **** --- 327,331 ---- cdll = _DLLS(CDLL) + pydll = _DLLS(PyDLL) if _os.name == "nt": windll = _DLLS(WinDLL) |
From: Thomas H. <th...@us...> - 2004-08-20 14:52:01
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17708 Modified Files: cfield.c Log Message: We cannot construct a Python object from a NULL pointer. If the error flag is already set, we simply return. If the error flag is not set, we must set it. Index: cfield.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/cfield.c,v retrieving revision 1.39 retrieving revision 1.40 diff -C2 -d -r1.39 -r1.40 *** cfield.c 20 Aug 2004 14:24:15 -0000 1.39 --- cfield.c 20 Aug 2004 14:51:50 -0000 1.40 *************** *** 372,376 **** O_get(void *ptr, unsigned size) { ! return *(PyObject **)ptr; } --- 372,384 ---- O_get(void *ptr, unsigned size) { ! PyObject *ob = *(PyObject **)ptr; ! if (ob == NULL) { ! if (!PyErr_Occurred()) ! /* Set an error if not yet set */ ! PyErr_SetString(PyExc_ValueError, ! "PyObject is NULL?"); ! return NULL; ! } ! return ob; } |
From: Thomas H. <th...@us...> - 2004-08-20 14:50:22
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17524 Modified Files: callproc.c Log Message: If after a FUNCFLAG_PYTHONAPI call the error flag is set, we *must* raise an error, otherwise really stange things may happen. Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.97 retrieving revision 1.98 diff -C2 -d -r1.97 -r1.98 *** callproc.c 20 Aug 2004 14:28:46 -0000 1.97 --- callproc.c 20 Aug 2004 14:50:13 -0000 1.98 *************** *** 662,665 **** --- 662,667 ---- } #endif + if ((flags & FUNCFLAG_PYTHONAPI) && PyErr_Occurred()) + return -1; return 0; } |
From: Thomas H. <th...@us...> - 2004-08-20 14:28:59
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13540 Modified Files: ctypes.h callproc.c Log Message: New FUNCFLAG_PYTHONAPI - functions using this don't release and reaquire the threadstate during the call. Required for calling Python API functions with ctypes. Index: ctypes.h =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/ctypes.h,v retrieving revision 1.47 retrieving revision 1.48 diff -C2 -d -r1.47 -r1.48 *** ctypes.h 23 Jun 2004 16:26:13 -0000 1.47 --- ctypes.h 20 Aug 2004 14:28:46 -0000 1.48 *************** *** 207,210 **** --- 207,211 ---- #define FUNCFLAG_CDECL 0x1 #define FUNCFLAG_HRESULT 0x2 + #define FUNCFLAG_PYTHONAPI 0x4 typedef struct { Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.96 retrieving revision 1.97 diff -C2 -d -r1.96 -r1.97 *** callproc.c 19 Aug 2004 11:37:42 -0000 1.96 --- callproc.c 20 Aug 2004 14:28:46 -0000 1.97 *************** *** 585,588 **** --- 585,589 ---- int argcount) { + PyThreadState *_save; ffi_cif cif; int cc; *************** *** 615,619 **** } ! Py_BEGIN_ALLOW_THREADS #ifdef MS_WIN32 #ifndef DEBUG_EXCEPTIONS --- 616,621 ---- } ! if ((flags & FUNCFLAG_PYTHONAPI) == 0) ! Py_UNBLOCK_THREADS #ifdef MS_WIN32 #ifndef DEBUG_EXCEPTIONS *************** *** 632,636 **** #endif #endif ! Py_END_ALLOW_THREADS #ifdef MS_WIN32 if (dwExceptionCode) { --- 634,639 ---- #endif #endif ! if ((flags & FUNCFLAG_PYTHONAPI) == 0) ! Py_BLOCK_THREADS #ifdef MS_WIN32 if (dwExceptionCode) { *************** *** 1108,1114 **** PyObject *result; - #ifdef _DEBUG - _asm int 3; - #endif if (!PyArg_ParseTuple(args, "iO!", --- 1111,1114 ---- *************** *** 1171,1174 **** --- 1171,1186 ---- + static PyObject * + My_PyObj_FromPtr(PyObject *self, PyObject *args) + { + int i; + PyObject *ob; + if (!PyArg_ParseTuple(args, "i", &i)) + return NULL; + ob = (PyObject *)i; + Py_INCREF(ob); + return ob; + } + PyMethodDef module_methods[] = { #ifdef MS_WIN32 *************** *** 1190,1193 **** --- 1202,1206 ---- {"call_function", call_function, METH_VARARGS }, {"call_cdeclfunction", call_cdeclfunction, METH_VARARGS }, + {"PyObj_FromPtr", My_PyObj_FromPtr, METH_VARARGS }, {NULL, NULL} /* Sentinel */ }; |
From: Thomas H. <th...@us...> - 2004-08-20 14:24:24
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12739 Modified Files: cfield.c Log Message: Conversion functions for the 'O' typecode. Index: cfield.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/cfield.c,v retrieving revision 1.38 retrieving revision 1.39 diff -C2 -d -r1.38 -r1.39 *** cfield.c 23 Jul 2004 14:35:54 -0000 1.38 --- cfield.c 20 Aug 2004 14:24:15 -0000 1.39 *************** *** 370,373 **** --- 370,388 ---- static PyObject * + O_get(void *ptr, unsigned size) + { + return *(PyObject **)ptr; + } + + static PyObject * + O_set(void *ptr, PyObject *value, unsigned size) + { + *(PyObject **)ptr = value; + Py_INCREF(value); + return value; + } + + + static PyObject * i_get(void *ptr, unsigned size) { *************** *** 873,876 **** --- 888,892 ---- { 'X', BSTR_set, BSTR_get, &ffi_type_pointer}, #endif + { 'O', O_set, O_get, &ffi_type_pointer}, { 0, NULL, NULL, NULL}, }; |