[ctypes-commit] ctypes/ctypes decorators.py,1.4,1.5
Brought to you by:
theller
From: Thomas H. <th...@us...> - 2005-02-04 18:05:40
|
Update of /cvsroot/ctypes/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16609 Modified Files: decorators.py Log Message: Remove the stuff that doesn't work. Index: decorators.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/decorators.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** decorators.py 28 Jan 2005 18:16:35 -0000 1.4 --- decorators.py 4 Feb 2005 18:05:29 -0000 1.5 *************** *** 28,41 **** cdef >>> - >>> @ cdecl(c_char_p, 'msvcrt', [c_char_p, c_int]) - ... def strchr(string, c): - ... 'find a character in a string' - ... - >>> print strchr('abcdef', ord('x')) - None - >>> print strchr('abcdef', ord('c')) - cdef - >>> """ import sys import ctypes --- 28,44 ---- cdef >>> """ + + # This doesn't work, see below. + ##>>> @ cdecl(c_char_p, 'msvcrt', [c_char_p, c_int]) + ##... def strchr(string, c): + ##... 'find a character in a string' + ##... + ##>>> print strchr('abcdef', ord('x')) + ##None + ##>>> print strchr('abcdef', ord('c')) + ##cdef + ##>>> + import sys import ctypes *************** *** 43,73 **** LOGGING = False ! def _create_func_codestring(func, doc=None): ! # given a function object <func>, build the source code for ! # another function, having the same argument list, and a function ! # body which contains a call to an _api_ function. ! # ! # Assuming the <func> has this definition: ! # def func(first, second="spam", third=42): ! # .... ! # a string containing the following code is returned: ! # def func(first, second="spam", third=42): ! # return _api_(first, second, third) ! import inspect ! args, varargs, varkw, defaults = inspect.getargspec(func) ! if varkw: ! raise TypeError, "function argument list cannot contain ** argument" ! if doc: ! return "def %s%s:\n %r\n return %s._api_%s" % \ ! (func.func_name, ! inspect.formatargspec(args, varargs, varkw, defaults), ! doc, ! func.func_name, ! inspect.formatargspec(args, varargs, varkw)) ! return "def %s%s:\n return %s._api_%s" % \ ! (func.func_name, ! inspect.formatargspec(args, varargs, varkw, defaults), ! func.func_name, ! inspect.formatargspec(args, varargs, varkw)) ################################################################ --- 46,76 ---- LOGGING = False ! ##def _create_func_codestring(func, doc=None): ! ## # given a function object <func>, build the source code for ! ## # another function, having the same argument list, and a function ! ## # body which contains a call to an _api_ function. ! ## # ! ## # Assuming the <func> has this definition: ! ## # def func(first, second="spam", third=42): ! ## # .... ! ## # a string containing the following code is returned: ! ## # def func(first, second="spam", third=42): ! ## # return _api_(first, second, third) ! ## import inspect ! ## args, varargs, varkw, defaults = inspect.getargspec(func) ! ## if varkw: ! ## raise TypeError, "function argument list cannot contain ** argument" ! ## if doc: ! ## return "def %s%s:\n %r\n return %s._api_%s" % \ ! ## (func.func_name, ! ## inspect.formatargspec(args, varargs, varkw, defaults), ! ## doc, ! ## func.func_name, ! ## inspect.formatargspec(args, varargs, varkw)) ! ## return "def %s%s:\n return %s._api_%s" % \ ! ## (func.func_name, ! ## inspect.formatargspec(args, varargs, varkw, defaults), ! ## func.func_name, ! ## inspect.formatargspec(args, varargs, varkw)) ################################################################ *************** *** 80,89 **** this_dll = dll api = ctypes.WINFUNCTYPE(restype, *argtypes)(func.func_name, this_dll) ! if len(func.func_code.co_code) == 4: ! # Hacky way to detect an empty function body. ! codestring = _create_func_codestring(func, func.__doc__) ! d = {} ! exec codestring in d ! func = d[func.func_name] func._api_ = api if logging or LOGGING: --- 83,92 ---- this_dll = dll api = ctypes.WINFUNCTYPE(restype, *argtypes)(func.func_name, this_dll) ! # This simple way to find out an empty function body doesn't work. ! ## if len(func.func_code.co_code) == 4: ! ## codestring = _create_func_codestring(func, func.__doc__) ! ## d = {} ! ## exec codestring in d ! ## func = d[func.func_name] func._api_ = api if logging or LOGGING: *************** *** 104,109 **** this_dll = dll api = ctypes.CFUNCTYPE(restype, *argtypes)(func.func_name, this_dll) ## if len(func.func_code.co_code) == 4: - ## # Hacky way to detect an empty function body. ## codestring = _create_func_codestring(func, func.__doc__) ## d = {} --- 107,112 ---- this_dll = dll api = ctypes.CFUNCTYPE(restype, *argtypes)(func.func_name, this_dll) + # This simple way to find out an empty function body doesn't work. ## if len(func.func_code.co_code) == 4: ## codestring = _create_func_codestring(func, func.__doc__) ## d = {} *************** *** 123,127 **** ################################################################ ! if __name__ == "__main__": import doctest doctest.testmod() --- 126,131 ---- ################################################################ ! ##if __name__ == "__main__": ! if 0: import doctest doctest.testmod() |