ctypes-commit Mailing List for ctypes (Page 106)
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-06-17 15:10:53
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31693 Modified Files: setup.py Log Message: Default verbosity for the tests is 1. Index: setup.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/setup.py,v retrieving revision 1.57 retrieving revision 1.58 diff -C2 -d -r1.57 -r1.58 *** setup.py 17 Jun 2004 11:21:59 -0000 1.57 --- setup.py 17 Jun 2004 15:10:44 -0000 1.58 *************** *** 230,234 **** self.test_prefix = 'test_' self.test_suffixes = None ! self.verbosity = 0 # initialize_options() --- 230,234 ---- self.test_prefix = 'test_' self.test_suffixes = None ! self.verbosity = 1 # initialize_options() |
From: Thomas H. <th...@us...> - 2004-06-17 11:22:08
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28882 Modified Files: setup.py Log Message: Add a 'verbosity' argument to the test subcommand, since we cannot use the standard 'verbose' argument with Python 2.2.2 - it cannot be made larger than 1 in this version. Index: setup.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/setup.py,v retrieving revision 1.56 retrieving revision 1.57 diff -C2 -d -r1.56 -r1.57 *** setup.py 16 Jun 2004 19:47:30 -0000 1.56 --- setup.py 17 Jun 2004 11:21:59 -0000 1.57 *************** *** 13,16 **** --- 13,17 ---- from distutils.core import setup, Extension, Command import distutils.core + from distutils.errors import DistutilsOptionError import os, sys *************** *** 180,184 **** else: ! def task_build_libffi(): pass LIBFFI_CFLAGS=[] --- 181,185 ---- else: ! def task_build_libffi(force=0): pass LIBFFI_CFLAGS=[] *************** *** 218,222 **** "prefix to the testcase filename"), ('test-suffixes=', None, ! "a list of suffixes used to generate names the of the testcases") ] --- 219,224 ---- "prefix to the testcase filename"), ('test-suffixes=', None, ! "a list of suffixes used to generate names the of the testcases"), ! ('verbosity=', 'V', "verbosity"), ] *************** *** 228,235 **** --- 230,244 ---- self.test_prefix = 'test_' self.test_suffixes = None + self.verbosity = 0 # initialize_options() def finalize_options(self): + try: + self.verbosity = int(self.verbosity) + except ValueError: + raise DistutilsOptionError, \ + "verbosity must be an integer" + if self.test_suffixes is None: self.test_suffixes = [] *************** *** 281,288 **** if test_suites: - suite = unittest.TestSuite(test_suites) self.announce("running unittests") ! runner = unittest.TextTestRunner(verbosity=self.verbose) runner.run(suite) --- 290,297 ---- if test_suites: self.announce("running unittests") ! runner = unittest.TextTestRunner(verbosity=self.verbosity) ! suite = unittest.TestSuite(test_suites) runner.run(suite) |
From: Thomas H. <th...@us...> - 2004-06-16 19:47:39
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14742 Modified Files: setup.py Log Message: *** empty log message *** Index: setup.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/setup.py,v retrieving revision 1.55 retrieving revision 1.56 diff -C2 -d -r1.55 -r1.56 *** setup.py 16 Jun 2004 19:45:07 -0000 1.55 --- setup.py 16 Jun 2004 19:47:30 -0000 1.56 *************** *** 167,171 **** subprocess('Building float1.c', ! "gcc -lffi build/libffi/testsuite/libffi.call/float1.c") LIBFFI_BASE='build/libffi' --- 167,171 ---- subprocess('Building float1.c', ! "gcc -lffi %s/libffi/testsuite/libffi.call/float1.c" % src_path) LIBFFI_BASE='build/libffi' |
From: Thomas H. <th...@us...> - 2004-06-16 19:45:27
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13049 Modified Files: setup.py Log Message: More hacks. Index: setup.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/setup.py,v retrieving revision 1.54 retrieving revision 1.55 diff -C2 -d -r1.54 -r1.55 *** setup.py 14 Jun 2004 11:13:34 -0000 1.54 --- setup.py 16 Jun 2004 19:45:07 -0000 1.55 *************** *** 128,131 **** --- 128,133 ---- def task_build_libffi(force=0): + if sys.platform == "win32": + return if not os.path.isdir(LIBFFI_SOURCES): sys.stderr.write( *************** *** 159,163 **** src_path = src_path.replace("'", "'\"'\"'") ! subprocess('Building FFI', "cd build/libffi/BLD && '%s/configure' --prefix='%s' --disable-shared --enable-static && make install"%(src_path, inst_dir), None) LIBFFI_BASE='build/libffi' --- 161,171 ---- src_path = src_path.replace("'", "'\"'\"'") ! subprocess('Building FFI', ! "cd build/libffi/BLD && '%s/configure' --prefix='%s' --disable-shared --enable-static && make install"%(src_path, inst_dir), None) ! subprocess('Building test', ! "cd build/libffi/BLD && '%s/configure' --prefix='%s' && make install"%(src_path, inst_dir), None) ! ! subprocess('Building float1.c', ! "gcc -lffi build/libffi/testsuite/libffi.call/float1.c") LIBFFI_BASE='build/libffi' |
From: Thomas H. <th...@us...> - 2004-06-15 09:20:42
|
Update of /cvsroot/ctypes/ctypes/win32/com/tools In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23242 Modified Files: readtlb.py Log Message: Remove debug code. Index: readtlb.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/win32/com/tools/readtlb.py,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** readtlb.py 21 Apr 2004 18:08:22 -0000 1.26 --- readtlb.py 15 Jun 2004 09:20:26 -0000 1.27 *************** *** 502,507 **** result.append("out_") if flags & PARAMFLAG_FRETVAL: - import pdb - pdb.set_trace() result.append("retval_") if flags & PARAMFLAG_FLCID: --- 502,505 ---- |
From: Thomas H. <th...@us...> - 2004-06-14 11:13:43
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1754 Modified Files: setup.py Log Message: hack, hack away. Index: setup.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/setup.py,v retrieving revision 1.53 retrieving revision 1.54 diff -C2 -d -r1.53 -r1.54 *** setup.py 14 Jun 2004 10:39:06 -0000 1.53 --- setup.py 14 Jun 2004 11:13:34 -0000 1.54 *************** *** 61,65 **** else: include_dirs = ["build/libffi/include", ! "build/libffi/lib/gcc/3.5.0/include/libffi"] library_dirs = ["build/libffi/lib"] ## if os.path.exists('source/libffi'): --- 61,66 ---- else: include_dirs = ["build/libffi/include", ! "build/libffi/lib/gcc/3.5.0/include/libffi", ! "build/libffi/lib/gcc/include/libffi"] library_dirs = ["build/libffi/lib"] ## if os.path.exists('source/libffi'): |
From: Thomas H. <th...@us...> - 2004-06-14 10:39:18
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8770 Modified Files: setup.py Log Message: hack, hack, hack. Index: setup.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/setup.py,v retrieving revision 1.52 retrieving revision 1.53 diff -C2 -d -r1.52 -r1.53 *** setup.py 14 Jun 2004 10:09:00 -0000 1.52 --- setup.py 14 Jun 2004 10:39:06 -0000 1.53 *************** *** 60,68 **** "source/libffi_msvc/ffi_common.h"]) else: ! include_dirs = [] ! library_dirs = [] ! if os.path.exists('source/libffi'): ! include_dirs.append('source/libffi/include') ! library_dirs.append('source/libffi/lib') extra_link_args = [] if sys.platform == "darwin": --- 60,69 ---- "source/libffi_msvc/ffi_common.h"]) else: ! include_dirs = ["build/libffi/include", ! "build/libffi/lib/gcc/3.5.0/include/libffi"] ! library_dirs = ["build/libffi/lib"] ! ## if os.path.exists('source/libffi'): ! ## include_dirs.append('source/libffi/include') ! ## library_dirs.append('source/libffi/lib') extra_link_args = [] if sys.platform == "darwin": *************** *** 95,99 **** distutils.sysconfig._config_vars['LDSHARED'] = y ! LIBFFI_SOURCES='libffi-src' if sys.platform != 'darwin' and os.path.exists('/usr/include/ffi.h'): # A system with a pre-existing libffi. --- 96,101 ---- distutils.sysconfig._config_vars['LDSHARED'] = y ! ##LIBFFI_SOURCES='libffi-src' ! LIBFFI_SOURCES='../gcc/libffi' if sys.platform != 'darwin' and os.path.exists('/usr/include/ffi.h'): # A system with a pre-existing libffi. *************** *** 102,110 **** def subprocess(taskName, cmd, validRes=None): print "Performing task: %s" % (taskName,) ! fd = os.popen(cmd, 'r') ! for ln in fd.xreadlines(): ! sys.stdout.write(ln) ! res = fd.close() if res is not validRes: sys.stderr.write("Task '%s' failed [%d]\n"%(taskName, res)) --- 104,116 ---- def subprocess(taskName, cmd, validRes=None): print "Performing task: %s" % (taskName,) ! res = os.system(cmd) ! validRes = 0 ! ## fd = os.popen(cmd, 'r') ! ## for data in fd.read(256): ! ## sys.stdout.write(data) ! ## if not data: ! ## break ! ## res = fd.close() if res is not validRes: sys.stderr.write("Task '%s' failed [%d]\n"%(taskName, res)) *************** *** 120,124 **** if LIBFFI_SOURCES is not None: ! def task_build_libffi(): if not os.path.isdir(LIBFFI_SOURCES): sys.stderr.write( --- 126,130 ---- if LIBFFI_SOURCES is not None: ! def task_build_libffi(force=0): if not os.path.isdir(LIBFFI_SOURCES): sys.stderr.write( *************** *** 136,140 **** os.mkdir('build/libffi/BLD') ! if not os.path.exists('build/libffi/lib/libffi.a'): # No pre-build version available, build it now. # Do not use a relative path for the build-tree, libtool on --- 142,146 ---- os.mkdir('build/libffi/BLD') ! if force or not os.path.exists('build/libffi/lib/libffi.a'): # No pre-build version available, build it now. # Do not use a relative path for the build-tree, libtool on *************** *** 161,164 **** --- 167,172 ---- '-L%s/lib'%LIBFFI_BASE, '-lffi', ] + libffi_include = ["include/%s" % LIBFFI_BASE] + libffi_lib = ["%s/lib" % LIBFFI_BASE] else: *************** *** 310,315 **** class my_build_ext(build_ext.build_ext): def run(self): ! task_build_libffi() ! build_ext.run(self) if __name__ == '__main__': --- 318,323 ---- class my_build_ext(build_ext.build_ext): def run(self): ! task_build_libffi(self.force) ! build_ext.build_ext.run(self) if __name__ == '__main__': |
From: Thomas H. <th...@us...> - 2004-06-14 08:32:51
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8048 Modified Files: callproc.c Log Message: Remove a debug print. Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.85 retrieving revision 1.86 diff -C2 -d -r1.85 -r1.86 *** callproc.c 13 Jun 2004 20:25:48 -0000 1.85 --- callproc.c 14 Jun 2004 08:32:42 -0000 1.86 *************** *** 613,617 **** return -1; } ! printf("ffi_call, &res->value is %p\n", &res->value); Py_BEGIN_ALLOW_THREADS #ifdef MS_WIN32 --- 613,617 ---- return -1; } ! Py_BEGIN_ALLOW_THREADS #ifdef MS_WIN32 |
From: Thomas H. <th...@us...> - 2004-06-13 20:25:56
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9096 Modified Files: callproc.c Log Message: debugging. Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.84 retrieving revision 1.85 diff -C2 -d -r1.84 -r1.85 *** callproc.c 11 Jun 2004 19:18:30 -0000 1.84 --- callproc.c 13 Jun 2004 20:25:48 -0000 1.85 *************** *** 613,617 **** return -1; } ! Py_BEGIN_ALLOW_THREADS #ifdef MS_WIN32 --- 613,617 ---- return -1; } ! printf("ffi_call, &res->value is %p\n", &res->value); Py_BEGIN_ALLOW_THREADS #ifdef MS_WIN32 |
From: Thomas H. <th...@us...> - 2004-06-11 20:16:45
|
Update of /cvsroot/ctypes/ctypes/build/lib.win32-2.4 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18097 Modified Files: _ctypes_test.pyd _ctypes.pyd Log Message: Recompiled. Index: _ctypes_test.pyd =================================================================== RCS file: /cvsroot/ctypes/ctypes/build/lib.win32-2.4/_ctypes_test.pyd,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 Binary files /tmp/cvsVQFzo6 and /tmp/cvse5v9Nd differ Index: _ctypes.pyd =================================================================== RCS file: /cvsroot/ctypes/ctypes/build/lib.win32-2.4/_ctypes.pyd,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 Binary files /tmp/cvsVw0DZj and /tmp/cvs01YWzr differ |
From: Thomas H. <th...@us...> - 2004-06-11 20:16:36
|
Update of /cvsroot/ctypes/ctypes/build/lib.win32-2.3 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17946 Modified Files: _ctypes_test.pyd _ctypes.pyd Log Message: Recompiled. Index: _ctypes_test.pyd =================================================================== RCS file: /cvsroot/ctypes/ctypes/build/lib.win32-2.3/_ctypes_test.pyd,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 Binary files /tmp/cvsOqqkqv and /tmp/cvsnCkAJv differ Index: _ctypes.pyd =================================================================== RCS file: /cvsroot/ctypes/ctypes/build/lib.win32-2.3/_ctypes.pyd,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 Binary files /tmp/cvsx41PmK and /tmp/cvsI4CWNK differ |
From: Thomas H. <th...@us...> - 2004-06-11 19:22:07
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3558 Modified Files: benchmark.py Log Message: Update the linux figures. Index: benchmark.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/benchmark.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** benchmark.py 11 Jun 2004 19:19:25 -0000 1.4 --- benchmark.py 11 Jun 2004 19:21:57 -0000 1.5 *************** *** 20,32 **** t = Timer("ex_func_si('abc', 3)", "from __main__ import ex_func_si") # win32: 1.20 us ! # suse9.1 (vmware): 2.314 us t1 = t.timeit(REPEAT) *1e6 / REPEAT print >> sys.stderr, "dll call, 2 args: %.2f us" % t1 t = Timer("py_func_si('abc', 3)", "from __main__ import py_func_si") # win32: 0.65 us ! # suse9.1(vmware): 0.910 us t2 = t.timeit(REPEAT) *1e6 / REPEAT print >> sys.stderr, "func call, 2 args: %.2f us" % t2 # win32: ratio 1.9 print >> sys.stderr, "ratio %.1f" % (t1 / t2) print >> sys.stderr --- 20,33 ---- t = Timer("ex_func_si('abc', 3)", "from __main__ import ex_func_si") # win32: 1.20 us ! # suse9.1 (vmware): 3.56 us t1 = t.timeit(REPEAT) *1e6 / REPEAT print >> sys.stderr, "dll call, 2 args: %.2f us" % t1 t = Timer("py_func_si('abc', 3)", "from __main__ import py_func_si") # win32: 0.65 us ! # suse9.1(vmware): 0.89 us t2 = t.timeit(REPEAT) *1e6 / REPEAT print >> sys.stderr, "func call, 2 args: %.2f us" % t2 # win32: ratio 1.9 + # suse9.1(vmware): 4.0 print >> sys.stderr, "ratio %.1f" % (t1 / t2) print >> sys.stderr *************** *** 34,46 **** t = Timer("ex_func()", "from __main__ import ex_func") # win32: 0.82 us ! # suse9.1(vmware): 1.521 us t1 = t.timeit(REPEAT) *1e6 / REPEAT print >> sys.stderr, "dll call, no args: %.2f us" % t1 t = Timer("py_func()", "from __main__ import py_func") # win32: 0.14 us ! # suse9.1(vmware): 0.231 us t2 = t.timeit(REPEAT) *1e6 / REPEAT print >> sys.stderr, "func call, no args: %.2f us" % t2 # win32: ratio 5.8 print >> sys.stderr, "ratio %.1f" % (t1 / t2) print >> sys.stderr --- 35,48 ---- t = Timer("ex_func()", "from __main__ import ex_func") # win32: 0.82 us ! # suse9.1(vmware): 1.44 us t1 = t.timeit(REPEAT) *1e6 / REPEAT print >> sys.stderr, "dll call, no args: %.2f us" % t1 t = Timer("py_func()", "from __main__ import py_func") # win32: 0.14 us ! # suse9.1(vmware): 0.23 us t2 = t.timeit(REPEAT) *1e6 / REPEAT print >> sys.stderr, "func call, no args: %.2f us" % t2 # win32: ratio 5.8 + # suse9.1(vmware): ratio 6.3 print >> sys.stderr, "ratio %.1f" % (t1 / t2) print >> sys.stderr |
From: Thomas H. <th...@us...> - 2004-06-11 19:19:42
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1649 Modified Files: benchmark.py Log Message: REPEAT count, less meaningless precision in the output, figures for win32. Index: benchmark.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/benchmark.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** benchmark.py 11 Jun 2004 11:25:11 -0000 1.3 --- benchmark.py 11 Jun 2004 19:19:25 -0000 1.4 *************** *** 1,32 **** import sys ! from ctypes import cdll import _ctypes_test ex_func_si = cdll[_ctypes_test.__file__]._py_func_si py_func_si = _ctypes_test.func_si ex_func = cdll[_ctypes_test.__file__]._py_func py_func = _ctypes_test.func if __name__ == "__main__": from timeit import Timer t = Timer("ex_func_si('abc', 3)", "from __main__ import ex_func_si") ! # win32: 1.284 us # suse9.1 (vmware): 2.314 us ! print >> sys.stderr, "dll call, 2 args: %.3f us" % t.timeit() t = Timer("py_func_si('abc', 3)", "from __main__ import py_func_si") ! # win32: 0.629 us # suse9.1(vmware): 0.910 us ! print >> sys.stderr, "func call, 2 args: %.3f us" % t.timeit() print >> sys.stderr t = Timer("ex_func()", "from __main__ import ex_func") ! # win32: 0.773 us # suse9.1(vmware): 1.521 us ! print >> sys.stderr, "dll call, no args: %.3f us" % (t.timeit(10000000) / 10) t = Timer("py_func()", "from __main__ import py_func") ! # win32: 0.139 us # suse9.1(vmware): 0.231 us ! print >> sys.stderr, "func call, no args: %.3f us" % (t.timeit(10000000) / 10) print >> sys.stderr --- 1,46 ---- import sys ! from ctypes import cdll, c_int, c_char_p import _ctypes_test ex_func_si = cdll[_ctypes_test.__file__]._py_func_si + ##ex_func_si.argtypes = c_char_p, c_int + ##ex_func_si.restype = None py_func_si = _ctypes_test.func_si ex_func = cdll[_ctypes_test.__file__]._py_func + ##ex_func.argtypes = () + ##ex_func.restype = None py_func = _ctypes_test.func + REPEAT = int(1e6) + if __name__ == "__main__": from timeit import Timer t = Timer("ex_func_si('abc', 3)", "from __main__ import ex_func_si") ! # win32: 1.20 us # suse9.1 (vmware): 2.314 us ! t1 = t.timeit(REPEAT) *1e6 / REPEAT ! print >> sys.stderr, "dll call, 2 args: %.2f us" % t1 t = Timer("py_func_si('abc', 3)", "from __main__ import py_func_si") ! # win32: 0.65 us # suse9.1(vmware): 0.910 us ! t2 = t.timeit(REPEAT) *1e6 / REPEAT ! print >> sys.stderr, "func call, 2 args: %.2f us" % t2 ! # win32: ratio 1.9 ! print >> sys.stderr, "ratio %.1f" % (t1 / t2) print >> sys.stderr t = Timer("ex_func()", "from __main__ import ex_func") ! # win32: 0.82 us # suse9.1(vmware): 1.521 us ! t1 = t.timeit(REPEAT) *1e6 / REPEAT ! print >> sys.stderr, "dll call, no args: %.2f us" % t1 t = Timer("py_func()", "from __main__ import py_func") ! # win32: 0.14 us # suse9.1(vmware): 0.231 us ! t2 = t.timeit(REPEAT) *1e6 / REPEAT ! print >> sys.stderr, "func call, no args: %.2f us" % t2 ! # win32: ratio 5.8 ! print >> sys.stderr, "ratio %.1f" % (t1 / t2) print >> sys.stderr |
From: Thomas H. <th...@us...> - 2004-06-11 19:18:43
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv924 Modified Files: callproc.c Log Message: We need to keep a reference to the original object in ConvParam in some cases. Fix pass-struct-by-value Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.83 retrieving revision 1.84 diff -C2 -d -r1.83 -r1.84 *** callproc.c 11 Jun 2004 18:44:50 -0000 1.83 --- callproc.c 11 Jun 2004 19:18:30 -0000 1.84 *************** *** 435,438 **** --- 435,439 ---- struct argument { ffi_type *ffi_type; + PyObject *keep; union { char c; *************** *** 458,462 **** PyCArgObject *carg = (PyCArgObject *)obj; pa->ffi_type = carg->pffi_type; - /* XXX What about structures by value? */ memcpy(&pa->value, &carg->value, sizeof(pa->value)); return 0; --- 459,462 ---- *************** *** 521,527 **** PyCArgObject *carg = (PyCArgObject *)arg; pa->ffi_type = carg->pffi_type; - /* XXX What about structures by value? */ memcpy(&pa->value, &carg->value, sizeof(pa->value)); ! Py_DECREF(arg); /* XXX */ return 0; } --- 521,526 ---- PyCArgObject *carg = (PyCArgObject *)arg; pa->ffi_type = carg->pffi_type; memcpy(&pa->value, &carg->value, sizeof(pa->value)); ! pa->keep = arg; return 0; } *************** *** 529,533 **** pa->ffi_type = &ffi_type_sint; pa->value.l = PyInt_AS_LONG(arg); ! Py_DECREF(arg); return 0; } --- 528,532 ---- pa->ffi_type = &ffi_type_sint; pa->value.l = PyInt_AS_LONG(arg); ! pa->keep = arg; return 0; } *************** *** 847,852 **** atypes = (ffi_type **)alloca(sizeof(ffi_type *) * argcount); for (i = 0; i < argcount; ++i) { - avalues[i] = (void *)&args[i].value; atypes[i] = args[i].ffi_type; } --- 846,854 ---- atypes = (ffi_type **)alloca(sizeof(ffi_type *) * argcount); for (i = 0; i < argcount; ++i) { atypes[i] = args[i].ffi_type; + if (atypes[i]->type == FFI_TYPE_STRUCT) + avalues[i] = (void *)args[i].value.p; + else + avalues[i] = (void *)&args[i].value; } *************** *** 864,867 **** --- 866,871 ---- retval = GetResult(restype, &result); cleanup: + for (i = 0; i < argcount; ++i) + Py_XDECREF(args[i].keep); return retval; } |
From: Thomas H. <th...@us...> - 2004-06-11 18:45:01
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9475 Modified Files: callproc.c Log Message: Simplified ConvParam a lot. All unittests pass, except test_win.Structures.test_struct_by_value. Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.82 retrieving revision 1.83 diff -C2 -d -r1.82 -r1.83 *** callproc.c 11 Jun 2004 16:07:52 -0000 1.82 --- callproc.c 11 Jun 2004 18:44:50 -0000 1.83 *************** *** 433,507 **** */ /* * Convert a single Python object into a PyCArgObject and return it. */ ! static PyCArgObject *ConvParam(PyObject *obj, int index) { - PyCArgObject *parm; if (PyCArg_CheckExact(obj)) { ! Py_INCREF(obj); ! return (PyCArgObject *)obj; } - parm = new_CArgObject(); - if (!parm) - return NULL; - /* check for None, integer, string or unicode and use directly if successful */ if (obj == Py_None) { ! parm->pffi_type = &ffi_type_pointer; ! parm->tag = 'P'; ! parm->value.p = NULL; ! Py_INCREF(Py_None); ! parm->obj = Py_None; ! return parm; } if (PyInt_Check(obj)) { ! parm->pffi_type = &ffi_type_sint; ! parm->tag = 'i'; ! parm->value.i = PyInt_AS_LONG(obj); ! Py_INCREF(obj); ! parm->obj = obj; ! return parm; } if (PyLong_Check(obj)) { ! parm->pffi_type = &ffi_type_sint; ! parm->tag = 'i'; ! parm->value.i = (long)PyLong_AsUnsignedLong(obj); ! if (parm->value.i == -1 && PyErr_Occurred()) { PyErr_Clear(); ! parm->value.i = PyLong_AsLong(obj); ! if (parm->value.i == -1 && PyErr_Occurred()) { PyErr_SetString(PyExc_OverflowError, "long int too long to convert"); ! return NULL; } } ! Py_INCREF(obj); ! parm->obj = obj; ! return parm; } if (PyString_Check(obj)) { ! parm->pffi_type = &ffi_type_pointer; ! parm->tag = 'P'; ! parm->value.p = PyString_AS_STRING(obj); ! Py_INCREF(obj); ! parm->obj = obj; ! return parm; } #ifdef HAVE_USABLE_WCHAR_T if (PyUnicode_Check(obj)) { ! parm->pffi_type = &ffi_type_pointer; ! parm->tag = 'P'; ! parm->value.p = PyUnicode_AS_UNICODE(obj); ! Py_INCREF(obj); ! parm->obj = obj; ! return parm; } #endif { PyObject *arg; --- 433,508 ---- */ + struct argument { + ffi_type *ffi_type; + union { + char c; + char b; + short h; + int i; + long l; + #ifdef HAVE_LONG_LONG + PY_LONG_LONG q; + #endif + double d; + float f; + void *p; + } value; + }; + /* * Convert a single Python object into a PyCArgObject and return it. */ ! static int ConvParam(PyObject *obj, int index, struct argument *pa) { if (PyCArg_CheckExact(obj)) { ! PyCArgObject *carg = (PyCArgObject *)obj; ! pa->ffi_type = carg->pffi_type; ! /* XXX What about structures by value? */ ! memcpy(&pa->value, &carg->value, sizeof(pa->value)); ! return 0; } /* check for None, integer, string or unicode and use directly if successful */ if (obj == Py_None) { ! pa->ffi_type = &ffi_type_pointer; ! pa->value.p = NULL; ! return 0; } if (PyInt_Check(obj)) { ! pa->ffi_type = &ffi_type_sint; ! pa->value.l = PyInt_AS_LONG(obj); ! return 0; } if (PyLong_Check(obj)) { ! pa->ffi_type = &ffi_type_sint; ! pa->value.l = (long)PyLong_AsUnsignedLong(obj); ! if (pa->value.l == -1 && PyErr_Occurred()) { PyErr_Clear(); ! pa->value.l = PyLong_AsLong(obj); ! if (pa->value.l == -1 && PyErr_Occurred()) { PyErr_SetString(PyExc_OverflowError, "long int too long to convert"); ! return -1; } } ! return 0; } if (PyString_Check(obj)) { ! pa->ffi_type = &ffi_type_pointer; ! pa->value.p = PyString_AS_STRING(obj); ! return 0; } #ifdef HAVE_USABLE_WCHAR_T if (PyUnicode_Check(obj)) { ! pa->ffi_type = &ffi_type_pointer; ! pa->value.p = PyUnicode_AS_UNICODE(obj); ! return 0; } #endif + { PyObject *arg; *************** *** 513,533 **** */ if (arg == 0) { - Py_DECREF(parm); PyErr_Format(PyExc_TypeError, "Don't know how to convert parameter %d", index); ! return NULL; } if (PyCArg_CheckExact(arg)) { ! Py_DECREF(parm); ! return (PyCArgObject *)arg; } if (PyInt_Check(arg)) { ! parm->pffi_type = &ffi_type_sint; ! parm->tag = 'i'; ! parm->value.i = PyInt_AS_LONG(arg); Py_DECREF(arg); ! Py_INCREF(obj); ! parm->obj = obj; ! return parm; } #if 0 --- 514,534 ---- */ if (arg == 0) { PyErr_Format(PyExc_TypeError, "Don't know how to convert parameter %d", index); ! return -1; } if (PyCArg_CheckExact(arg)) { ! PyCArgObject *carg = (PyCArgObject *)arg; ! pa->ffi_type = carg->pffi_type; ! /* XXX What about structures by value? */ ! memcpy(&pa->value, &carg->value, sizeof(pa->value)); ! Py_DECREF(arg); /* XXX */ ! return 0; } if (PyInt_Check(arg)) { ! pa->ffi_type = &ffi_type_sint; ! pa->value.l = PyInt_AS_LONG(arg); Py_DECREF(arg); ! return 0; } #if 0 *************** *** 548,555 **** #endif #endif ! Py_DECREF(parm); PyErr_Format(PyExc_TypeError, "Don't know how to convert parameter %d", index); ! return NULL; } } --- 549,556 ---- #endif #endif ! Py_DECREF(arg); PyErr_Format(PyExc_TypeError, "Don't know how to convert parameter %d", index); ! return -1; } } *************** *** 565,585 **** - struct argument { - ffi_type *ffi_type; - union { - char c; - char b; - short h; - int i; - long l; - #ifdef HAVE_LONG_LONG - PY_LONG_LONG q; - #endif - double d; - float f; - void *p; - } value; - }; - /* * libffi uses: --- 566,569 ---- *************** *** 596,607 **** static int _call_function_pointer(int flags, PPROC pProc, ! PyCArgObject **parms, struct argument *res, int argcount) { ffi_cif cif; - ffi_type **atypes; - void **values; - int i; int cc; #ifdef MS_WIN32 --- 580,589 ---- static int _call_function_pointer(int flags, PPROC pProc, ! void **avalues, ! ffi_type **atypes, struct argument *res, int argcount) { ffi_cif cif; int cc; #ifdef MS_WIN32 *************** *** 610,634 **** EXCEPTION_RECORD record; #endif ! atypes = (ffi_type **)alloca(argcount * sizeof(ffi_type *)); ! values = (void **)alloca(argcount * sizeof(void *)); ! ! for (i = 0; i < argcount; ++i) { ! ffi_type *tp = parms[i]->pffi_type; ! if (tp == NULL) { ! PyErr_SetString(PyExc_RuntimeError, ! "No ffi_type for an argument"); ! return -1; ! } ! atypes[i] = tp; ! /* For structure parameters (by value), parg->value doesn't ! contain the structure data itself, instead parg->value.p ! *points* to the structure's data. See also _ctypes.c, function ! Struct_as_parameter(). ! */ ! if (tp->type == FFI_TYPE_STRUCT) ! values[i] = parms[i]->value.p; ! else ! values[i] = &parms[i]->value; ! } if (res->ffi_type == NULL) { PyErr_SetString(PyExc_RuntimeError, --- 592,596 ---- EXCEPTION_RECORD record; #endif ! /* XXX check before here */ if (res->ffi_type == NULL) { PyErr_SetString(PyExc_RuntimeError, *************** *** 660,664 **** delta = #endif ! ffi_call(&cif, (void *)pProc, &res->value, values); #ifdef MS_WIN32 #ifndef DEBUG_EXCEPTIONS --- 622,626 ---- delta = #endif ! ffi_call(&cif, (void *)pProc, &res->value, avalues); #ifdef MS_WIN32 #ifndef DEBUG_EXCEPTIONS *************** *** 826,880 **** int i, n, argcount; struct argument result; ! ! PyCArgObject **pargs, **pp; PyObject *retval = NULL; n = argcount = PyTuple_GET_SIZE(argtuple); ! ! /* a COM object this pointer */ if (pIunk) ++argcount; ! pargs = (PyCArgObject **)alloca(sizeof(PyCArgObject *) * argcount); ! memset(pargs, 0, sizeof(pargs) * argcount); if (pIunk) { ! pargs[0] = new_CArgObject(); ! if (pargs[0] == NULL) ! return NULL; ! pargs[0]->pffi_type = &ffi_type_pointer; ! pargs[0]->tag = 'P'; ! pargs[0]->value.p = pIunk; ! pp = &pargs[1]; } else { ! pp = &pargs[0]; } /* Convert the arguments */ ! for (i = 0; i < n; ++i, ++pp) { PyObject *converter; PyObject *arg; arg = PyTuple_GET_ITEM(argtuple, i); /* borrowed ref */ if (argtypes) { converter = PyTuple_GET_ITEM(argtypes, i); ! /* new ref */ ! arg = PyObject_CallFunctionObjArgs(converter, arg, NULL); ! if (arg == NULL) { Extend_Error_Info("while constructing argument %d:\n", i+1); goto cleanup; } ! *pp = ConvParam(arg, i+1); ! Py_DECREF(arg); ! if (!*pp) { Extend_Error_Info("while constructing argument %d:\n", i+1); goto cleanup; } } else { ! *pp = ConvParam(arg, i+1); ! if (!*pp) { Extend_Error_Info("while constructing argument %d:\n", i+1); goto cleanup; /* leaking ? */ --- 788,839 ---- int i, n, argcount; struct argument result; ! struct argument *args, *pa; ! ffi_type **atypes; ! void **avalues; PyObject *retval = NULL; n = argcount = PyTuple_GET_SIZE(argtuple); ! /* an optional COM object this pointer */ if (pIunk) ++argcount; ! args = (struct argument *)alloca(sizeof(struct argument) * argcount); ! memset(args, 0, sizeof(struct argument) * argcount); if (pIunk) { ! args[0].ffi_type = &ffi_type_pointer; ! args[0].value.p = pIunk; ! pa = &args[1]; } else { ! pa = &args[0]; } /* Convert the arguments */ ! for (i = 0; i < n; ++i, ++pa) { PyObject *converter; PyObject *arg; + int err; arg = PyTuple_GET_ITEM(argtuple, i); /* borrowed ref */ if (argtypes) { + PyObject *v; converter = PyTuple_GET_ITEM(argtypes, i); ! v = PyObject_CallFunctionObjArgs(converter, arg, NULL); ! if (v == NULL) { Extend_Error_Info("while constructing argument %d:\n", i+1); goto cleanup; } ! err = ConvParam(v, i+1, pa); ! Py_DECREF(v); ! if (-1 == err) { Extend_Error_Info("while constructing argument %d:\n", i+1); goto cleanup; } } else { ! err = ConvParam(arg, i+1, pa); ! if (-1 == err) { Extend_Error_Info("while constructing argument %d:\n", i+1); goto cleanup; /* leaking ? */ *************** *** 885,889 **** result.ffi_type = GetType(restype); ! if (-1 == _call_function_pointer(flags, pProc, pargs, &result, argcount)) goto cleanup; --- 844,855 ---- result.ffi_type = GetType(restype); ! avalues = (void **)alloca(sizeof(void *) * argcount); ! atypes = (ffi_type **)alloca(sizeof(ffi_type *) * argcount); ! for (i = 0; i < argcount; ++i) { ! avalues[i] = (void *)&args[i].value; ! atypes[i] = args[i].ffi_type; ! } ! ! if (-1 == _call_function_pointer(flags, pProc, avalues, atypes, &result, argcount)) goto cleanup; *************** *** 898,904 **** retval = GetResult(restype, &result); cleanup: - for (i = 0; i < argcount; ++i) { - Py_XDECREF(pargs[i]); - } return retval; } --- 864,867 ---- |
From: Thomas H. <th...@us...> - 2004-06-11 17:44:23
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28101 Modified Files: test_refcounts.py Log Message: Replace failUnless(a == b) with failUnlessEqual(a, b), for more meaningful output when a test fails. Index: test_refcounts.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_refcounts.py,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** test_refcounts.py 4 May 2004 09:15:19 -0000 1.13 --- test_refcounts.py 11 Jun 2004 17:44:11 -0000 1.14 *************** *** 23,37 **** return value ! self.failUnless(grc(callback) == 2) cb = MyCallback(callback) self.failUnless(grc(callback) > 2) result = f(-10, cb) ! self.failUnless(result == -18) cb = None gc.collect() ! self.failUnless(grc(callback) == 2) --- 23,37 ---- return value ! self.failUnlessEqual(grc(callback), 2) cb = MyCallback(callback) self.failUnless(grc(callback) > 2) result = f(-10, cb) ! self.failUnlessEqual(result, -18) cb = None gc.collect() ! self.failUnlessEqual(grc(callback), 2) *************** *** 41,45 **** pass # this is the standard refcount for func ! self.failUnless(grc(func) == 2) # the CFuncPtr instance holds atr least one refcount on func: --- 41,45 ---- pass # this is the standard refcount for func ! self.failUnlessEqual(grc(func), 2) # the CFuncPtr instance holds atr least one refcount on func: *************** *** 81,85 **** del f gc.collect() ! self.failUnless(grc(func) == 2) --- 81,85 ---- del f gc.collect() ! self.failUnlessEqual(grc(func), 2) |
From: Thomas H. <th...@us...> - 2004-06-11 16:08:02
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9821 Modified Files: callproc.c Log Message: Finish rename a label. Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.81 retrieving revision 1.82 diff -C2 -d -r1.81 -r1.82 *** callproc.c 11 Jun 2004 15:14:46 -0000 1.81 --- callproc.c 11 Jun 2004 16:07:52 -0000 1.82 *************** *** 865,869 **** if (arg == NULL) { Extend_Error_Info("while constructing argument %d:\n", i+1); ! goto error; } --- 865,869 ---- if (arg == NULL) { Extend_Error_Info("while constructing argument %d:\n", i+1); ! goto cleanup; } *************** *** 872,876 **** if (!*pp) { Extend_Error_Info("while constructing argument %d:\n", i+1); ! goto error; } } else { --- 872,876 ---- if (!*pp) { Extend_Error_Info("while constructing argument %d:\n", i+1); ! goto cleanup; } } else { *************** *** 878,882 **** if (!*pp) { Extend_Error_Info("while constructing argument %d:\n", i+1); ! goto error; /* leaking ? */ } } --- 878,882 ---- if (!*pp) { Extend_Error_Info("while constructing argument %d:\n", i+1); ! goto cleanup; /* leaking ? */ } } |
From: Thomas H. <th...@us...> - 2004-06-11 15:14:55
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27538 Modified Files: callproc.c Log Message: Rename a label. Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.80 retrieving revision 1.81 diff -C2 -d -r1.80 -r1.81 *** callproc.c 11 Jun 2004 15:12:13 -0000 1.80 --- callproc.c 11 Jun 2004 15:14:46 -0000 1.81 *************** *** 805,808 **** --- 805,811 ---- } + #ifdef MS_WIN32 + #define alloca _alloca + #endif /* * Requirements, must be ensured by the caller: *************** *** 823,826 **** --- 826,830 ---- int i, n, argcount; struct argument result; + PyCArgObject **pargs, **pp; PyObject *retval = NULL; *************** *** 832,838 **** ++argcount; - #ifdef MS_WIN32 - #define alloca _alloca - #endif pargs = (PyCArgObject **)alloca(sizeof(PyCArgObject *) * argcount); memset(pargs, 0, sizeof(pargs) * argcount); --- 836,839 ---- *************** *** 885,889 **** if (-1 == _call_function_pointer(flags, pProc, pargs, &result, argcount)) ! goto error; #ifdef MS_WIN32 --- 886,890 ---- if (-1 == _call_function_pointer(flags, pProc, pargs, &result, argcount)) ! goto cleanup; #ifdef MS_WIN32 *************** *** 896,900 **** #endif retval = GetResult(restype, &result); ! error: for (i = 0; i < argcount; ++i) { Py_XDECREF(pargs[i]); --- 897,901 ---- #endif retval = GetResult(restype, &result); ! cleanup: for (i = 0; i < argcount; ++i) { Py_XDECREF(pargs[i]); |
From: Thomas H. <th...@us...> - 2004-06-11 15:12:27
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25978 Modified Files: ctypes.h callproc.c callbacks.c Log Message: Make GetType() public. Use a stack-allocated structure for the result. Index: ctypes.h =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/ctypes.h,v retrieving revision 1.45 retrieving revision 1.46 diff -C2 -d -r1.45 -r1.46 *** ctypes.h 11 Jun 2004 14:42:50 -0000 1.45 --- ctypes.h 11 Jun 2004 15:12:12 -0000 1.46 *************** *** 254,257 **** --- 254,259 ---- extern char basespec_string[]; + extern ffi_type *GetType(PyObject *obj); + /* Local Variables: Index: callbacks.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callbacks.c,v retrieving revision 1.52 retrieving revision 1.53 diff -C2 -d -r1.52 -r1.53 *** callbacks.c 11 Jun 2004 14:42:50 -0000 1.52 --- callbacks.c 11 Jun 2004 15:12:13 -0000 1.53 *************** *** 200,212 **** } - static ffi_type *GetType(PyObject *obj) - { - StgDictObject *dict = PyType_stgdict(obj); - if (dict == NULL) - return &ffi_type_sint; - return &dict->ffi_type; - } - - THUNK AllocFunctionCallback(PyObject *callable, int nArgBytes, --- 200,203 ---- Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.79 retrieving revision 1.80 diff -C2 -d -r1.79 -r1.80 *** callproc.c 11 Jun 2004 13:04:07 -0000 1.79 --- callproc.c 11 Jun 2004 15:12:13 -0000 1.80 *************** *** 556,559 **** --- 556,585 ---- + ffi_type *GetType(PyObject *obj) + { + StgDictObject *dict = PyType_stgdict(obj); + if (dict == NULL) + return &ffi_type_sint; + return &dict->ffi_type; + } + + + struct argument { + ffi_type *ffi_type; + union { + char c; + char b; + short h; + int i; + long l; + #ifdef HAVE_LONG_LONG + PY_LONG_LONG q; + #endif + double d; + float f; + void *p; + } value; + }; + /* * libffi uses: *************** *** 571,575 **** PPROC pProc, PyCArgObject **parms, ! PyCArgObject *res, int argcount) { --- 597,601 ---- PPROC pProc, PyCArgObject **parms, ! struct argument *res, int argcount) { *************** *** 605,609 **** values[i] = &parms[i]->value; } ! if (res->pffi_type == NULL) { PyErr_SetString(PyExc_RuntimeError, "No ffi_type for result"); --- 631,635 ---- values[i] = &parms[i]->value; } ! if (res->ffi_type == NULL) { PyErr_SetString(PyExc_RuntimeError, "No ffi_type for result"); *************** *** 620,624 **** cc, argcount, ! res->pffi_type, atypes)) { PyErr_SetString(PyExc_RuntimeError, --- 646,650 ---- cc, argcount, ! res->ffi_type, atypes)) { PyErr_SetString(PyExc_RuntimeError, *************** *** 711,715 **** * Convert the C value in result into an instance described by restype */ ! static PyObject *GetResult(PyObject *restype, PyCArgObject *result) { StgDictObject *dict; --- 737,741 ---- * Convert the C value in result into an instance described by restype */ ! static PyObject *GetResult(PyObject *restype, struct argument *result) { StgDictObject *dict; *************** *** 796,805 **** { int i, n, argcount; ! PyCArgObject result; PyCArgObject **pargs, **pp; PyObject *retval = NULL; - result.obj = NULL; - n = argcount = PyTuple_GET_SIZE(argtuple); --- 822,829 ---- { int i, n, argcount; ! struct argument result; PyCArgObject **pargs, **pp; PyObject *retval = NULL; n = argcount = PyTuple_GET_SIZE(argtuple); *************** *** 858,862 **** } ! PrepareResult(restype, &result); if (-1 == _call_function_pointer(flags, pProc, pargs, &result, argcount)) --- 882,886 ---- } ! result.ffi_type = GetType(restype); if (-1 == _call_function_pointer(flags, pProc, pargs, &result, argcount)) *************** *** 876,880 **** Py_XDECREF(pargs[i]); } - Py_XDECREF(result.obj); return retval; } --- 900,903 ---- |
From: Thomas H. <th...@us...> - 2004-06-11 15:05:29
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21853 Modified Files: _ctypes.c Log Message: ffi_type for function pointers. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.146 retrieving revision 1.147 diff -C2 -d -r1.146 -r1.147 *** _ctypes.c 11 Jun 2004 13:34:04 -0000 1.146 --- _ctypes.c 11 Jun 2004 15:05:16 -0000 1.147 *************** *** 1407,1410 **** --- 1407,1411 ---- stgdict->setfunc = NULL; stgdict->getfunc = NULL; + stgdict->ffi_type = ffi_type_pointer; ob = PyDict_GetItemString((PyObject *)stgdict, "_flags_"); |
From: Thomas H. <th...@us...> - 2004-06-11 14:43:02
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3927 Modified Files: ctypes.h callbacks.c Log Message: Replace the GetResult hack with a GetType function. Index: ctypes.h =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/ctypes.h,v retrieving revision 1.44 retrieving revision 1.45 diff -C2 -d -r1.44 -r1.45 *** ctypes.h 9 Jun 2004 15:39:36 -0000 1.44 --- ctypes.h 11 Jun 2004 14:42:50 -0000 1.45 *************** *** 246,251 **** extern void Extend_Error_Info(char *fmt, ...); - extern void PrepareResult(PyObject *restype, PyCArgObject *result); - struct basespec { CDataObject *base; --- 246,249 ---- Index: callbacks.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callbacks.c,v retrieving revision 1.51 retrieving revision 1.52 diff -C2 -d -r1.51 -r1.52 *** callbacks.c 9 Jun 2004 19:52:27 -0000 1.51 --- callbacks.c 11 Jun 2004 14:42:50 -0000 1.52 *************** *** 200,203 **** --- 200,212 ---- } + static ffi_type *GetType(PyObject *obj) + { + StgDictObject *dict = PyType_stgdict(obj); + if (dict == NULL) + return &ffi_type_sint; + return &dict->ffi_type; + } + + THUNK AllocFunctionCallback(PyObject *callable, int nArgBytes, *************** *** 209,213 **** ffi_info *p; int nArgs, i; - PyCArgObject cResult; ffi_abi cc; --- 218,221 ---- *************** *** 221,231 **** for (i = 0; i < nArgs; ++i) { PyObject *cnv = PySequence_GetItem(converters, i); ! PrepareResult(cnv, &cResult); ! p->atypes[i] = cResult.pffi_type; Py_DECREF(cnv); } p->atypes[i] = NULL; - PrepareResult(restype, &cResult); { StgDictObject *dict = PyType_stgdict(restype); --- 229,237 ---- for (i = 0; i < nArgs; ++i) { PyObject *cnv = PySequence_GetItem(converters, i); ! p->atypes[i] = GetType(cnv); Py_DECREF(cnv); } p->atypes[i] = NULL; { StgDictObject *dict = PyType_stgdict(restype); *************** *** 242,246 **** #endif result = ffi_prep_cif(&p->cif, cc, nArgs, ! cResult.pffi_type, &p->atypes[0]); if (result != FFI_OK) { --- 248,252 ---- #endif result = ffi_prep_cif(&p->cif, cc, nArgs, ! GetType(restype), &p->atypes[0]); if (result != FFI_OK) { |
From: Thomas H. <th...@us...> - 2004-06-11 13:34:13
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9975 Modified Files: _ctypes.c Log Message: Initialize pointer ffi_type. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.145 retrieving revision 1.146 diff -C2 -d -r1.145 -r1.146 *** _ctypes.c 9 Jun 2004 15:38:55 -0000 1.145 --- _ctypes.c 11 Jun 2004 13:34:04 -0000 1.146 *************** *** 463,466 **** --- 463,467 ---- stgdict->align = getentry("P")->pffi_type->alignment; stgdict->length = 2; + stgdict->ffi_type = ffi_type_pointer; proto = PyDict_GetItemString(typedict, "_type_"); /* Borrowed ref */ |
From: Thomas H. <th...@us...> - 2004-06-11 13:04:17
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19415 Modified Files: callproc.c Log Message: Simplify GetResult a bit, and fix a bug. Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.78 retrieving revision 1.79 diff -C2 -d -r1.78 -r1.79 *** callproc.c 11 Jun 2004 12:37:19 -0000 1.78 --- callproc.c 11 Jun 2004 13:04:07 -0000 1.79 *************** *** 686,738 **** if (restype == NULL) { result->pffi_type = &ffi_type_sint; - result->tag = 'i'; return; } - /* XXX Wouldn't it be better to store the 'fmt' directly - in the stgdict? And for the libffi version, store the ffi_type - pointer there? - */ dict = PyType_stgdict(restype); ! if (dict && dict->getfunc && dict->proto && PyString_Check(dict->proto)) { ! char *fmt = PyString_AS_STRING(dict->proto); ! /* XXX This should probably be checked when assigning the restype ! attribute ! */ ! if (strchr("zcbBhHiIlLqQdfP", fmt[0])) { ! result->tag = fmt[0]; ! result->pffi_type = &dict->ffi_type; ! return; ! } ! } ! ! if (PointerTypeObject_Check(restype)) { ! result->pffi_type = &ffi_type_pointer; ! result->tag = 'P'; return; } - #if 0 - if (SimpleTypeObject_Check(restype)) { - /* Simple data types as return value don't make too much sense - * (why would you prefer a c_int instance over a plain Python integer?) - * but subclasses DO make sense. Think 'class HRESULT(c_int): pass'. - */ - /* - * If this would be enabled, it would start with this code: - */ - StgDictObject *dict; - - dict = PyType_stgdict(restype); - if (!dict || !PyString_Check(dict->proto)) { - PyErr_SetString(PyExc_TypeError, - "invalid restype: has no stgdict or proto invalid"); - goto error; - } - format = PyString_AS_STRING(dict->proto)[0]; - } - #endif if (PyCallable_Check(restype)) { - result->tag = 'i'; /* call with integer result */ result->pffi_type = &ffi_type_sint; return; --- 686,699 ---- if (restype == NULL) { result->pffi_type = &ffi_type_sint; return; } dict = PyType_stgdict(restype); ! if (dict && dict->getfunc) { ! result->pffi_type = &dict->ffi_type; return; } if (PyCallable_Check(restype)) { result->pffi_type = &ffi_type_sint; return; *************** *** 740,750 **** if (restype == Py_None) { - result->tag = 'v'; /* call with void result */ result->pffi_type = &ffi_type_void; return; } ! ! /* XXX This should not occur... */ ! result->tag = 'i'; result->pffi_type = &ffi_type_sint; } --- 701,708 ---- if (restype == Py_None) { result->pffi_type = &ffi_type_void; return; } ! /* should not occurr */ result->pffi_type = &ffi_type_sint; } *************** *** 916,920 **** error: for (i = 0; i < argcount; ++i) { ! Py_XDECREF(pargs[i]->obj); } Py_XDECREF(result.obj); --- 874,878 ---- error: for (i = 0; i < argcount; ++i) { ! Py_XDECREF(pargs[i]); } Py_XDECREF(result.obj); |
From: Thomas H. <th...@us...> - 2004-06-11 12:37:29
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1010 Modified Files: callproc.c Log Message: Allocate result on the stack instead of the heap. Slightly faster. Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.77 retrieving revision 1.78 diff -C2 -d -r1.77 -r1.78 *** callproc.c 9 Jun 2004 15:40:30 -0000 1.77 --- callproc.c 11 Jun 2004 12:37:19 -0000 1.78 *************** *** 707,718 **** } - /* Remove later */ - if (PyString_Check(restype)) { - assert(0); - /* XXX Is it single letter? */ - result->tag = PyString_AS_STRING(restype)[0]; - return; - } - if (PointerTypeObject_Check(restype)) { result->pffi_type = &ffi_type_pointer; --- 707,710 ---- *************** *** 846,853 **** { int i, n, argcount; ! PyCArgObject *result = NULL; PyCArgObject **pargs, **pp; PyObject *retval = NULL; n = argcount = PyTuple_GET_SIZE(argtuple); --- 838,847 ---- { int i, n, argcount; ! PyCArgObject result; PyCArgObject **pargs, **pp; PyObject *retval = NULL; + result.obj = NULL; + n = argcount = PyTuple_GET_SIZE(argtuple); *************** *** 906,933 **** } ! /* Is it possible to allocate Python objects on the stack ! instead of on the heap? */ ! result = new_CArgObject(); ! if (result == NULL) ! goto error; ! PrepareResult(restype, result); ! if (-1 == _call_function_pointer(flags, pProc, pargs, result, argcount)) goto error; #ifdef MS_WIN32 if (flags & FUNCFLAG_HRESULT) { ! if (result->value.i & 0x80000000) ! retval = PyErr_SetFromWindowsErr(result->value.i); else ! retval = PyInt_FromLong(result->value.i); } else #endif ! retval = GetResult(restype, result); error: for (i = 0; i < argcount; ++i) { ! Py_XDECREF(pargs[i]); } ! Py_XDECREF(result); return retval; } --- 900,922 ---- } ! PrepareResult(restype, &result); ! if (-1 == _call_function_pointer(flags, pProc, pargs, &result, argcount)) goto error; #ifdef MS_WIN32 if (flags & FUNCFLAG_HRESULT) { ! if (result.value.i & 0x80000000) ! retval = PyErr_SetFromWindowsErr(result.value.i); else ! retval = PyInt_FromLong(result.value.i); } else #endif ! retval = GetResult(restype, &result); error: for (i = 0; i < argcount; ++i) { ! Py_XDECREF(pargs[i]->obj); } ! Py_XDECREF(result.obj); return retval; } |
From: Thomas H. <th...@us...> - 2004-06-11 11:25:23
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3482 Modified Files: benchmark.py Log Message: Add comments with the preformance results on my machine, win32 and suse. Index: benchmark.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/benchmark.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** benchmark.py 29 Jan 2004 11:15:51 -0000 1.2 --- benchmark.py 11 Jun 2004 11:25:11 -0000 1.3 *************** *** 13,24 **** --- 13,32 ---- t = Timer("ex_func_si('abc', 3)", "from __main__ import ex_func_si") + # win32: 1.284 us + # suse9.1 (vmware): 2.314 us print >> sys.stderr, "dll call, 2 args: %.3f us" % t.timeit() t = Timer("py_func_si('abc', 3)", "from __main__ import py_func_si") + # win32: 0.629 us + # suse9.1(vmware): 0.910 us print >> sys.stderr, "func call, 2 args: %.3f us" % t.timeit() print >> sys.stderr t = Timer("ex_func()", "from __main__ import ex_func") + # win32: 0.773 us + # suse9.1(vmware): 1.521 us print >> sys.stderr, "dll call, no args: %.3f us" % (t.timeit(10000000) / 10) t = Timer("py_func()", "from __main__ import py_func") + # win32: 0.139 us + # suse9.1(vmware): 0.231 us print >> sys.stderr, "func call, no args: %.3f us" % (t.timeit(10000000) / 10) print >> sys.stderr |