Thread: [ctypes-commit] ctypes/ctypes decorators.py,1.11,1.12 __init__.py,1.78,1.79
Brought to you by:
theller
From: Thomas H. <th...@us...> - 2006-03-07 19:47:52
|
Update of /cvsroot/ctypes/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23875 Modified Files: decorators.py __init__.py Log Message: Removed the decorators module. Index: decorators.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/decorators.py,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** decorators.py 3 Mar 2006 20:11:31 -0000 1.11 --- decorators.py 7 Mar 2006 19:47:46 -0000 1.12 *************** *** 1,102 **** ! """ ! This module implements decorators for native api function calls. ! ! name_library(name, so_name) ! cdecl(restype, dllname, argtypes) ! stdcall(restype, dllname, argtypes) - windows only ! """ ! ! LOGGING = False ! ! import os ! import ctypes ! ! def cdecl(restype, dllname, argtypes, logging=False): ! """cdecl(restype, dllname, argtypes, logging=False) -> decorator. ! ! The decorator, when applied to a function, attaches an '_api_' ! attribute to the function. Calling this attribute calls the ! function exported from the dll, using the standard C calling ! convention. ! ! restype - result type ! dll - name or instance of a dll/shared library ! argtypes - list of argument types ! logging - if this is True, the result of each function call ! is printed to stderr. ! """ ! def decorate(func): ! library = ctypes.cdll.find(dllname, False) ! api = ctypes.CFUNCTYPE(restype, *argtypes)(func.func_name, library) ! func._api_ = api ! # The following few lines trigger a pychecker bug, see ! # https://sourceforge.net/tracker/index.php?func=detail&aid=1114902&group_id=24686&atid=382217 ! if logging or LOGGING: ! def f(*args): ! result = func(*args) ! print >> sys.stderr, "# function call: %s%s -> %s" % (func.func_name, args, result) ! return result ! return f ! return func ! return decorate ! ! if os.name == "nt": ! def stdcall(restype, dllname, argtypes, logging=False): ! """stdcall(restype, dllname, argtypes, logging=False) -> decorator. ! ! The decorator, when applied to a function, attaches an '_api_' ! attribute to the function. Calling this attribute calls the ! function exported from the dll, using the MS '__stdcall' calling ! convention. ! ! restype - result type ! dll - name or instance of a dll ! argtypes - list of argument types ! logging - if this is True, the result of each function call ! is printed to stderr. ! """ ! def decorate(func): ! library = ctypes.windll.find(dllname, False) ! api = ctypes.WINFUNCTYPE(restype, *argtypes)(func.func_name, library) ! func._api_ = api ! # The following few lines trigger a pychecker bug, see ! # https://sourceforge.net/tracker/index.php?func=detail&aid=1114902&group_id=24686&atid=382217 ! if logging or LOGGING: ! def f(*args): ! result = func(*args) ! print >> sys.stderr, "# function call: %s%s -> %s" % (func.func_name, args, result) ! return result ! return f ! return func ! return decorate ! ! ################################################################ ! ! def _test(): ! import os, sys ! from ctypes import c_char, c_int, c_ulong, c_double, \ ! POINTER, create_string_buffer, sizeof ! ! if os.name == "nt": ! from ctypes import WinError ! ! #@ stdcall(ctypes.c_ulong, "kernel32", [c_ulong, POINTER(c_char), c_ulong]) ! def GetModuleFileNameA(handle=0): ! buf = create_string_buffer(256) ! if 0 == GetModuleFileNameA._api_(handle, buf, sizeof(buf)): ! raise WinError() ! return buf.value ! GetModuleFileNameA = stdcall(ctypes.c_ulong, "kernel32", ! [c_ulong, POINTER(c_char), c_ulong])(GetModuleFileNameA) ! ! assert(sys.executable == GetModuleFileNameA()) ! ! #@ cdecl(c_double, 'libm', [c_double]) ! def sqrt(value): ! return sqrt._api_(value) ! sqrt = cdecl(c_double, 'm', [c_double])(sqrt) ! ! assert sqrt(4.0) == 2.0 ! ! if __name__ == "__main__": ! _test() --- 1 ---- ! # unused. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/__init__.py,v retrieving revision 1.78 retrieving revision 1.79 diff -C2 -d -r1.78 -r1.79 *** __init__.py 3 Mar 2006 20:11:31 -0000 1.78 --- __init__.py 7 Mar 2006 19:47:46 -0000 1.79 *************** *** 427,434 **** - from decorators import cdecl - if _os.name == "nt": - from decorators import stdcall - if _os.name == "nt": # COM stuff def DllGetClassObject(rclsid, riid, ppv): --- 427,430 ---- |