ctypes-commit Mailing List for ctypes (Page 75)
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...> - 2005-01-29 21:42:34
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18755 Added Files: make.bat README.txt Log Message: Some docs for the code generator. --- NEW FILE: make.bat --- @echo off setlocal set FLAGS=-s -g -t --stylesheet=default.css py24 \python24\Scripts\rst2html.py %FLAGS% README.txt README.html --- NEW FILE: README.txt --- =============================== README: ctypes code generation =============================== .. _REST quickref: http://docutils.sourceforge.net/docs/user/rst/quickstart.html This document describes the ctypes code generator. The generator converts declarations in C header files into executable Python code: enums, structs, unions, function declarations, and preprocessor definitions. The ability to convert preprocessor definitions allows to use the code generator as an improved version of the ``Tools/Scripts/h2py.py`` script included with Python itself. .. contents:: Overview ======== Creating wrappers for C header file(s) is a two step process. First, the ``h2xml.py`` script runs gccxml_ over the include file(s), creating a XML file containing declarations and definitions. Second, the ``xml2py.py`` script parses the XML files and creates Python code containing all or a subset of these definitions. Python code is generated for C enums, structure, unions, typedefs and function declarations. Also included are preprocessor definitions, as far as they can be converted to valid Python code. It is possible to filter the output so that only a subset of the definitions are converted, so it is either possible to generate a complete Python module wrapping a shared library, or the generator can be used to create snippets of Python code which can be pasted into a manually written module. Requirements ============ gccxml_ is required to parse C header files into an XML description. **Unfortunately the latest official version 0.6.0 does not fulfill the ctypes code generator requirements.** For windows, you can download a prebuild windows installer from `the ctypes download page`_. Please note that the installation of gccxml requires that MSVC 6, 7, or 7.1 is installed on your system, because it needs the system header files. If you don't want to or can not install gccxml, you can also download a prebuilt windows.xml file from the same location. For other platforms you must `get the development version from CVS`_ and `build gccxml from source`_. .. _the ctypes download page: http://www.iontof.com/ .. _gccxml: http://www.gccxml.org/ .. _build gccxml from source: http://www.gccxml.org/HTML/Install.html .. _get the development version from CVS: http://www.gccxml.org/HTML/Download.html Usage examples ============== Parse the windows header files (this may take a while):: C:\>python h2xml.py windows.h -o windows.xml -q C:\> Generate code for the RECT structure:: C:\>xml2py.py windows.xml -s RECT from ctypes import * LONG = c_long class tagRECT(Structure): pass RECT = tagRECT tagRECT._fields_ = [ ('left', c_long), ('top', c_long), ('right', c_long), ('bottom', c_long), ] assert sizeof(tagRECT) == 16, sizeof(tagRECT) assert alignment(tagRECT) == 4, alignment(tagRECT) C:\> Generate the MB_xxx constants, which are flags used for the MessageBox function:: c:\>python xml2py.py windows.xml -r MB_.* # generated by 'xml2py.py' # flags 'windows.xml -r MB_.*' MB_USERICON = 128 MB_DEFBUTTON3 = 512 MB_USEGLYPHCHARS = 4 MB_ABORTRETRYIGNORE = 2 MB_ICONASTERISK = 64 MB_ICONINFORMATION = MB_ICONASTERISK MB_ICONHAND = 16 MB_ICONERROR = MB_ICONHAND MB_ICONEXCLAMATION = 48 MB_ICONWARNING = MB_ICONEXCLAMATION MB_RIGHT = 524288 MB_SYSTEMMODAL = 4096 MB_ICONQUESTION = 32 MB_APPLMODAL = 0 MB_OK = 0 MB_TYPEMASK = 15 MB_MODEMASK = 12288 MB_TASKMODAL = 8192 MB_OKCANCEL = 1 MB_RETRYCANCEL = 5 MB_DEFAULT_DESKTOP_ONLY = 131072 MB_RTLREADING = 1048576 MB_PRECOMPOSED = 1 MB_DEFBUTTON1 = 0 MB_DEFMASK = 3840 MB_DEFBUTTON2 = 256 MB_YESNOCANCEL = 3 MB_CANCELTRYCONTINUE = 6 MB_HELP = 16384 MB_ICONMASK = 240 MB_SETFOREGROUND = 65536 MB_TOPMOST = 262144 MB_COMPOSITE = 2 MB_DEFBUTTON4 = 768 MB_YESNO = 4 MB_ERR_INVALID_CHARS = 8 MB_NOFOCUS = 32768 MB_ICONSTOP = MB_ICONHAND MB_MISCMASK = 49152 C:\> Generate code for the RegisterClass function, please note how this pulls in a lot of types:: C:\>python xml2py.py windows.xml -w -s RegisterClass -d # generated by 'xml2py' # flags 'windows.xml -w -s RegisterClass' from ctypes import * from ctypes import decorators WORD = c_ushort ATOM = WORD class tagWNDCLASSA(Structure): pass WNDCLASSA = tagWNDCLASSA user32 = CDLL('user32') @ decorators.stdcall(ATOM, user32, [POINTER(WNDCLASSA)]) def RegisterClassA(p1): return RegisterClassA._api_(p1) RegisterClass = RegisterClassA UINT = c_uint LONG_PTR = c_long LRESULT = LONG_PTR WNDPROC = WINFUNCTYPE(LRESULT, c_void_p, c_uint, c_uint, c_long) PVOID = c_void_p HANDLE = PVOID HINSTANCE = HANDLE HICON = HANDLE HCURSOR = HICON HBRUSH = HANDLE CHAR = c_char LPCSTR = POINTER(CHAR) tagWNDCLASSA._fields_ = [ ('style', UINT), ('lpfnWndProc', WNDPROC), ('cbClsExtra', c_int), ('cbWndExtra', c_int), ('hInstance', HINSTANCE), ('hIcon', HICON), ('hCursor', HCURSOR), ('hbrBackground', HBRUSH), ('lpszMenuName', LPCSTR), ('lpszClassName', LPCSTR), ] assert sizeof(tagWNDCLASSA) == 40, sizeof(tagWNDCLASSA) assert alignment(tagWNDCLASSA) == 4, alignment(tagWNDCLASSA) Create a Python module ``win_lean.py`` containing wrappers for the 'lean' windows api, that this creates a fairly large file:: C:\>python h2xml.py windows.h -D WIN32_LEAN_AND_MEAN -D NO_STRICT -o win_lean.xml -q C:\>python xml2py.py win_lean.xml -w -o win_lean.py Create a Python module ``SDL.py`` containing wrappers for the SDL library. To work around a problem gccxml has with a certain construct in the SDL header files, you must define the SDLCALL macro to an empty value:: C:\>python h2xml.py SDL.h -I SDL\include -D SDLCALL= -o SDL.xml -q C:\>python xml2py.py SDL.xml -o SDL.py -l SDL.dll C:\> The h2xml.py script =================== ``h2xml.py`` lets you specify the names of the header files to parse, the name of the XML output file, and a few options which are passed to gccxml. The ``-D``, ``-E``, and ``-I`` flags may occur several times. ``-h, --help`` Print a short usage summary and exit. ``-q, --quiet`` Run in quiet mode. The default mode is verbose, ``h2xml.py`` prints what it is currently doing. ``-D name[=value]`` This flag defines a preprocessor name. ``-U name`` This flag undefines a preprocessor name. ``-I directory`` This flag defines an additional include directory. ``-o xmlfile`` This flag specifies name and path of the XML output file. The xml2py.py script ==================== ``-h, --help`` Print a short usage summary and exit. ``-d`` Use Python 2.4 decorators for wrapped functions. ``-k[d][e][f][m][s][t]`` Specifies the kind of types to include in the output: d = simple preprocessor definitions: #define <identifier> <identifier> e = enumerations f = function declarations m = preprocessor macros taking parameters: #define <ident>(parameters) something s = structures and unions t = typedefs ``-l sharedlib`` specify shared library to search for exported functions. ``-m module`` specifies a Python module containing symbols that will be imported instead of generated. ``-o outputfile`` name of the output file containing Python code. If not specified, the code is printed to standard output. ``-r regular_expression`` regular expression specifying names of symbols to include. ``-s symbol`` name of symbol to include. ``-v`` verbose mode: prints a short summary of types generated. ``-w`` windows only: add all standard windows dlls to the list of shared libraries searched for functions. Note that specifying the ``-k``, ``-s``, and ``-r`` flags create a start set of type declarations, the generated code, however, may also contain other types. If, for example, the code for an external function is generated, code for the argument and return types is also needed. Also note that code for function declarations is only created when xml2py.py can locate the function in one of the shared libraries specified with -l or -w. Project Files & Directories =========================== * README.txt: You're reading it. Getting Help ============ If you have questions or need assistance with ctypes or the code generator, please `post a message`_ to the `ctypes-users mailing list`. .. _post a message: mailto:cty...@li... .. _ctypes-users mailing list: http://lists.sourceforge.net/lists/listinfo/ctypes-users .. Local Variables: mode: indented-text indent-tabs-mode: nil sentence-end-double-space: t fill-column: 70 compile-command: "make" End: |
From: Thomas H. <th...@us...> - 2005-01-28 21:13:44
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27112 Added Files: VARIANT.py Log Message: This file is not ready, doesn't belong here, and hasn't the correct name. Nevertheless, it's the first large example of a file created by xml2py which will be actually useful in the future, and it was a test case how to beautify a generated file by hand, with extreme dependencies of the types. --- NEW FILE: VARIANT.py --- # todo: DECIMAL and CY need cleanup. # # generated by 'xml2py' # flags 'windows.xml -s VARIANT -s ARRAYDESC -o VARIANT.py' # # Then, in one or two hours cleaned up to be human readable (somewhat) from ctypes import * from comtypes import GUID, IUnknown, STDMETHOD ################################################################ # types HREFTYPE = c_ulong VARTYPE = c_ushort VARIANT_BOOL = c_short SCODE = c_long DATE = c_double LCID = c_ulong DISPID = c_long MEMBERID = c_long # enums tagINVOKEKIND = c_int INVOKE_FUNC = 1 INVOKE_PROPERTYGET = 2 INVOKE_PROPERTYPUT = 4 INVOKE_PROPERTYPUTREF = 8 INVOKEKIND = tagINVOKEKIND tagSYSKIND = c_int SYS_WIN16 = 0 SYS_WIN32 = 1 SYS_MAC = 2 SYS_WIN64 = 3 SYSKIND = tagSYSKIND tagTYPEKIND = c_int TKIND_ENUM = 0 TKIND_RECORD = 1 TKIND_MODULE = 2 TKIND_INTERFACE = 3 TKIND_DISPATCH = 4 TKIND_COCLASS = 5 TKIND_ALIAS = 6 TKIND_UNION = 7 TKIND_MAX = 8 TYPEKIND = tagTYPEKIND tagDESCKIND = c_int DESCKIND_NONE = 0 DESCKIND_FUNCDESC = 1 DESCKIND_VARDESC = 2 DESCKIND_TYPECOMP = 3 DESCKIND_IMPLICITAPPOBJ = 4 DESCKIND_MAX = 5 DESCKIND = tagDESCKIND tagFUNCKIND = c_int FUNC_VIRTUAL = 0 FUNC_PUREVIRTUAL = 1 FUNC_NONVIRTUAL = 2 FUNC_STATIC = 3 FUNC_DISPATCH = 4 FUNCKIND = tagFUNCKIND tagCALLCONV = c_int CC_FASTCALL = 0 CC_CDECL = 1 CC_MSCPASCAL = 2 CC_PASCAL = 2 CC_MACPASCAL = 3 CC_STDCALL = 4 CC_FPFASTCALL = 5 CC_SYSCALL = 6 CC_MPWCDECL = 7 CC_MPWPASCAL = 8 CC_MAX = 9 CALLCONV = tagCALLCONV tagVARKIND = c_int VAR_PERINSTANCE = 0 VAR_STATIC = 1 VAR_CONST = 2 VAR_DISPATCH = 3 VARKIND = tagVARKIND ################################################################ # forward declaration of com interfaces # # com method tables are at the end of the file class IDispatch(IUnknown): pass class IRecordInfo(IUnknown): pass class ITypeInfo(IUnknown): pass class ITypeComp(IUnknown): pass class ITypeLib(IUnknown): pass ################################################################ class tagTLIBATTR(Structure): _fields_ = [ ('guid', GUID), ('lcid', c_ulong), ('syskind', tagSYSKIND), ('wMajorVerNum', c_ushort), ('wMinorVerNum', c_ushort), ('wLibFlags', c_ushort), ] TLIBATTR = tagTLIBATTR assert sizeof(tagTLIBATTR) == 32, sizeof(tagTLIBATTR) assert alignment(tagTLIBATTR) == 4, alignment(tagTLIBATTR) class tagSAFEARRAYBOUND(Structure): # C:/Programme/gccxml/bin/Vc71/PlatformSDK/oaidl.h 226 _fields_ = [ ('cElements', c_ulong), ('lLbound', c_long), ] assert sizeof(tagSAFEARRAYBOUND) == 8, sizeof(tagSAFEARRAYBOUND) assert alignment(tagSAFEARRAYBOUND) == 4, alignment(tagSAFEARRAYBOUND) SAFEARRAYBOUND = tagSAFEARRAYBOUND class tagSAFEARRAY(Structure): # C:/Programme/gccxml/bin/Vc71/PlatformSDK/oaidl.h 321 _fields_ = [ ('cDims', c_ushort), ('fFeatures', c_ushort), ('cbElements', c_ulong), ('cLocks', c_ulong), ('pvData', c_void_p), ('rgsabound', tagSAFEARRAYBOUND * 1), ] SAFEARRAY = tagSAFEARRAY assert sizeof(tagSAFEARRAY) == 24, sizeof(tagSAFEARRAY) assert alignment(tagSAFEARRAY) == 4, alignment(tagSAFEARRAY) class tagEXCEPINFO(Structure): # C:/Programme/gccxml/bin/Vc71/PlatformSDK/oaidl.h 722 pass tagEXCEPINFO._fields_ = [ ('wCode', c_ushort), ('wReserved', c_ushort), ('bstrSource', POINTER(c_wchar)), ('bstrDescription', POINTER(c_wchar)), ('bstrHelpFile', POINTER(c_wchar)), ('dwHelpContext', c_ulong), ('pvReserved', c_void_p), ('pfnDeferredFillIn', WINFUNCTYPE(c_long, POINTER(tagEXCEPINFO))), ('scode', c_long), ] assert sizeof(tagEXCEPINFO) == 32, sizeof(tagEXCEPINFO) assert alignment(tagEXCEPINFO) == 4, alignment(tagEXCEPINFO) EXCEPINFO = tagEXCEPINFO # typedef C:/Programme/gccxml/bin/Vc71/PlatformSDK/oaidl.h 732 ################################################################ # ARRAYDESC, TYPEDESC class tagARRAYDESC(Structure): pass ARRAYDESC = tagARRAYDESC class tagTYPEDESC(Structure): pass TYPEDESC = tagTYPEDESC class _tagTYPEDESC_203E(Union): _fields_ = [ ('lptdesc', POINTER(tagTYPEDESC)), ('lpadesc', POINTER(tagARRAYDESC)), ('hreftype', c_ulong), ] tagTYPEDESC._fields_ = [ # C:/Programme/gccxml/bin/Vc71/PlatformSDK/oaidl.h 582 # Unnamed field renamed to '_' ('_', _tagTYPEDESC_203E), ('vt', c_ushort), ] assert sizeof(tagTYPEDESC) == 8, sizeof(tagTYPEDESC) assert alignment(tagTYPEDESC) == 4, alignment(tagTYPEDESC) tagARRAYDESC._fields_ = [ # C:/Programme/gccxml/bin/Vc71/PlatformSDK/oaidl.h 594 ('tdescElem', tagTYPEDESC), ('cDims', c_ushort), ('rgbounds', tagSAFEARRAYBOUND * 1), ] assert sizeof(tagARRAYDESC) == 20, sizeof(tagARRAYDESC) assert alignment(tagARRAYDESC) == 4, alignment(tagARRAYDESC) ################################################################ ## CY start class tagCY(Union): # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/wtypes.h 990 pass class N5tagCY5DOLLAR_143E(Structure): # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/wtypes.h 991 pass N5tagCY5DOLLAR_143E._fields_ = [ # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/wtypes.h 991 ('Lo', c_ulong), ('Hi', c_long), ] assert sizeof(N5tagCY5DOLLAR_143E) == 8, sizeof(N5tagCY5DOLLAR_143E) assert alignment(N5tagCY5DOLLAR_143E) == 4, alignment(N5tagCY5DOLLAR_143E) tagCY._fields_ = [ # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/wtypes.h 990 # Unnamed field renamed to '_' ('_', N5tagCY5DOLLAR_143E), ('int64', c_longlong), ] assert sizeof(tagCY) == 8, sizeof(tagCY) assert alignment(tagCY) == 8, alignment(tagCY) CY = tagCY CURRENY = tagCY ################################################################ # DECIMAL class tagDEC(Structure): pass DECIMAL = tagDEC class N6tagDEC5DOLLAR_144E(Union): # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/wtypes.h 1022 pass class N6tagDEC5DOLLAR_1445DOLLAR_145E(Structure): # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/wtypes.h 1023 pass N6tagDEC5DOLLAR_1445DOLLAR_145E._fields_ = [ # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/wtypes.h 1023 ('scale', c_ubyte), ('sign', c_ubyte), ] assert sizeof(N6tagDEC5DOLLAR_1445DOLLAR_145E) == 2, sizeof(N6tagDEC5DOLLAR_1445DOLLAR_145E) assert alignment(N6tagDEC5DOLLAR_1445DOLLAR_145E) == 1, alignment(N6tagDEC5DOLLAR_1445DOLLAR_145E) N6tagDEC5DOLLAR_144E._fields_ = [ # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/wtypes.h 1022 # Unnamed field renamed to '_' ('_', N6tagDEC5DOLLAR_1445DOLLAR_145E), ('signscale', c_ushort), ] assert sizeof(N6tagDEC5DOLLAR_144E) == 2, sizeof(N6tagDEC5DOLLAR_144E) assert alignment(N6tagDEC5DOLLAR_144E) == 2, alignment(N6tagDEC5DOLLAR_144E) class N6tagDEC5DOLLAR_146E(Union): # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/wtypes.h 1030 pass class N6tagDEC5DOLLAR_1465DOLLAR_147E(Structure): # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/wtypes.h 1031 pass N6tagDEC5DOLLAR_1465DOLLAR_147E._fields_ = [ # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/wtypes.h 1031 ('Lo32', c_ulong), ('Mid32', c_ulong), ] assert sizeof(N6tagDEC5DOLLAR_1465DOLLAR_147E) == 8, sizeof(N6tagDEC5DOLLAR_1465DOLLAR_147E) assert alignment(N6tagDEC5DOLLAR_1465DOLLAR_147E) == 4, alignment(N6tagDEC5DOLLAR_1465DOLLAR_147E) N6tagDEC5DOLLAR_146E._fields_ = [ # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/wtypes.h 1030 # Unnamed field renamed to '_' ('_', N6tagDEC5DOLLAR_1465DOLLAR_147E), ('Lo64', c_ulonglong), ] assert sizeof(N6tagDEC5DOLLAR_146E) == 8, sizeof(N6tagDEC5DOLLAR_146E) assert alignment(N6tagDEC5DOLLAR_146E) == 8, alignment(N6tagDEC5DOLLAR_146E) tagDEC._fields_ = [ # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/wtypes.h 1020 ('wReserved', c_ushort), # Unnamed field renamed to '_' ('_', N6tagDEC5DOLLAR_144E), ('Hi32', c_ulong), # Unnamed field renamed to '_1' ('_1', N6tagDEC5DOLLAR_146E), ] assert sizeof(tagDEC) == 16, sizeof(tagDEC) assert alignment(tagDEC) == 8, alignment(tagDEC) ################################################################ # VARIANT class tagVARIANT(Structure): pass class __tagVARIANT(Structure): class _201E(Union): class __tagBRECORD_(Structure): _fields_ = [ ('pvRecord', c_void_p), ('pRecInfo', POINTER(IRecordInfo)), ] _fields_ = [ # union _201E ('llVal', c_longlong), ('lVal', c_long), ('bVal', c_ubyte), ('iVal', c_short), ('fltVal', c_float), ('dblVal', c_double), ('boolVal', c_short), ('scode', c_long), ('cyVal', tagCY), ('date', c_double), ('bstrVal', POINTER(c_wchar)), ('punkVal', POINTER(IUnknown)), ('pdispVal', POINTER(IDispatch)), ('parray', POINTER(tagSAFEARRAY)), ('pbVal', POINTER(c_ubyte)), ('piVal', POINTER(c_short)), ('plVal', POINTER(c_long)), ('pllVal', POINTER(c_longlong)), ('pfltVal', POINTER(c_float)), ('pdblVal', POINTER(c_double)), ('pboolVal', POINTER(c_short)), ('pscode', POINTER(c_long)), ('pcyVal', POINTER(tagCY)), ('pdate', POINTER(c_double)), ('pbstrVal', POINTER(POINTER(c_wchar))), ('ppunkVal', POINTER(POINTER(IUnknown))), ('ppdispVal', POINTER(POINTER(IDispatch))), ('pparray', POINTER(POINTER(tagSAFEARRAY))), ('pvarVal', POINTER(tagVARIANT)), ('byref', c_void_p), ('cVal', c_char), ('uiVal', c_ushort), ('ulVal', c_ulong), ('ullVal', c_ulonglong), ('intVal', c_int), ('uintVal', c_uint), ('pdecVal', POINTER(tagDEC)), ('pcVal', POINTER(c_char)), ('puiVal', POINTER(c_ushort)), ('pulVal', POINTER(c_ulong)), ('pullVal', POINTER(c_ulonglong)), ('pintVal', POINTER(c_int)), ('puintVal', POINTER(c_uint)), ('brecVal', __tagBRECORD_), ] # union _201E _fields_ = [ # __tagVARIANT ('vt', c_ushort), ('wReserved1', c_ushort), ('wReserved2', c_ushort), ('wReserved3', c_ushort), ('n3', _201E), ] # __tagVARIANT assert sizeof(__tagVARIANT) == 16, sizeof(__tagVARIANT) assert alignment(__tagVARIANT) == 8, alignment(__tagVARIANT) class _tagVARIANT_200E(Union): pass _tagVARIANT_200E._fields_ = [ ('n2', __tagVARIANT), ('decVal', tagDEC), ] assert sizeof(_tagVARIANT_200E) == 16, sizeof(_tagVARIANT_200E) assert alignment(_tagVARIANT_200E) == 8, alignment(_tagVARIANT_200E) tagVARIANT._fields_ = [ # C:/Programme/gccxml/bin/Vc71/PlatformSDK/oaidl.h 424 ('n1', _tagVARIANT_200E), ] VARIANT = tagVARIANT VARIANTARG = tagVARIANT assert sizeof(tagVARIANT) == 16, sizeof(tagVARIANT) assert alignment(tagVARIANT) == 8, alignment(tagVARIANT) ################################################################ # DISPPARAMS class tagDISPPARAMS(Structure): # C:/Programme/gccxml/bin/Vc71/PlatformSDK/oaidl.h 696 _fields_ = [ ('rgvarg', POINTER(tagVARIANT)), ('rgdispidNamedArgs', POINTER(c_long)), ('cArgs', c_uint), ('cNamedArgs', c_uint), ] DISPPARAMS = tagDISPPARAMS # typedef C:/Programme/gccxml/bin/Vc71/PlatformSDK/oaidl.h 701 assert sizeof(tagDISPPARAMS) == 16, sizeof(tagDISPPARAMS) assert alignment(tagDISPPARAMS) == 4, alignment(tagDISPPARAMS) ################################################################ class tagIDLDESC(Structure): _fields_ = [ ('dwReserved', c_ulong), ('wIDLFlags', c_ushort), ] assert sizeof(tagIDLDESC) == 8, sizeof(tagIDLDESC) assert alignment(tagIDLDESC) == 4, alignment(tagIDLDESC) IDLDESC = tagIDLDESC # typedef C:/Programme/gccxml/bin/Vc71/PlatformSDK/oaidl.h 636 class tagTYPEATTR(Structure): _fields_ = [ ('guid', GUID), ('lcid', c_ulong), ('dwReserved', c_ulong), ('memidConstructor', c_long), ('memidDestructor', c_long), ('lpstrSchema', POINTER(c_wchar)), ('cbSizeInstance', c_ulong), ('typekind', tagTYPEKIND), ('cFuncs', c_ushort), ('cVars', c_ushort), ('cImplTypes', c_ushort), ('cbSizeVft', c_ushort), ('cbAlignment', c_ushort), ('wTypeFlags', c_ushort), ('wMajorVerNum', c_ushort), ('wMinorVerNum', c_ushort), ('tdescAlias', tagTYPEDESC), ('idldescType', tagIDLDESC), ] assert sizeof(tagTYPEATTR) == 76, sizeof(tagTYPEATTR) assert alignment(tagTYPEATTR) == 4, alignment(tagTYPEATTR) TYPEATTR = tagTYPEATTR # typedef C:/Programme/gccxml/bin/Vc71/PlatformSDK/oaidl.h 691 ################################################################ # PARAMDESC, PARAMDESCEX class tagPARAMDESC(Structure): pass class tagPARAMDESCEX(Structure): # C:/Programme/gccxml/bin/Vc71/PlatformSDK/oaidl.h 601 _fields_ = [ ('cBytes', c_ulong), ('varDefaultValue', tagVARIANT), ] assert sizeof(tagPARAMDESCEX) == 24, sizeof(tagPARAMDESCEX) assert alignment(tagPARAMDESCEX) == 8, alignment(tagPARAMDESCEX) PARAMDESCEX = tagPARAMDESCEX tagPARAMDESC._fields_ = [ # C:/Programme/gccxml/bin/Vc71/PlatformSDK/oaidl.h 609 ('pparamdescex', POINTER(tagPARAMDESCEX)), ('wParamFlags', c_ushort), ] assert sizeof(tagPARAMDESC) == 8, sizeof(tagPARAMDESC) assert alignment(tagPARAMDESC) == 4, alignment(tagPARAMDESC) PARAMDESC = tagPARAMDESC ################################################################ # ELEMDESC class tagELEMDESC(Structure): class _tagELEMDESC_204E(Union): _fields_ = [ ('idldesc', tagIDLDESC), ('paramdesc', tagPARAMDESC), ] _fields_ = [ ('tdesc', tagTYPEDESC), # Unnamed field renamed to '_' ('_', _tagELEMDESC_204E), ] assert sizeof(tagELEMDESC) == 16, sizeof(tagELEMDESC) assert alignment(tagELEMDESC) == 4, alignment(tagELEMDESC) ELEMDESC = tagELEMDESC # typedef C:/Programme/gccxml/bin/Vc71/PlatformSDK/oaidl.h 667 ################################################################ class tagVARDESC(Structure): # C:/Programme/gccxml/bin/Vc71/PlatformSDK/oaidl.h 803 class N10tagVARDESC5DOLLAR_205E(Union): _fields_ = [ ('oInst', c_ulong), ('lpvarValue', POINTER(tagVARIANT)), ] _fields_ = [ ('memid', c_long), ('lpstrSchema', POINTER(c_wchar)), # Unnamed field renamed to '_' ('_', N10tagVARDESC5DOLLAR_205E), ('elemdescVar', tagELEMDESC), ('wVarFlags', c_ushort), ('varkind', tagVARKIND), ] assert sizeof(tagVARDESC) == 36, sizeof(tagVARDESC) assert alignment(tagVARDESC) == 4, alignment(tagVARDESC) VARDESC = tagVARDESC ################################################################ # FUNCDESC class tagFUNCDESC(Structure): _fields_ = [ # C:/Programme/gccxml/bin/Vc71/PlatformSDK/oaidl.h 769 ('memid', c_long), ('lprgscode', POINTER(c_long)), ('lprgelemdescParam', POINTER(tagELEMDESC)), ('funckind', tagFUNCKIND), ('invkind', tagINVOKEKIND), ('callconv', tagCALLCONV), ('cParams', c_short), ('cParamsOpt', c_short), ('oVft', c_short), ('cScodes', c_short), ('elemdescFunc', tagELEMDESC), ('wFuncFlags', c_ushort), ] assert sizeof(tagFUNCDESC) == 52, sizeof(tagFUNCDESC) assert alignment(tagFUNCDESC) == 4, alignment(tagFUNCDESC) FUNCDESC = tagFUNCDESC ################################################################ # BINDPTR class tagBINDPTR(Union): # C:/Programme/gccxml/bin/Vc71/PlatformSDK/oaidl.h 3075 _fields_ = [ ('lpfuncdesc', POINTER(tagFUNCDESC)), ('lpvardesc', POINTER(tagVARDESC)), ('lptcomp', POINTER(ITypeComp)), ] assert sizeof(tagBINDPTR) == 4, sizeof(tagBINDPTR) assert alignment(tagBINDPTR) == 4, alignment(tagBINDPTR) BINDPTR = tagBINDPTR ################################################################ # COM interface method tables IDispatch._methods_ = [ # C:/Programme/gccxml/bin/Vc71/PlatformSDK/oaidl.h 2710 STDMETHOD(c_long, 'GetTypeInfoCount', [POINTER(c_uint)]), STDMETHOD(c_long, 'GetTypeInfo', [c_uint, c_ulong, POINTER(POINTER(ITypeInfo))]), STDMETHOD(c_long, 'GetIDsOfNames', [POINTER(GUID), POINTER(POINTER(c_wchar)), c_uint, c_ulong, POINTER(c_long)]), STDMETHOD(c_long, 'Invoke', [c_long, POINTER(GUID), c_ulong, c_ushort, POINTER(tagDISPPARAMS), POINTER(tagVARIANT), POINTER(tagEXCEPINFO), POINTER(c_uint)]), ] IRecordInfo._methods_ = [ # C:/Programme/gccxml/bin/Vc71/PlatformSDK/oaidl.h 5926 STDMETHOD(c_long, 'RecordInit', [c_void_p]), STDMETHOD(c_long, 'RecordClear', [c_void_p]), STDMETHOD(c_long, 'RecordCopy', [c_void_p, c_void_p]), STDMETHOD(c_long, 'GetGuid', [POINTER(GUID)]), STDMETHOD(c_long, 'GetName', [POINTER(POINTER(c_wchar))]), STDMETHOD(c_long, 'GetSize', [POINTER(c_ulong)]), STDMETHOD(c_long, 'GetTypeInfo', [POINTER(POINTER(ITypeInfo))]), STDMETHOD(c_long, 'GetField', [c_void_p, POINTER(c_wchar), POINTER(tagVARIANT)]), STDMETHOD(c_long, 'GetFieldNoCopy', [c_void_p, POINTER(c_wchar), POINTER(tagVARIANT), POINTER(c_void_p)]), STDMETHOD(c_long, 'PutField', [c_ulong, c_void_p, POINTER(c_wchar), POINTER(tagVARIANT)]), STDMETHOD(c_long, 'PutFieldNoCopy', [c_ulong, c_void_p, POINTER(c_wchar), POINTER(tagVARIANT)]), STDMETHOD(c_long, 'GetFieldNames', [POINTER(c_ulong), POINTER(POINTER(c_wchar))]), STDMETHOD(c_int, 'IsMatchingType', [POINTER(IRecordInfo)]), STDMETHOD(c_void_p, 'RecordCreate', []), STDMETHOD(c_long, 'RecordCreateCopy', [c_void_p, POINTER(c_void_p)]), STDMETHOD(c_long, 'RecordDestroy', [c_void_p]), ] ITypeInfo._methods_ = [ # C:/Programme/gccxml/bin/Vc71/PlatformSDK/oaidl.h 3230 STDMETHOD(c_long, 'GetTypeAttr', [POINTER(POINTER(tagTYPEATTR))]), STDMETHOD(c_long, 'GetTypeComp', [POINTER(POINTER(ITypeComp))]), STDMETHOD(c_long, 'GetFuncDesc', [c_uint, POINTER(POINTER(tagFUNCDESC))]), STDMETHOD(c_long, 'GetVarDesc', [c_uint, POINTER(POINTER(tagVARDESC))]), STDMETHOD(c_long, 'GetNames', [c_long, POINTER(POINTER(c_wchar)), c_uint, POINTER(c_uint)]), STDMETHOD(c_long, 'GetRefTypeOfImplType', [c_uint, POINTER(c_ulong)]), STDMETHOD(c_long, 'GetImplTypeFlags', [c_uint, POINTER(c_int)]), STDMETHOD(c_long, 'GetIDsOfNames', [POINTER(POINTER(c_wchar)), c_uint, POINTER(c_long)]), STDMETHOD(c_long, 'Invoke', [c_void_p, c_long, c_ushort, POINTER(tagDISPPARAMS), POINTER(tagVARIANT), POINTER(tagEXCEPINFO), POINTER(c_uint)]), STDMETHOD(c_long, 'GetDocumentation', [c_long, POINTER(POINTER(c_wchar)), POINTER(POINTER(c_wchar)), POINTER(c_ulong), POINTER(POINTER(c_wchar))]), STDMETHOD(c_long, 'GetDllEntry', [c_long, tagINVOKEKIND, POINTER(POINTER(c_wchar)), POINTER(POINTER(c_wchar)), POINTER(c_ushort)]), STDMETHOD(c_long, 'GetRefTypeInfo', [c_ulong, POINTER(POINTER(ITypeInfo))]), STDMETHOD(c_long, 'AddressOfMember', [c_long, tagINVOKEKIND, POINTER(c_void_p)]), STDMETHOD(c_long, 'CreateInstance', [POINTER(IUnknown), POINTER(GUID), POINTER(c_void_p)]), STDMETHOD(c_long, 'GetMops', [c_long, POINTER(POINTER(c_wchar))]), STDMETHOD(c_long, 'GetContainingTypeLib', [POINTER(POINTER(ITypeLib)), POINTER(c_uint)]), STDMETHOD(None, 'ReleaseTypeAttr', [POINTER(tagTYPEATTR)]), STDMETHOD(None, 'ReleaseFuncDesc', [POINTER(tagFUNCDESC)]), STDMETHOD(None, 'ReleaseVarDesc', [POINTER(tagVARDESC)]), ] ITypeLib._methods_ = [ # C:/Programme/gccxml/bin/Vc71/PlatformSDK/oaidl.h 4455 STDMETHOD(c_uint, 'GetTypeInfoCount', []), STDMETHOD(c_long, 'GetTypeInfo', [c_uint, POINTER(POINTER(ITypeInfo))]), STDMETHOD(c_long, 'GetTypeInfoType', [c_uint, POINTER(tagTYPEKIND)]), STDMETHOD(c_long, 'GetTypeInfoOfGuid', [POINTER(GUID), POINTER(POINTER(ITypeInfo))]), STDMETHOD(c_long, 'GetLibAttr', [POINTER(POINTER(tagTLIBATTR))]), STDMETHOD(c_long, 'GetTypeComp', [POINTER(POINTER(ITypeComp))]), STDMETHOD(c_long, 'GetDocumentation', [c_int, POINTER(POINTER(c_wchar)), POINTER(POINTER(c_wchar)), POINTER(c_ulong), POINTER(POINTER(c_wchar))]), STDMETHOD(c_long, 'IsName', [POINTER(c_wchar), c_ulong, POINTER(c_int)]), STDMETHOD(c_long, 'FindName', [POINTER(c_wchar), c_ulong, POINTER(POINTER(ITypeInfo)), POINTER(c_long), POINTER(c_ushort)]), STDMETHOD(None, 'ReleaseTLibAttr', [POINTER(tagTLIBATTR)]), ] ITypeComp._methods_ = [ # C:/Programme/gccxml/bin/Vc71/PlatformSDK/oaidl.h 3090 STDMETHOD(c_long, 'Bind', [POINTER(c_wchar), c_ulong, c_ushort, POINTER(POINTER(ITypeInfo)), POINTER(tagDESCKIND), POINTER(tagBINDPTR)]), STDMETHOD(c_long, 'BindType', [POINTER(c_wchar), c_ulong, POINTER(POINTER(ITypeInfo)), POINTER(POINTER(ITypeComp))]), ] |
From: Thomas H. <th...@us...> - 2005-01-28 17:29:27
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30519 Added Files: test_checkretval.py Log Message: Test the _check_retval_ mechanism. --- NEW FILE: test_checkretval.py --- import unittest import sys from ctypes import * class Test(unittest.TestCase): def test_checkretval(self): class CHECKED(c_int): def _check_retval_(value): return str(value) _check_retval_ = staticmethod(_check_retval_) import _ctypes_test dll = CDLL(_ctypes_test.__file__) self.failUnlessEqual(42, dll._testfunc_p_p(42)) dll._testfunc_p_p.restype = CHECKED self.failUnlessEqual("42", dll._testfunc_p_p(42)) dll._testfunc_p_p.restype = None self.failUnlessEqual(None, dll._testfunc_p_p(42)) del dll._testfunc_p_p.restype self.failUnlessEqual(42, dll._testfunc_p_p(42)) try: oledll except NameError: pass else: def test_oledll(self): self.failUnlessRaises(WindowsError, oledll.oleaut32.CreateTypeLib, 0, 0, 0) if __name__ == "__main__": unittest.main() |
From: Thomas H. <th...@us...> - 2005-01-28 16:48:31
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24480 Modified Files: stgdict.c _ctypes.c Log Message: Add checker attribute to StgDict, as well. Index: stgdict.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/stgdict.c,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** stgdict.c 2 Dec 2004 09:13:38 -0000 1.28 --- stgdict.c 28 Jan 2005 16:47:45 -0000 1.29 *************** *** 28,31 **** --- 28,32 ---- Py_CLEAR(self->converters); Py_CLEAR(self->restype); + Py_CLEAR(self->checker); return 0; } *************** *** 59,62 **** --- 60,64 ---- Py_XINCREF(dst->converters); Py_XINCREF(dst->restype); + Py_XINCREF(dst->checker); if (src->ffi_type.elements == NULL) Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.202 retrieving revision 1.203 diff -C2 -d -r1.202 -r1.203 *** _ctypes.c 28 Jan 2005 16:20:08 -0000 1.202 --- _ctypes.c 28 Jan 2005 16:47:45 -0000 1.203 *************** *** 1501,1504 **** --- 1501,1507 ---- Py_INCREF(ob); stgdict->restype = ob; + stgdict->checker = PyObject_GetAttrString(ob, "_check_retval_"); + if (stgdict->checker == NULL) + PyErr_Clear(); } return 0; *************** *** 2456,2460 **** restype = self->restype ? self->restype : dict->restype; converters = self->converters ? self->converters : dict->converters; ! checker = self->checker; #ifdef MS_WIN32 --- 2459,2463 ---- restype = self->restype ? self->restype : dict->restype; converters = self->converters ? self->converters : dict->converters; ! checker = self->checker ? self->checker : dict->checker; #ifdef MS_WIN32 |
From: Thomas H. <th...@us...> - 2005-01-28 16:48:07
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24426 Modified Files: ctypes.h Log Message: Add checker attribute to StgDict, as well. Index: ctypes.h =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/ctypes.h,v retrieving revision 1.67 retrieving revision 1.68 diff -C2 -d -r1.67 -r1.68 *** ctypes.h 28 Jan 2005 16:08:05 -0000 1.67 --- ctypes.h 28 Jan 2005 16:47:29 -0000 1.68 *************** *** 162,165 **** --- 162,166 ---- PyObject *converters; /* tuple([t.from_param for t in argtypes]) */ PyObject *restype; /* CDataObject or NULL */ + PyObject *checker; int flags; /* calling convention and such */ int nArgBytes; /* number of argument bytes for callback */ |
From: Thomas H. <th...@us...> - 2005-01-28 16:20:45
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16765 Modified Files: _ctypes.c Log Message: Manage the 'checker' attribute of CFuncPtr object, and pass it to _CallProc. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.201 retrieving revision 1.202 diff -C2 -d -r1.201 -r1.202 *** _ctypes.c 26 Jan 2005 12:22:50 -0000 1.201 --- _ctypes.c 28 Jan 2005 16:20:08 -0000 1.202 *************** *** 2126,2132 **** --- 2126,2135 ---- CFuncPtr_set_restype(CFuncPtrObject *self, PyObject *ob) { + PyObject *checker; if (ob == NULL) { Py_XDECREF(self->restype); self->restype = NULL; + Py_XDECREF(self->checker); + self->checker = NULL; return 0; } *************** *** 2139,2142 **** --- 2142,2151 ---- Py_INCREF(ob); self->restype = ob; + checker = PyObject_GetAttrString(ob, "_check_retval_"); + if (checker == NULL) { + PyErr_Clear(); + return 0; + } + self->checker = checker; return 0; } *************** *** 2437,2440 **** --- 2446,2450 ---- PyObject *restype; PyObject *converters; + PyObject *checker; StgDictObject *dict = PyObject_stgdict((PyObject *)self); #ifdef MS_WIN32 *************** *** 2446,2449 **** --- 2456,2460 ---- restype = self->restype ? self->restype : dict->restype; converters = self->converters ? self->converters : dict->converters; + checker = self->checker; #ifdef MS_WIN32 *************** *** 2516,2520 **** dict->flags, converters, ! restype); Py_DECREF(a); return result; --- 2527,2532 ---- dict->flags, converters, ! restype, ! checker); Py_DECREF(a); return result; *************** *** 2526,2530 **** dict->flags, converters, ! restype); } --- 2538,2543 ---- dict->flags, converters, ! restype, ! checker); } *************** *** 2534,2537 **** --- 2547,2551 ---- Py_VISIT(self->callable); Py_VISIT(self->restype); + Py_VISIT(self->checker); Py_VISIT(self->argtypes); Py_VISIT(self->converters); *************** *** 2549,2552 **** --- 2563,2569 ---- self->restype = NULL; + Py_XDECREF(self->checker); + self->checker = NULL; + Py_XDECREF(self->argtypes); self->argtypes = NULL; |
From: Thomas H. <th...@us...> - 2005-01-28 16:10:29
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14090 Modified Files: callproc.c Log Message: Pass the 'checker' object into function calls, so that it finally can be called by GetResult. Before we were asking the restype for the '_check_retval_' attribute each time, which totally killed performance on function calls. Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.124 retrieving revision 1.125 diff -C2 -d -r1.124 -r1.125 *** callproc.c 26 Jan 2005 11:07:20 -0000 1.124 --- callproc.c 28 Jan 2005 16:09:47 -0000 1.125 *************** *** 714,718 **** * Convert the C value in result into an instance described by restype */ ! static PyObject *GetResult(PyObject *restype, void *result) { StgDictObject *dict; --- 714,718 ---- * Convert the C value in result into an instance described by restype */ ! static PyObject *GetResult(PyObject *restype, void *result, PyObject *checker) { StgDictObject *dict; *************** *** 768,772 **** Is there another way? */ ! PyObject *retval, *checker; char c; short s; --- 768,772 ---- Is there another way? */ ! PyObject *retval; char c; short s; *************** *** 800,810 **** if (retval == NULL) return NULL; ! checker = PyObject_GetAttrString(restype, "_check_retval_"); ! if (checker == NULL) { ! PyErr_Clear(); return retval; ! } else { ! PyObject *v = PyObject_CallFunctionObjArgs(checker, retval, NULL); ! Py_DECREF(checker); Py_DECREF(retval); return v; --- 800,810 ---- if (retval == NULL) return NULL; ! if (checker == NULL) return retval; ! { ! PyObject *v; ! v = PyObject_CallFunctionObjArgs(checker, retval, NULL); ! if (v == NULL) ! _AddTraceback("GetResult", __FILE__, __LINE__-2); Py_DECREF(retval); return v; *************** *** 874,878 **** not a type (the .from_param class nethod) */ ! PyObject *restype) { int i, n, argcount, argtype_count; --- 874,879 ---- not a type (the .from_param class nethod) */ ! PyObject *restype, ! PyObject *checker) { int i, n, argcount, argtype_count; *************** *** 962,966 **** } else #endif ! retval = GetResult(restype, resbuf); cleanup: for (i = 0; i < argcount; ++i) --- 963,967 ---- } else #endif ! retval = GetResult(restype, resbuf, checker); cleanup: for (i = 0; i < argcount; ++i) *************** *** 1075,1079 **** FUNCFLAG_HRESULT, /* flags */ argtypes, /* self->argtypes */ ! NULL); /* self->restype */ return result; } --- 1076,1081 ---- FUNCFLAG_HRESULT, /* flags */ argtypes, /* self->argtypes */ ! NULL, /* self->restype */ ! NULL); /* checker */ return result; } *************** *** 1189,1193 **** 0, /* flags */ NULL, /* self->argtypes */ ! NULL); /* self->restype */ return result; } --- 1191,1196 ---- 0, /* flags */ NULL, /* self->argtypes */ ! NULL, /* self->restype */ ! NULL); /* checker */ return result; } *************** *** 1216,1220 **** FUNCFLAG_CDECL, /* flags */ NULL, /* self->argtypes */ ! NULL); /* self->restype */ return result; } --- 1219,1224 ---- FUNCFLAG_CDECL, /* flags */ NULL, /* self->argtypes */ ! NULL, /* self->restype */ ! NULL); /* checker */ return result; } |
From: Thomas H. <th...@us...> - 2005-01-28 16:08:40
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13650 Modified Files: ctypes.h Log Message: Make _AddTraceback global. Add checker attribute to CFuncPtr objects. Index: ctypes.h =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/ctypes.h,v retrieving revision 1.66 retrieving revision 1.67 diff -C2 -d -r1.66 -r1.67 *** ctypes.h 17 Dec 2004 13:08:23 -0000 1.66 --- ctypes.h 28 Jan 2005 16:08:05 -0000 1.67 *************** *** 58,61 **** --- 58,62 ---- PyObject *argtypes; PyObject *restype; + PyObject *checker; #ifdef MS_WIN32 int index; *************** *** 180,203 **** int flags, PyObject *argtypes, ! PyObject *restype); ! ! /* ! * TODO: ! * call_commethod is really slow. ! * ! * It should also take an optional argtypes (hm, converters) argument. ! * It should not be called with the (integer) this argument, ! * instead it should retrieve the 'this' value itself - IOW, use ! * the b_ptr contents directly. ! * ! * Change the signature of _CallProc into: ! * ! PyObject *_CallProc(PPROC pProc, ! PyObject *argtuple, ! void *pIunk, ! int flags, ! PyObject *converters, ! PyObject *restype); ! */ --- 181,186 ---- int flags, PyObject *argtypes, ! PyObject *restype, ! PyObject *checker); *************** *** 309,312 **** --- 292,297 ---- extern void *MallocClosure(void); + extern void _AddTraceback(char *, char *, int); + /* Local Variables: |
From: Thomas H. <th...@us...> - 2005-01-28 16:08:15
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13491 Modified Files: callbacks.c Log Message: Make _AddTraceback global. Index: callbacks.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callbacks.c,v retrieving revision 1.69 retrieving revision 1.70 diff -C2 -d -r1.69 -r1.70 *** callbacks.c 20 Jan 2005 19:58:09 -0000 1.69 --- callbacks.c 28 Jan 2005 16:07:32 -0000 1.70 *************** *** 60,64 **** /* after code that pyrex generates */ ! static void _AddTraceback(char *funcname, char *filename, int lineno) { PyObject *py_srcfile = 0; --- 60,64 ---- /* after code that pyrex generates */ ! void _AddTraceback(char *funcname, char *filename, int lineno) { PyObject *py_srcfile = 0; |
From: Thomas H. <th...@us...> - 2005-01-28 15:12:30
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32710 Modified Files: cfield.c Log Message: Better to not divide by zero. Index: cfield.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/cfield.c,v retrieving revision 1.71 retrieving revision 1.72 diff -C2 -d -r1.71 -r1.72 *** cfield.c 20 Jan 2005 21:05:56 -0000 1.71 --- cfield.c 28 Jan 2005 15:11:54 -0000 1.72 *************** *** 141,145 **** else align = dict->align; ! if (*poffset % align) { int delta = align - (*poffset % align); *psize += delta; --- 141,145 ---- else align = dict->align; ! if (align && *poffset % align) { int delta = align - (*poffset % align); *psize += delta; |
From: Thomas H. <th...@us...> - 2005-01-28 09:48:33
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27325 Modified Files: codegenerator.py Log Message: Forgot to delete some unneeded, commented out code. Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/codegenerator.py,v retrieving revision 1.42 retrieving revision 1.43 diff -C2 -d -r1.42 -r1.43 *** codegenerator.py 28 Jan 2005 09:27:11 -0000 1.42 --- codegenerator.py 28 Jan 2005 09:48:20 -0000 1.43 *************** *** 435,440 **** print >> self.stream, "]" - ## self.done.add(body) - def find_dllname(self, func): if hasattr(func, "dllname"): --- 435,438 ---- |
From: Thomas H. <th...@us...> - 2005-01-28 09:27:21
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22520 Modified Files: codegenerator.py Log Message: Now that all code is generated through calls to the general dispatcher self.generate, we can move common code into this function. Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/codegenerator.py,v retrieving revision 1.41 retrieving revision 1.42 diff -C2 -d -r1.41 -r1.42 *** codegenerator.py 28 Jan 2005 09:14:25 -0000 1.41 --- codegenerator.py 28 Jan 2005 09:27:11 -0000 1.42 *************** *** 219,225 **** def Alias(self, alias): - if alias in self.done: - return - self.done.add(alias) if alias.typ is not None: # we can resolve it self.generate(alias.typ) --- 219,222 ---- *************** *** 234,239 **** def Macro(self, macro): - if macro in self.done: - return # We don't know if we can generate valid, error free Python # code All we can do is to try to compile the code. If the --- 231,234 ---- *************** *** 248,256 **** print >> self.stream, code self.names.add(macro.name) - self.done.add(macro) def StructureHead(self, head): - if head in self.done: - return for struct in head.struct.bases: self.generate(struct.get_head()) --- 243,248 ---- *************** *** 272,285 **** print >> self.stream, " pass" self.names.add(head.struct.name) - self.done.add(head) _structures = 0 def Structure(self, struct): - if struct in self.done: - return self._structures += 1 self.generate(struct.get_head()) self.generate(struct.get_body()) - self.done.add(struct) Union = Structure --- 264,273 ---- *************** *** 287,292 **** _typedefs = 0 def Typedef(self, tp): - if tp in self.done: - return self._typedefs += 1 if type(tp.typ) in (typedesc.Structure, typedesc.Union): --- 275,278 ---- *************** *** 303,330 **** (tp.name, self.type_name(tp.typ)) self.names.add(tp.name) - self.done.add(tp) _arraytypes = 0 def ArrayType(self, tp): - if tp in self.done: - return self._arraytypes += 1 self.generate(get_real_type(tp.typ)) self.generate(tp.typ) - self.done.add(tp) _functiontypes = 0 def FunctionType(self, tp): - if tp in self.done: - return self._functiontypes += 1 self.generate(tp.returns) self.generate_all(tp.arguments) - self.done.add(tp) _pointertypes = 0 def PointerType(self, tp): - if tp in self.done: - return self._pointertypes += 1 if type(tp.typ) is typedesc.PointerType: --- 289,307 ---- *************** *** 337,354 **** else: self.generate(tp.typ) - self.done.add(tp) def CvQualifiedType(self, tp): - if tp in self.done: - return self.generate(tp.typ) - self.done.add(tp) _variables = 0 def Variable(self, tp): - if tp in self.done: - return self._variables += 1 - self.done.add(tp) if tp.init is None: # wtypes.h contains IID_IProcessInitControl, for example --- 314,324 ---- *************** *** 367,372 **** _enumvalues = 0 def EnumValue(self, tp): - if tp in self.done: - return value = int(tp.value) print >> self.stream, \ --- 337,340 ---- *************** *** 374,384 **** self.names.add(tp.name) self._enumvalues += 1 - self.done.add(tp) _enumtypes = 0 def Enumeration(self, tp): - if tp in self.done: - return - self.done.add(tp) self._enumtypes += 1 if tp.name: --- 342,348 ---- *************** *** 389,394 **** def StructureBody(self, body): - if body in self.done: - return fields = [] methods = [] --- 353,356 ---- *************** *** 473,477 **** print >> self.stream, "]" ! self.done.add(body) def find_dllname(self, func): --- 435,439 ---- print >> self.stream, "]" ! ## self.done.add(body) def find_dllname(self, func): *************** *** 524,529 **** _notfound_functiontypes = 0 def Function(self, func): - if func in self.done: - return dllname = self.find_dllname(func) if dllname: --- 486,489 ---- *************** *** 555,567 **** else: self._notfound_functiontypes += 1 - self.done.add(func) def FundamentalType(self, item): ! if item in self.done: ! return ! name = ctypes_names[item.name] ## if name != "None": ## print >> self.stream, "from ctypes import %s" % name ! self.done.add(item) ######## --- 515,525 ---- else: self._notfound_functiontypes += 1 def FundamentalType(self, item): ! pass # we should check if this is known somewhere ! ## name = ctypes_names[item.name] ## if name != "None": ## print >> self.stream, "from ctypes import %s" % name ! ## self.done.add(item) ######## *************** *** 577,580 **** --- 535,539 ---- mth = getattr(self, type(item).__name__) mth(item) + self.done.add(item) def generate_all(self, items): |
From: Thomas H. <th...@us...> - 2005-01-28 09:14:39
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19783 Modified Files: codegenerator.py Log Message: Always call the general self.generate method instead of calling the typedesc handlers directly. Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/codegenerator.py,v retrieving revision 1.40 retrieving revision 1.41 diff -C2 -d -r1.40 -r1.41 *** codegenerator.py 28 Jan 2005 08:44:39 -0000 1.40 --- codegenerator.py 28 Jan 2005 09:14:25 -0000 1.41 *************** *** 254,258 **** return for struct in head.struct.bases: ! self.StructureHead(struct.get_head()) self.more.add(struct) basenames = [self.type_name(b) for b in head.struct.bases] --- 254,258 ---- return for struct in head.struct.bases: ! self.generate(struct.get_head()) self.more.add(struct) basenames = [self.type_name(b) for b in head.struct.bases] *************** *** 279,286 **** return self._structures += 1 ! head = struct.get_head() ! self.StructureHead(head) ! body = struct.get_body() ! self.StructureBody(body) self.done.add(struct) --- 279,284 ---- return self._structures += 1 ! self.generate(struct.get_head()) ! self.generate(struct.get_body()) self.done.add(struct) *************** *** 293,297 **** self._typedefs += 1 if type(tp.typ) in (typedesc.Structure, typedesc.Union): ! self.StructureHead(tp.typ.get_head()) self.more.add(tp.typ) else: --- 291,295 ---- self._typedefs += 1 if type(tp.typ) in (typedesc.Structure, typedesc.Union): ! self.generate(tp.typ.get_head()) self.more.add(tp.typ) else: *************** *** 331,337 **** self._pointertypes += 1 if type(tp.typ) is typedesc.PointerType: ! self.PointerType(tp.typ) elif type(tp.typ) in (typedesc.Union, typedesc.Structure): ! self.StructureHead(tp.typ.get_head()) self.more.add(tp.typ) elif type(tp.typ) is typedesc.Typedef: --- 329,335 ---- self._pointertypes += 1 if type(tp.typ) is typedesc.PointerType: ! self.generate(tp.typ) elif type(tp.typ) in (typedesc.Union, typedesc.Structure): ! self.generate(tp.typ.get_head()) self.more.add(tp.typ) elif type(tp.typ) is typedesc.Typedef: *************** *** 388,392 **** print >> self.stream, "%s = C.c_int # enum" % tp.name for item in tp.values: ! self.EnumValue(item) def StructureBody(self, body): --- 386,390 ---- print >> self.stream, "%s = C.c_int # enum" % tp.name for item in tp.values: ! self.generate(item) def StructureBody(self, body): *************** *** 421,425 **** if body.struct.bases: assert len(body.struct.bases) == 1 ! self.StructureBody(body.struct.bases[0].get_body()) # field definition normally span several lines. # Before we generate them, we need to 'import' everything they need. --- 419,423 ---- if body.struct.bases: assert len(body.struct.bases) == 1 ! self.generate(body.struct.bases[0].get_body()) # field definition normally span several lines. # Before we generate them, we need to 'import' everything they need. |
From: Thomas H. <th...@us...> - 2005-01-28 08:44:48
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12492 Modified Files: codegenerator.py Log Message: Specifying a string for the dll in the decorators does not yet work. Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/codegenerator.py,v retrieving revision 1.39 retrieving revision 1.40 diff -C2 -d -r1.39 -r1.40 *** codegenerator.py 27 Jan 2005 19:24:04 -0000 1.39 --- codegenerator.py 28 Jan 2005 08:44:39 -0000 1.40 *************** *** 284,287 **** --- 284,289 ---- self.StructureBody(body) self.done.add(struct) + + Union = Structure _typedefs = 0 *************** *** 539,543 **** print >> self.stream if self.use_decorators: ! print >> self.stream, "@ %s(%s, '%s', [%s])" % \ (cc, self.type_name(func.returns), libname, ", ".join(args)) argnames = ["p%d" % i for i in range(1, 1+len(args))] --- 541,545 ---- print >> self.stream if self.use_decorators: ! print >> self.stream, "@ %s(%s, %s, [%s])" % \ (cc, self.type_name(func.returns), libname, ", ".join(args)) argnames = ["p%d" % i for i in range(1, 1+len(args))] *************** *** 548,552 **** print >> self.stream, " return %s._api_(%s)" % (func.name, ", ".join(argnames)) if not self.use_decorators: ! print >> self.stream, "%s = %s(%s, '%s', [%s]) (%s)" % \ (func.name, cc, self.type_name(func.returns), libname, ", ".join(args), func.name) print >> self.stream --- 550,554 ---- print >> self.stream, " return %s._api_(%s)" % (func.name, ", ".join(argnames)) if not self.use_decorators: ! print >> self.stream, "%s = %s(%s, %s, [%s]) (%s)" % \ (func.name, cc, self.type_name(func.returns), libname, ", ".join(args), func.name) print >> self.stream *************** *** 557,562 **** self.done.add(func) - Union = Structure - def FundamentalType(self, item): if item in self.done: --- 559,562 ---- |
From: Thomas H. <th...@us...> - 2005-01-27 20:30:20
|
Update of /cvsroot/ctypes/ctypes/comtypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15476 Modified Files: automation.py Log Message: Add PARMAFLAGS, make GetDllEntry usable. Index: automation.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/automation.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** automation.py 25 Jan 2005 15:32:17 -0000 1.1 --- automation.py 27 Jan 2005 20:30:04 -0000 1.2 *************** *** 5,8 **** --- 5,17 ---- from comtypes import IUnknown, GUID, BSTR, STDMETHOD + PARAMFLAG_NONE = 0 # Variable c_int + PARAMFLAG_FIN = 1 # Variable c_int + PARAMFLAG_FOUT = 2 # Variable c_int + PARAMFLAG_FLCID = 4 # Variable c_int + PARAMFLAG_FRETVAL = 8 # Variable c_int + PARAMFLAG_FOPT = 16 # Variable c_int + PARAMFLAG_FHASDEFAULT = 32 # Variable c_int + PARAMFLAG_FHASCUSTDATA = 64 # Variable c_int + UINT = c_uint # typedef LONG = c_long # typedef *************** *** 220,225 **** return name.value, doc.value, helpcontext.value, helpfile.value ! def GetDllEntry(self, p0, p1, p2, p3, p4): ! pass def GetRefTypeInfo(self, hreftype): --- 229,239 ---- return name.value, doc.value, helpcontext.value, helpfile.value ! def GetDllEntry(self, memid, invkind): ! "Return the dll name, function name, and ordinal for a function and invkind." ! dllname = BSTR() ! name = BSTR() ! ordinal = c_ushort() ! self.__com_GetDllEntry(memid, invkind, byref(dllname), byref(name), byref(ordinal)) ! return dllname.value, name.value, ordinal.value def GetRefTypeInfo(self, hreftype): |
From: Thomas H. <th...@us...> - 2005-01-27 19:24:18
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30057 Modified Files: codegenerator.py Log Message: The short form looks much nicer, especially in long argument type lists: C.c_int instead of ctypes.c_int Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/codegenerator.py,v retrieving revision 1.38 retrieving revision 1.39 diff -C2 -d -r1.38 -r1.39 *** codegenerator.py 27 Jan 2005 19:14:47 -0000 1.38 --- codegenerator.py 27 Jan 2005 19:24:04 -0000 1.39 *************** *** 13,37 **** # XXX Should this be in ctypes itself? ctypes_names = { ! "unsigned char": "ctypes.c_ubyte", ! "signed char": "ctypes.c_byte", ! "char": "ctypes.c_char", ! "wchar_t": "ctypes.c_wchar", ! "short unsigned int": "ctypes.c_ushort", ! "short int": "ctypes.c_short", ! "long unsigned int": "ctypes.c_ulong", ! "long int": "ctypes.c_long", ! "long signed int": "ctypes.c_long", ! "unsigned int": "ctypes.c_uint", ! "int": "ctypes.c_int", ! "long long unsigned int": "ctypes.c_ulonglong", ! "long long int": "ctypes.c_longlong", ! "double": "ctypes.c_double", ! "float": "ctypes.c_float", # Hm... --- 13,37 ---- # XXX Should this be in ctypes itself? ctypes_names = { ! "unsigned char": "C.c_ubyte", ! "signed char": "C.c_byte", ! "char": "C.c_char", ! "wchar_t": "C.c_wchar", ! "short unsigned int": "C.c_ushort", ! "short int": "C.c_short", ! "long unsigned int": "C.c_ulong", ! "long int": "C.c_long", ! "long signed int": "C.c_long", ! "unsigned int": "C.c_uint", ! "int": "C.c_int", ! "long long unsigned int": "C.c_ulonglong", ! "long long int": "C.c_longlong", ! "double": "C.c_double", ! "float": "C.c_float", # Hm... *************** *** 139,149 **** def init_value(self, t, init): tn = self.type_name(t, False) ! if tn in ["ctypes.c_ulonglong", "ctypes.c_ulong", "ctypes.c_uint", "ctypes.c_ushort", "ctypes.c_ubyte"]: return decode_value(init) ! elif tn in ["ctypes.c_longlong", "ctypes.c_long", "ctypes.c_int", "ctypes.c_short", "ctypes.c_byte"]: return decode_value(init) ! elif tn in ["ctypes.c_float", "ctypes.c_double"]: return float(init) ! elif tn == "ctypes.POINTER(ctypes.c_char)": if init[0] == '"': value = eval(init) --- 139,149 ---- def init_value(self, t, init): tn = self.type_name(t, False) ! if tn in ["C.c_ulonglong", "C.c_ulong", "C.c_uint", "C.c_ushort", "C.c_ubyte"]: return decode_value(init) ! elif tn in ["C.c_longlong", "C.c_long", "C.c_int", "C.c_short", "C.c_byte"]: return decode_value(init) ! elif tn in ["C.c_float", "C.c_double"]: return float(init) ! elif tn == "C.POINTER(C.c_char)": if init[0] == '"': value = eval(init) *************** *** 151,155 **** value = int(init, 16) return value ! elif tn == "ctypes.POINTER(ctypes.c_wchar)": if init[0] == '"': value = eval(init) --- 151,155 ---- value = int(init, 16) return value ! elif tn == "C.POINTER(C.c_wchar)": if init[0] == '"': value = eval(init) *************** *** 160,164 **** value = value.decode("utf-16") # XXX Is this correct? return value ! elif tn == "ctypes.c_void_p": if init[0] == "0": value = int(init, 16) --- 160,164 ---- value = value.decode("utf-16") # XXX Is this correct? return value ! elif tn == "C.c_void_p": if init[0] == "0": value = int(init, 16) *************** *** 167,178 **** # Hm, ctypes represents them as SIGNED int return value ! elif tn == "ctypes.c_char": return decode_value(init) ! elif tn == "ctypes.c_wchar": value = decode_value(init) if isinstance(value, int): return unichr(value) return value ! elif tn.startswith("ctypes.POINTER("): # Hm, POINTER(HBITMAP__) for example return decode_value(init) --- 167,178 ---- # Hm, ctypes represents them as SIGNED int return value ! elif tn == "C.c_char": return decode_value(init) ! elif tn == "C.c_wchar": value = decode_value(init) if isinstance(value, int): return unichr(value) return value ! elif tn.startswith("C.POINTER("): # Hm, POINTER(HBITMAP__) for example return decode_value(init) *************** *** 182,195 **** def type_name(self, t, generate=True): # Return a string, containing an expression which can be used to ! # refer to the type. Assumes the ctypes.* namespace is available. if isinstance(t, typedesc.PointerType): ! result = "ctypes.POINTER(%s)" % self.type_name(t.typ, generate) # XXX Better to inspect t.typ! ! if result.startswith("ctypes.POINTER(ctypes.WINFUNCTYPE"): ! return result[len("ctypes.POINTER("):-1] ! if result.startswith("ctypes.POINTER(ctypes.CFUNCTYPE"): ! return result[len("ctypes.POINTER("):-1] ! elif result == "ctypes.POINTER(None)": ! return "ctypes.c_void_p" return result elif isinstance(t, typedesc.ArrayType): --- 182,195 ---- def type_name(self, t, generate=True): # Return a string, containing an expression which can be used to ! # refer to the type. Assumes the C.* namespace is available. if isinstance(t, typedesc.PointerType): ! result = "C.POINTER(%s)" % self.type_name(t.typ, generate) # XXX Better to inspect t.typ! ! if result.startswith("C.POINTER(C.WINFUNCTYPE"): ! return result[len("C.POINTER("):-1] ! if result.startswith("C.POINTER(C.CFUNCTYPE"): ! return result[len("C.POINTER("):-1] ! elif result == "C.POINTER(None)": ! return "C.c_void_p" return result elif isinstance(t, typedesc.ArrayType): *************** *** 198,204 **** args = [self.type_name(x, generate) for x in [t.returns] + t.arguments] if "__stdcall__" in t.attributes: ! return "ctypes.WINFUNCTYPE(%s)" % ", ".join(args) else: ! return "ctypes.CFUNCTYPE(%s)" % ", ".join(args) elif isinstance(t, typedesc.CvQualifiedType): # const and volatile are ignored --- 198,204 ---- args = [self.type_name(x, generate) for x in [t.returns] + t.arguments] if "__stdcall__" in t.attributes: ! return "C.WINFUNCTYPE(%s)" % ", ".join(args) else: ! return "C.CFUNCTYPE(%s)" % ", ".join(args) elif isinstance(t, typedesc.CvQualifiedType): # const and volatile are ignored *************** *** 211,215 **** if t.name: return t.name ! return "ctypes.c_int" # enums are integers elif isinstance(t, typedesc.Typedef): return t.name --- 211,215 ---- if t.name: return t.name ! return "C.c_int" # enums are integers elif isinstance(t, typedesc.Typedef): return t.name *************** *** 265,271 **** print >> self.stream, "class %s(_com_interface):" % head.struct.name elif type(head.struct) == typedesc.Structure: ! print >> self.stream, "class %s(ctypes.Structure):" % head.struct.name elif type(head.struct) == typedesc.Union: ! print >> self.stream, "class %s(ctypes.Union):" % head.struct.name if head.struct.location: print >> self.stream, " # %s %s" % head.struct.location --- 265,271 ---- print >> self.stream, "class %s(_com_interface):" % head.struct.name elif type(head.struct) == typedesc.Structure: ! print >> self.stream, "class %s(C.Structure):" % head.struct.name elif type(head.struct) == typedesc.Union: ! print >> self.stream, "class %s(C.Union):" % head.struct.name if head.struct.location: print >> self.stream, " # %s %s" % head.struct.location *************** *** 384,388 **** if tp.name: print >> self.stream ! print >> self.stream, "%s = ctypes.c_int # enum" % tp.name for item in tp.values: self.EnumValue(item) --- 384,388 ---- if tp.name: print >> self.stream ! print >> self.stream, "%s = C.c_int # enum" % tp.name for item in tp.values: self.EnumValue(item) *************** *** 448,455 **** if body.struct.size and body.struct.name not in dont_assert_size: size = body.struct.size // 8 ! print >> self.stream, "assert ctypes.sizeof(%s) == %s, ctypes.sizeof(%s)" % \ (body.struct.name, size, body.struct.name) align = body.struct.align // 8 ! print >> self.stream, "assert ctypes.alignment(%s) == %s, ctypes.alignment(%s)" % \ (body.struct.name, align, body.struct.name) --- 448,455 ---- if body.struct.size and body.struct.name not in dont_assert_size: size = body.struct.size // 8 ! print >> self.stream, "assert C.sizeof(%s) == %s, C.sizeof(%s)" % \ (body.struct.name, size, body.struct.name) align = body.struct.align // 8 ! print >> self.stream, "assert C.alignment(%s) == %s, C.alignment(%s)" % \ (body.struct.name, align, body.struct.name) *************** *** 467,471 **** for m in methods: args = [self.type_name(a) for a in m.arguments] ! print >> self.stream, " ctypes.STDMETHOD(%s, '%s', [%s])," % ( self.type_name(m.returns), m.name, --- 467,471 ---- for m in methods: args = [self.type_name(a) for a in m.arguments] ! print >> self.stream, " C.STDMETHOD(%s, '%s', [%s])," % ( self.type_name(m.returns), m.name, *************** *** 503,507 **** name, ext = os.path.splitext(basename) self._loadedlibs[dllname] = name ! print >> self.stream, "%s = ctypes.CDLL(%r)" % (name, dllname) return name --- 503,507 ---- name, ext = os.path.splitext(basename) self._loadedlibs[dllname] = name ! print >> self.stream, "%s = C.CDLL(%r)" % (name, dllname) return name *************** *** 539,543 **** print >> self.stream if self.use_decorators: ! print >> self.stream, "@ %s(%s, %s, [%s])" % \ (cc, self.type_name(func.returns), libname, ", ".join(args)) argnames = ["p%d" % i for i in range(1, 1+len(args))] --- 539,543 ---- print >> self.stream if self.use_decorators: ! print >> self.stream, "@ %s(%s, '%s', [%s])" % \ (cc, self.type_name(func.returns), libname, ", ".join(args)) argnames = ["p%d" % i for i in range(1, 1+len(args))] *************** *** 548,552 **** print >> self.stream, " return %s._api_(%s)" % (func.name, ", ".join(argnames)) if not self.use_decorators: ! print >> self.stream, "%s = %s(%s, %s, [%s]) (%s)" % \ (func.name, cc, self.type_name(func.returns), libname, ", ".join(args), func.name) print >> self.stream --- 548,552 ---- print >> self.stream, " return %s._api_(%s)" % (func.name, ", ".join(argnames)) if not self.use_decorators: ! print >> self.stream, "%s = %s(%s, '%s', [%s]) (%s)" % \ (func.name, cc, self.type_name(func.returns), libname, ", ".join(args), func.name) print >> self.stream *************** *** 585,589 **** def generate_code(self, items, known_symbols, searched_dlls): ! print >> self.stream, "import ctypes" items = set(items) if known_symbols: --- 585,589 ---- def generate_code(self, items, known_symbols, searched_dlls): ! print >> self.stream, "import ctypes as C" items = set(items) if known_symbols: |
From: Thomas H. <th...@us...> - 2005-01-27 19:15:05
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27625 Modified Files: codegenerator.py Log Message: Don't hardcode length of some strings. Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/codegenerator.py,v retrieving revision 1.37 retrieving revision 1.38 diff -C2 -d -r1.37 -r1.38 *** codegenerator.py 27 Jan 2005 19:04:45 -0000 1.37 --- codegenerator.py 27 Jan 2005 19:14:47 -0000 1.38 *************** *** 187,194 **** # XXX Better to inspect t.typ! if result.startswith("ctypes.POINTER(ctypes.WINFUNCTYPE"): ! return result[15:-1] if result.startswith("ctypes.POINTER(ctypes.CFUNCTYPE"): ! return result[15:-1] ! # XXX See comment above... elif result == "ctypes.POINTER(None)": return "ctypes.c_void_p" --- 187,193 ---- # XXX Better to inspect t.typ! if result.startswith("ctypes.POINTER(ctypes.WINFUNCTYPE"): ! return result[len("ctypes.POINTER("):-1] if result.startswith("ctypes.POINTER(ctypes.CFUNCTYPE"): ! return result[len("ctypes.POINTER("):-1] elif result == "ctypes.POINTER(None)": return "ctypes.c_void_p" |
From: Thomas H. <th...@us...> - 2005-01-27 19:04:57
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25249 Modified Files: codegenerator.py Log Message: Don't emit all those 'from ctypes import xxx' statements, instead emit a general 'import ctypes', and always generate 'ctypes.xxx' identifiers. It may turn out that these are too long, then we could probably do: import ctypes as C ..... C.POINTER(C.c_int) or so. Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/codegenerator.py,v retrieving revision 1.36 retrieving revision 1.37 diff -C2 -d -r1.36 -r1.37 *** codegenerator.py 27 Jan 2005 18:41:26 -0000 1.36 --- codegenerator.py 27 Jan 2005 19:04:45 -0000 1.37 *************** *** 13,37 **** # XXX Should this be in ctypes itself? ctypes_names = { ! "unsigned char": "c_ubyte", ! "signed char": "c_byte", ! "char": "c_char", ! "wchar_t": "c_wchar", ! "short unsigned int": "c_ushort", ! "short int": "c_short", ! "long unsigned int": "c_ulong", ! "long int": "c_long", ! "long signed int": "c_long", ! "unsigned int": "c_uint", ! "int": "c_int", ! "long long unsigned int": "c_ulonglong", ! "long long int": "c_longlong", ! "double": "c_double", ! "float": "c_float", # Hm... --- 13,37 ---- # XXX Should this be in ctypes itself? ctypes_names = { ! "unsigned char": "ctypes.c_ubyte", ! "signed char": "ctypes.c_byte", ! "char": "ctypes.c_char", ! "wchar_t": "ctypes.c_wchar", ! "short unsigned int": "ctypes.c_ushort", ! "short int": "ctypes.c_short", ! "long unsigned int": "ctypes.c_ulong", ! "long int": "ctypes.c_long", ! "long signed int": "ctypes.c_long", ! "unsigned int": "ctypes.c_uint", ! "int": "ctypes.c_int", ! "long long unsigned int": "ctypes.c_ulonglong", ! "long long int": "ctypes.c_longlong", ! "double": "ctypes.c_double", ! "float": "ctypes.c_float", # Hm... *************** *** 139,149 **** def init_value(self, t, init): tn = self.type_name(t, False) ! if tn in ["c_ulonglong", "c_ulong", "c_uint", "c_ushort", "c_ubyte"]: return decode_value(init) ! elif tn in ["c_longlong", "c_long", "c_int", "c_short", "c_byte"]: return decode_value(init) ! elif tn in ["c_float", "c_double"]: return float(init) ! elif tn == "POINTER(c_char)": if init[0] == '"': value = eval(init) --- 139,149 ---- def init_value(self, t, init): tn = self.type_name(t, False) ! if tn in ["ctypes.c_ulonglong", "ctypes.c_ulong", "ctypes.c_uint", "ctypes.c_ushort", "ctypes.c_ubyte"]: return decode_value(init) ! elif tn in ["ctypes.c_longlong", "ctypes.c_long", "ctypes.c_int", "ctypes.c_short", "ctypes.c_byte"]: return decode_value(init) ! elif tn in ["ctypes.c_float", "ctypes.c_double"]: return float(init) ! elif tn == "ctypes.POINTER(ctypes.c_char)": if init[0] == '"': value = eval(init) *************** *** 151,155 **** value = int(init, 16) return value ! elif tn == "POINTER(c_wchar)": if init[0] == '"': value = eval(init) --- 151,155 ---- value = int(init, 16) return value ! elif tn == "ctypes.POINTER(ctypes.c_wchar)": if init[0] == '"': value = eval(init) *************** *** 160,164 **** value = value.decode("utf-16") # XXX Is this correct? return value ! elif tn == "c_void_p": if init[0] == "0": value = int(init, 16) --- 160,164 ---- value = value.decode("utf-16") # XXX Is this correct? return value ! elif tn == "ctypes.c_void_p": if init[0] == "0": value = int(init, 16) *************** *** 167,178 **** # Hm, ctypes represents them as SIGNED int return value ! elif tn == "c_char": return decode_value(init) ! elif tn == "c_wchar": value = decode_value(init) if isinstance(value, int): return unichr(value) return value ! elif tn.startswith("POINTER("): # Hm, POINTER(HBITMAP__) for example return decode_value(init) --- 167,178 ---- # Hm, ctypes represents them as SIGNED int return value ! elif tn == "ctypes.c_char": return decode_value(init) ! elif tn == "ctypes.c_wchar": value = decode_value(init) if isinstance(value, int): return unichr(value) return value ! elif tn.startswith("ctypes.POINTER("): # Hm, POINTER(HBITMAP__) for example return decode_value(init) *************** *** 184,204 **** # refer to the type. Assumes the ctypes.* namespace is available. if isinstance(t, typedesc.PointerType): ! result = "POINTER(%s)" % self.type_name(t.typ, generate) # XXX Better to inspect t.typ! ! if result.startswith("POINTER(WINFUNCTYPE"): ! if generate: ! self.need_POINTER() ! return result[8:-1] ! if result.startswith("POINTER(CFUNCTYPE"): ! if generate: ! self.need_POINTER() ! return result[8:-1] # XXX See comment above... ! elif result == "POINTER(None)": ! if generate: ! self.need_c_void_p() ! return "c_void_p" ! if generate: ! self.need_POINTER() return result elif isinstance(t, typedesc.ArrayType): --- 184,196 ---- # refer to the type. Assumes the ctypes.* namespace is available. if isinstance(t, typedesc.PointerType): ! result = "ctypes.POINTER(%s)" % self.type_name(t.typ, generate) # XXX Better to inspect t.typ! ! if result.startswith("ctypes.POINTER(ctypes.WINFUNCTYPE"): ! return result[15:-1] ! if result.startswith("ctypes.POINTER(ctypes.CFUNCTYPE"): ! return result[15:-1] # XXX See comment above... ! elif result == "ctypes.POINTER(None)": ! return "ctypes.c_void_p" return result elif isinstance(t, typedesc.ArrayType): *************** *** 207,217 **** args = [self.type_name(x, generate) for x in [t.returns] + t.arguments] if "__stdcall__" in t.attributes: ! if generate: ! self.need_WINFUNCTYPE() ! return "WINFUNCTYPE(%s)" % ", ".join(args) else: ! if generate: ! self.need_CFUNCTYPE() ! return "CFUNCTYPE(%s)" % ", ".join(args) elif isinstance(t, typedesc.CvQualifiedType): # const and volatile are ignored --- 199,205 ---- args = [self.type_name(x, generate) for x in [t.returns] + t.arguments] if "__stdcall__" in t.attributes: ! return "ctypes.WINFUNCTYPE(%s)" % ", ".join(args) else: ! return "ctypes.CFUNCTYPE(%s)" % ", ".join(args) elif isinstance(t, typedesc.CvQualifiedType): # const and volatile are ignored *************** *** 224,228 **** if t.name: return t.name ! return "c_int" # enums are integers elif isinstance(t, typedesc.Typedef): return t.name --- 212,216 ---- if t.name: return t.name ! return "ctypes.c_int" # enums are integers elif isinstance(t, typedesc.Typedef): return t.name *************** *** 278,286 **** print >> self.stream, "class %s(_com_interface):" % head.struct.name elif type(head.struct) == typedesc.Structure: ! self.need_Structure() ! print >> self.stream, "class %s(Structure):" % head.struct.name elif type(head.struct) == typedesc.Union: ! self.need_Union() ! print >> self.stream, "class %s(Union):" % head.struct.name if head.struct.location: print >> self.stream, " # %s %s" % head.struct.location --- 266,272 ---- print >> self.stream, "class %s(_com_interface):" % head.struct.name elif type(head.struct) == typedesc.Structure: ! print >> self.stream, "class %s(ctypes.Structure):" % head.struct.name elif type(head.struct) == typedesc.Union: ! print >> self.stream, "class %s(ctypes.Union):" % head.struct.name if head.struct.location: print >> self.stream, " # %s %s" % head.struct.location *************** *** 395,404 **** if tp in self.done: return - self.need_c_int() self.done.add(tp) self._enumtypes += 1 if tp.name: print >> self.stream ! print >> self.stream, "%s = c_int # enum" % tp.name for item in tp.values: self.EnumValue(item) --- 381,389 ---- if tp in self.done: return self.done.add(tp) self._enumtypes += 1 if tp.name: print >> self.stream ! print >> self.stream, "%s = ctypes.c_int # enum" % tp.name for item in tp.values: self.EnumValue(item) *************** *** 464,473 **** if body.struct.size and body.struct.name not in dont_assert_size: size = body.struct.size // 8 ! self.need_sizeof() ! print >> self.stream, "assert sizeof(%s) == %s, sizeof(%s)" % \ (body.struct.name, size, body.struct.name) align = body.struct.align // 8 ! self.need_alignment() ! print >> self.stream, "assert alignment(%s) == %s, alignment(%s)" % \ (body.struct.name, align, body.struct.name) --- 449,456 ---- if body.struct.size and body.struct.name not in dont_assert_size: size = body.struct.size // 8 ! print >> self.stream, "assert ctypes.sizeof(%s) == %s, ctypes.sizeof(%s)" % \ (body.struct.name, size, body.struct.name) align = body.struct.align // 8 ! print >> self.stream, "assert ctypes.alignment(%s) == %s, ctypes.alignment(%s)" % \ (body.struct.name, align, body.struct.name) *************** *** 480,484 **** for a in m.arguments: self.type_name(a) - self.need_STDMETHOD() print >> self.stream, "%s._methods_ = [" % body.struct.name if body.struct.location: --- 463,466 ---- *************** *** 486,490 **** for m in methods: args = [self.type_name(a) for a in m.arguments] ! print >> self.stream, " STDMETHOD(%s, '%s', [%s])," % ( self.type_name(m.returns), m.name, --- 468,472 ---- for m in methods: args = [self.type_name(a) for a in m.arguments] ! print >> self.stream, " ctypes.STDMETHOD(%s, '%s', [%s])," % ( self.type_name(m.returns), m.name, *************** *** 511,515 **** _loadedlibs = None - _CDLL_defined = False def get_sharedlib(self, dllname): if self._loadedlibs is None: --- 493,496 ---- *************** *** 523,530 **** name, ext = os.path.splitext(basename) self._loadedlibs[dllname] = name ! if not self._CDLL_defined: ! print >> self.stream, "from ctypes import CDLL" ! self._CDLL_defined = True ! print >> self.stream, "%s = CDLL(%r)" % (name, dllname) return name --- 504,508 ---- name, ext = os.path.splitext(basename) self._loadedlibs[dllname] = name ! print >> self.stream, "%s = ctypes.CDLL(%r)" % (name, dllname) return name *************** *** 536,622 **** self._cominterface_defined = True ! _STDMETHOD_defined = False ! def need_STDMETHOD(self): ! if self._STDMETHOD_defined: ! return ! print >> self.stream, "from comtypes import STDMETHOD" ! self._STDMETHOD_defined = True ! ! _stdcall_defined = False ! def need_stdcall(self): ! if self._stdcall_defined: ! return ! print >> self.stream, "from ctypes.decorators import stdcall" ! self._stdcall_defined = True ! ! _cdecl_defined = False ! def need_cdecl(self): ! if self._cdecl_defined: ! return ! print >> self.stream, "from ctypes.decorators import cdecl" ! self._cdecl_defined = True ! ! _Union_defined = False ! def need_Union(self): ! if self._Union_defined: ! return ! print >> self.stream, "from ctypes import Union" ! self._Union_defined = True ! ! _Structure_defined = False ! def need_Structure(self): ! if self._Structure_defined: ! return ! print >> self.stream, "from ctypes import Structure" ! self._Structure_defined = True ! ! _sizeof_defined = False ! def need_sizeof(self): ! if self._sizeof_defined: ! return ! print >> self.stream, "from ctypes import sizeof" ! self._sizeof_defined = True ! ! _alignment_defined = False ! def need_alignment(self): ! if self._alignment_defined: ! return ! print >> self.stream, "from ctypes import alignment" ! self._alignment_defined = True ! ! _c_int_defined = False ! def need_c_int(self): ! if self._c_int_defined: ! return ! print >> self.stream, "from ctypes import c_int" ! self._c_int_defined = True ! ! _c_void_p_defined = False ! def need_c_void_p(self): ! if self._c_void_p_defined: ! return ! print >> self.stream, "from ctypes import c_void_p" ! self._c_void_p_defined = True ! ! _WINFUNCTYPE_defined = False ! def need_WINFUNCTYPE(self): ! if self._WINFUNCTYPE_defined: ! return ! print >> self.stream, "from ctypes import WINFUNCTYPE" ! self._WINFUNCTYPE_defined = True ! ! _CFUNCTYPE_defined = False ! def need_CFUNCTYPE(self): ! if self._CFUNCTYPE_defined: ! return ! print >> self.stream, "from ctypes import CFUNCTYPE" ! self._CFUNCTYPE_defined = True ! ! _POINTER_defined = False ! def need_POINTER(self): ! if self._POINTER_defined: ! return ! print >> self.stream, "from ctypes import POINTER" ! self._POINTER_defined = True _functiontypes = 0 --- 514,524 ---- self._cominterface_defined = True ! _decorators_defined = False ! def need_decorators(self): ! if self._decorators_defined: ! return "decorators" ! print >> self.stream, "from ctypes import decorators" ! self._decorators_defined = True ! return "decorators" _functiontypes = 0 *************** *** 630,639 **** self.generate_all(func.arguments) args = [self.type_name(a) for a in func.arguments] if "__stdcall__" in func.attributes: ! self.need_stdcall() ! cc = "stdcall" else: ! self.need_cdecl() ! cc = "cdecl" libname = self.get_sharedlib(dllname) print >> self.stream --- 532,540 ---- self.generate_all(func.arguments) args = [self.type_name(a) for a in func.arguments] + prefix = self.need_decorators() if "__stdcall__" in func.attributes: ! cc = "%s.stdcall" % prefix else: ! cc = "%s.cdecl" % prefix libname = self.get_sharedlib(dllname) print >> self.stream *************** *** 663,668 **** return name = ctypes_names[item.name] ! if name != "None": ! print >> self.stream, "from ctypes import %s" % name self.done.add(item) --- 564,569 ---- return name = ctypes_names[item.name] ! ## if name != "None": ! ## print >> self.stream, "from ctypes import %s" % name self.done.add(item) *************** *** 685,688 **** --- 586,590 ---- def generate_code(self, items, known_symbols, searched_dlls): + print >> self.stream, "import ctypes" items = set(items) if known_symbols: |
From: Thomas H. <th...@us...> - 2005-01-27 18:41:38
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19188 Modified Files: codegenerator.py Log Message: Added get_real_type back again - it's needed to handle dependencies between type descriptions. Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/codegenerator.py,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** codegenerator.py 25 Jan 2005 15:06:59 -0000 1.35 --- codegenerator.py 27 Jan 2005 18:41:26 -0000 1.36 *************** *** 118,123 **** def get_real_type(tp): # why was this? ! ## if type(tp) is typedesc.Typedef: ! ## return get_real_type(tp.typ) return tp --- 118,123 ---- def get_real_type(tp): # why was this? ! if type(tp) is typedesc.Typedef: ! return get_real_type(tp.typ) return tp |
From: Thomas H. <th...@us...> - 2005-01-26 12:23:01
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18362 Modified Files: _ctypes.c Log Message: Prevent a crash when a function's restype or argtypes attribute is deleted. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.200 retrieving revision 1.201 diff -C2 -d -r1.200 -r1.201 *** _ctypes.c 20 Jan 2005 21:11:25 -0000 1.200 --- _ctypes.c 26 Jan 2005 12:22:50 -0000 1.201 *************** *** 2126,2129 **** --- 2126,2134 ---- CFuncPtr_set_restype(CFuncPtrObject *self, PyObject *ob) { + if (ob == NULL) { + Py_XDECREF(self->restype); + self->restype = NULL; + return 0; + } if (ob != Py_None && !PyType_stgdict(ob) && !PyCallable_Check(ob)) { PyErr_SetString(PyExc_TypeError, *************** *** 2161,2165 **** PyObject *converters; ! if (ob == Py_None) { Py_XDECREF(self->converters); self->converters = NULL; --- 2166,2170 ---- PyObject *converters; ! if (ob == NULL || ob == Py_None) { Py_XDECREF(self->converters); self->converters = NULL; |
From: Thomas H. <th...@us...> - 2005-01-26 11:07:34
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2360 Modified Files: callproc.c Log Message: Add a missing DECREF. Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.123 retrieving revision 1.124 diff -C2 -d -r1.123 -r1.124 *** callproc.c 17 Dec 2004 13:08:23 -0000 1.123 --- callproc.c 26 Jan 2005 11:07:20 -0000 1.124 *************** *** 806,809 **** --- 806,810 ---- } else { PyObject *v = PyObject_CallFunctionObjArgs(checker, retval, NULL); + Py_DECREF(checker); Py_DECREF(retval); return v; |
From: Thomas H. <th...@us...> - 2005-01-25 15:53:38
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19578 Added Files: tlbparser.py Log Message: A typelib parser. --- NEW FILE: tlbparser.py --- from comtypes import automation import typedesc ################################ def PTR(typ): return typedesc.PointerType(typ, 32, 32) # basic C data types, with size and alingment in bits char_type = typedesc.FundamentalType("char", 8, 8) uchar_type = typedesc.FundamentalType("unsigned char", 8, 8) wchar_t_type = typedesc.FundamentalType("wchar_t", 16, 16) short_type = typedesc.FundamentalType("short int", 16, 16) ushort_type = typedesc.FundamentalType("short unsigned int", 16, 16) int_type = typedesc.FundamentalType("int", 32, 32) uint_type = typedesc.FundamentalType("unsigned int", 32, 32) long_type = typedesc.FundamentalType("long int", 32, 32) ulong_type = typedesc.FundamentalType("long unsigned int", 32, 32) longlong_type = typedesc.FundamentalType("long long int", 64, 64) ulonglong_type = typedesc.FundamentalType("long long unsigned int", 64, 64) float_type = typedesc.FundamentalType("float", 32, 32) double_type = typedesc.FundamentalType("double", 64, 64) # basic COM data types BSTR_type = typedesc.Typedef("BSTR", PTR(wchar_t_type)) SCODE_type = typedesc.Typedef("SCODE", int_type) VARIANT_BOOL_type = typedesc.Typedef("VARIANT_BOOL", short_type) HRESULT_type = typedesc.Typedef("HRESULT", ulong_type) VARIANT_type = typedesc.Typedef("VARIANT", None) # 128 , 32 ? # faked COM data types CURRENCY_type = float_type # wrong DATE_type = double_type DECIMAL_type = double_type # wrong - it's a 12 byte structure COMTYPES = { automation.VT_I2: short_type, # 2 automation.VT_I4: int_type, # 3 automation.VT_R4: float_type, # 4 automation.VT_R8: double_type, # 5 automation.VT_CY: CURRENCY_type, # 6 automation.VT_DATE: DATE_type, # 7 automation.VT_BSTR: BSTR_type, # 8 automation.VT_DISPATCH: PTR(int_type), # 9 XXXX automation.VT_ERROR: SCODE_type, # 10 automation.VT_BOOL: VARIANT_BOOL_type, # 11 automation.VT_VARIANT: VARIANT_type, # 12 automation.VT_UNKNOWN: PTR(int_type), # 13 XXX automation.VT_DECIMAL: DECIMAL_type, # 14 automation.VT_I1: char_type, # 16 automation.VT_UI1: uchar_type, # 17 automation.VT_UI2: ushort_type, # 18 automation.VT_UI4: ulong_type, # 19 automation.VT_I8: longlong_type, # 20 automation.VT_UI8: ulonglong_type, # 21 automation.VT_INT: int_type, # 22 automation.VT_UINT: uint_type, # 23 automation.VT_VOID: typedesc.Typedef("None", None), # 24 automation.VT_HRESULT: HRESULT_type, # 25 automation.VT_LPSTR: PTR(char_type), # 30 automation.VT_LPWSTR: PTR(wchar_t_type), # 31 } #automation.VT_PTR = 26 # enum VARENUM #automation.VT_SAFEARRAY = 27 # enum VARENUM #automation.VT_CARRAY = 28 # enum VARENUM #automation.VT_USERDEFINED = 29 # enum VARENUM #automation.VT_RECORD = 36 # enum VARENUM #automation.VT_ARRAY = 8192 # enum VARENUM #automation.VT_BYREF = 16384 # enum VARENUM known_symbols = {"VARIANT": "comtypes", "BSTR": "comtypes", "None": "ctypes", "ERROR": "ctypes", "GUID": "comtypes"} ################################################################ class TlbParser(object): def __init__(self, path): self.tlib = automation.LoadTypeLibEx(path) self.items = {} def make_type(self, tdesc, tinfo): try: return COMTYPES[tdesc.vt] except KeyError: pass if tdesc.vt == automation.VT_CARRAY: typ = self.make_type(tdesc._.lpadesc[0].tdescElem, tinfo) for i in range(tdesc._.lpadesc[0].cDims): typ = typedesc.ArrayType(typ, tdesc._.lpadesc[0].rgbounds[i].lLbound, tdesc._.lpadesc[0].rgbounds[i].cElements-1) return typ elif tdesc.vt == automation.VT_PTR: typ = self.make_type(tdesc._.lptdesc[0], tinfo) return typedesc.PointerType(typ, 32, 32) elif tdesc.vt == automation.VT_USERDEFINED: ti = tinfo.GetRefTypeInfo(tdesc._.hreftype) result = self.parse_typeinfo(ti) assert result is not None, ti.GetDocumentation(-1)[0] return result # VT_SAFEARRAY ??? raise "NYI", tdesc.vt ################################################################ # TKIND_ENUM = 0 def ParseEnum(self, tinfo, ta): ta = tinfo.GetTypeAttr() enum_name, doc, helpcntext, helpfile = tinfo.GetDocumentation(-1) enum = typedesc.Enumeration(enum_name, 32, 32) self.items[enum_name] = enum for i in range(ta.cVars): vd = tinfo.GetVarDesc(i) name = tinfo.GetDocumentation(vd.memid)[0] # XXX should be handled by VARIANT assert vd._.lpvarValue[0].n1.n2.vt == automation.VT_I4 assert vd.varkind == automation.VAR_CONST num_val = vd._.lpvarValue[0].n1.n2.n3.iVal v = typedesc.EnumValue(name, num_val, enum) enum.add_value(v) return enum # TKIND_RECORD = 1 def ParseRecord(self, tinfo, ta): members = [] # will be filled later struct_name, doc, helpcntext, helpfile = tinfo.GetDocumentation(-1) struct = typedesc.Structure(struct_name, align=ta.cbAlignment*8, members=members, bases=[], size=ta.cbSizeInstance*8) self.items[struct_name] = struct for i in range(ta.cVars): vd = tinfo.GetVarDesc(i) name = tinfo.GetDocumentation(vd.memid)[0] offset = vd._.oInst * 8 assert vd.varkind == automation.VAR_PERINSTANCE typ = self.make_type(vd.elemdescVar.tdesc, tinfo) field = typedesc.Field(name, typ, None, # bits offset) members.append(field) return struct # TKIND_MODULE = 2 def ParseModule(self, tinfo, ta): assert 0 == ta.cImplTypes dllname = tinfo.GetDocumentation(-1)[0] # dllname? # functions for i in range(ta.cFuncs): fd = tinfo.GetFuncDesc(i) func_name, func_doc = tinfo.GetDocumentation(fd.memid)[:2] assert 0 == fd.cParamsOpt # ? returns = self.make_type(fd.elemdescFunc.tdesc, tinfo) if fd.callconv == automation.CC_CDECL: attributes = "__cdecl__" elif fd.callconv == automation.CC_STDCALL: attributes = "__stdcall__" else: raise "NYI", fd.callconv func = typedesc.Function(func_name, returns, attributes, extern=1) func.dllname = dllname self.items[func_name] = func for i in range(fd.cParams): argtype = self.make_type(fd.lprgelemdescParam[i].tdesc, tinfo) func.add_argument(argtype) # constants are disabled for now, we need VARIANT # functionality to create them, and codegenerator fixes also. # But then, constants are not really common in typelibs. return # constants for i in range(ta.cVars): vd = tinfo.GetVarDesc(i) name = tinfo.GetDocumentation(vd.memid)[0] vt = vd._.lpvarValue[0].n1.n2.vt assert vd.varkind == automation.VAR_CONST # XXX Should be handled by VARIANT if vt == automation.VT_I4: typ = self.make_type(vd.elemdescVar.tdesc, tinfo) num_val = vd._.lpvarValue[0].n1.n2.n3.iVal v = typedesc.Variable(name, typ, repr(num_val)) self.items[name] = v elif vt == automation.VT_BSTR: typ = self.make_type(vd.elemdescVar.tdesc, tinfo) str_val = vd._.lpvarValue[0].n1.n2.n3.bstrVal v = typedesc.Variable(name, typ, '''"%s"''' % str_val) self.items[name] = v else: print "VT", vt # TKIND_INTERFACE = 3 # TKIND_DISPATCH = 4 # TKIND_COCLASS = 5 # TKIND_UNION = 7 def ParseUnion(self, tinfo, ta): union_name, doc, helpcntext, helpfile = tinfo.GetDocumentation(-1) members = [] union = typedesc.Union(union_name, align=ta.cbAlignment*8, members=members, bases=[], size=ta.cbSizeInstance*8) self.items[union_name] = union for i in range(ta.cVars): vd = tinfo.GetVarDesc(i) name = tinfo.GetDocumentation(vd.memid)[0] offset = vd._.oInst * 8 assert vd.varkind == automation.VAR_PERINSTANCE typ = self.make_type(vd.elemdescVar.tdesc, tinfo) field = typedesc.Field(name, typ, None, # bits offset) members.append(field) return struct # TKIND_ALIAS = 6 def ParseAlias(self, tinfo, ta): name = tinfo.GetDocumentation(-1)[0] typ = self.make_type(ta.tdescAlias, tinfo) alias = typedesc.Typedef(name, typ) self.items[name] = alias return alias ################################################################ def parse_typeinfo(self, tinfo): name = tinfo.GetDocumentation(-1)[0] try: return self.items[name] except KeyError: pass ta = tinfo.GetTypeAttr() tkind = ta.typekind if tkind == automation.TKIND_ENUM: # 0 return self.ParseEnum(tinfo, ta) elif tkind == automation.TKIND_RECORD: # 1 return self.ParseRecord(tinfo, ta) elif tkind == automation.TKIND_MODULE: # 2 return self.ParseModule(tinfo, ta) elif tkind == automation.TKIND_ALIAS: # 6 return self.ParseAlias(tinfo, ta) elif tkind == automation.TKIND_UNION: # 7 return self.ParseUnion(tinfo, ta) ## else: ## raise "NYI", tkind ## print "NYI", tkind ################################################################ def parse(self): for i in range(self.tlib.GetTypeInfoCount()): tinfo = self.tlib.GetTypeInfo(i) self.parse_typeinfo(tinfo) return self.items ################################################################ def main(): import sys ## path = r"c:\windows\system32\hnetcfg.dll" ## path = r"c:\windows\system32\simpdata.tlb" ## path = r"c:\windows\system32\nscompat.tlb" path = r"c:\windows\system32\mshtml.tlb" ## path = r"stdole32.tlb" path = r"c:\tss5\include\MeasurementModule.tlb" path = r"c:\tss5\include\fpanel.tlb" ## path = r"shdocvw.dll" ## path = r"c:\Programme\Microsoft Office\Office\MSO97.DLL" ## path = r"c:\Programme\Microsoft Office\Office\MSWORD8.OLB" ## path = r"c:\windows\system32\msi.dll" ## path = r"c:\tss5\include\ITDPersist.tlb" ## path = r"c:\Windows\System32\PICCLP32.OCX" ## path = r"c:\windows\system32\Macromed\Flash\swflash.ocx" ## path = r"C:\Dokumente und Einstellungen\thomas\Desktop\tlb\win.tlb" ## path = r"C:\WINDOWS\System32\MSHFLXGD.OCX" ## path = r"c:\windows\system32\scrrun.dll" ## path = r"c:\Programme\Gemeinsame Dateien\Microsoft Shared\Speech\sapi.dll" ## path = r"C:\Dokumente und Einstellungen\thomas\Desktop\tlb\threadapi.tlb" path = r"C:\Dokumente und Einstellungen\thomas\Desktop\tlb\win32.tlb" p = TlbParser(path) items = p.parse() from codegenerator import Generator gen = Generator(sys.stdout) loops = gen.generate_code(items.values(), known_symbols, []) if __name__ == "__main__": main() |
From: Thomas H. <th...@us...> - 2005-01-25 15:32:33
|
Update of /cvsroot/ctypes/ctypes/comtypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14453 Added Files: automation.py Log Message: A mostly autogenerated, then manually hacked automation module. --- NEW FILE: automation.py --- # generated by 'xml2py' # flags 'windows.xml -s ITypeLib -s TYPEFLAGS' # ... and patched by hand from ctypes import * from comtypes import IUnknown, GUID, BSTR, STDMETHOD UINT = c_uint # typedef LONG = c_long # typedef INT = c_int # typedef WCHAR = c_wchar # typedef OLECHAR = WCHAR # typedef DWORD = c_ulong # typedef LPOLESTR = POINTER(OLECHAR) # typedef BOOL = c_int # typedef DISPID = LONG # typedef MEMBERID = DISPID # typedef USHORT = c_ushort # typedef WORD = c_ushort # typedef LCID = DWORD # typedef HREFTYPE = DWORD # typedef PVOID = c_void_p # typedef SCODE = LONG # typedef VARTYPE = c_ushort # typedef ULONG_PTR = c_ulong # typedef LONGLONG = c_longlong # typedef BYTE = c_ubyte # typedef SHORT = c_short # typedef FLOAT = c_float # typedef DOUBLE = c_double # typedef VARIANT_BOOL = c_short # typedef DATE = c_double # typedef CHAR = c_char # typedef ULONGLONG = c_ulonglong # typedef VARENUM = c_int # enum VT_EMPTY = 0 # enum VARENUM VT_NULL = 1 # enum VARENUM VT_I2 = 2 # enum VARENUM VT_I4 = 3 # enum VARENUM VT_R4 = 4 # enum VARENUM VT_R8 = 5 # enum VARENUM VT_CY = 6 # enum VARENUM VT_DATE = 7 # enum VARENUM VT_BSTR = 8 # enum VARENUM VT_DISPATCH = 9 # enum VARENUM VT_ERROR = 10 # enum VARENUM VT_BOOL = 11 # enum VARENUM VT_VARIANT = 12 # enum VARENUM VT_UNKNOWN = 13 # enum VARENUM VT_DECIMAL = 14 # enum VARENUM VT_I1 = 16 # enum VARENUM VT_UI1 = 17 # enum VARENUM VT_UI2 = 18 # enum VARENUM VT_UI4 = 19 # enum VARENUM VT_I8 = 20 # enum VARENUM VT_UI8 = 21 # enum VARENUM VT_INT = 22 # enum VARENUM VT_UINT = 23 # enum VARENUM VT_VOID = 24 # enum VARENUM VT_HRESULT = 25 # enum VARENUM VT_PTR = 26 # enum VARENUM VT_SAFEARRAY = 27 # enum VARENUM VT_CARRAY = 28 # enum VARENUM VT_USERDEFINED = 29 # enum VARENUM VT_LPSTR = 30 # enum VARENUM VT_LPWSTR = 31 # enum VARENUM VT_RECORD = 36 # enum VARENUM VT_INT_PTR = 37 # enum VARENUM VT_UINT_PTR = 38 # enum VARENUM VT_FILETIME = 64 # enum VARENUM VT_BLOB = 65 # enum VARENUM VT_STREAM = 66 # enum VARENUM VT_STORAGE = 67 # enum VARENUM VT_STREAMED_OBJECT = 68 # enum VARENUM VT_STORED_OBJECT = 69 # enum VARENUM VT_BLOB_OBJECT = 70 # enum VARENUM VT_CF = 71 # enum VARENUM VT_CLSID = 72 # enum VARENUM VT_VERSIONED_STREAM = 73 # enum VARENUM VT_BSTR_BLOB = 4095 # enum VARENUM VT_VECTOR = 4096 # enum VARENUM VT_ARRAY = 8192 # enum VARENUM VT_BYREF = 16384 # enum VARENUM VT_RESERVED = 32768 # enum VARENUM VT_ILLEGAL = 65535 # enum VARENUM VT_ILLEGALMASKED = 4095 # enum VARENUM VT_TYPEMASK = 4095 # enum VARENUM tagTYPEFLAGS = c_int # enum TYPEFLAG_FAPPOBJECT = 1 # enum tagTYPEFLAGS TYPEFLAG_FCANCREATE = 2 # enum tagTYPEFLAGS TYPEFLAG_FLICENSED = 4 # enum tagTYPEFLAGS TYPEFLAG_FPREDECLID = 8 # enum tagTYPEFLAGS TYPEFLAG_FHIDDEN = 16 # enum tagTYPEFLAGS TYPEFLAG_FCONTROL = 32 # enum tagTYPEFLAGS TYPEFLAG_FDUAL = 64 # enum tagTYPEFLAGS TYPEFLAG_FNONEXTENSIBLE = 128 # enum tagTYPEFLAGS TYPEFLAG_FOLEAUTOMATION = 256 # enum tagTYPEFLAGS TYPEFLAG_FRESTRICTED = 512 # enum tagTYPEFLAGS TYPEFLAG_FAGGREGATABLE = 1024 # enum tagTYPEFLAGS TYPEFLAG_FREPLACEABLE = 2048 # enum tagTYPEFLAGS TYPEFLAG_FDISPATCHABLE = 4096 # enum tagTYPEFLAGS TYPEFLAG_FREVERSEBIND = 8192 # enum tagTYPEFLAGS TYPEFLAG_FPROXY = 16384 # enum tagTYPEFLAGS TYPEFLAGS = tagTYPEFLAGS # typedef class ITypeLib(IUnknown): # c:/vc98/include/OAIDL.H 4460 _iid_ = GUID("{00020402-0000-0000-C000-000000000046}") ## STDMETHOD(UINT, 'GetTypeInfoCount', []), ## def GetTypeInfoCount(self): ## "Return the number of typeinfos in this library" ## return self.__com_GetTypeInfoCount() ## STDMETHOD(HRESULT, 'GetTypeInfo', [UINT, POINTER(POINTER(ITypeInfo))]), def GetTypeInfo(self, index): "Return typeinfo for index" p = POINTER(ITypeInfo)() self.__com_GetTypeInfo(index, byref(p)) return p ## STDMETHOD(HRESULT, 'GetTypeInfoType', [UINT, POINTER(TYPEKIND)]), def GetTypeInfoType(self, index): "Return the TYPEKIND for this typeinfo" p = TYPEKIND() self.__com_GetTypeInfoType(index, byref(p)) return p.value ## STDMETHOD(HRESULT, 'GetTypeInfoOfGuid', [POINTER(GUID), POINTER(POINTER(ITypeInfo))]), def GetTypeInfoOfGuid(self, p0, p1): pass ## STDMETHOD(HRESULT, 'GetLibAttr', [POINTER(POINTER(TLIBATTR))]), def GetLibAttr(self): p = POINTER(TLIBATTR)() self.GetLibAttr._api_(byref(p)) # XXX register for release return p.value ## STDMETHOD(HRESULT, 'GetTypeComp', [POINTER(POINTER(ITypeComp))]), def GetTypeComp(self, p0): pass ## STDMETHOD(HRESULT, 'GetDocumentation', [INT, POINTER(BSTR), POINTER(BSTR), POINTER(DWORD), POINTER(BSTR)]), def GetDocumentation(self, index): " Return the name, documentation, helpcontext, and helpfile for this typeinfo" name = BSTR() doc = BSTR() helpcontext = DWORD() helpfile = BSTR() self.__com_GetDocumentation(index, byref(name), byref(doc), byref(helpcontext), byref(helpfile)) return name.value, doc.value, helpcontext.value, helpfile.value ## STDMETHOD(HRESULT, 'IsName', [LPOLESTR, DWORD, POINTER(BOOL)]), def IsName(self, p0, p1, p2): pass ## STDMETHOD(HRESULT, 'FindName', [LPOLESTR, DWORD, POINTER(POINTER(ITypeInfo)), POINTER(MEMBERID), POINTER(USHORT)]), def FindName(self, p0, p1, p2, p3, p4): pass ## STDMETHOD(None, 'ReleaseTLibAttr', [POINTER(TLIBATTR)]), def ReleaseTLibAttr(self, p0): pass class ITypeInfo(IUnknown): def GetTypeAttr(self): p = POINTER(TYPEATTR)() self.__com_GetTypeAttr(byref(p)) result = p[0] result._owner = (self, p) return result def GetTypeComp(self, p0): pass def GetFuncDesc(self, index): p = POINTER(FUNCDESC)() self.__com_GetFuncDesc(index, byref(p)) # XXX release return p[0] def GetVarDesc(self, index): pvd = POINTER(VARDESC)() self.__com_GetVarDesc(index, byref(pvd)) return pvd[0] def GetNames(self, memid, count): rgNames = (BSTR * count)() cNames = c_uint() self.__com_GetNames(memid, rgNames, count, byref(cNames)) return rgNames[:cNames.value] def GetRefTypeOfImplType(self, index): "Return the reftype for a base interface" hreftype = HREFTYPE() self.__com_GetRefTypeOfImplType(index, byref(hreftype)) return hreftype.value def GetImplTypeFlags(self, p0, p1): pass def GetIDsOfNames(self, p0, p1, p2): pass def Invoke(self, p0, p1, p2, p3, p4, p5, p6): pass def GetDocumentation(self, memberid): " Return the name, documentation, helpcontext, and helpfile for this typeinfo" name = BSTR() doc = BSTR() helpcontext = DWORD() helpfile = BSTR() self.__com_GetDocumentation(memberid, byref(name), byref(doc), byref(helpcontext), byref(helpfile)) return name.value, doc.value, helpcontext.value, helpfile.value def GetDllEntry(self, p0, p1, p2, p3, p4): pass def GetRefTypeInfo(self, hreftype): "Return a referenced typeinfo" p = POINTER(ITypeInfo)() self.__com_GetRefTypeInfo(hreftype, byref(p)) return p def AddressOfMember(self, p0, p1, p2): pass def CreateInstance(self, p0, p1, p2): pass def GetMops(self, p0, p1): pass def GetContainingTypeLib(self, p0, p1): pass def ReleaseTypeAttr(self, pta): self.__com_ReleaseTypeAttr(pta) def ReleaseFuncDesc(self, p0): pass def ReleaseVarDesc(self, p0): pass tagTYPEKIND = c_int # enum TKIND_ENUM = 0 # enum tagTYPEKIND TKIND_RECORD = 1 # enum tagTYPEKIND TKIND_MODULE = 2 # enum tagTYPEKIND TKIND_INTERFACE = 3 # enum tagTYPEKIND TKIND_DISPATCH = 4 # enum tagTYPEKIND TKIND_COCLASS = 5 # enum tagTYPEKIND TKIND_ALIAS = 6 # enum tagTYPEKIND TKIND_UNION = 7 # enum tagTYPEKIND TKIND_MAX = 8 # enum tagTYPEKIND TYPEKIND = tagTYPEKIND # typedef class tagTLIBATTR(Structure): pass TLIBATTR = tagTLIBATTR # typedef class ITypeComp(IUnknown): def Bind(self, p0, p1, p2, p3, p4, p5): pass def BindType(self, p0, p1, p2, p3): pass ITypeLib._methods_ = [ STDMETHOD(UINT, 'GetTypeInfoCount', []), STDMETHOD(HRESULT, 'GetTypeInfo', [UINT, POINTER(POINTER(ITypeInfo))]), STDMETHOD(HRESULT, 'GetTypeInfoType', [UINT, POINTER(TYPEKIND)]), STDMETHOD(HRESULT, 'GetTypeInfoOfGuid', [POINTER(GUID), POINTER(POINTER(ITypeInfo))]), STDMETHOD(HRESULT, 'GetLibAttr', [POINTER(POINTER(TLIBATTR))]), STDMETHOD(HRESULT, 'GetTypeComp', [POINTER(POINTER(ITypeComp))]), STDMETHOD(HRESULT, 'GetDocumentation', [INT, POINTER(BSTR), POINTER(BSTR), POINTER(DWORD), POINTER(BSTR)]), STDMETHOD(HRESULT, 'IsName', [LPOLESTR, DWORD, POINTER(BOOL)]), STDMETHOD(HRESULT, 'FindName', [LPOLESTR, DWORD, POINTER(POINTER(ITypeInfo)), POINTER(MEMBERID), POINTER(USHORT)]), STDMETHOD(None, 'ReleaseTLibAttr', [POINTER(TLIBATTR)]), ] IID = GUID # typedef tagDESCKIND = c_int # enum DESCKIND_NONE = 0 # enum tagDESCKIND DESCKIND_FUNCDESC = 1 # enum tagDESCKIND DESCKIND_VARDESC = 2 # enum tagDESCKIND DESCKIND_TYPECOMP = 3 # enum tagDESCKIND DESCKIND_IMPLICITAPPOBJ = 4 # enum tagDESCKIND DESCKIND_MAX = 5 # enum tagDESCKIND DESCKIND = tagDESCKIND # typedef class tagBINDPTR(Union): pass BINDPTR = tagBINDPTR # typedef ITypeComp._methods_ = [ STDMETHOD(HRESULT, 'Bind', [LPOLESTR, DWORD, WORD, POINTER(POINTER(ITypeInfo)), POINTER(DESCKIND), POINTER(BINDPTR)]), STDMETHOD(HRESULT, 'BindType', [LPOLESTR, DWORD, POINTER(POINTER(ITypeInfo)), POINTER(POINTER(ITypeComp))]), ] tagSYSKIND = c_int # enum SYS_WIN16 = 0 # enum tagSYSKIND SYS_WIN32 = 1 # enum tagSYSKIND SYS_MAC = 2 # enum tagSYSKIND SYS_WIN64 = 3 # enum tagSYSKIND SYSKIND = tagSYSKIND # typedef # tagTLIBATTR tagTLIBATTR._fields_ = [ ('guid', GUID), ('lcid', LCID), ('syskind', SYSKIND), ('wMajorVerNum', WORD), ('wMinorVerNum', WORD), ('wLibFlags', WORD), ] assert sizeof(tagTLIBATTR) == 32, sizeof(tagTLIBATTR) assert alignment(tagTLIBATTR) == 4, alignment(tagTLIBATTR) class tagTYPEATTR(Structure): _owner = None def __del__(self): if self._owner: self._owner[0].ReleaseTypeAttr(self._owner[1]) TYPEATTR = tagTYPEATTR # typedef class tagFUNCDESC(Structure): pass FUNCDESC = tagFUNCDESC # typedef class tagVARDESC(Structure): pass VARDESC = tagVARDESC # typedef class tagDISPPARAMS(Structure): pass DISPPARAMS = tagDISPPARAMS # typedef class tagVARIANT(Structure): pass VARIANT = tagVARIANT # typedef class tagEXCEPINFO(Structure): pass EXCEPINFO = tagEXCEPINFO # typedef tagINVOKEKIND = c_int # enum INVOKE_FUNC = 1 # enum tagINVOKEKIND INVOKE_PROPERTYGET = 2 # enum tagINVOKEKIND INVOKE_PROPERTYPUT = 4 # enum tagINVOKEKIND INVOKE_PROPERTYPUTREF = 8 # enum tagINVOKEKIND INVOKEKIND = tagINVOKEKIND # typedef ITypeInfo._methods_ = [ STDMETHOD(HRESULT, 'GetTypeAttr', [POINTER(POINTER(TYPEATTR))]), STDMETHOD(HRESULT, 'GetTypeComp', [POINTER(POINTER(ITypeComp))]), STDMETHOD(HRESULT, 'GetFuncDesc', [UINT, POINTER(POINTER(FUNCDESC))]), STDMETHOD(HRESULT, 'GetVarDesc', [UINT, POINTER(POINTER(VARDESC))]), STDMETHOD(HRESULT, 'GetNames', [MEMBERID, POINTER(BSTR), UINT, POINTER(UINT)]), STDMETHOD(HRESULT, 'GetRefTypeOfImplType', [UINT, POINTER(HREFTYPE)]), STDMETHOD(HRESULT, 'GetImplTypeFlags', [UINT, POINTER(INT)]), STDMETHOD(HRESULT, 'GetIDsOfNames', [POINTER(LPOLESTR), UINT, POINTER(MEMBERID)]), STDMETHOD(HRESULT, 'Invoke', [PVOID, MEMBERID, WORD, POINTER(DISPPARAMS), POINTER(VARIANT), POINTER(EXCEPINFO), POINTER(UINT)]), STDMETHOD(HRESULT, 'GetDocumentation', [MEMBERID, POINTER(BSTR), POINTER(BSTR), POINTER(DWORD), POINTER(BSTR)]), STDMETHOD(HRESULT, 'GetDllEntry', [MEMBERID, INVOKEKIND, POINTER(BSTR), POINTER(BSTR), POINTER(WORD)]), STDMETHOD(HRESULT, 'GetRefTypeInfo', [HREFTYPE, POINTER(POINTER(ITypeInfo))]), STDMETHOD(HRESULT, 'AddressOfMember', [MEMBERID, INVOKEKIND, POINTER(PVOID)]), STDMETHOD(HRESULT, 'CreateInstance', [POINTER(IUnknown), POINTER(IID), POINTER(PVOID)]), STDMETHOD(HRESULT, 'GetMops', [MEMBERID, POINTER(BSTR)]), STDMETHOD(HRESULT, 'GetContainingTypeLib', [POINTER(POINTER(ITypeLib)), POINTER(UINT)]), STDMETHOD(None, 'ReleaseTypeAttr', [POINTER(TYPEATTR)]), STDMETHOD(None, 'ReleaseFuncDesc', [POINTER(FUNCDESC)]), STDMETHOD(None, 'ReleaseVarDesc', [POINTER(VARDESC)]), ] # tagEXCEPINFO tagEXCEPINFO._fields_ = [ ('wCode', WORD), ('wReserved', WORD), ('bstrSource', BSTR), ('bstrDescription', BSTR), ('bstrHelpFile', BSTR), ('dwHelpContext', DWORD), ('pvReserved', PVOID), ('pfnDeferredFillIn', WINFUNCTYPE(HRESULT, POINTER(tagEXCEPINFO))), ('scode', SCODE), ] assert sizeof(tagEXCEPINFO) == 32, sizeof(tagEXCEPINFO) assert alignment(tagEXCEPINFO) == 4, alignment(tagEXCEPINFO) VARIANTARG = VARIANT # typedef # tagDISPPARAMS tagDISPPARAMS._fields_ = [ ('rgvarg', POINTER(VARIANTARG)), ('rgdispidNamedArgs', POINTER(DISPID)), ('cArgs', UINT), ('cNamedArgs', UINT), ] assert sizeof(tagDISPPARAMS) == 16, sizeof(tagDISPPARAMS) assert alignment(tagDISPPARAMS) == 4, alignment(tagDISPPARAMS) # tagBINDPTR tagBINDPTR._fields_ = [ ('lpfuncdesc', POINTER(FUNCDESC)), ('lpvardesc', POINTER(VARDESC)), ('lptcomp', POINTER(ITypeComp)), ] assert sizeof(tagBINDPTR) == 4, sizeof(tagBINDPTR) assert alignment(tagBINDPTR) == 4, alignment(tagBINDPTR) class tagTYPEDESC(Structure): pass class tagARRAYDESC(Structure): pass # _py_N11tagTYPEDESC5__203E class _py_N11tagTYPEDESC5__203E(Union): _fields_ = [ ('lptdesc', POINTER(tagTYPEDESC)), ('lpadesc', POINTER(tagARRAYDESC)), ('hreftype', HREFTYPE), ] assert sizeof(_py_N11tagTYPEDESC5__203E) == 4, sizeof(_py_N11tagTYPEDESC5__203E) assert alignment(_py_N11tagTYPEDESC5__203E) == 4, alignment(_py_N11tagTYPEDESC5__203E) # tagTYPEDESC tagTYPEDESC._fields_ = [ # Unnamed field renamed to '_' ('_', _py_N11tagTYPEDESC5__203E), ('vt', VARTYPE), ] assert sizeof(tagTYPEDESC) == 8, sizeof(tagTYPEDESC) assert alignment(tagTYPEDESC) == 4, alignment(tagTYPEDESC) TYPEDESC = tagTYPEDESC # typedef class tagIDLDESC(Structure): pass # tagIDLDESC tagIDLDESC._fields_ = [ ('dwReserved', ULONG_PTR), ('wIDLFlags', USHORT), ] assert sizeof(tagIDLDESC) == 8, sizeof(tagIDLDESC) assert alignment(tagIDLDESC) == 4, alignment(tagIDLDESC) IDLDESC = tagIDLDESC # typedef # tagTYPEATTR tagTYPEATTR._fields_ = [ ('guid', GUID), ('lcid', LCID), ('dwReserved', DWORD), ('memidConstructor', MEMBERID), ('memidDestructor', MEMBERID), ('lpstrSchema', LPOLESTR), ('cbSizeInstance', DWORD), ('typekind', TYPEKIND), ('cFuncs', WORD), ('cVars', WORD), ('cImplTypes', WORD), ('cbSizeVft', WORD), ('cbAlignment', WORD), ('wTypeFlags', WORD), ('wMajorVerNum', WORD), ('wMinorVerNum', WORD), ('tdescAlias', TYPEDESC), ('idldescType', IDLDESC), ] assert sizeof(tagTYPEATTR) == 76, sizeof(tagTYPEATTR) assert alignment(tagTYPEATTR) == 4, alignment(tagTYPEATTR) class _py_N10tagVARIANT5__200E(Union): pass class __tagVARIANT(Structure): pass class _py_N10tagVARIANT5__20012__tagVARIANT5__201E(Union): pass class tagCY(Union): pass class _py_N5tagCY5__143E(Structure): pass # _py_N5tagCY5__143E _py_N5tagCY5__143E._fields_ = [ ('Lo', c_ulong), ('Hi', c_long), ] assert sizeof(_py_N5tagCY5__143E) == 8, sizeof(_py_N5tagCY5__143E) assert alignment(_py_N5tagCY5__143E) == 4, alignment(_py_N5tagCY5__143E) # tagCY tagCY._fields_ = [ # Unnamed field renamed to '_' ('_', _py_N5tagCY5__143E), ('int64', LONGLONG), ] assert sizeof(tagCY) == 8, sizeof(tagCY) assert alignment(tagCY) == 8, alignment(tagCY) CY = tagCY # typedef class IDispatch(IUnknown): def GetTypeInfoCount(self, p0): pass def GetTypeInfo(self, p0, p1, p2): pass def GetIDsOfNames(self, p0, p1, p2, p3, p4): pass def Invoke(self, p0, p1, p2, p3, p4, p5, p6, p7): pass class tagSAFEARRAY(Structure): pass SAFEARRAY = tagSAFEARRAY # typedef class tagDEC(Structure): pass DECIMAL = tagDEC # typedef class __tagBRECORD(Structure): pass class IRecordInfo(IUnknown): def RecordInit(self, p0): pass def RecordClear(self, p0): pass def RecordCopy(self, p0, p1): pass def GetGuid(self, p0): pass def GetName(self, p0): pass def GetSize(self, p0): pass def GetTypeInfo(self, p0): pass def GetField(self, p0, p1, p2): pass def GetFieldNoCopy(self, p0, p1, p2, p3): pass def PutField(self, p0, p1, p2, p3): pass def PutFieldNoCopy(self, p0, p1, p2, p3): pass def GetFieldNames(self, p0, p1): pass def IsMatchingType(self, p0): pass def RecordCreate(self): pass def RecordCreateCopy(self, p0, p1): pass def RecordDestroy(self, p0): pass # __tagBRECORD __tagBRECORD._fields_ = [ ('pvRecord', PVOID), ('pRecInfo', POINTER(IRecordInfo)), ] assert sizeof(__tagBRECORD) == 8, sizeof(__tagBRECORD) assert alignment(__tagBRECORD) == 4, alignment(__tagBRECORD) # _py_N10tagVARIANT5__20012__tagVARIANT5__201E _py_N10tagVARIANT5__20012__tagVARIANT5__201E._fields_ = [ ('llVal', LONGLONG), ('lVal', LONG), ('bVal', BYTE), ('iVal', SHORT), ('fltVal', FLOAT), ('dblVal', DOUBLE), ('boolVal', VARIANT_BOOL), ('scode', SCODE), ('cyVal', CY), ('date', DATE), ('bstrVal', BSTR), ('punkVal', POINTER(IUnknown)), ('pdispVal', POINTER(IDispatch)), ('parray', POINTER(SAFEARRAY)), ('pbVal', POINTER(BYTE)), ('piVal', POINTER(SHORT)), ('plVal', POINTER(LONG)), ('pllVal', POINTER(LONGLONG)), ('pfltVal', POINTER(FLOAT)), ('pdblVal', POINTER(DOUBLE)), ('pboolVal', POINTER(VARIANT_BOOL)), ('pscode', POINTER(SCODE)), ('pcyVal', POINTER(CY)), ('pdate', POINTER(DATE)), ('pbstrVal', POINTER(BSTR)), ('ppunkVal', POINTER(POINTER(IUnknown))), ('ppdispVal', POINTER(POINTER(IDispatch))), ('pparray', POINTER(POINTER(SAFEARRAY))), ('pvarVal', POINTER(VARIANT)), ('byref', PVOID), ('cVal', CHAR), ('uiVal', USHORT), ('ulVal', DWORD), ('ullVal', ULONGLONG), ('intVal', INT), ('uintVal', UINT), ('pdecVal', POINTER(DECIMAL)), ('pcVal', POINTER(CHAR)), ('puiVal', POINTER(USHORT)), ('pulVal', POINTER(DWORD)), ('pullVal', POINTER(ULONGLONG)), ('pintVal', POINTER(INT)), ('puintVal', POINTER(UINT)), ('brecVal', __tagBRECORD), ] assert sizeof(_py_N10tagVARIANT5__20012__tagVARIANT5__201E) == 8, sizeof(_py_N10tagVARIANT5__20012__tagVARIANT5__201E) assert alignment(_py_N10tagVARIANT5__20012__tagVARIANT5__201E) == 8, alignment(_py_N10tagVARIANT5__20012__tagVARIANT5__201E) # __tagVARIANT __tagVARIANT._fields_ = [ ('vt', VARTYPE), ('wReserved1', WORD), ('wReserved2', WORD), ('wReserved3', WORD), ('n3', _py_N10tagVARIANT5__20012__tagVARIANT5__201E), ] assert sizeof(__tagVARIANT) == 16, sizeof(__tagVARIANT) assert alignment(__tagVARIANT) == 8, alignment(__tagVARIANT) class _py_N6tagDEC5__144E(Union): pass class _py_N6tagDEC5__1445__145E(Structure): pass # _py_N6tagDEC5__1445__145E _py_N6tagDEC5__1445__145E._fields_ = [ ('scale', BYTE), ('sign', BYTE), ] assert sizeof(_py_N6tagDEC5__1445__145E) == 2, sizeof(_py_N6tagDEC5__1445__145E) assert alignment(_py_N6tagDEC5__1445__145E) == 1, alignment(_py_N6tagDEC5__1445__145E) # _py_N6tagDEC5__144E _py_N6tagDEC5__144E._fields_ = [ # Unnamed field renamed to '_' ('_', _py_N6tagDEC5__1445__145E), ('signscale', USHORT), ] assert sizeof(_py_N6tagDEC5__144E) == 2, sizeof(_py_N6tagDEC5__144E) assert alignment(_py_N6tagDEC5__144E) == 2, alignment(_py_N6tagDEC5__144E) class _py_N6tagDEC5__146E(Union): pass class _py_N6tagDEC5__1465__147E(Structure): pass # _py_N6tagDEC5__1465__147E _py_N6tagDEC5__1465__147E._fields_ = [ ('Lo32', DWORD), ('Mid32', DWORD), ] assert sizeof(_py_N6tagDEC5__1465__147E) == 8, sizeof(_py_N6tagDEC5__1465__147E) assert alignment(_py_N6tagDEC5__1465__147E) == 4, alignment(_py_N6tagDEC5__1465__147E) # _py_N6tagDEC5__146E _py_N6tagDEC5__146E._fields_ = [ # Unnamed field renamed to '_' ('_', _py_N6tagDEC5__1465__147E), ('Lo64', ULONGLONG), ] assert sizeof(_py_N6tagDEC5__146E) == 8, sizeof(_py_N6tagDEC5__146E) assert alignment(_py_N6tagDEC5__146E) == 8, alignment(_py_N6tagDEC5__146E) # tagDEC tagDEC._fields_ = [ ('wReserved', USHORT), # Unnamed field renamed to '_' ('_', _py_N6tagDEC5__144E), ('Hi32', DWORD), # Unnamed field renamed to '_1' ('_1', _py_N6tagDEC5__146E), ] assert sizeof(tagDEC) == 16, sizeof(tagDEC) assert alignment(tagDEC) == 8, alignment(tagDEC) # _py_N10tagVARIANT5__200E _py_N10tagVARIANT5__200E._fields_ = [ ('n2', __tagVARIANT), ('decVal', DECIMAL), ] assert sizeof(_py_N10tagVARIANT5__200E) == 16, sizeof(_py_N10tagVARIANT5__200E) assert alignment(_py_N10tagVARIANT5__200E) == 8, alignment(_py_N10tagVARIANT5__200E) # tagVARIANT tagVARIANT._fields_ = [ ('n1', _py_N10tagVARIANT5__200E), ] assert sizeof(tagVARIANT) == 16, sizeof(tagVARIANT) assert alignment(tagVARIANT) == 8, alignment(tagVARIANT) class _py_N10tagVARDESC5__205E(Union): pass # _py_N10tagVARDESC5__205E _py_N10tagVARDESC5__205E._fields_ = [ ('oInst', DWORD), ('lpvarValue', POINTER(VARIANT)), ] assert sizeof(_py_N10tagVARDESC5__205E) == 4, sizeof(_py_N10tagVARDESC5__205E) assert alignment(_py_N10tagVARDESC5__205E) == 4, alignment(_py_N10tagVARDESC5__205E) class tagELEMDESC(Structure): pass class _py_N11tagELEMDESC5__204E(Union): pass class tagPARAMDESC(Structure): pass class tagPARAMDESCEX(Structure): pass LPPARAMDESCEX = POINTER(tagPARAMDESCEX) # typedef # tagPARAMDESC tagPARAMDESC._fields_ = [ ('pparamdescex', LPPARAMDESCEX), ('wParamFlags', USHORT), ] assert sizeof(tagPARAMDESC) == 8, sizeof(tagPARAMDESC) assert alignment(tagPARAMDESC) == 4, alignment(tagPARAMDESC) PARAMDESC = tagPARAMDESC # typedef # _py_N11tagELEMDESC5__204E _py_N11tagELEMDESC5__204E._fields_ = [ ('idldesc', IDLDESC), ('paramdesc', PARAMDESC), ] assert sizeof(_py_N11tagELEMDESC5__204E) == 8, sizeof(_py_N11tagELEMDESC5__204E) assert alignment(_py_N11tagELEMDESC5__204E) == 4, alignment(_py_N11tagELEMDESC5__204E) # tagELEMDESC tagELEMDESC._fields_ = [ ('tdesc', TYPEDESC), # Unnamed field renamed to '_' ('_', _py_N11tagELEMDESC5__204E), ] assert sizeof(tagELEMDESC) == 16, sizeof(tagELEMDESC) assert alignment(tagELEMDESC) == 4, alignment(tagELEMDESC) ELEMDESC = tagELEMDESC # typedef tagVARKIND = c_int # enum VAR_PERINSTANCE = 0 # enum tagVARKIND VAR_STATIC = 1 # enum tagVARKIND VAR_CONST = 2 # enum tagVARKIND VAR_DISPATCH = 3 # enum tagVARKIND VARKIND = tagVARKIND # typedef # tagVARDESC tagVARDESC._fields_ = [ ('memid', MEMBERID), ('lpstrSchema', LPOLESTR), # Unnamed field renamed to '_' ('_', _py_N10tagVARDESC5__205E), ('elemdescVar', ELEMDESC), ('wVarFlags', WORD), ('varkind', VARKIND), ] assert sizeof(tagVARDESC) == 36, sizeof(tagVARDESC) assert alignment(tagVARDESC) == 4, alignment(tagVARDESC) tagFUNCKIND = c_int # enum FUNC_VIRTUAL = 0 # enum tagFUNCKIND FUNC_PUREVIRTUAL = 1 # enum tagFUNCKIND FUNC_NONVIRTUAL = 2 # enum tagFUNCKIND FUNC_STATIC = 3 # enum tagFUNCKIND FUNC_DISPATCH = 4 # enum tagFUNCKIND FUNCKIND = tagFUNCKIND # typedef tagCALLCONV = c_int # enum CC_FASTCALL = 0 # enum tagCALLCONV CC_CDECL = 1 # enum tagCALLCONV CC_MSCPASCAL = 2 # enum tagCALLCONV CC_PASCAL = 2 # enum tagCALLCONV CC_MACPASCAL = 3 # enum tagCALLCONV CC_STDCALL = 4 # enum tagCALLCONV CC_FPFASTCALL = 5 # enum tagCALLCONV CC_SYSCALL = 6 # enum tagCALLCONV CC_MPWCDECL = 7 # enum tagCALLCONV CC_MPWPASCAL = 8 # enum tagCALLCONV CC_MAX = 9 # enum tagCALLCONV CALLCONV = tagCALLCONV # typedef # tagFUNCDESC tagFUNCDESC._fields_ = [ ('memid', MEMBERID), ('lprgscode', POINTER(SCODE)), ('lprgelemdescParam', POINTER(ELEMDESC)), ('funckind', FUNCKIND), ('invkind', INVOKEKIND), ('callconv', CALLCONV), ('cParams', SHORT), ('cParamsOpt', SHORT), ('oVft', SHORT), ('cScodes', SHORT), ('elemdescFunc', ELEMDESC), ('wFuncFlags', WORD), ] assert sizeof(tagFUNCDESC) == 52, sizeof(tagFUNCDESC) assert alignment(tagFUNCDESC) == 4, alignment(tagFUNCDESC) class tagSAFEARRAYBOUND(Structure): pass # tagSAFEARRAYBOUND tagSAFEARRAYBOUND._fields_ = [ ('cElements', DWORD), ('lLbound', LONG), ] assert sizeof(tagSAFEARRAYBOUND) == 8, sizeof(tagSAFEARRAYBOUND) assert alignment(tagSAFEARRAYBOUND) == 4, alignment(tagSAFEARRAYBOUND) SAFEARRAYBOUND = tagSAFEARRAYBOUND # typedef # tagSAFEARRAY tagSAFEARRAY._fields_ = [ ('cDims', USHORT), ('fFeatures', USHORT), ('cbElements', DWORD), ('cLocks', DWORD), ('pvData', PVOID), ('rgsabound', SAFEARRAYBOUND * 1), ] assert sizeof(tagSAFEARRAY) == 24, sizeof(tagSAFEARRAY) assert alignment(tagSAFEARRAY) == 4, alignment(tagSAFEARRAY) # tagPARAMDESCEX tagPARAMDESCEX._fields_ = [ ('cBytes', DWORD), ('varDefaultValue', VARIANTARG), ] assert sizeof(tagPARAMDESCEX) == 24, sizeof(tagPARAMDESCEX) assert alignment(tagPARAMDESCEX) == 8, alignment(tagPARAMDESCEX) # tagARRAYDESC tagARRAYDESC._fields_ = [ ('tdescElem', TYPEDESC), ('cDims', USHORT), ('rgbounds', SAFEARRAYBOUND * 1), ] assert sizeof(tagARRAYDESC) == 20, sizeof(tagARRAYDESC) assert alignment(tagARRAYDESC) == 4, alignment(tagARRAYDESC) LPCOLESTR = POINTER(OLECHAR) # typedef IRecordInfo._methods_ = [ STDMETHOD(HRESULT, 'RecordInit', [PVOID]), STDMETHOD(HRESULT, 'RecordClear', [PVOID]), STDMETHOD(HRESULT, 'RecordCopy', [PVOID, PVOID]), STDMETHOD(HRESULT, 'GetGuid', [POINTER(GUID)]), STDMETHOD(HRESULT, 'GetName', [POINTER(BSTR)]), STDMETHOD(HRESULT, 'GetSize', [POINTER(DWORD)]), STDMETHOD(HRESULT, 'GetTypeInfo', [POINTER(POINTER(ITypeInfo))]), STDMETHOD(HRESULT, 'GetField', [PVOID, LPCOLESTR, POINTER(VARIANT)]), STDMETHOD(HRESULT, 'GetFieldNoCopy', [PVOID, LPCOLESTR, POINTER(VARIANT), POINTER(PVOID)]), STDMETHOD(HRESULT, 'PutField', [DWORD, PVOID, LPCOLESTR, POINTER(VARIANT)]), STDMETHOD(HRESULT, 'PutFieldNoCopy', [DWORD, PVOID, LPCOLESTR, POINTER(VARIANT)]), STDMETHOD(HRESULT, 'GetFieldNames', [POINTER(DWORD), POINTER(BSTR)]), STDMETHOD(BOOL, 'IsMatchingType', [POINTER(IRecordInfo)]), STDMETHOD(PVOID, 'RecordCreate', []), STDMETHOD(HRESULT, 'RecordCreateCopy', [PVOID, POINTER(PVOID)]), STDMETHOD(HRESULT, 'RecordDestroy', [PVOID]), ] IDispatch._methods_ = [ STDMETHOD(HRESULT, 'GetTypeInfoCount', [POINTER(UINT)]), STDMETHOD(HRESULT, 'GetTypeInfo', [UINT, LCID, POINTER(POINTER(ITypeInfo))]), STDMETHOD(HRESULT, 'GetIDsOfNames', [POINTER(IID), POINTER(LPOLESTR), UINT, LCID, POINTER(DISPID)]), STDMETHOD(HRESULT, 'Invoke', [DISPID, POINTER(IID), LCID, WORD, POINTER(DISPPARAMS), POINTER(VARIANT), POINTER(EXCEPINFO), POINTER(UINT)]), ] from ctypes.decorators import stdcall @ stdcall(HRESULT, "oleaut32", [c_wchar_p, POINTER(POINTER(ITypeLib))]) def LoadTypeLib(name): p = POINTER(ITypeLib)() LoadTypeLib._api_(name, byref(p)) return p tagREGKIND = c_int # enum REGKIND_DEFAULT = 0 # enum tagREGKIND REGKIND_REGISTER = 1 # enum tagREGKIND REGKIND_NONE = 2 # enum tagREGKIND REGKIND = tagREGKIND # typedef @ stdcall(HRESULT, "oleaut32", [c_wchar_p, REGKIND, POINTER(POINTER(ITypeLib))]) def LoadTypeLibEx(name, regkind=REGKIND_NONE): p = POINTER(ITypeLib)() LoadTypeLibEx._api_(name, regkind, byref(p)) return p if __name__ == "__main__": import ctypes print ctypes.__file__ p = LoadTypeLibEx("aaa.bbb") print p.AddRef() |
From: Thomas H. <th...@us...> - 2005-01-25 15:31:21
|
Update of /cvsroot/ctypes/ctypes/comtypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14171 Modified Files: __init__.py Log Message: Lots of changes. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/__init__.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** __init__.py 13 Jan 2005 09:34:45 -0000 1.2 --- __init__.py 25 Jan 2005 15:31:11 -0000 1.3 *************** *** 1,7 **** from ctypes import * - try: - HRESULT - except NameError: # ctypes 0.92 and older - from _ctypes import HRESULT from comtypes.GUID import GUID --- 1,5 ---- + # requires ctypes 0.9.3 or later + import new from ctypes import * from comtypes.GUID import GUID *************** *** 9,40 **** # The metaclasses... - # would c_void_p be a better base? Conflicts with the QueryInterface signature... - _pbase = POINTER(c_void_p) - #_pbase = c_void_p - - def _create_method_codestring(func, doc=None): - # Assuming the <func> has this definition: - # def func(self, first, second="spam", third=42): - # .... - # a string containing the following code is returned: - # def func(self, first, second="spam", third=42): - # return self.func._api_(self, first, second, third) - import inspect - args, varargs, varkw, defaults = inspect.getargspec(func) - if varkw: - raise TypeError, "%s argument list must not contain ** argument" % func.func_name - if doc: - return "def %s%s:\n %r\n return self.%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 self.%s._api_%s" % \ - (func.func_name, - inspect.formatargspec(args, varargs, varkw, defaults), - func.func_name, - inspect.formatargspec(args, varargs, varkw)) - class _cominterface_meta(type): # Metaclass for COM interface classes. --- 7,10 ---- *************** *** 43,63 **** methods = namespace.pop("_methods_", None) cls = type.__new__(self, name, bases, namespace) if methods: setattr(cls, "_methods_", methods) ! # The interface 'cls' is used as a mixin for the ! # POINTER(interface) class: ! def __del__(s_): ! "Release the COM refcount we own." ! if s_: ! result = s_.Release() ! ## def __eq__(s_, other): ! ## return cast(s_, c_int).value == cast(other, c_int).value ! # POINTER(interface) looks nice as class name, but is it ok? ! p = _compointer_meta("POINTER(%s)" % cls.__name__, ! (cls, _pbase), ! {"__del__": __del__, ! ## "__eq__": __eq__, # XXX fixme: COM identity rules ! "_type_": c_int # XXX fixme ! }) from ctypes import _pointer_type_cache _pointer_type_cache[cls] = p --- 13,25 ---- methods = namespace.pop("_methods_", None) cls = type.__new__(self, name, bases, namespace) + # XXX ??? First assign the _methods_, or first create the POINTER class? + # or does it not matter? if methods: setattr(cls, "_methods_", methods) ! # The interface 'cls' is used as a mixin. ! # XXX "POINTER(<interface>)" looks nice as class name, but is it ok? ! p = type(_compointer_base)("POINTER(%s)" % cls.__name__, ! (cls, _compointer_base), ! {}) from ctypes import _pointer_type_cache _pointer_type_cache[cls] = p *************** *** 68,95 **** if name != "_methods_": return ! self.make_methods(value) ! ! def __get_method(self, name): ! # should create a method if doesn't have one. ! mth = getattr(self, name, None) ! if mth is None: ! def func(self, *args): ! return getattr(self, name)._api_(self, *args) ! setattr(self, name, func) ! # convert into unbound method ! mth = getattr(self, name) ! return mth ! ! func = mth.im_func ! if len(func.func_code.co_code) == 4: ! # method has no body - create one ! codestring = _create_method_codestring(func, func.func_doc) ! ns = {} ! exec codestring in ns ! func = ns[func.func_name] ! # convert into unbound method ! setattr(self, name, func) ! mth = getattr(self, name) ! return mth def __get_baseinterface_methodcount(self): --- 30,34 ---- if name != "_methods_": return ! self._make_methods(value) def __get_baseinterface_methodcount(self): *************** *** 98,121 **** for itf in self.__mro__[1:]]) ! def make_methods(self, methods): ! if not methods: ! return vtbl_offset = self.__get_baseinterface_methodcount() for i, (restype, name, argtypes) in enumerate(methods): # the function prototype prototype = WINFUNCTYPE(restype, *argtypes) ! # the actual COM interface method object, will invoke ! # the method in the VTable of the COM interface pointer ! func = prototype(i + vtbl_offset, name) ! ! # the Python method implementation in the interface ! mth = self.__get_method(name) ! mth.im_func._api_ = func ! # This class only to avoid a metaclass confict. No additional ! # behaviour here. ! class _compointer_meta(type(_pbase), _cominterface_meta): pass ################################################################ --- 37,72 ---- for itf in self.__mro__[1:]]) ! def _make_methods(self, methods): vtbl_offset = self.__get_baseinterface_methodcount() for i, (restype, name, argtypes) in enumerate(methods): # the function prototype prototype = WINFUNCTYPE(restype, *argtypes) ! # create a bound method, which will call into the COM vtbl ! # the three-argument call requires ctypes 0.9.3 ! mth = prototype(i + vtbl_offset, name, self) ! impl = getattr(self, name, None) ! if impl is None: ! setattr(self, name, mth) ! else: ! mthname = "_%s__com_%s" % (self.__name__, name) ! # attach it with a private name (__com_AddRef, for example) ! setattr(self, mthname, mth) ! # metaclass for COM interface pointers ! class _compointer_meta(type(c_void_p), _cominterface_meta): pass + # base class for COM interface pointers + class _compointer_base(c_void_p): + __metaclass__ = _compointer_meta + def __del__(self): + "Release the COM refcount we own." + if self.value: + self.Release() + def __eq__(self, other): + if not isinstance(other, _compointer_base): + return False + return self.value == other.value + ################################################################ *************** *** 123,154 **** def STDMETHOD(restype, name, argtypes=()): ! "Defines a COM method" return restype, name, argtypes ! class IUnknown(object): __metaclass__ = _cominterface_meta _iid_ = GUID("{00000000-0000-0000-C000-000000000046}") def QueryInterface(self, interface): "QueryInterface(klass) -> instance" p = POINTER(interface)() ! self.QueryInterface._api_(self, byref(interface._iid_), byref(p)) return p def AddRef(self): "Increase the internal refcount by one" def Release(self): "Decrease the internal refcount by one" ! ! _methods_ = [ ! STDMETHOD(HRESULT, "QueryInterface", ! [POINTER(GUID), POINTER(_pbase)]), ! STDMETHOD(c_ulong, "AddRef"), ! STDMETHOD(c_ulong, "Release") ! ] __all__ = "IUnknown GUID HRESULT BSTR STDMETHOD".split() if __name__ == "__main__": ! help(POINTER(IUnknown)) --- 74,131 ---- def STDMETHOD(restype, name, argtypes=()): ! "Specifies a COM method slot" return restype, name, argtypes ! class _com_interface(object): __metaclass__ = _cominterface_meta + + class IUnknown(_com_interface): _iid_ = GUID("{00000000-0000-0000-C000-000000000046}") + _methods_ = [ + STDMETHOD(HRESULT, "QueryInterface", + [POINTER(GUID), POINTER(c_void_p)]), + STDMETHOD(c_ulong, "AddRef"), + STDMETHOD(c_ulong, "Release") + ] + def QueryInterface(self, interface): "QueryInterface(klass) -> instance" p = POINTER(interface)() ! self.__com_QueryInterface(byref(interface._iid_), byref(p)) return p def AddRef(self): "Increase the internal refcount by one" + return self.__com_AddRef() def Release(self): "Decrease the internal refcount by one" ! return self.__com_Release() __all__ = "IUnknown GUID HRESULT BSTR STDMETHOD".split() if __name__ == "__main__": ! POINTER(IUnknown)() ! ! p = POINTER(IUnknown)() ! ! ## assert bool(p) is True ! ## assert bool(p) is False ! ! windll.oleaut32.CreateTypeLib(1, u"blabla", byref(p)) ! assert (2, 1) == (p.AddRef(), p.Release()) ! ! p1 = p.QueryInterface(IUnknown) ! assert (3, 2) == (p1.AddRef(), p1.Release()) ! p2 = p1.QueryInterface(IUnknown) ! ! assert p1 == p2 ! ! del p2 ! del p ! assert (2, 1) == (p1.AddRef(), p1.Release()) ! ! ## help(POINTER(IUnknown)) ! ! del p1 |
From: Thomas H. <th...@us...> - 2005-01-25 15:07:30
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7735 Modified Files: codegenerator.py Log Message: Disable the get_real_type function - I currently do not remember why it was there. Allow typedesc.Function to have a dllname attribute specifying the dll that exports it. Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/codegenerator.py,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** codegenerator.py 24 Jan 2005 12:48:08 -0000 1.34 --- codegenerator.py 25 Jan 2005 15:06:59 -0000 1.35 *************** *** 117,122 **** def get_real_type(tp): ! if type(tp) is typedesc.Typedef: ! return get_real_type(tp.typ) return tp --- 117,123 ---- def get_real_type(tp): ! # why was this? ! ## if type(tp) is typedesc.Typedef: ! ## return get_real_type(tp.typ) return tp *************** *** 374,380 **** return print >> self.stream, \ ! "%s = %r # %s" % (tp.name, ! value, ! self.type_name(tp.typ, False)) self.names.add(tp.name) --- 375,381 ---- return print >> self.stream, \ ! "%s = %r # Variable %s" % (tp.name, ! value, ! self.type_name(tp.typ, False)) self.names.add(tp.name) *************** *** 493,497 **** self.done.add(body) ! def find_dllname(self, name): for dll in self.searched_dlls: try: --- 494,501 ---- self.done.add(body) ! def find_dllname(self, func): ! if hasattr(func, "dllname"): ! return func.dllname ! name = func.name for dll in self.searched_dlls: try: *************** *** 621,625 **** if func in self.done: return ! dllname = self.find_dllname(func.name) if dllname: self.generate(func.returns) --- 625,629 ---- if func in self.done: return ! dllname = self.find_dllname(func) if dllname: self.generate(func.returns) |