ctypes-commit Mailing List for ctypes (Page 14)
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...> - 2006-03-27 18:39:58
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4775 Modified Files: setup.py Log Message: Fixes from Khalid A. Bakr for MingW compiling ctypes. He writes: I have made some changes (see attached diff) to the setup.py to have MinGW pass the "--enable-stdcall-fixup" to the linker to suppress some warnings. And I have added another linker option, namely "--kill-at" to remove the @XY decoration that MinGW normally attaches to stdcall functions. With the latter change, test_cfuncs (which had previously reported 26 failures out of 52 tests) now only reports 3. It seems that the stdcall part now passes as it does when compiled with a MSVC type compiler. Index: setup.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/setup.py,v retrieving revision 1.136 retrieving revision 1.137 diff -C2 -d -r1.136 -r1.137 *** setup.py 18 Mar 2006 16:56:59 -0000 1.136 --- setup.py 27 Mar 2006 18:39:51 -0000 1.137 *************** *** 133,148 **** # is in sources, we have to add '.s'. self.compiler.src_extensions.append('.s') - # We should add the '--enable-stdcall-fixup' compiler flag for ext in self.extensions: if ext.name == "_ctypes": ext.sources.remove("source/libffi_msvc/win32.c") - # This doesn't work - the option goes to the end of the command line, - # but it should probably be at the beginning. So, we have to live - # with the warning. - ## ext.extra_compile_args.append("--enable-stdcall-fixup") else: for ext in self.extensions: if ext.name == "_ctypes": ext.sources.remove("source/libffi_msvc/win32.S") build_ext.build_ext.build_extensions(self) --- 133,144 ---- # is in sources, we have to add '.s'. self.compiler.src_extensions.append('.s') for ext in self.extensions: if ext.name == "_ctypes": ext.sources.remove("source/libffi_msvc/win32.c") else: for ext in self.extensions: if ext.name == "_ctypes": ext.sources.remove("source/libffi_msvc/win32.S") + ext.extra_link_args = [] build_ext.build_ext.build_extensions(self) *************** *** 255,260 **** --- 251,277 ---- else: extra_compile_args = [] + + # Extra arguments passed to linker from MinGW, + # will be removed, in my_build_ext, if compiler <> MinGW + extra_link_args = [] + + # In MinGW32, the first linker option should be: + # -Xlinker --enable-stdcall-fixup + # but here this option is split into two options to + # force distutils not to surroud the entire option + # with double quotes as it sees a space in it. So: + + extra_link_args.extend(["-Xlinker", "--enable-stdcall-fixup", + + # In MinGW32, the --kill-at linker option forces MinGW to + # remove the @XY decoration from function names, hence making + # the stdcall functions of _ctypes_test and those tested in + # test_cfuns.py behave similarly to the one compiled in MSVC. + + "-Wl,--kill-at"]) + extensions = [Extension("_ctypes", extra_compile_args = extra_compile_args, + extra_link_args = extra_link_args, export_symbols=["DllGetClassObject,PRIVATE", "DllCanUnloadNow,PRIVATE"], *************** *** 263,266 **** --- 280,285 ---- **kw), Extension("_ctypes_test", + extra_compile_args = extra_compile_args, + extra_link_args = extra_link_args, libraries=["oleaut32", "user32"], sources=["source/_ctypes_test.c"], |
From: Thomas H. <th...@us...> - 2006-03-27 08:47:14
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13881 Modified Files: tutorial.txt Log Message: *** empty log message *** Index: tutorial.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/tutorial.txt,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** tutorial.txt 27 Mar 2006 08:45:40 -0000 1.10 --- tutorial.txt 27 Mar 2006 08:47:12 -0000 1.11 *************** *** 927,933 **** ... break ... ! __hello__ 100 ! __phello__ -100 ! __phello__.spam 100 None 0 >>> --- 927,933 ---- ... break ... ! __hello__ 104 ! __phello__ -104 ! __phello__.spam 104 None 0 >>> |
From: Thomas H. <th...@us...> - 2006-03-27 08:45:42
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12895 Modified Files: tutorial.txt Log Message: Use pythonapi instead of loading the python dll. Index: tutorial.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/tutorial.txt,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** tutorial.txt 27 Mar 2006 07:30:23 -0000 1.9 --- tutorial.txt 27 Mar 2006 08:45:40 -0000 1.10 *************** *** 877,882 **** >>> from ctypes import * ! >>> pydll = cdll.python22 ! >>> opt_flag = c_int.in_dll(pydll, "Py_OptimizeFlag") >>> print opt_flag c_long(0) --- 877,881 ---- >>> from ctypes import * ! >>> opt_flag = c_int.in_dll(pythonapi, "Py_OptimizeFlag") >>> print opt_flag c_long(0) *************** *** 901,905 **** >>> from ctypes import * - >>> pydll = cdll.python22 >>> >>> class struct_frozen(Structure): --- 900,903 ---- *************** *** 915,919 **** >>> FrozenTable = POINTER(struct_frozen) ! >>> table = FrozenTable.in_dll(pydll, "PyImport_FrozenModules") >>> --- 913,917 ---- >>> FrozenTable = POINTER(struct_frozen) ! >>> table = FrozenTable.in_dll(pythonapi, "PyImport_FrozenModules") >>> |
From: Thomas H. <th...@us...> - 2006-03-27 08:44:40
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12322 Modified Files: test-tutorial.py Log Message: Make executable. Index: test-tutorial.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/test-tutorial.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** test-tutorial.py 27 Mar 2006 06:48:33 -0000 1.1 --- test-tutorial.py 27 Mar 2006 08:44:36 -0000 1.2 *************** *** 1,2 **** --- 1,3 ---- + #!/usr/bin/env python import doctest SKIP = doctest.register_optionflag("SKIP") |
From: Thomas H. <th...@us...> - 2006-03-27 07:26:31
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24481 Modified Files: simple_types.txt Log Message: Fix typo. Index: simple_types.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/simple_types.txt,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** simple_types.txt 22 Mar 2006 07:09:10 -0000 1.4 --- simple_types.txt 27 Mar 2006 07:26:27 -0000 1.5 *************** *** 15,19 **** -------------------------------- ! ``__ctype__be__``, ``__ctype_le__`` If the type supports different byte order (pointer types do NOT --- 15,19 ---- -------------------------------- ! ``__ctype_be__``, ``__ctype_le__`` If the type supports different byte order (pointer types do NOT |
From: Thomas H. <th...@us...> - 2006-03-27 07:25:48
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24051 Modified Files: tutorial.txt Log Message: Make the qsort example shorter. Index: tutorial.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/tutorial.txt,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** tutorial.txt 27 Mar 2006 07:18:10 -0000 1.7 --- tutorial.txt 27 Mar 2006 07:25:43 -0000 1.8 *************** *** 759,764 **** >>> from ctypes import * ! >>> IntArray10 = c_int * 10 ! >>> ia = IntArray10(5, 4, 3, 1, 7, 9, 33, 2, 99, 0) >>> qsort = cdll.msvcrt.qsort >>> --- 759,764 ---- >>> from ctypes import * ! >>> IntArray5 = c_int * 5 ! >>> ia = IntArray5(5, 1, 7, 33, 99) >>> qsort = cdll.msvcrt.qsort >>> *************** *** 805,817 **** py_cmp_func <ctypes.LP_c_long object at 0x00C70AD0> <ctypes.LP_c_long object at 0x00C70B20> py_cmp_func <ctypes.LP_c_long object at 0x00C70AD0> <ctypes.LP_c_long object at 0x00C70B20> - py_cmp_func <ctypes.LP_c_long object at 0x00C70AD0> <ctypes.LP_c_long object at 0x00C70B20> - py_cmp_func <ctypes.LP_c_long object at 0x00C70AD0> <ctypes.LP_c_long object at 0x00C70B20> - py_cmp_func <ctypes.LP_c_long object at 0x00C70AD0> <ctypes.LP_c_long object at 0x00C70B20> - py_cmp_func <ctypes.LP_c_long object at 0x00C70AD0> <ctypes.LP_c_long object at 0x00C70B20> - py_cmp_func <ctypes.LP_c_long object at 0x00C70AD0> <ctypes.LP_c_long object at 0x00C70B20> - py_cmp_func <ctypes.LP_c_long object at 0x00C70AD0> <ctypes.LP_c_long object at 0x00C70B20> - py_cmp_func <ctypes.LP_c_long object at 0x00C70AD0> <ctypes.LP_c_long object at 0x00C70B20> - py_cmp_func <ctypes.LP_c_long object at 0x00C70AD0> <ctypes.LP_c_long object at 0x00C70B20> - py_cmp_func <ctypes.LP_c_long object at 0x00C70AD0> <ctypes.LP_c_long object at 0x00C70B20> -1 >>> --- 805,808 ---- *************** *** 819,894 **** We know how to access the contents of a pointer, so lets redefine our callback:: ! >>> def py_cmp_func(a, b): ! ... print "py_cmp_func", a[0], b[0] ! ... return 0 ! ... ! >>> cmp_func = CMPFUNC(py_cmp_func) ! >>> qsort(ia, len(ia), sizeof(c_int), cmp_func) ! py_cmp_func 5 9 ! py_cmp_func 5 0 ! py_cmp_func 9 0 ! py_cmp_func 4 9 ! py_cmp_func 3 9 ! py_cmp_func 1 9 ! py_cmp_func 7 9 ! py_cmp_func 33 9 ! py_cmp_func 2 9 ! py_cmp_func 99 9 ! py_cmp_func 0 9 ! py_cmp_func 99 9 ! py_cmp_func 99 9 ! py_cmp_func 2 9 ! py_cmp_func 33 9 ! py_cmp_func 7 9 ! py_cmp_func 1 9 ! py_cmp_func 3 9 ! py_cmp_func 4 9 ! -1 ! >>> Ah, we're nearly done! Last refinements:: ! >>> def py_cmp_func(a, b): ! ... print "py_cmp_func", a[0], b[0] ! ... return a[0] - b[0] ! ... ! >>> qsort(ia, len(ia), sizeof(c_int), CMPFUNC(py_cmp_func)) ! py_cmp_func 5 9 ! py_cmp_func 5 0 ! py_cmp_func 9 5 ! py_cmp_func 4 5 ! py_cmp_func 3 5 ! py_cmp_func 1 5 ! py_cmp_func 7 5 ! py_cmp_func 99 5 ! py_cmp_func 2 5 ! py_cmp_func 33 5 ! py_cmp_func 33 5 ! py_cmp_func 2 5 ! py_cmp_func 7 33 ! py_cmp_func 99 33 ! py_cmp_func 9 99 ! py_cmp_func 7 33 ! py_cmp_func 9 33 ! py_cmp_func 7 9 ! py_cmp_func 4 0 ! py_cmp_func 3 4 ! py_cmp_func 1 4 ! py_cmp_func 2 4 ! py_cmp_func 2 0 ! py_cmp_func 3 2 ! py_cmp_func 1 3 ! py_cmp_func 2 0 ! py_cmp_func 1 2 ! py_cmp_func 1 0 ! -1 ! >>> So, is our array sorted now:: ! >>> for i in ia: print i, ! ... ! 0 1 2 3 4 5 7 9 33 99 ! >>> Yep, it worked! --- 810,858 ---- We know how to access the contents of a pointer, so lets redefine our callback:: ! >>> def py_cmp_func(a, b): ! ... print "py_cmp_func", a[0], b[0] ! ... return 0 ! ... ! >>> cmp_func = CMPFUNC(py_cmp_func) ! >>> qsort(ia, len(ia), sizeof(c_int), cmp_func) ! py_cmp_func 7 1 ! py_cmp_func 33 1 ! py_cmp_func 99 1 ! py_cmp_func 5 1 ! py_cmp_func 7 5 ! py_cmp_func 33 5 ! py_cmp_func 99 5 ! py_cmp_func 7 99 ! py_cmp_func 33 99 ! py_cmp_func 7 33 ! -1 ! >>> Ah, we're nearly done! Last refinements:: ! >>> def py_cmp_func(a, b): ! ... print "py_cmp_func", a[0], b[0] ! ... return a[0] - b[0] ! ... ! >>> qsort(ia, len(ia), sizeof(c_int), CMPFUNC(py_cmp_func)) ! py_cmp_func 33 7 ! py_cmp_func 99 33 ! py_cmp_func 5 99 ! py_cmp_func 1 99 ! py_cmp_func 33 7 ! py_cmp_func 1 33 ! py_cmp_func 5 33 ! py_cmp_func 5 7 ! py_cmp_func 1 7 ! py_cmp_func 5 1 ! -1 ! >>> So, is our array sorted now:: ! >>> for i in ia: print i, ! ... ! 1 5 7 33 99 ! >>> Yep, it worked! |
From: Thomas H. <th...@us...> - 2006-03-24 21:03:30
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14878 Modified Files: reference.txt Log Message: Inserted all the files, does include not work? Index: reference.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/reference.txt,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** reference.txt 24 Mar 2006 20:37:23 -0000 1.1 --- reference.txt 24 Mar 2006 21:03:22 -0000 1.2 *************** *** 2,12 **** +++++++++++++ ! Shared libaries, DLLs ! --------------------- class LibraryLoader ................... ! predefined library loaders .......................... --- 2,746 ---- +++++++++++++ ! ! Shared Libraries, DLLs ! ---------------------- ! ! Shared libraries are accessed when compiling/linking a program, and ! when the program is run. The purpose of the ``find`` method is to ! locate a library in a way similar to what the compiler does (on ! platforms with several versions of a shared library the most recent ! should be loaded), while ``load`` acts like when a program is run, and ! uses the runtime loader directly. ``load_version`` works like ``load`` ! but tries to be platform independent (for cases where this makes ! sense). Loading via attribute access is a shorthand notation ! especially usefull for interactive use, it is equivalent to calling ! ``load_version`` with no version specified. ! class LibraryLoader ................... + Instances of ``LibraryLoader`` are used to load shared libraries. + Usually there is no need to create a libraryloader, instead one of the + predefined loaders should be used. + + Libraryloaders have the following methods: ! ``find(name, mode=None)`` ! ! Try to find a library, load and return it. ``name`` is the ! library name without any prefix like ``lib``, suffix like ``.so``, ! ``.dylib`` or version number (this is the form used for the posix ! linker option ``-l``). ! ! ``mode`` allows to override the default flags passed to the ! ``dlopen()`` function, ignored on Windows. ! ! On Windows, this method does exactly the same as the ``load`` ! method. ! ! On other platforms, this function might call other programs like ! the compiler to find the library. When using ctypes to write a ! shared library wrapping, consider using ``load_version`` or ! ``load`` instead. ! ! ``load_version(name, version=None, mode=None)`` ! ! Build a system dependent filename from ``name`` and optionally ! ``version``, then load and return it. ``name`` is the library ! name without any prefix like ``lib`` and suffix like ``.so`` or ! ``.dylib``. This method should be used if a library is available ! on different platforms, using the particular naming convention of ! each platform. ! ! ``mode`` allows to override the default flags passed to the ! ``dlopen()`` function, ignored on Windows. ! ! Example: calling ``loader.load_version('z', '1.1.3')`` would ! possibly load ``/usr/lib/libz.1.1.3.dylib`` on Mac OS X, or ! ``/lib/libz.so.1.1.3`` on a Linux system. ! ! ``load(libname, mode=None)`` ! ! Load and return the library with the given libname. On most ! systems ``libname`` is the filename of the shared library; when ! it's not a pathname it will be searched in a system dependent list ! of locations (on many systems additional search paths can be ! specified by an environment variable). Sometimes the file ! extension (like ``.dll`` on Windows) can be omitted. ! ! ``mode`` allows to override the default flags passed to the ! ``dlopen()`` function. ``RTLD_LOCAL`` and ``RTLD_GLOBAL`` are ! typical values. On Windows, ``mode`` is ignored. ! ! ``load_library(pathname, mode=None`` ! ! Load and return the library with the given pathname. This method ! passes the ``pathname`` directly to the underlying ``dlopen`` or ! ``LoadLibrary`` function. ! ! ``mode`` allows to override the default flags passed to the ! ``dlopen()`` function. ``RTLD_LOCAL`` and ``RTLD_GLOBAL`` are ! typical values. On Windows, ``mode`` is ignored. ! ! ``LoadLibrary(pathname, mode=None)`` ! ! This is an alias for the ``load_library`` method documented above, ! maintained for backwards comatibility only. ! ! ! Libaries can also be loaded by accessing them as attributes of the ! loader instance, internally this calls ``load_version`` without ! specifying ``version`` or ``mode``. Obviously this only works for ! libraries with names that are valid Python identifiers, and when the ! name does not start with a ``_`` character. ! ! Predefined library loaders ! .......................... ! ! ctypes provides some LibraryLoader instances, the differences between ! them are the calling conventions the functions will use and the ! default return type of the functions. All these loaders use the ! ``RTLD_LOCAL`` mode flag. ! ! Functions can be accessed as named attributes of loaded libraries. ! ! On Windows, structured exception handling is used around the function ! call to protect Python from crashing in case you pass invalid ! parameters to the function. ! ! ``cdll`` ! ! Functions provided by libraries loaded using the ``cdll`` loader ! will be called with the standard C calling convention, and have a ! default return type of ``int``. ctypes releases the Python global ! interpreter lock (GIL) just before calling the foreign function, ! and reacquires it before returing, so other threads are able to ! run. ! ! ``windll`` ! ! Windows only. Functions provided by libraries loaded by ! ``windll`` will be called using the Windows ``__stdcall`` calling ! convention. ctypes can detect when the wrong number ! of parameters has been passed to the function call by examining ! the stack pointer before and after the function call. If the ! wrong parameter count was used, an exception is raised (although ! the function really *has* been called). The return value of the ! function is lost in this case. Again, the GIL is released during ! the duration of the function call. ! ! ``oledll`` ! ! Windows only. ``oledll`` behaves in the same way as ``windll``, ! except that the called function is expected to return a ! ``HRESULT`` value. These are long values containing error or ! success codes. In case the function returns an error ``HRESULT`` ! value, a ``WindowsError`` is raised. The GIL is released during the ! duration of function call. ! ! ``pydll`` ! ! This loader allows to call functions in libraries using the ! *Python* calling convention, for example Python C API functions. ! The GIL is *not* released during the function call, and the state ! of the Python error flag is examined after the function returns. ! If the error flag is set, the Python exception is raised. ! ! ctypes provides a prefabricated instance of ``pydll`` exposing the ! Python C api as the ``pythonapi`` symbol, you should however make ! sure to set the correct ``restype`` for the functions you use. ! ! Library objects ! ............... ! ! The library loaders create instances of ``CDLL``, ``WinDLL``, ! ``OleDLL``, or ``PyDLL`` classes. You can, however, also load a ! library by constructing one of these classes by calling the ! constructor with the pathname of the library and an optional ``mode`` ! argument as described in the previous section. ! ! Library objects implement ``__getattr__`` and ``__getitem__`` methods ! that allow to access foreign functions by attribute access or ! indexing. The latter is useful if the name of the function is not a ! valid Python identifier, or clashes with special Python method names ! that start and end with two underscore characters. ! ! Library objects have two private attributes: ``_name`` is the pathname ! of the library, ``_handle`` is the handle to the library that ! ``dlopen`` has returned. ! ! ! Foreign functions ! ----------------- ! ! Functions exported from loaded shared libraries (foreign functions) ! can be accessed in two ways. The easiest way is to retrieve them as ! attributes of library objects by name:: ! ! libc = cdll.find("c") # posix ! libc = cdll.msvcrt # windows ! # attribute access ! atoi = libc.atoi ! # alternative indexing notation ! atoi = libc["atoi"] ! ! This creates an instance of a foreign function object, using the ! calling convention specified by the library object ``cdll``, bound to ! the C library ``atoi`` function. The C function is assumed to return ! an integer (which is correct for ``atoi``), and the argument types are ! not specified (``atoi`` expects a single ``char *`` argument). ! ! If the library function returns a type different from ``int``, the ! ``restype`` attribute can be set to a ctypes type that describes the ! return type, or to ``None`` meaning no return value (``void``). ! ! The optional ``argtypes`` attribute can be set to a sequence of ctypes ! types that the function expects. ! ! If needed, the function can (as in C) be called with more arguments ! than the length of the argtypes sequence. ! ! The optional ``errcheck`` attribute can be set to a Python callable, ! which can be used to validate and/or process the library function's return ! value. ``errcheck`` will be called with three arguments, after the ! library function has returned:: ! ! errcheck(retval, function, arguments) ! ! ``retval`` is the value that the library function returned, converted ! according to ``restype``. ``function`` is the ctypes function object ! (libc.atoi in this case), and ``arguments`` is a tuple containing the ! arguments that have been used to call ``function``. ``errcheck`` ! should validate the library function result, raise an error if it ! detects a failure, or return the needed return value otherwise. ! ! Function prototypes ! ................... ! ! Another way to access a function exported from shared libraries is to ! first create a prototype by calling a factory function, specifying the ! return type and the argument types. The factory function itself ! specifies the calling convention: ``CFUNCTYPE`` uses the standard C ! calling convention, ``WINFUNCTYPE`` (Windows only) uses the stdcall ! calling convention. The factory function must be called with the ! return type plus the argument types. For the C ``atoi`` function one ! would use ``CFUNCTYPE(c_int, c_char_p)``. ! ! This returns a function prototype, which is a ctypes type representing ! all functions that are compatible with the calling convention, return ! type, and argument types. ! ! The ``CFUNCTYPE`` and ``WINFUNCTYPE`` factory functions cache and ! reuse the types they create in internal caches, so is is cheap to call ! them over and over with the same or different arguments. ! ! An instance of this function prototype, bound to a foreign library ! function, can be created by calling the prototype with the name of the ! function as string, and a loaded library:: ! ! proto = CFUNCTYPE(c_int, c_char_p) ! atoi = proto("atoi", libc) ! ! Parameter flags ! ............... ! ! It is possible to specify a third argument ``paramflags`` when calling ! the prototype. This is used to specify additional information for ! each argument: direction of data transfer, the name, and a default ! value. ! ! A tuple with the same length as ``argtypes`` (the second argument in ! the prototype call) must be used. Each item in this tuple must be a ! tuple, having either one, two, or three items. ! ! The first item is the direction flag, an integer specifying if this is ! an input (use ``1``) or an output (use ``2``) parameter. The optional ! second item is a string containing the parameter name, the optional ! third item is a default value for the parameter. ! ! If parameter names are specified, the function object created can be ! called with named arguments in the usual way. Arguments with default ! values do not need to be specified when the function is called. ! ! ``out`` parameter types must be pointer types. When the function ! object is called, ctypes will automatically create empty instances of ! them, pass them to the library function, retrieve the value from them, ! and return the value, if there is exactly one ``out`` parameter, or a ! tuple of values, if there is more than one ``out`` parameter. The ! original foreign function return value is lost in this case (but see ! below for how it can be retrieved). ! ! If ``paramflags`` have been used in the prototype call, and an ! ``errcheck`` attribute is also present, the ``errcheck`` callable will ! be called with a fourth parameter ``outargs``:: ! ! errcheck(retval, function, arguments, outargs) ! ! ``outargs`` is a tuple containing all the ``out`` parameters that ! ctypes has created. Without the ``errcheck`` function ctypes would ! retrieve the values contained in these pointer objects, and return ! them. The ``errcheck`` function can let ctypes continue this ! processing by returning the ``outargs`` tuple. It could also return ! something else, or raise an error if it detects that the library ! function has failed. ! ! Callback functions ! .................. ! ! ctypes is able to create C callable functions from Python callables. ! This is useful because sometimes library functions need a callback ! function parameter; the ``qsort`` C function is such an example. ! ! Callback functions are created by first creating a function prototype ! with a call to ``CFUNCTYPE`` or ``WINFUNCTYPE``, specifying the return ! type and the argument types that the callback function will receive. ! ! Calling the prototype with a single Python callable will create and ! return a C-callable function pointer or callback function. Note that ! this allows using prototypes as decorators creating callback ! functions (Windows example):: ! ! @WINFUNCTYPE(BOOL, HWND, LPARAM) ! def enumwindowsproc(hwnd, lParam): ! .... ! return True ! ! When a Python exception is raised in the Python callable, the return ! value of the C callable function is undefined. ! ! Important note: You must keep a reference to the callback AS LONG as ! foreign code will call it! Segfaults will result if the callback is ! cleaned up by Python's garbage collector and external code then ! tries to call it. ! ! Callback objects can also be called from Python - this may be useful ! for debugging. ! ! ! COM methods (Windows only) .......................... + + XXX Should this be left undocumented? Mentioned for completeness. + + The prototypes created by ``WINFUNCTYPE`` can be called with a + positive small integer ``index``, a string ``name``, an optional + ``paramflags`` tuple, and a optional ``iid`` parameter. + + This creates a function object wrapping a COM method. ``index`` is + the index into the COM object's virtual function table, ``name`` is + the name of the COM method (only useful for debugging), ``paramflags`` + has the same meaning as for normal function objects, and ``iid`` is a + string or buffer containing the interface id of the COM interface + this method belongs to. ``iid`` is used to get extended COM error + information in case the method returns a FAILED ''HRESULT`` value. + + Note that COM methods expect an additional first argument that is NOT + listed in the prototypes ``argtypes`` when they are called: this must + be the integer address of a COM interface pointer. + + + Simple types + ------------ + + Simple types have some special behaviour: When they are accessed as + structure or union fields, items of array instances, or as foreign + function return values, they are transparently converted from and to + the native Python types int, long, string, and unicode. + + This is *not* the case for subclasses of simple data types, so while a + ``c_void_p`` type is transparently converted from and to Python + integer or long, a subclass of c_void_p is *not* converted. This + allows you to define new behaviour almost completely. + + Class attributes of simple types + ................................ + + ``__ctype__be__``, ``__ctype_le__`` + + If the type supports different byte order (pointer types do NOT + support this), ``__ctype_be__`` and ``__ctype_le__`` are types + with bug endian and little endian byte order. For example, + ``c_int.__ctype_be__`` is an integer type with the memory block in + big endian byte order. + + ``_type_`` + + Implementation artifact: the typecode for this type, a single + character string code compatible to what the ``struct`` module uses. + Additional characters are used for types that the ``struct`` module + does not support. + + + Class methods of simple types + ............................. + + (To be exact, these are not class methods, instead these are methods + of the metaclass. The most prominent difference to classmethods is + that you can call these methods on the class, but not on the instance + of the simple type.) + + ``__ctypes_from_outparam__`` + + TBD + + ``from_address`` + + TBD + + ``from_param`` + + This class method is used to adapt function parameters. If a type + is specified in a function's argtypes sequence, in a function call + the ``from_param(arg)`` method will be called with the actual + argument, and the result will be passed to the foreign function + call as a parameter. + + ``from_param`` usually returns an internal object that you cannot + use in Python code - it only makes sense to pass this object to + foreign functions. + + On one hand, ``from_param`` is a performance optimization - it + allows you to pass Python integers to function calls expecting a + ``c_int`` argument type, without having to create a full-featured + ``c_int`` instance. + + On the other hand, ``from_param`` can adapt other objects to + parameters. XXX explain the automatic ``byref`` call for byref + arguments. + + ``in_dll`` + + TBD + + Instance attributes of simple types + ................................... + + ``value`` + + Allows to get or set the current value of the object. For simple + types, this is always a native Python object like integer, long, + string, unicode, or None. + + ``_objects`` (never modify this) + + Implementation artifact: a Python object keeping references to + other objects which must be kept alive. Never modify anything on + the returned object. XXX Should probably not be exposed. + + ``_b_base_`` (readonly) + + Implementation artifact: the base object owning the memory block + (if any). + + ``_b_needsfree_`` (readonly) + + Implementation artifact: does this object have to free its memory + block on destruction. + + ``_as_parameter_`` (readonly) + + Implementation artifact (?): how to pass this object as a function + parameter. + + + Numeric types + ............. + + Integer types are ``c_byte``, ``c_short``, ``c_int``, ``c_long``, + ``c_longlong`` and their unsigned variants ``c_ubyte``, ``c_ushort``, + ``c_uint``, ``c_ulong`` and ``c_ulonglong``, floating point types are + ``c_float`` and ``c_double``. + + The constructor and the ``from_param`` class method accept a Python + integer for integer types, a Python float for floating point types. + + On 32-bit platforms where sizeof(int) == sizeof(long), ``c_int`` is an + alias for ``c_long``, on 64-bit platforms where sizeof(long) == + sizeof(long long), ``c_long`` is an alias for ``c_longlong``. + + Character types + ............... + + Character types are ``c_char`` and ``c_wchar``, representing the C + ``char`` and ``wchar_t`` types. + + The constructor and the ``from_param`` class method accept a single + character Python string or unicode string. Conversion between string + and unicode, if needed, is done according to the ctypes + encoding/decoding rules. + + + Pointer types + ............. + + The only simple pointer type is ``c_void_p``, which represents the C + ``void *`` data type. ``c_void_p`` can also be written as + ``POINTER(None)``. + + The constructor accepts one optional argument, which must be an + integer or long (interpreted as an address), or ``None``. + + The ``from_param`` class method accepts everything that could be used + as a pointer. XXX Should accept objects using the buffer interface as + well. + + The ``value`` attribute accepts and returns None or integer. + + XXX Shouldn't the constructor accept the same types as from_param? + + + String types + ............ + + ctypes has the ``c_char_p`` and ``c_wchar_p`` types which represent + const pointers to zero terminated strings in C: ``const char *`` and + ``const wchar_t *``. Since strings and Unicode instances are + immutable, these types should be considered readonly: do not pass them + to functions that write into the buffer. + + The constructor accepts one optional argument, which must be a Python + or unicode string, an integer, or ``None``. + + The ``from_param`` class method accepts a string or a Unicode string, + as well as ``None``. Conversion between string and Unicode, if + needed, is done according to the ctypes encoding/decoding rules. + + XXX Why does the constructor accept an integer, and from_param doesn't? + + Structure and union types + ------------------------- + + ctypes provides the abstract base classes ``Structure`` and ``Union`` + to define structure and union types. Subclasses must at least define + a ``_fields_`` attribute. + + Defining field names and types + .............................. + + ``_fields_`` must be a sequence of tuples. The first item of each + tuple is a string specifying the name of the structure/union field. + The second item must by a ctypes type. + + A descriptor will be created for each field, allowing you to access the + field's contents from instances. Accessed from the class, the fields + expose readonly ``.offset`` and ``.size`` attributes. ``offset`` is + the byte-offset of the field from the beginning of the + structure/union, ``size`` is the number of bytes the field contains. + + A simple example is a POINT structure containing integer fields named + ``x`` and ``y``:: + + class Point(Structure): + _fields_ = [("x", c_int), + ("y", c_int)] + + + + Field alignment + ............... + + Normally fields are aligned in the same way as the host's C compiler + would do it. This native alignment can be overridden by setting a + ``_pack_`` attribute in the type. It must be a small positive integer + which is the maximum field alignment. + + Bit fields + .......... + + Integer fields support bit sizes. The bit-size must be specified as + the third item of the ``_fields_`` tuple. Bit fields are constructed + in the same way the host's C compiler does it. For bit fields, the + field descriptor's ``.size`` attribute contains the number of bits in + the high word, and the bit offset from the beginning of the structure in + the low word. XXX is that correct? + + Recursive data types + .................... + + To define recursive types, it is possible to assign the ``_fields_`` + value *after* the class statement. Here is an example of a linked + list data structure, which contains a pointer to itself:: + + class Node(Structure): + pass + Node._fields_ = [("next", POINTER(Node)), + ("value", ...)] + + ``_fields_`` must be set, and cannot be changed, after the type is + used for the first time. + + Byte order + .......... + + It is possible to create Structure and Union types using non-native + byte order by using the ``BigEndianStructure``, + ``LittleEndianStructure``, ``BigEndianUnion``, and + ``LittleEndianUnion`` base classes. Structures and Unions with + non-native byte order do *not* support pointer fields. + + + Builtin functions + ----------------- + + ``addressof(object)`` + + Returns the address of a ctypes instance as an integer. + + ``alignment(type_or_object)`` + + Returns the alignment requirements in bytes of a ctypes type or + instance. + + ``byref(object)`` + + Returns a light-weight pointer to a ctypes instance. The returned + object can only be used as function call parameter. Behaves the + same as calling ``pointer(object)``, but is a lot faster. Same as + ``&object`` in C. + + ``cast(object, typ)`` + + This function is similar to the cast operator in C. Returns a new + instance of ``type`` which shares the memory block of ``object``. + ``typ`` must be a pointer type. + + ``CFUNCTYPE(restype, *argtypes)`` + + Create a function prototype using the C calling convention. + + + ``create_string_buffer(init, size=None)`` + + Convenience function to create a mutable character buffer. + + ``init`` must be a string. If ``size`` is supplied it must be a + positive integer that specifies the size of the buffer, otherwise + the length of the ``init`` string is used. + This function returns a ctypes array of characters ``c_char``. + + ``create_unicode_buffer(init, size=None)`` + + Convenience function to create a mutable unicode buffer. + + ``init`` must be a unicode string. If ``size`` is supplied it + must be a positive integer that specifies the number of characters + in the buffer, otherwise the length of the ``init`` string is + used. This function returns a ctypes array of characters ``c_wchar``. + + + ``DllCanUnloadNow()``, ``DllGetClassObject(rclsid, riid, ppv)`` (Windows only) + + Functions used to implement COM servers. + + + ``FormatError([code])`` (Windows only) + + Returns a textual description of the error code, or the last error + code set by Windows. + + ``GetLastError()`` (Windows only) + + Returns the last error code set by Windows. + + ``memmove(dst, src, count)`` + + Same as the standard C ``memmove`` library function: copies + ``count`` bytes from ``src`` to ``dst``. ``dst`` and ``src`` must + be integers or anything else that can be converted into a pointer. + + ``memset(dst, c, count)`` + + Same as the standard C ``memset`` function. Fills the memory block + at address ``dst`` with ``count`` bytes of value ``c``. ``dst`` must be + an integer specifying an address, or a ctypes instance. + + + ``pointer(object)`` + + This function creates a new pointer instance, pointing to the + supplied argument which must be an instance of a ctypes type. The + return pointer is of type ``POINTER(type(object))``. If you have + a ctypes instance, and you want to pass the address of it to a + function call, you should use ``byref(object)`` instead which is + much faster. + + NULL pointer instances are boolean``False``, so to check for a + NULL pointer do this:: + + # assuming ptr is in ctypes pointer instance + if ptr: + print "Non-NULL pointer instance" + else: + print "NULL pointer instance" + + + ``POINTER(cls)`` + + This factory function creates and returns a new ctypes type. + Pointer types are cached, so calling this function is cheap. + + To create a ``NULL`` pointer instance, call the created type + without an argument:: + + null_ptr = POINTER(c_int)() + + + ``set_conversion_mode(encoding, errors)`` + + This function sets the encoding/decoding rules which are used when + ctypes has to convert between unicode and byte strings. It + returns the previous encoding, as well as a tuple of any errors. + If not set, default conversions are used: + On Windows, ``msbc, ignore`` , on other systems, ``ascii, strict``. + + + ``sizeof(type_or_object)`` + + Returns the size in bytes of a ctypes type or instance memory + buffer. Does the same as the C sizeof() function. + + + ``string_at(addr[, size])`` + + This function does the same as the Python ``PyString_FromString`` / + ``PyString_FromStringAndSize`` C api functions. + + ``WinError(code=None, descr=None)`` + + XXX This is probably the worst named thing in ctypes! + + This function creates a ``WindowsError`` instance. If ``code`` is + not specified, GetLastError() is called to determine the error + code. If ``descr`` is not specified, ``FormatError`` is called to + get a textual description of the error. + + ``WINFUNCTYPE(restype, *argtypes)`` (Windows only) + + Create a function prototype using the __stdcall calling convention + (on Windows), or using the C calling convention (on Windows CE). + + ``wstring_at(addr[, size])`` + + This function does the same as the Python ``PyUnicode_FromWideString`` + C api function. If ``size`` is not specified, ``wcslen`` is used + to determine the string length. + + + Deprecated functions + .................... + + These deprecated functions are still supported for backwards + comatibility, they should not be used for new code: + + ``c_buffer(init, size=None)`` + + Deprecated. Use ``create_string_buffer()`` instead. + + ``ARRAY(cls, len)`` + + Deprecated. Use ``cls * len`` instead. + + ``SetPointerType(pointer_class, cls)`` + + Deprecated. |
From: Thomas H. <th...@us...> - 2006-03-24 20:40:38
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3027 Modified Files: mkpydoc.py Log Message: *** empty log message *** Index: mkpydoc.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/mkpydoc.py,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** mkpydoc.py 24 Mar 2006 20:02:37 -0000 1.6 --- mkpydoc.py 24 Mar 2006 20:40:31 -0000 1.7 *************** *** 282,287 **** def main(): ! ## convert("manual.txt", "manual.tex") ! convert("tutorial.txt", "../../../trunk/Doc/lib/libctypes.tex") if missing: mod = open("missing.py", "w") --- 282,286 ---- def main(): ! convert("libctypes.txt", "../../../trunk/Doc/lib/libctypes.tex") if missing: mod = open("missing.py", "w") |
From: Thomas H. <th...@us...> - 2006-03-24 20:37:27
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1486 Added Files: .cvsignore libctypes.txt reference.txt Log Message: libctypes.txt is the top-level file for generating the Python docs. --- NEW FILE: .cvsignore --- manual *.pyc *.pyo missing.py tutorial --- NEW FILE: libctypes.txt --- Blah blah short overview of ctypes. .. include:: tutorial.txt .. include:: reference.txt --- NEW FILE: reference.txt --- ctypes manual +++++++++++++ Shared libaries, DLLs --------------------- class LibraryLoader ................... predefined library loaders .......................... |
From: Thomas H. <th...@us...> - 2006-03-24 20:02:45
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14432 Added Files: mkpydoc.py Log Message: remove and add with executable flag set --- NEW FILE: mkpydoc.py --- #!/usr/bin/python # Convert the ctypes docs to LaTeX for use in Python docs # This script is a hacked version taken from the Optik SVN repository. import sys, os import re from popen2 import popen2 from glob import glob import rfc822 from distutils.dep_util import newer_group, newer from docutils.core import Publisher from docutils.readers.standalone import Reader as StandaloneReader from docutils.transforms import Transform from docutils.writers.latex2e import Writer as LaTeXWriter, LaTeXTranslator from docutils import nodes class OptikReader(StandaloneReader): #default_transforms = (StandaloneReader.default_transforms + # (ReplacementTransform,)) pass from markup import codemarkup missing = set() class PyLaTeXWriter(LaTeXWriter): def __init__(self): LaTeXWriter.__init__(self) self.translator_class = PyLaTeXTranslator class PyLaTeXTranslator(LaTeXTranslator): remap_title = { } # XXX need to factor this out module_name = "ctypes" module_summary = "A foreign function library for Python." module_type = "standard" module_author = "Thomas Heller" module_author_email = "th...@py..." module_synopsis = ("A foreign function library for Python.") version_added = "2.5" refuri_override = { "reference" : "reference-guide", "callbacks" : "option-callbacks", } def __init__(self, document): LaTeXTranslator.__init__(self, document) self.head_prefix = [] self.head = [] self.body_prefix = [] self.in_title = False # Disable a bunch of methods from the base class. empty_method = lambda self: None for nodetype in ('field_argument', 'field_body', 'field_list', 'field_name'): setattr(self, 'visit_' + nodetype, empty_method) setattr(self, 'depart_' + nodetype, empty_method) self.head_prefix = [ "\\section{\\module{%(module_name)s} --- %(module_summary)s}\n" "\\declaremodule{%(module_type)s}{%(module_name)s}\n" "\\moduleauthor{%(module_author)s}{%(module_author_email)s}\n" "\\modulesynopsis{%(module_synopsis)s}\n" "\\versionadded{%(version_added)s}\n" % vars(self.__class__) ] def astext(self): return ''.join(self.head_prefix + self.head + self.body_prefix + self.body + self.body_suffix) def generate_section_label(self, title): title = title.lower() title = re.sub(r'\([^\)]*\)', '', title) title = re.sub(r'[^\w\s\-]', '', title) title = re.sub(r'\b(the|an?|and|your|are)\b', '', title) title = re.sub(r'(example \d+).*', r'\1', title) ## title = title.replace("optik", "optparse") return "ctypes-" + "-".join(title.split()) def visit_document(self, node): pass def depart_document(self, node): pass def visit_docinfo(self, node): #print "visit_docinfo: %r" % node self.docinfo = [] def depart_docinfo(self, node): #print "depart_docinfo: %r" % node self.body = self.docinfo + self.body self.docinfo = None def visit_docinfo_item(self, node, name): #print "visit_docinfo_item: node=%r, name=%r" % (node, name) if name == "author": (name, email) = rfc822.parseaddr(node.astext()) self.docinfo.append("\\sectionauthor{%s}{%s}\n" % (name, email)) raise nodes.SkipNode def depart_docinfo_item(self, node): pass #def visit_field(self, node): # (name, value) = (node[0].astext(), node[1].astext()) # print "visit_field: node=%r (name=%r, value=%r)" % (node, name, value) # if self.docinfo is not None: # if name == "VersionAdded": # self.docinfo.append("\\versionadded{%s}\n" % value) # raise nodes.SkipNode _quoted_string_re = re.compile(r'\"[^\"]*\"') _short_opt_string_re = re.compile(r'-[a-zA-Z]') _long_opt_string_re = re.compile(r'--[a-zA-Z-]+') _identifier_re = re.compile(r'[a-zA-Z_][a-zA-Z_0-9]*' r'(\.[a-zA-Z_][a-zA-Z_0-9]*)*' r'(\(\))?$') def visit_literal(self, node): assert isinstance(node[0], nodes.Text) text = node[0].data #### text = re.sub(r'optik(\.[a-z]+)?\.', 'optparse.', text) if self.in_title: cmd = None elif self._quoted_string_re.match(text): cmd = 'code' elif self._short_opt_string_re.match(text): cmd = 'programopt' elif self._long_opt_string_re.match(text): cmd = 'longprogramopt' text = text[2:] elif self._identifier_re.match(text): cmd = codemarkup.get(text) if cmd is None: ## print "warning: unrecognized code word %r" % text missing.add(text) cmd = 'code' else: cmd = 'code' self.literal = 1 node[0].data = text if cmd is not None: self.body.append('\\%s{' % cmd) def depart_literal(self, node): if not self.in_title: self.body.append('}') self.literal = 0 def visit_literal_block(self, node): self.body.append("\\begin{verbatim}\n") self.verbatim = 1 def depart_literal_block(self, node): self.verbatim = 0 self.body.append("\n\\end{verbatim}\n") def visit_title(self, node): title = node.astext() title = self.remap_title.get(title, title) label = self.generate_section_label(title) #print "%s -> %s" % (title, label) section_name = self.d_class.section(self.section_level + 1) self.body.append("\n\n\\%s{" % section_name) self.context.append("\\label{%s}}\n" % label) self.in_title = True def depart_title(self, node): self.in_title = False self.body.append(self.context.pop()) def visit_target(self, node): pass def depart_target(self, node): pass def bookmark(self, node): pass def visit_definition(self, node): pass def depart_definition(self, node): pass def visit_definition_list_item(self, node): pass def depart_definition_list_item(self, node): pass # override merely to lose the newline, which causes problems # in one obscure case -- can go away if the docutils developers # accept my second patch to latex2e.py def depart_term(self, node): self.body.append(']') def visit_reference(self, node): if node.has_key('refuri'): refuri = node['refuri'] basename = os.path.splitext(refuri)[0] label = "optparse-" + self.refuri_override.get(basename, basename) print "got refuri=%r, label=%r" % (refuri, label) elif node.has_key('refid'): label = self.generate_section_label(node['refid']) print "got refid=%r, label=%r" % (node['refid'], label) else: print "warning: unhandled reference: node=%r" % node LaTeXTranslator.visit_reference(self, node) self.body.append("section~\\ref{%s}, " % label) raise nodes.SkipDeparture _quoted_phrase_re = re.compile(r'"([^"]+)"') _em_dash_re = re.compile(r'\s+\-\-\s+') def visit_Text(self, node): text = node.astext() if self.in_title: text = self.remap_title.get(text, text) if not (self.literal or self.verbatim): text = self._em_dash_re.sub(u"\u2014", text) text = self._quoted_phrase_re.sub(u"\u201C\\1\u201D", text) text = re.sub(r'\bdocument\b', "section", text) #### text = re.sub(r'optik(\.[a-z]+)?', 'optparse', text) text = self.encode(text) # A couple of transformations are easiest if they go direct # to LaTeX, so do them *after* encode(). ## text = text.replace("Optik", "\\module{optparse}") text = text.replace("UNIX", "\\UNIX{}") self.body.append(text) def depart_Text(self, node): pass def concatenate_sources(sources, target): print "concatenating source files to %s" % target outdir = os.path.dirname(target) if not os.path.isdir(outdir): os.makedirs(outdir) outfile = open(target, "wt") for filename in sources: file = open(filename, "rt") for line in file: outfile.write(line) outfile.write("\n\n") file.close() outfile.close() def convert(infilename, outfilename): print "converting %s to %s" % (infilename, outfilename) pub = Publisher() pub.set_components('standalone', # reader 'restructuredtext', # parser 'latex') # writer (arg, will be discarded) pub.reader = OptikReader() pub.writer = PyLaTeXWriter() pub.process_programmatic_settings(None, None, None) pub.set_source(source_path=infilename) pub.set_destination(destination_path=outfilename) pub.publish() def main(): ## convert("manual.txt", "manual.tex") convert("tutorial.txt", "../../../trunk/Doc/lib/libctypes.tex") if missing: mod = open("missing.py", "w") mod.write("# possible markups:\n") mod.write("# module, code, method, class, function, member, var. Are there more?\n") mod.write("codemarkup = {\n") keys = sorted(missing) for name in keys: mod.write(" '%s': 'code',\n" % name) mod.write("}\n") mod.close() main() |
From: Thomas H. <th...@us...> - 2006-03-24 20:02:06
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13977 Removed Files: mkpydoc.py Log Message: remove and add with executable flag set --- mkpydoc.py DELETED --- |
From: Thomas H. <th...@us...> - 2006-03-24 19:58:58
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12373 Modified Files: tutorial.txt Log Message: Change title underlines. Index: tutorial.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/tutorial.txt,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** tutorial.txt 24 Mar 2006 19:48:20 -0000 1.5 --- tutorial.txt 24 Mar 2006 19:58:50 -0000 1.6 *************** *** 1,5 **** - =============== ctypes tutorial ! =============== This tutorial describes version 0.9.9 of ``ctypes``. --- 1,4 ---- ctypes tutorial ! +++++++++++++++ This tutorial describes version 0.9.9 of ``ctypes``. *************** *** 8,12 **** Loading dynamic link libraries ! ============================== ``ctypes`` exports the ``cdll``, and on Windows also ``windll`` and --- 7,11 ---- Loading dynamic link libraries ! ------------------------------ ``ctypes`` exports the ``cdll``, and on Windows also ``windll`` and *************** *** 51,55 **** Accessing functions from loaded dlls ! ==================================== Functions are accessed as attributes of dll objects:: --- 50,54 ---- Accessing functions from loaded dlls ! ------------------------------------ Functions are accessed as attributes of dll objects:: *************** *** 97,101 **** Calling functions ! ================= You can call these functions like any other Python callable. This --- 96,100 ---- Calling functions ! ----------------- You can call these functions like any other Python callable. This *************** *** 147,151 **** Simple data types ! ================= ``ctypes`` defines a number of primitive C compatible data types : --- 146,150 ---- Simple data types ! ----------------- ``ctypes`` defines a number of primitive C compatible data types : *************** *** 223,227 **** Calling functions, continued ! ============================ Note that printf prints to the real standard output channel, *not* to --- 222,226 ---- Calling functions, continued ! ---------------------------- Note that printf prints to the real standard output channel, *not* to *************** *** 258,262 **** Calling functions with your own custom data types ! ================================================= You can also customize ``ctypes`` argument conversion to allow --- 257,261 ---- Calling functions with your own custom data types ! ------------------------------------------------- You can also customize ``ctypes`` argument conversion to allow *************** *** 283,287 **** Specifying the required argument types (function prototypes) ! ============================================================ It is possible to specify the required argument types of functions --- 282,286 ---- Specifying the required argument types (function prototypes) ! ------------------------------------------------------------ It is possible to specify the required argument types of functions *************** *** 325,329 **** Return types ! ============ By default functions are assumed to return integers. Other return --- 324,328 ---- Return types ! ------------ By default functions are assumed to return integers. Other return *************** *** 399,403 **** Passing pointers (or: passing parameters by reference) ! ====================================================== Sometimes a C api function expects a *pointer* to a data type as --- 398,402 ---- Passing pointers (or: passing parameters by reference) ! ------------------------------------------------------ Sometimes a C api function expects a *pointer* to a data type as *************** *** 426,430 **** Structures and Unions ! ===================== Structures and unions must derive from the ``Structure`` and ``Union`` --- 425,429 ---- Structures and Unions ! --------------------- Structures and unions must derive from the ``Structure`` and ``Union`` *************** *** 503,507 **** Arrays ! ====== Arrays are sequences, containing a fixed number of instances of the --- 502,506 ---- Arrays ! ------ Arrays are sequences, containing a fixed number of instances of the *************** *** 550,554 **** Pointers ! ======== Pointer instances are created by calling the ``pointer`` function on a --- 549,553 ---- Pointers ! -------- Pointer instances are created by calling the ``pointer`` function on a *************** *** 601,605 **** Pointer classes/types ! ===================== Behind the scenes, the ``pointer`` function does more than simply --- 600,604 ---- Pointer classes/types ! --------------------- Behind the scenes, the ``pointer`` function does more than simply *************** *** 621,625 **** Incomplete Types ! ================ **Note:** This code seems to work in older versions, but the past --- 620,624 ---- Incomplete Types ! ---------------- **Note:** This code seems to work in older versions, but the past *************** *** 689,693 **** Callback functions ! ================== (This example is too long, I should have used a shorter array) --- 688,692 ---- Callback functions ! ------------------ (This example is too long, I should have used a shorter array) *************** *** 858,862 **** Accessing values exported from dlls ! =================================== Sometimes, a dll not only exports functions, it also exports --- 857,861 ---- Accessing values exported from dlls ! ----------------------------------- Sometimes, a dll not only exports functions, it also exports *************** *** 935,939 **** Surprises ! ========= There are some corners in ``ctypes`` where you may be expect something --- 934,938 ---- Surprises ! --------- There are some corners in ``ctypes`` where you may be expect something *************** *** 979,983 **** Bugs, ToDo and non-implemented things ! ===================================== XXX Wrong --- 978,982 ---- Bugs, ToDo and non-implemented things ! ------------------------------------- XXX Wrong |
From: Thomas H. <th...@us...> - 2006-03-24 19:57:14
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11354 Modified Files: mkpydoc.py Log Message: Remove more optik-specific stuff. Index: mkpydoc.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/mkpydoc.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** mkpydoc.py 24 Mar 2006 17:47:50 -0000 1.3 --- mkpydoc.py 24 Mar 2006 19:57:06 -0000 1.4 *************** *** 1,5 **** #!/usr/bin/python ! # Convert the Optik docs to LaTeX for use in Python docs import sys, os --- 1,7 ---- #!/usr/bin/python ! # Convert the ctypes docs to LaTeX for use in Python docs ! ! # This script is a hacked version taken from the Optik SVN repository. import sys, os *************** *** 30,36 **** class PyLaTeXTranslator(LaTeXTranslator): remap_title = { - "The Tao of Option Parsing" : "Background", - "Optik Tutorial": "Tutorial", - "Optik Reference Guide": "Reference Guide", } --- 32,35 ---- *************** *** 87,91 **** title = re.sub(r'\b(the|an?|and|your|are)\b', '', title) title = re.sub(r'(example \d+).*', r'\1', title) ! title = title.replace("optik", "optparse") return "ctypes-" + "-".join(title.split()) --- 86,90 ---- title = re.sub(r'\b(the|an?|and|your|are)\b', '', title) title = re.sub(r'(example \d+).*', r'\1', title) ! ## title = title.replace("optik", "optparse") return "ctypes-" + "-".join(title.split()) *************** *** 244,248 **** # A couple of transformations are easiest if they go direct # to LaTeX, so do them *after* encode(). ! text = text.replace("Optik", "\\module{optparse}") text = text.replace("UNIX", "\\UNIX{}") --- 243,247 ---- # A couple of transformations are easiest if they go direct # to LaTeX, so do them *after* encode(). ! ## text = text.replace("Optik", "\\module{optparse}") text = text.replace("UNIX", "\\UNIX{}") *************** *** 283,287 **** def main(): ! convert("manual.txt", "manual.tex") if missing: mod = open("missing.py", "w") --- 282,287 ---- def main(): ! ## convert("manual.txt", "manual.tex") ! convert("tutorial.txt", "../../../trunk/Doc/lib/libctypes.tex") if missing: mod = open("missing.py", "w") |
From: Thomas H. <th...@us...> - 2006-03-24 19:48:23
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6450 Modified Files: tutorial.txt Log Message: Streamline formatting. Index: tutorial.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/tutorial.txt,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** tutorial.txt 24 Mar 2006 19:03:12 -0000 1.4 --- tutorial.txt 24 Mar 2006 19:48:20 -0000 1.5 *************** *** 7,28 **** when needed. ! 1. Loading dynamic link libraries ! ================================= ! ``ctypes`` exports the ``cdll``, and on Windows also ``windll`` ! and ``oledll`` objects to load dynamic link libraries. ! You load libraries by accessing them as attributes of these ! objects. ``cdll`` loads libraries which export functions using the [...1388 lines suppressed...] --- 967,985 ---- >>> rc.b = temp1 ! Note that ``temp0`` and ``temp1`` are objects still using the internal ! buffer of the ``rc`` object above. So executing ``rc.a = temp0`` ! copies the buffer contents of ``temp0`` into ``rc`` 's buffer. This, ! in turn, changes the contents of ``temp1``. So, the last assignment ! ``rc.b = temp1``, doesn't have the expected effect. ! Keep in mind that retrieving subobjects from Structure, Unions, and ! Arrays doesn't *copy* the subobject, it does more retrieve a wrapper ! object accessing the root-object's underlying buffer. ! Bugs, ToDo and non-implemented things ! ===================================== + XXX Wrong Bitfields are not implemented. |
From: Thomas H. <th...@us...> - 2006-03-24 19:03:57
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12411 Modified Files: tutorial.txt Added Files: table.txt Log Message: save the table separately Index: tutorial.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/tutorial.txt,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** tutorial.txt 21 Mar 2006 21:17:51 -0000 1.3 --- tutorial.txt 24 Mar 2006 19:03:12 -0000 1.4 *************** *** 3,12 **** =============== - This tutorial is based on Thomas Heller's tutorial, which is included in - ctypes distribution, and available online at - http://starship.python.net/crew/theller/ctypes/tutorial.html - - .. contents:: - This tutorial describes version 0.9.9 of ``ctypes``. Since older versions are quite common, I'll mention major differences --- 3,6 ---- *************** *** 160,203 **** ``ctypes`` defines a number of primitive C compatible data types : ! +---------------+-----------------------+-----------+ ! |ctypes' type |C type |Python type| ! +===============+=======================+===========+ ! |``c_char`` |``char`` |character | ! +---------------+-----------------------+-----------+ ! |``c_byte`` |``char`` |integer | ! +---------------+-----------------------+-----------+ ! |``c_ubyte`` |``unsigned char`` |integer | ! +---------------+-----------------------+-----------+ ! |``c_short`` |``short`` |integer | ! +---------------+-----------------------+-----------+ ! |``c_ushort`` |``unsigned short`` |integer | ! +---------------+-----------------------+-----------+ ! |``c_int`` |``int`` |integer | ! +---------------+-----------------------+-----------+ ! |``c_uint`` |``unsigned int`` |integer | ! +---------------+-----------------------+-----------+ ! |``c_long`` |``long`` |integer | ! +---------------+-----------------------+-----------+ ! |``c_ulong`` |``unsigned long`` |long | ! +---------------+-----------------------+-----------+ ! |``c_longlong`` |``__int64`` or |long | ! | |``long long`` | | ! +---------------+-----------------------+-----------+ ! |``c_ulonglong``|``unsigned __int64`` or|long | ! | |``unsigned long long`` | | ! +---------------+-----------------------+-----------+ ! |``c_float`` |``float`` |float | ! +---------------+-----------------------+-----------+ ! |``c_double`` |``double`` |float | ! +---------------+-----------------------+-----------+ ! |``c_char_p`` |``char *`` |string or | ! | |(NUL terminated) |``None`` | ! +---------------+-----------------------+-----------+ ! |``c_wchar_p`` |``wchar_t *`` |unicode or | ! | |(NUL terminated) |``None`` | ! +---------------+-----------------------+-----------+ ! |``c_void_p`` |``void *`` |integer or | ! | | |``None`` | ! +---------------+-----------------------+-----------+ All these types can be created by calling them with an optional --- 154,158 ---- ``ctypes`` defines a number of primitive C compatible data types : ! XXX table missing, rst2latex is not able to handle it ;-( All these types can be created by calling them with an optional --- NEW FILE: table.txt --- +---------------+-----------------------+-----------+ |ctypes' type |C type |Python type| +===============+=======================+===========+ |``c_char`` |``char`` |character | +---------------+-----------------------+-----------+ |``c_byte`` |``char`` |integer | +---------------+-----------------------+-----------+ |``c_ubyte`` |``unsigned char`` |integer | +---------------+-----------------------+-----------+ |``c_short`` |``short`` |integer | +---------------+-----------------------+-----------+ |``c_ushort`` |``unsigned short`` |integer | +---------------+-----------------------+-----------+ |``c_int`` |``int`` |integer | +---------------+-----------------------+-----------+ |``c_uint`` |``unsigned int`` |integer | +---------------+-----------------------+-----------+ |``c_long`` |``long`` |integer | +---------------+-----------------------+-----------+ |``c_ulong`` |``unsigned long`` |long | +---------------+-----------------------+-----------+ |``c_longlong`` |``__int64`` or |long | | |``long long`` | | +---------------+-----------------------+-----------+ |``c_ulonglong``|``unsigned __int64`` or|long | | |``unsigned long long`` | | +---------------+-----------------------+-----------+ |``c_float`` |``float`` |float | +---------------+-----------------------+-----------+ |``c_double`` |``double`` |float | +---------------+-----------------------+-----------+ |``c_char_p`` |``char *`` |string or | | |(NUL terminated) |``None`` | +---------------+-----------------------+-----------+ |``c_wchar_p`` |``wchar_t *`` |unicode or | | |(NUL terminated) |``None`` | +---------------+-----------------------+-----------+ |``c_void_p`` |``void *`` |integer or | | | |``None`` | +---------------+-----------------------+-----------+ |
From: Thomas H. <th...@us...> - 2006-03-22 07:09:14
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20880 Modified Files: simple_types.txt manual.html Log Message: Index: manual.html =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/manual.html,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** manual.html 21 Mar 2006 21:17:51 -0000 1.3 --- manual.html 22 Mar 2006 07:09:10 -0000 1.4 *************** *** 307,313 **** <li><a class="reference" href="#parameter-flags" id="id7" name="id7">Parameter flags</a></li> <li><a class="reference" href="#com-methods-windows-only" id="id8" name="id8">COM methods (Windows only)</a></li> </ul> </li> - <li><a class="reference" href="#callback-functions" id="id9" name="id9">Callback functions</a></li> <li><a class="reference" href="#simple-types" id="id10" name="id10">Simple types</a><ul> <li><a class="reference" href="#class-attributes-of-simple-types" id="id11" name="id11">Class attributes of simple types</a></li> --- 307,313 ---- <li><a class="reference" href="#parameter-flags" id="id7" name="id7">Parameter flags</a></li> <li><a class="reference" href="#com-methods-windows-only" id="id8" name="id8">COM methods (Windows only)</a></li> + <li><a class="reference" href="#callback-functions" id="id9" name="id9">Callback functions</a></li> </ul> </li> <li><a class="reference" href="#simple-types" id="id10" name="id10">Simple types</a><ul> <li><a class="reference" href="#class-attributes-of-simple-types" id="id11" name="id11">Class attributes of simple types</a></li> *************** *** 592,598 **** be the integer address of a COM interface pointer.</p> </div> - </div> <div class="section"> ! <h1><a class="toc-backref" href="#id9" id="callback-functions" name="callback-functions">Callback functions</a></h1> <p>ctypes is able to create C callable functions from Python callables. This is useful because sometimes library functions need a callback --- 592,597 ---- be the integer address of a COM interface pointer.</p> </div> <div class="section"> ! <h2><a class="toc-backref" href="#id9" id="callback-functions" name="callback-functions">Callback functions</a></h2> <p>ctypes is able to create C callable functions from Python callables. This is useful because sometimes library functions need a callback *************** *** 620,623 **** --- 619,623 ---- for debugging.</p> </div> + </div> <div class="section"> <h1><a class="toc-backref" href="#id10" id="simple-types" name="simple-types">Simple types</a></h1> Index: simple_types.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/simple_types.txt,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** simple_types.txt 21 Mar 2006 21:17:51 -0000 1.3 --- simple_types.txt 22 Mar 2006 07:09:10 -0000 1.4 *************** *** 49,61 **** ``from_param`` ! This is a class method (an instance method of the metaclass, to be ! exact) that is used to adapt function parameters. If a ! ``c_int`` type is specified in a function's argtypes sequence, ! ``c_int.from_param(arg)`` will be called by ctypes and the result ! will be passed to the foreign function call as a parameter. ``from_param`` usually returns an internal object that you cannot ! use in Python code - it only makes sense to pass this to foreign ! functions. On one hand, ``from_param`` is a performance optimization - it --- 49,61 ---- ``from_param`` ! This class method is used to adapt function parameters. If a type ! is specified in a function's argtypes sequence, in a function call ! the ``from_param(arg)`` method will be called with the actual ! argument, and the result will be passed to the foreign function ! call as a parameter. ``from_param`` usually returns an internal object that you cannot ! use in Python code - it only makes sense to pass this object to ! foreign functions. On one hand, ``from_param`` is a performance optimization - it *************** *** 75,78 **** --- 75,84 ---- ----------------------------------- + ``value`` + + Allows to get or set the current value of the object. For simple + types, this is always a native Python object like integer, long, + string, unicode, or None. + ``_objects`` (never modify this) *************** *** 91,100 **** block on destruction. - ``value`` - - Allows to get or set the current value of the object. For simpe - types, this is always a native Python object like integer, long, - string, or unicode. - ``_as_parameter_`` (readonly) --- 97,100 ---- |
From: Thomas H. <th...@us...> - 2006-03-20 09:39:43
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5950 Modified Files: test-cf.py Log Message: Do 'setup.py test' by default only. Index: test-cf.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/test-cf.py,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** test-cf.py 10 Mar 2006 19:04:57 -0000 1.5 --- test-cf.py 20 Mar 2006 09:39:40 -0000 1.6 *************** *** 49,53 **** cmd = "cd ~/ctypes; %s setup.py %s" % (python, " ".join(sys.argv[1:])) else: ! cmd = "cd ~/ctypes; %s setup.py -q build_ext -f test -v " % python print cmd ret = os.system('ssh -l theller cf-shell.sf.net "ssh %s \'%s\'"' % (hostname, cmd)) --- 49,53 ---- cmd = "cd ~/ctypes; %s setup.py %s" % (python, " ".join(sys.argv[1:])) else: ! cmd = "cd ~/ctypes; %s setup.py test " % python print cmd ret = os.system('ssh -l theller cf-shell.sf.net "ssh %s \'%s\'"' % (hostname, cmd)) |
From: Thomas H. <th...@us...> - 2006-03-20 09:37:33
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5123 Modified Files: ctypes.h _ctypes.c Log Message: Apply patch from Martin v. Loewis: Avoid function pointer casts. https://sourceforge.net/tracker/?func=detail&atid=532156&aid=1453037&group_id=71702 Index: ctypes.h =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/ctypes.h,v retrieving revision 1.101 retrieving revision 1.102 diff -C2 -d -r1.101 -r1.102 *** ctypes.h 14 Mar 2006 20:04:07 -0000 1.101 --- ctypes.h 20 Mar 2006 09:37:29 -0000 1.102 *************** *** 3,15 **** #if (PY_VERSION_HEX < 0x02050000) typedef int Py_ssize_t; - #define lenfunc inquiry - #define readbufferproc getreadbufferproc - #define writebufferproc getwritebufferproc - #define segcountproc getsegcountproc - #define charbufferproc getcharbufferproc - #define ssizeargfunc intargfunc - #define ssizessizeargfunc intintargfunc - #define ssizeobjargproc intobjargproc - #define ssizessizeobjargproc intintobjargproc #endif --- 3,6 ---- Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.314 retrieving revision 1.315 diff -C2 -d -r1.314 -r1.315 *** _ctypes.c 17 Mar 2006 21:02:01 -0000 1.314 --- _ctypes.c 20 Mar 2006 09:37:29 -0000 1.315 *************** *** 1880,1885 **** }; ! static Py_ssize_t CData_GetBuffer(CDataObject *self, Py_ssize_t seg, void **pptr) { if (seg != 0) { /* Hm. Must this set an exception? */ --- 1880,1886 ---- }; ! static Py_ssize_t CData_GetBuffer(PyObject *_self, Py_ssize_t seg, void **pptr) { + CDataObject *self = (CDataObject *)_self; if (seg != 0) { /* Hm. Must this set an exception? */ *************** *** 1890,1894 **** } ! static Py_ssize_t CData_GetSegcount(CDataObject *self, Py_ssize_t *lenp) { if (lenp) --- 1891,1895 ---- } ! static Py_ssize_t CData_GetSegcount(PyObject *_self, Py_ssize_t *lenp) { if (lenp) *************** *** 1898,1905 **** static PyBufferProcs CData_as_buffer = { ! (readbufferproc)CData_GetBuffer, ! (writebufferproc)CData_GetBuffer, ! (segcountproc)CData_GetSegcount, ! (charbufferproc)NULL, }; --- 1899,1906 ---- static PyBufferProcs CData_as_buffer = { ! CData_GetBuffer, ! CData_GetBuffer, ! CData_GetSegcount, ! NULL, }; *************** *** 3494,3499 **** static PyObject * ! Array_item(CDataObject *self, int index) { int offset, size; StgDictObject *stgdict; --- 3495,3501 ---- static PyObject * ! Array_item(PyObject *_self, int index) { + CDataObject *self = (CDataObject *)_self; int offset, size; StgDictObject *stgdict; *************** *** 3518,3523 **** static PyObject * ! Array_slice(CDataObject *self, Py_ssize_t ilow, Py_ssize_t ihigh) { StgDictObject *stgdict, *itemdict; PyObject *proto; --- 3520,3526 ---- static PyObject * ! Array_slice(PyObject *_self, Py_ssize_t ilow, Py_ssize_t ihigh) { + CDataObject *self = (CDataObject *)_self; StgDictObject *stgdict, *itemdict; PyObject *proto; *************** *** 3553,3557 **** for (i = 0; i < len; i++) { ! PyObject *v = Array_item(self, i+ilow); PyList_SET_ITEM(np, i, v); } --- 3556,3560 ---- for (i = 0; i < len; i++) { ! PyObject *v = Array_item(_self, i+ilow); PyList_SET_ITEM(np, i, v); } *************** *** 3560,3565 **** static int ! Array_ass_item(CDataObject *self, int index, PyObject *value) { int size, offset; StgDictObject *stgdict; --- 3563,3569 ---- static int ! Array_ass_item(PyObject *_self, int index, PyObject *value) { + CDataObject *self = (CDataObject *)_self; int size, offset; StgDictObject *stgdict; *************** *** 3587,3592 **** static int ! Array_ass_slice(CDataObject *self, int ilow, int ihigh, PyObject *value) { int i, len; --- 3591,3597 ---- static int ! Array_ass_slice(PyObject *_self, int ilow, int ihigh, PyObject *value) { + CDataObject *self = (CDataObject *)_self; int i, len; *************** *** 3619,3623 **** if (item == NULL) return -1; ! result = Array_ass_item(self, i+ilow, item); Py_DECREF(item); if (result == -1) --- 3624,3628 ---- if (item == NULL) return -1; ! result = Array_ass_item(_self, i+ilow, item); Py_DECREF(item); if (result == -1) *************** *** 3628,3644 **** static int ! Array_length(CDataObject *self) { return self->b_length; } static PySequenceMethods Array_as_sequence = { ! (lenfunc)Array_length, /* sq_length; */ 0, /* sq_concat; */ 0, /* sq_repeat; */ ! (ssizeargfunc)Array_item, /* sq_item; */ ! (ssizessizeargfunc)Array_slice, /* sq_slice; */ ! (ssizeobjargproc)Array_ass_item, /* sq_ass_item; */ ! (ssizessizeobjargproc)Array_ass_slice, /* sq_ass_slice; */ 0, /* sq_contains; */ --- 3633,3650 ---- static int ! Array_length(PyObject *_self) { + CDataObject *self = (CDataObject *)_self; return self->b_length; } static PySequenceMethods Array_as_sequence = { ! Array_length, /* sq_length; */ 0, /* sq_concat; */ 0, /* sq_repeat; */ ! Array_item, /* sq_item; */ ! Array_slice, /* sq_slice; */ ! Array_ass_item, /* sq_ass_item; */ ! Array_ass_slice, /* sq_ass_slice; */ 0, /* sq_contains; */ *************** *** 3992,3997 **** */ static PyObject * ! Pointer_item(CDataObject *self, int index) { int size, offset; StgDictObject *stgdict, *itemdict; --- 3998,4004 ---- */ static PyObject * ! Pointer_item(PyObject *_self, int index) { + CDataObject *self = (CDataObject *)_self; int size, offset; StgDictObject *stgdict, *itemdict; *************** *** 4019,4024 **** static int ! Pointer_ass_item(CDataObject *self, int index, PyObject *value) { int size; StgDictObject *stgdict; --- 4026,4032 ---- static int ! Pointer_ass_item(PyObject *_self, int index, PyObject *value) { + CDataObject *self = (CDataObject *)_self; int size; StgDictObject *stgdict; *************** *** 4161,4166 **** static PyObject * ! Pointer_slice(CDataObject *self, Py_ssize_t ilow, Py_ssize_t ihigh) { PyListObject *np; StgDictObject *stgdict, *itemdict; --- 4169,4175 ---- static PyObject * ! Pointer_slice(PyObject *_self, Py_ssize_t ilow, Py_ssize_t ihigh) { + CDataObject *self = (CDataObject *)_self; PyListObject *np; StgDictObject *stgdict, *itemdict; *************** *** 4192,4196 **** for (i = 0; i < len; i++) { ! PyObject *v = Pointer_item(self, i+ilow); PyList_SET_ITEM(np, i, v); } --- 4201,4205 ---- for (i = 0; i < len; i++) { ! PyObject *v = Pointer_item(_self, i+ilow); PyList_SET_ITEM(np, i, v); } *************** *** 4202,4208 **** 0, /* binaryfunc sq_concat; */ 0, /* intargfunc sq_repeat; */ ! (ssizeargfunc)Pointer_item, /* intargfunc sq_item; */ ! (ssizessizeargfunc)Pointer_slice, /* intintargfunc sq_slice; */ ! (ssizeobjargproc)Pointer_ass_item, /* intobjargproc sq_ass_item; */ 0, /* intintobjargproc sq_ass_slice; */ 0, /* objobjproc sq_contains; */ --- 4211,4217 ---- 0, /* binaryfunc sq_concat; */ 0, /* intargfunc sq_repeat; */ ! Pointer_item, /* intargfunc sq_item; */ ! Pointer_slice, /* intintargfunc sq_slice; */ ! Pointer_ass_item, /* intobjargproc sq_ass_item; */ 0, /* intintobjargproc sq_ass_slice; */ 0, /* objobjproc sq_contains; */ |
From: Thomas H. <th...@us...> - 2006-03-19 11:06:21
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15067/source Modified Files: Tag: unaligned_branch cfield.c Log Message: unaligned acces works on sparc solaris now Index: cfield.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/cfield.c,v retrieving revision 1.117.2.5 retrieving revision 1.117.2.6 diff -C2 -d -r1.117.2.5 -r1.117.2.6 *** cfield.c 18 Mar 2006 19:34:29 -0000 1.117.2.5 --- cfield.c 19 Mar 2006 11:06:15 -0000 1.117.2.6 *************** *** 554,560 **** if (get_long(value, &val) < 0) return NULL; ! field = SWAP_2(*(short *)ptr); field = SET(field, (short)val, size); ! *(short *)ptr = SWAP_2(field); _RET(value); } --- 554,562 ---- if (get_long(value, &val) < 0) return NULL; ! memcpy(&field, ptr, sizeof(field)); ! field = SWAP_2(field); field = SET(field, (short)val, size); ! field = SWAP_2(field); ! memcpy(ptr, &field, sizeof(field)); _RET(value); } *************** *** 563,569 **** h_get(void *ptr, unsigned size) { ! short val = *(short *)ptr; GET_BITFIELD(val, size); ! return PyInt_FromLong(val); } --- 565,572 ---- h_get(void *ptr, unsigned size) { ! short val; ! memcpy(&val, ptr, sizeof(val)); GET_BITFIELD(val, size); ! return PyInt_FromLong((long)val); } *************** *** 571,575 **** h_get_sw(void *ptr, unsigned size) { ! short val = *(short *)ptr; val = SWAP_2(val); GET_BITFIELD(val, size); --- 574,579 ---- h_get_sw(void *ptr, unsigned size) { ! short val; ! memcpy(&val, ptr, sizeof(val)); val = SWAP_2(val); GET_BITFIELD(val, size); *************** *** 597,603 **** if (get_ulong(value, &val) < 0) return NULL; ! field = SWAP_2(*(unsigned short *)ptr); field = SET(field, (unsigned short)val, size); ! *(unsigned short *)ptr = SWAP_2(field); _RET(value); } --- 601,609 ---- if (get_ulong(value, &val) < 0) return NULL; ! memcpy(&field, ptr, sizeof(field)); ! field = SWAP_2(field); field = SET(field, (unsigned short)val, size); ! field = SWAP_2(field); ! memcpy(ptr, &field, sizeof(field)); _RET(value); } *************** *** 607,611 **** H_get(void *ptr, unsigned size) { ! unsigned short val = *(unsigned short *)ptr; GET_BITFIELD(val, size); return PyInt_FromLong(val); --- 613,618 ---- H_get(void *ptr, unsigned size) { ! unsigned short val; ! memcpy(&val, ptr, sizeof(val)); GET_BITFIELD(val, size); return PyInt_FromLong(val); *************** *** 615,619 **** H_get_sw(void *ptr, unsigned size) { ! unsigned short val = *(unsigned short *)ptr; val = SWAP_2(val); GET_BITFIELD(val, size); --- 622,627 ---- H_get_sw(void *ptr, unsigned size) { ! unsigned short val; ! memcpy(&val, ptr, sizeof(val)); val = SWAP_2(val); GET_BITFIELD(val, size); *************** *** 641,647 **** if (get_long(value, &val) < 0) return NULL; ! field = SWAP_INT(*(int *)ptr); field = SET(field, (int)val, size); ! *(int *)ptr = SWAP_INT(field); _RET(value); } --- 649,657 ---- if (get_long(value, &val) < 0) return NULL; ! memcpy(&field, ptr, sizeof(field)); ! field = SWAP_INT(field); field = SET(field, (int)val, size); ! field = SWAP_INT(field); ! memcpy(ptr, &field, sizeof(field)); _RET(value); } *************** *** 651,655 **** i_get(void *ptr, unsigned size) { ! int val = *(int *)ptr; GET_BITFIELD(val, size); return PyInt_FromLong(val); --- 661,666 ---- i_get(void *ptr, unsigned size) { ! int val; ! memcpy(&val, ptr, sizeof(val)); GET_BITFIELD(val, size); return PyInt_FromLong(val); *************** *** 659,663 **** i_get_sw(void *ptr, unsigned size) { ! int val = *(int *)ptr; val = SWAP_INT(val); GET_BITFIELD(val, size); --- 670,675 ---- i_get_sw(void *ptr, unsigned size) { ! int val; ! memcpy(&val, ptr, sizeof(val)); val = SWAP_INT(val); GET_BITFIELD(val, size); *************** *** 709,715 **** if (get_ulong(value, &val) < 0) return NULL; ! field = SWAP_INT(*(unsigned int *)ptr); field = (unsigned int)SET(field, (unsigned int)val, size); ! *(unsigned int *)ptr = SWAP_INT(field); _RET(value); } --- 721,728 ---- if (get_ulong(value, &val) < 0) return NULL; ! memcpy(&field, ptr, sizeof(field)); field = (unsigned int)SET(field, (unsigned int)val, size); ! field = SWAP_INT(field); ! memcpy(ptr, &field, sizeof(field)); _RET(value); } *************** *** 719,723 **** I_get(void *ptr, unsigned size) { ! unsigned int val = *(unsigned int *)ptr; GET_BITFIELD(val, size); return PyLong_FromUnsignedLong(val); --- 732,737 ---- I_get(void *ptr, unsigned size) { ! unsigned int val; ! memcpy(&val, ptr, sizeof(val)); GET_BITFIELD(val, size); return PyLong_FromUnsignedLong(val); *************** *** 727,731 **** I_get_sw(void *ptr, unsigned size) { ! unsigned int val = *(unsigned int *)ptr; val = SWAP_INT(val); GET_BITFIELD(val, size); --- 741,746 ---- I_get_sw(void *ptr, unsigned size) { ! unsigned int val; ! memcpy(&val, ptr, sizeof(val)); val = SWAP_INT(val); GET_BITFIELD(val, size); *************** *** 753,759 **** if (get_long(value, &val) < 0) return NULL; ! field = SWAP_LONG(*(long *)ptr); field = (long)SET(field, val, size); ! *(long *)ptr = SWAP_LONG(field); _RET(value); } --- 768,776 ---- if (get_long(value, &val) < 0) return NULL; ! memcpy(&field, ptr, sizeof(field)); ! field = SWAP_LONG(field); field = (long)SET(field, val, size); ! field = SWAP_LONG(field); ! memcpy(ptr, &field, sizeof(field)); _RET(value); } *************** *** 763,767 **** l_get(void *ptr, unsigned size) { ! long val = *(long *)ptr; GET_BITFIELD(val, size); return PyInt_FromLong(val); --- 780,785 ---- l_get(void *ptr, unsigned size) { ! long val; ! memcpy(&val, ptr, sizeof(val)); GET_BITFIELD(val, size); return PyInt_FromLong(val); *************** *** 771,775 **** l_get_sw(void *ptr, unsigned size) { ! long val = *(long *)ptr; val = SWAP_LONG(val); GET_BITFIELD(val, size); --- 789,794 ---- l_get_sw(void *ptr, unsigned size) { ! long val; ! memcpy(&val, ptr, sizeof(val)); val = SWAP_LONG(val); GET_BITFIELD(val, size); *************** *** 797,803 **** if (get_ulong(value, &val) < 0) return NULL; ! field = SWAP_LONG(*(unsigned long *)ptr); field = (unsigned long)SET(field, val, size); ! *(unsigned long *)ptr = SWAP_LONG(field); _RET(value); } --- 816,824 ---- if (get_ulong(value, &val) < 0) return NULL; ! memcpy(&field, ptr, sizeof(field)); ! field = SWAP_LONG(field); field = (unsigned long)SET(field, val, size); ! field = SWAP_LONG(field); ! memcpy(ptr, &field, sizeof(field)); _RET(value); } *************** *** 807,811 **** L_get(void *ptr, unsigned size) { ! unsigned long val = *(unsigned long *)ptr; GET_BITFIELD(val, size); return PyLong_FromUnsignedLong(val); --- 828,833 ---- L_get(void *ptr, unsigned size) { ! unsigned long val; ! memcpy(&val, ptr, sizeof(val)); GET_BITFIELD(val, size); return PyLong_FromUnsignedLong(val); *************** *** 815,819 **** L_get_sw(void *ptr, unsigned size) { ! unsigned long val = *(unsigned long *)ptr; val = SWAP_LONG(val); GET_BITFIELD(val, size); --- 837,842 ---- L_get_sw(void *ptr, unsigned size) { ! unsigned long val; ! memcpy(&val, ptr, sizeof(val)); val = SWAP_LONG(val); GET_BITFIELD(val, size); *************** *** 842,848 **** if (get_longlong(value, &val) < 0) return NULL; ! field = SWAP_8(*(PY_LONG_LONG *)ptr); field = (PY_LONG_LONG)SET(field, val, size); ! *(PY_LONG_LONG *)ptr = SWAP_8(field); _RET(value); } --- 865,873 ---- if (get_longlong(value, &val) < 0) return NULL; ! memcpy(&field, ptr, sizeof(field)); ! field = SWAP_8(field); field = (PY_LONG_LONG)SET(field, val, size); ! field = SWAP_8(field); ! memcpy(ptr, &field, sizeof(field)); _RET(value); } *************** *** 851,855 **** q_get(void *ptr, unsigned size) { ! PY_LONG_LONG val = *(PY_LONG_LONG *)ptr; GET_BITFIELD(val, size); return PyLong_FromLongLong(val); --- 876,881 ---- q_get(void *ptr, unsigned size) { ! PY_LONG_LONG val; ! memcpy(&val, ptr, sizeof(val)); GET_BITFIELD(val, size); return PyLong_FromLongLong(val); *************** *** 859,863 **** q_get_sw(void *ptr, unsigned size) { ! PY_LONG_LONG val = *(PY_LONG_LONG *)ptr; val = SWAP_8(val); GET_BITFIELD(val, size); --- 885,890 ---- q_get_sw(void *ptr, unsigned size) { ! PY_LONG_LONG val; ! memcpy(&val, ptr, sizeof(val)); val = SWAP_8(val); GET_BITFIELD(val, size); *************** *** 885,891 **** if (get_ulonglong(value, &val) < 0) return NULL; ! field = SWAP_8(*(unsigned PY_LONG_LONG *)ptr); field = (unsigned PY_LONG_LONG)SET(field, val, size); ! *(unsigned PY_LONG_LONG *)ptr = SWAP_8(field); _RET(value); } --- 912,920 ---- if (get_ulonglong(value, &val) < 0) return NULL; ! memcpy(&field, ptr, sizeof(field)); ! field = SWAP_8(field); field = (unsigned PY_LONG_LONG)SET(field, val, size); ! field = SWAP_8(field); ! memcpy(ptr, &field, sizeof(field)); _RET(value); } *************** *** 894,898 **** Q_get(void *ptr, unsigned size) { ! unsigned PY_LONG_LONG val = *(unsigned PY_LONG_LONG *)ptr; GET_BITFIELD(val, size); return PyLong_FromUnsignedLongLong(val); --- 923,928 ---- Q_get(void *ptr, unsigned size) { ! unsigned PY_LONG_LONG val; ! memcpy(&val, ptr, sizeof(val)); GET_BITFIELD(val, size); return PyLong_FromUnsignedLongLong(val); *************** *** 902,906 **** Q_get_sw(void *ptr, unsigned size) { ! unsigned PY_LONG_LONG val = *(unsigned PY_LONG_LONG *)ptr; val = SWAP_8(val); GET_BITFIELD(val, size); --- 932,937 ---- Q_get_sw(void *ptr, unsigned size) { ! unsigned PY_LONG_LONG val; ! memcpy(&val, ptr, sizeof(val)); val = SWAP_8(val); GET_BITFIELD(val, size); *************** *** 934,938 **** d_get(void *ptr, unsigned size) { ! return PyFloat_FromDouble(*(double *)ptr); } --- 965,971 ---- d_get(void *ptr, unsigned size) { ! double val; ! memcpy(&val, ptr, sizeof(val)); ! return PyFloat_FromDouble(val); } *************** *** 988,992 **** f_get(void *ptr, unsigned size) { ! return PyFloat_FromDouble(*(float *)ptr); } --- 1021,1027 ---- f_get(void *ptr, unsigned size) { ! float val; ! memcpy(&val, ptr, sizeof(val)); ! return PyFloat_FromDouble(val); } |
From: Thomas H. <th...@us...> - 2006-03-19 11:06:21
|
Update of /cvsroot/ctypes/ctypes/ctypes/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15067/ctypes/test Modified Files: Tag: unaligned_branch test_unaligned_structures.py test_byteswap.py Log Message: unaligned acces works on sparc solaris now Index: test_unaligned_structures.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/test/Attic/test_unaligned_structures.py,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -C2 -d -r1.1.2.3 -r1.1.2.4 *** test_unaligned_structures.py 18 Mar 2006 20:09:20 -0000 1.1.2.3 --- test_unaligned_structures.py 19 Mar 2006 11:06:16 -0000 1.1.2.4 *************** *** 36,40 **** def test_swapped(self): for typ in byteswapped_structures: ! print typ.value self.failUnlessEqual(typ.value.offset, 1) o = typ() --- 36,40 ---- def test_swapped(self): for typ in byteswapped_structures: ! ## print >> sys.stderr, typ.value self.failUnlessEqual(typ.value.offset, 1) o = typ() Index: test_byteswap.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/test/test_byteswap.py,v retrieving revision 1.7.2.1 retrieving revision 1.7.2.2 diff -C2 -d -r1.7.2.1 -r1.7.2.2 *** test_byteswap.py 18 Mar 2006 17:21:34 -0000 1.7.2.1 --- test_byteswap.py 19 Mar 2006 11:06:16 -0000 1.7.2.2 *************** *** 3,7 **** from ctypes import * - from ctypes.test import is_resource_enabled def bin(s): --- 3,6 ---- *************** *** 17,21 **** class Test(unittest.TestCase): def X_test(self): ! print sys.byteorder for i in range(32): bits = BITS() --- 16,20 ---- class Test(unittest.TestCase): def X_test(self): ! print >> sys.stderr, sys.byteorder for i in range(32): bits = BITS() *************** *** 223,290 **** self.failUnlessEqual(bin(s1), bin(s2)) ! if is_resource_enabled("unaligned_access"): ! ! def test_unaligned_nonnative_struct_fields(self): ! if sys.byteorder == "little": ! base = BigEndianStructure ! fmt = ">b h xi xd" ! else: ! base = LittleEndianStructure ! fmt = "<b h xi xd" ! class S(base): ! _pack_ = 1 ! _fields_ = [("b", c_byte), ! ("h", c_short), ! ("_1", c_byte), ! ("i", c_int), ! ("_2", c_byte), ! ("d", c_double)] ! s1 = S() ! print "SET b" ! s1.b = 0x12 ! print "SET h" ! s1.h = 0x1234 ! print "SET i" ! s1.i = 0x12345678 ! print "SET d" ! s1.d = 3.14 ! s2 = struct.pack(fmt, 0x12, 0x1234, 0x12345678, 3.14) ! self.failUnlessEqual(bin(s1), bin(s2)) ! def test_unaligned_native_struct_fields(self): ! if sys.byteorder == "little": ! fmt = "<b h xi xd" ! else: ! base = LittleEndianStructure ! fmt = ">b h xi xd" ! class S(Structure): ! _pack_ = 1 ! _fields_ = [("b", c_byte), ! ("h", c_short), ! ("_1", c_byte), ! ("i", c_int), ! ("_2", c_byte), ! ("d", c_double)] ! s1 = S() ! print "SET b" ! s1.b = 0x12 ! print "SET h" ! s1.h = 0x1234 ! print "SET i" ! s1.i = 0x12345678 ! print "SET d" ! s1.d = 3.14 ! s2 = struct.pack(fmt, 0x12, 0x1234, 0x12345678, 3.14) ! self.failUnlessEqual(bin(s1), bin(s2)) if __name__ == "__main__": --- 222,279 ---- self.failUnlessEqual(bin(s1), bin(s2)) ! def test_unaligned_nonnative_struct_fields(self): ! if sys.byteorder == "little": ! base = BigEndianStructure ! fmt = ">b h xi xd" ! else: ! base = LittleEndianStructure ! fmt = "<b h xi xd" ! class S(base): ! _pack_ = 1 ! _fields_ = [("b", c_byte), ! ("h", c_short), ! ("_1", c_byte), ! ("i", c_int), ! ("_2", c_byte), ! ("d", c_double)] ! s1 = S() ! s1.b = 0x12 ! s1.h = 0x1234 ! s1.i = 0x12345678 ! s1.d = 3.14 ! s2 = struct.pack(fmt, 0x12, 0x1234, 0x12345678, 3.14) ! self.failUnlessEqual(bin(s1), bin(s2)) ! def test_unaligned_native_struct_fields(self): ! if sys.byteorder == "little": ! fmt = "<b h xi xd" ! else: ! base = LittleEndianStructure ! fmt = ">b h xi xd" ! class S(Structure): ! _pack_ = 1 ! _fields_ = [("b", c_byte), ! ("h", c_short), ! ("_1", c_byte), ! ("i", c_int), ! ("_2", c_byte), ! ("d", c_double)] ! s1 = S() ! s1.b = 0x12 ! s1.h = 0x1234 ! s1.i = 0x12345678 ! s1.d = 3.14 ! s2 = struct.pack(fmt, 0x12, 0x1234, 0x12345678, 3.14) ! self.failUnlessEqual(bin(s1), bin(s2)) if __name__ == "__main__": |
From: Thomas H. <th...@us...> - 2006-03-18 20:09:23
|
Update of /cvsroot/ctypes/ctypes/ctypes/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14299 Modified Files: Tag: unaligned_branch test_unaligned_structures.py Log Message: Add test for accessing non-aligned fields in structures with non-native byte order. Index: test_unaligned_structures.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/test/Attic/test_unaligned_structures.py,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** test_unaligned_structures.py 18 Mar 2006 19:36:09 -0000 1.1.2.2 --- test_unaligned_structures.py 18 Mar 2006 20:09:20 -0000 1.1.2.3 *************** *** 1,6 **** ! import unittest from ctypes import * structures = [] for typ in [c_short, c_int, c_long, c_longlong, c_float, c_double, --- 1,14 ---- ! import sys, unittest from ctypes import * structures = [] + byteswapped_structures = [] + + + if sys.byteorder == "little": + SwappedStructure = BigEndianStructure + else: + SwappedStructure = LittleEndianStructure + for typ in [c_short, c_int, c_long, c_longlong, c_float, c_double, *************** *** 10,18 **** _fields_ = [("pad", c_byte), ("value", typ)] structures.append(X) class TestStructures(unittest.TestCase): ! def test_set(self): for typ in structures: print typ.value self.failUnlessEqual(typ.value.offset, 1) --- 18,39 ---- _fields_ = [("pad", c_byte), ("value", typ)] + class Y(SwappedStructure): + _pack_ = 1 + _fields_ = [("pad", c_byte), + ("value", typ)] structures.append(X) + byteswapped_structures.append(Y) class TestStructures(unittest.TestCase): ! def test_native(self): for typ in structures: + ## print typ.value + self.failUnlessEqual(typ.value.offset, 1) + o = typ() + o.value = 4 + self.failUnlessEqual(o.value, 4) + + def test_swapped(self): + for typ in byteswapped_structures: print typ.value self.failUnlessEqual(typ.value.offset, 1) |
From: Thomas H. <th...@us...> - 2006-03-18 19:36:12
|
Update of /cvsroot/ctypes/ctypes/ctypes/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32107 Modified Files: Tag: unaligned_branch test_unaligned_structures.py Log Message: Get the field's value. Index: test_unaligned_structures.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/test/Attic/test_unaligned_structures.py,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** test_unaligned_structures.py 18 Mar 2006 19:09:39 -0000 1.1.2.1 --- test_unaligned_structures.py 18 Mar 2006 19:36:09 -0000 1.1.2.2 *************** *** 19,22 **** --- 19,23 ---- o = typ() o.value = 4 + self.failUnlessEqual(o.value, 4) if __name__ == '__main__': |
From: Thomas H. <th...@us...> - 2006-03-18 19:34:32
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31353 Modified Files: Tag: unaligned_branch cfield.c Log Message: Setting unaligned structure fields works now Index: cfield.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/cfield.c,v retrieving revision 1.117.2.4 retrieving revision 1.117.2.5 diff -C2 -d -r1.117.2.4 -r1.117.2.5 *** cfield.c 18 Mar 2006 17:40:44 -0000 1.117.2.4 --- cfield.c 18 Mar 2006 19:34:29 -0000 1.117.2.5 *************** *** 540,546 **** if (get_long(value, &val) < 0) return NULL; ! memcpy(&x, ptr, sizeof(short)); x = SET(x, (short)val, size); ! memcpy(ptr, &x, sizeof(short)); _RET(value); } --- 540,546 ---- if (get_long(value, &val) < 0) return NULL; ! memcpy(&x, ptr, sizeof(x)); x = SET(x, (short)val, size); ! memcpy(ptr, &x, sizeof(x)); _RET(value); } *************** *** 581,588 **** { unsigned long val; if (get_ulong(value, &val) < 0) return NULL; ! *(unsigned short *)ptr = (unsigned short)SET(*(unsigned short *)ptr, ! (unsigned short)val, size); _RET(value); } --- 581,590 ---- { unsigned long val; + unsigned short x; if (get_ulong(value, &val) < 0) return NULL; ! memcpy(&x, ptr, sizeof(x)); ! x = SET(x, (unsigned short)val, size); ! memcpy(ptr, &x, sizeof(x)); _RET(value); } *************** *** 691,697 **** { unsigned long val; if (get_ulong(value, &val) < 0) return NULL; ! *(unsigned int *)ptr = (unsigned int)SET(*(unsigned int *)ptr, (unsigned int)val, size); _RET(value); } --- 693,702 ---- { unsigned long val; + unsigned int x; if (get_ulong(value, &val) < 0) return NULL; ! memcpy(&x, ptr, sizeof(x)); ! x = SET(x, (unsigned int)val, size); ! memcpy(ptr, &x, sizeof(x)); _RET(value); } *************** *** 776,782 **** { unsigned long val; if (get_ulong(value, &val) < 0) return NULL; ! *(unsigned long *)ptr = (unsigned long)SET(*(unsigned long *)ptr, val, size); _RET(value); } --- 781,790 ---- { unsigned long val; + unsigned long x; if (get_ulong(value, &val) < 0) return NULL; ! memcpy(&x, ptr, sizeof(x)); ! x = SET(x, val, size); ! memcpy(ptr, &x, sizeof(x)); _RET(value); } *************** *** 818,824 **** { PY_LONG_LONG val; if (get_longlong(value, &val) < 0) return NULL; ! *(PY_LONG_LONG *)ptr = (PY_LONG_LONG)SET(*(PY_LONG_LONG *)ptr, val, size); _RET(value); } --- 826,835 ---- { PY_LONG_LONG val; + PY_LONG_LONG x; if (get_longlong(value, &val) < 0) return NULL; ! memcpy(&x, ptr, sizeof(x)); ! x = SET(x, val, size); ! memcpy(ptr, &x, sizeof(x)); _RET(value); } *************** *** 858,864 **** { unsigned PY_LONG_LONG val; if (get_ulonglong(value, &val) < 0) return NULL; ! *(unsigned PY_LONG_LONG *)ptr = (unsigned PY_LONG_LONG)SET(*(unsigned PY_LONG_LONG *)ptr, val, size); _RET(value); } --- 869,878 ---- { unsigned PY_LONG_LONG val; + unsigned PY_LONG_LONG x; if (get_ulonglong(value, &val) < 0) return NULL; ! memcpy(&x, ptr, sizeof(x)); ! x = SET(x, val, size); ! memcpy(ptr, &x, sizeof(x)); _RET(value); } *************** *** 967,971 **** return NULL; } ! *(float *)ptr = x; _RET(value); } --- 981,985 ---- return NULL; } ! memcpy(ptr, &x, sizeof(x)); _RET(value); } |
From: Thomas H. <th...@us...> - 2006-03-18 19:09:43
|
Update of /cvsroot/ctypes/ctypes/ctypes/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20312 Added Files: Tag: unaligned_branch test_unaligned_structures.py Log Message: Test accessing unaligned structure fields. --- NEW FILE: test_unaligned_structures.py --- import unittest from ctypes import * structures = [] for typ in [c_short, c_int, c_long, c_longlong, c_float, c_double, c_ushort, c_uint, c_ulong, c_ulonglong]: class X(Structure): _pack_ = 1 _fields_ = [("pad", c_byte), ("value", typ)] structures.append(X) class TestStructures(unittest.TestCase): def test_set(self): for typ in structures: print typ.value self.failUnlessEqual(typ.value.offset, 1) o = typ() o.value = 4 if __name__ == '__main__': unittest.main() |
From: Thomas H. <th...@us...> - 2006-03-18 17:34:46
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7812 Modified Files: Tag: unaligned_branch cfield.c Log Message: Make i_set handle unaligned accesses. Index: cfield.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/cfield.c,v retrieving revision 1.117.2.2 retrieving revision 1.117.2.3 diff -C2 -d -r1.117.2.2 -r1.117.2.3 *** cfield.c 18 Mar 2006 17:31:56 -0000 1.117.2.2 --- cfield.c 18 Mar 2006 17:34:43 -0000 1.117.2.3 *************** *** 623,629 **** { long val; if (get_long(value, &val) < 0) return NULL; ! *(int *)ptr = (int)SET(*(int *)ptr, (int)val, size); _RET(value); } --- 623,632 ---- { long val; + int x; if (get_long(value, &val) < 0) return NULL; ! memcpy(&x, ptr, sizeof(x)); ! x = SET(x, (int)val, size); ! memcpy(ptr, &x, sizeof(x)); _RET(value); } |