ctypes-commit Mailing List for ctypes (Page 11)
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-05-19 15:51:10
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv14671 Modified Files: _ctypes.c Log Message: Allow zero-sized arrays again, although accessing elements will raise IndexError. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.327 retrieving revision 1.328 diff -C2 -d -r1.327 -r1.328 *** _ctypes.c 19 May 2006 15:41:49 -0000 1.327 --- _ctypes.c 19 May 2006 15:51:02 -0000 1.328 *************** *** 343,347 **** CDataType_repeat(PyObject *self, Py_ssize_t length) { ! if (length <= 0) return PyErr_Format(PyExc_ValueError, "Array length must be >= 0, not %d", --- 343,347 ---- CDataType_repeat(PyObject *self, Py_ssize_t length) { ! if (length < 0) return PyErr_Format(PyExc_ValueError, "Array length must be >= 0, not %d", *************** *** 3551,3555 **** StgDictObject *stgdict; ! if (index < 0 || (self->b_length > 1 && index >= self->b_length)) { PyErr_SetString(PyExc_IndexError, "invalid index"); --- 3551,3555 ---- StgDictObject *stgdict; ! if (self->b_length == 0 || index < 0 || (self->b_length > 1 && index >= self->b_length)) { PyErr_SetString(PyExc_IndexError, "invalid index"); *************** *** 3627,3631 **** stgdict = PyObject_stgdict((PyObject *)self); ! if (index < 0 || (self->b_length > 1 && index >= self->b_length)) { PyErr_SetString(PyExc_IndexError, "invalid index"); --- 3627,3632 ---- stgdict = PyObject_stgdict((PyObject *)self); ! if (self->b_length == 0 || index < 0 ! || (self->b_length > 1 && index >= self->b_length)) { PyErr_SetString(PyExc_IndexError, "invalid index"); |
From: Thomas H. <th...@us...> - 2006-05-19 15:51:00
|
Update of /cvsroot/ctypes/ctypes/ctypes/test In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv14650 Modified Files: test_varsize_struct.py Log Message: Allow zero-sized arrays again, although accessing elements will raise IndexError. Index: test_varsize_struct.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/test/test_varsize_struct.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** test_varsize_struct.py 12 May 2006 20:26:10 -0000 1.1 --- test_varsize_struct.py 19 May 2006 15:50:56 -0000 1.2 *************** *** 34,40 **** def test_array_invalid_length(self): # cannot create arrays with non-positive size ! self.failUnlessRaises(ValueError, lambda: c_int * 0) self.failUnlessRaises(ValueError, lambda: c_int * -3) def test_varsized_array(self): array = (c_int * 20)(20, 21, 22, 23, 24, 25, 26, 27, 28, 29) --- 34,50 ---- def test_array_invalid_length(self): # cannot create arrays with non-positive size ! self.failUnlessRaises(ValueError, lambda: c_int * -1) self.failUnlessRaises(ValueError, lambda: c_int * -3) + def test_zerosized_array(self): + array = (c_int * 0)() + # accessing elements of zero-sized arrays raise IndexError + self.failUnlessRaises(IndexError, array.__setitem__, 0, None) + self.failUnlessRaises(IndexError, array.__getitem__, 0) + self.failUnlessRaises(IndexError, array.__setitem__, 1, None) + self.failUnlessRaises(IndexError, array.__getitem__, 1) + self.failUnlessRaises(IndexError, array.__setitem__, -1, None) + self.failUnlessRaises(IndexError, array.__getitem__, -1) + def test_varsized_array(self): array = (c_int * 20)(20, 21, 22, 23, 24, 25, 26, 27, 28, 29) |
From: Thomas H. <th...@us...> - 2006-05-19 15:41:52
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv8674 Modified Files: _ctypes.c Log Message: Change the way unique_key calculates the keys into the b_objects array. The previous way was broken for arrays or structures having more than 256 components, which led to strange errors. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.326 retrieving revision 1.327 diff -C2 -d -r1.326 -r1.327 *** _ctypes.c 18 May 2006 09:45:53 -0000 1.326 --- _ctypes.c 19 May 2006 15:41:49 -0000 1.327 *************** *** 1814,1834 **** static PyObject * ! unique_key(CDataObject *target, int index) { ! char string[256]; /* XXX is that enough? */ char *cp = string; ! *cp++ = index + '0'; while (target->b_base) { ! *cp++ = target->b_index + '0'; target = target->b_base; } return PyString_FromStringAndSize(string, cp-string); } ! /* Keep a reference to 'keep' in the 'target', at index 'index' */ /* ! * KeepRef travels the target's b_base pointer down to the root, ! * building a sequence of indexes during the path. The indexes, which are a ! * couple of small integers, are used to build a byte string usable as ! * key int the root object's _objects dict. * * Note: This function steals a refcount of the third argument, even if it --- 1814,1853 ---- static PyObject * ! unique_key(CDataObject *target, Py_ssize_t index) { ! char string[256]; char *cp = string; ! size_t bytes_left; ! ! assert(sizeof(string) - 1 > sizeof(Py_ssize_t) * 2); ! cp += sprintf(cp, "%x", index); while (target->b_base) { ! bytes_left = sizeof(string) - (cp - string) - 1; ! /* Hex format needs 2 characters per byte */ ! if (bytes_left < sizeof(Py_ssize_t) * 2) { ! PyErr_SetString(PyExc_ValueError, ! "ctypes object structure too deep"); ! return NULL; ! } ! cp += sprintf(cp, ":%x", index); target = target->b_base; } return PyString_FromStringAndSize(string, cp-string); } ! /* ! * Keep a reference to 'keep' in the 'target', at index 'index'. ! * ! * If 'keep' is None, do nothing. ! * ! * Otherwise create a dictionary (if it does not yet exist) id the root ! * objects 'b_objects' item, which will store the 'keep' object under a unique ! * key. ! * ! * The unique_key helper travels the target's b_base pointer down to the root, ! * building a string containing hex-formatted indexes found during traversal, ! * separated by colons. ! * ! * The index tuple is used as a key into the root object's b_objects dict. * * Note: This function steals a refcount of the third argument, even if it *************** *** 1854,1857 **** --- 1873,1880 ---- } key = unique_key(target, index); + if (key == NULL) { + Py_DECREF(keep); + return -1; + } result = PyDict_SetItem(ob->b_objects, key, keep); Py_DECREF(key); |
From: Thomas H. <th...@us...> - 2006-05-19 15:40:36
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv8259 Modified Files: ChangeLog Log Message: Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/ChangeLog,v retrieving revision 1.128 retrieving revision 1.129 diff -C2 -d -r1.128 -r1.129 *** ChangeLog 18 May 2006 09:47:09 -0000 1.128 --- ChangeLog 19 May 2006 15:40:28 -0000 1.129 *************** *** 1,4 **** --- 1,7 ---- 2006-05-18 Thomas Heller <th...@py...> + * source\callproc.c: Fix compiler warning about comparison of + signed and unsigned values. + * source\_ctypes.c: Correct recount issues in the (unlikely) case that KeepRef fails. |
From: Thomas H. <th...@us...> - 2006-05-18 20:09:52
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv31041 Modified Files: callproc.c Log Message: Fix compiler warning about comparison of signed and unsigned values. Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.165 retrieving revision 1.166 diff -C2 -d -r1.165 -r1.166 *** callproc.c 12 May 2006 20:26:18 -0000 1.165 --- callproc.c 18 May 2006 20:09:46 -0000 1.166 *************** *** 1460,1464 **** return NULL; } ! if (size < (size_t)dict->size) { PyErr_Format(PyExc_ValueError, "minimum size is %d", dict->size); --- 1460,1464 ---- return NULL; } ! if (size < dict->size) { PyErr_Format(PyExc_ValueError, "minimum size is %d", dict->size); |
From: Thomas H. <th...@us...> - 2006-04-20 17:53:47
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21281 Modified Files: MANIFEST.in Log Message: Remove non-existing or uninteresting files. Add tools to create the docs. Only include the tutorial, not the manual. Index: MANIFEST.in =================================================================== RCS file: /cvsroot/ctypes/ctypes/MANIFEST.in,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** MANIFEST.in 3 Mar 2006 20:07:59 -0000 1.13 --- MANIFEST.in 20 Apr 2006 17:53:44 -0000 1.14 *************** *** 6,11 **** include ctypes/.CTYPES_DEVEL include setup.py - include test-cf.py - include setup.cfg # libffi build files --- 6,9 ---- *************** *** 28,31 **** # docs/manual ! include docs/manual/*.txt ! include docs/manual/*.html --- 26,31 ---- # docs/manual ! include docs/manual/tutorial.txt ! include docs/manual/tutorial.html ! include docs/manual/mkpydoc.py ! include docs/manual/markup.py |
From: Thomas H. <th...@us...> - 2006-04-20 17:52:57
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20601 Modified Files: ACKS Log Message: Two more names. Index: ACKS =================================================================== RCS file: /cvsroot/ctypes/ctypes/ACKS,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** ACKS 3 Mar 2006 20:07:59 -0000 1.15 --- ACKS 20 Apr 2006 17:52:52 -0000 1.16 *************** *** 27,33 **** --- 27,35 ---- Andrew MacIntyre Paul Moore + Neal Norwitz Ronald Oussoren Henk Punt Jimmy Retzlaff + Armin Rigo Just van Rossum Alexander Semenov |
From: Thomas H. <th...@us...> - 2006-04-20 15:49:41
|
Update of /cvsroot/ctypes/ctypes/ctypes/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28479 Modified Files: test_loading.py Log Message: Whitespace normalization. Index: test_loading.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/test/test_loading.py,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** test_loading.py 13 Apr 2006 18:48:29 -0000 1.17 --- test_loading.py 20 Apr 2006 15:49:38 -0000 1.18 *************** *** 54,58 **** print find_library("kernel32") print find_library("user32") ! if os.name == "nt": windll.kernel32.GetModuleHandleW --- 54,58 ---- print find_library("kernel32") print find_library("user32") ! if os.name == "nt": windll.kernel32.GetModuleHandleW |
From: Thomas H. <th...@us...> - 2006-04-19 19:37:26
|
Update of /cvsroot/ctypes/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17815 Removed Files: _loader.py Log Message: _loader is no longer. --- _loader.py DELETED --- |
From: Thomas H. <th...@us...> - 2006-04-19 19:23:09
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7392 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.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** tutorial.txt 19 Apr 2006 18:48:58 -0000 1.22 --- tutorial.txt 19 Apr 2006 19:23:06 -0000 1.23 *************** *** 704,721 **** ---------------- - **Note:** This code seems to work in older versions, but the past - convention was to use the now deprecated ``SetPointerType`` function. - If you have an older version and the following example does not work - for you, try looking up that function. - *Incomplete Types* are structures, unions or arrays whose members are ! not yet specified. In the ``ctypes`` context, you can create types ! representing pointers to these incomplete types by passing their name ! (as a string) to the POINTER function, and complete the result ! subclass later. ! ! Consider this example (C-code):: ! struct cell; struct { --- 704,712 ---- ---------------- *Incomplete Types* are structures, unions or arrays whose members are ! not yet specified. In C, they are specified by forward declarations, which ! are defined later:: ! struct cell; /* forward declaration */ struct { *************** *** 738,745 **** because the new ``class cell`` is not available in the class statement ! itself. ! ! We can do it by creating an *incomplete type*. Just leave out the ! ``_fields_`` declaration and fill it up later:: >>> from ctypes import * --- 729,734 ---- because the new ``class cell`` is not available in the class statement ! itself. In ``ctypes``, we can define the ``cell`` class and set the ! ``_fields_`` attribute later, after the class statement:: >>> from ctypes import * *************** *** 776,787 **** First, you must create a class for the callback function, the class ! knows the calling convention, the result type the function has to ! return, and the number and types of the arguments this function will ! receive. ! ``ctypes`` provides the CFUNCTYPE factory function to create types for ! callback functions using the normal cdecl calling convention, and, on ! Windows, the WINFUNCTYPE factory function to create types for callback ! functions using the stdcall calling convention. Both of these factory functions are called with the result type as --- 765,775 ---- First, you must create a class for the callback function, the class ! knows the calling convention, the return type, and the number and ! types of arguments this function will receive. ! The CFUNCTYPE factory function creates types for callback functions ! using the normal cdecl calling convention, and, on Windows, the ! WINFUNCTYPE factory function creates types for callback functions ! using the stdcall calling convention. Both of these factory functions are called with the result type as *************** *** 801,809 **** ``qsort`` must be called with a pointer to the data to sort, the ! number of items in the data array, the size of one item, and the sort ! function, which is the callback. The callback function will then be called with two pointers to items, and it must return a negative ! integer if the first item is smaller than the second, a 0 if they are ! equal, and a positive integer else. So our callback function receives pointers to integers, and must --- 789,797 ---- ``qsort`` must be called with a pointer to the data to sort, the ! number of items in the data array, the size of one item, and a pointer ! to the comparison function, the callback. The callback will then be called with two pointers to items, and it must return a negative ! integer if the first item is smaller than the second, a zero if they ! are equal, and a positive integer else. So our callback function receives pointers to integers, and must *************** *** 815,819 **** For the first implementation of the callback function, we simply print ! the arguments we get, and return 0 (incremental development):: >>> def py_cmp_func(a, b): --- 803,807 ---- For the first implementation of the callback function, we simply print ! the arguments we get, and return 0 (incremental development ;-):: >>> def py_cmp_func(a, b): *************** *** 823,827 **** >>> ! Create the C callable function:: >>> cmp_func = CMPFUNC(py_cmp_func) --- 811,815 ---- >>> ! Create the C callable callback:: >>> cmp_func = CMPFUNC(py_cmp_func) *************** *** 878,882 **** >>> ! Ah, we're nearly done! Last refinements:: >>> def py_cmp_func(a, b): --- 866,871 ---- >>> ! Ah, we're nearly done! The last step is to actually compare the two ! items and return a useful result:: >>> def py_cmp_func(a, b): *************** *** 886,890 **** >>> ! Windows:: >>> qsort(ia, len(ia), sizeof(c_int), CMPFUNC(py_cmp_func)) # doctest: +WINDOWS --- 875,879 ---- >>> ! Final run on Windows:: >>> qsort(ia, len(ia), sizeof(c_int), CMPFUNC(py_cmp_func)) # doctest: +WINDOWS *************** *** 901,905 **** >>> ! Linux:: >>> qsort(ia, len(ia), sizeof(c_int), CMPFUNC(py_cmp_func)) # doctest: +LINUX --- 890,894 ---- >>> ! and on Linux:: >>> qsort(ia, len(ia), sizeof(c_int), CMPFUNC(py_cmp_func)) # doctest: +LINUX *************** *** 928,940 **** Sometimes, a dll not only exports functions, it also exports ! values. Examples in the Python dll itself are the ``Py_OptimizeFlag``, ! an integer set to 0, 1, or 2, depending on the ``-O`` or ``-OO`` flag ! given on startup. ! Starting with version 0.6.1, ``ctypes`` can access values like this ! with the ``in_dll`` class methods of the types. The following examples ! only work on Windows:: - >>> from ctypes import * >>> opt_flag = c_int.in_dll(pythonapi, "Py_OptimizeFlag") >>> print opt_flag --- 917,928 ---- Sometimes, a dll not only exports functions, it also exports ! values. An example in the Python library itself is the ! ``Py_OptimizeFlag``, an integer set to 0, 1, or 2, depending on the ! ``-O`` or ``-OO`` flag given on startup. ! ``ctypes`` can access values like this with the ``in_dll`` class ! methods of the type. ``pythonapi`` ìs a predefined symbol giving ! access to the Python C api:: >>> opt_flag = c_int.in_dll(pythonapi, "Py_OptimizeFlag") >>> print opt_flag *************** *** 946,950 **** been specified. ! A somewhat extended example which also demontrates the use of pointers accesses the ``PyImport_FrozenModules`` pointer exported by Python. --- 934,938 ---- been specified. ! An extended example which also demonstrates the use of pointers accesses the ``PyImport_FrozenModules`` pointer exported by Python. *************** *** 968,974 **** >>> ! XXX Should use pythonapi instead!!! ! We have ``loaded`` the Python dll and defined the ``struct _frozen`` ! data type, so we can get the pointer to the table:: >>> FrozenTable = POINTER(struct_frozen) --- 956,961 ---- >>> ! We have defined the ``struct _frozen`` data type, so we can get the ! pointer to the table:: >>> FrozenTable = POINTER(struct_frozen) *************** *** 976,984 **** >>> ! Since ``table`` is a ``pointer`` to the ``struct_frozen`` records, we ! can iterate over it, we just have to make sure that our loop ! terminates, because pointers have no size. Sooner or later it would ! probably crash with an access violation or whatever, so it's better to ! break out of the loop when we hit the NULL entry:: >>> for item in table: --- 963,971 ---- >>> ! Since ``table`` is a ``pointer`` to the array of ``struct_frozen`` ! records, we can iterate over it, but we just have to make sure that ! our loop terminates, because pointers have no size. Sooner or later it ! would probably crash with an access violation or whatever, so it's ! better to break out of the loop when we hit the NULL entry:: >>> for item in table: *************** *** 994,998 **** The fact that standard Python has a frozen module and a frozen package ! (indicated by the negative size member) is not wellknown, AFAIK it is used for testing. Try it out with ``import __hello__`` for example. --- 981,985 ---- The fact that standard Python has a frozen module and a frozen package ! (indicated by the negative size member) is not wellknown, it is only used for testing. Try it out with ``import __hello__`` for example. *************** *** 1003,1007 **** --------- ! There are some corners in ``ctypes`` where you may be expect something else than what actually happens. --- 990,994 ---- --------- ! There are some edges in ``ctypes`` where you may be expect something else than what actually happens. *************** *** 1040,1052 **** 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 - Enumeration types are not implemented. You can do it easily yourself, using ``c_int`` as the base class. --- 1027,1054 ---- Keep in mind that retrieving subobjects from Structure, Unions, and ! Arrays doesn't *copy* the subobject, instead it retrieves a wrapper object accessing the root-object's underlying buffer. + Another example that may behave different from what one would expect is this:: + + >>> s = c_char_p() + >>> s.value = "abc def ghi" + >>> s.value + 'abc def ghi' + >>> s.value is s.value + False + >>> + + Why is it printing ``False``? ctypes instances are objects containing + a memory block plus some descriptors accessing the contents of the + memory. Storing a Python object in the memory block does not store + the object itself, instead the ``contents`` of the object is stored. + Accessing the contents again constructs a new Python each time! + + Bugs, ToDo and non-implemented things ------------------------------------- Enumeration types are not implemented. You can do it easily yourself, using ``c_int`` as the base class. |
From: Thomas H. <th...@us...> - 2006-04-19 18:49:04
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12359 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.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** tutorial.txt 19 Apr 2006 18:47:39 -0000 1.21 --- tutorial.txt 19 Apr 2006 18:48:58 -0000 1.22 *************** *** 911,915 **** >>> ! So, is our array sorted now:: >>> for i in ia: print i, --- 911,915 ---- >>> ! So, our array sorted now:: >>> for i in ia: print i, *************** *** 918,923 **** >>> - Yep, it worked! - **Important note for callback functions:** --- 918,921 ---- |
From: Thomas H. <th...@us...> - 2006-04-19 18:47:45
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11411 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.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** tutorial.txt 19 Apr 2006 18:35:30 -0000 1.20 --- tutorial.txt 19 Apr 2006 18:47:39 -0000 1.21 *************** *** 481,485 **** >>> ! Structures and Unions --------------------- --- 481,485 ---- >>> ! Structures and unions --------------------- *************** *** 547,551 **** ! Structure/Union Alignment and Byte Order ---------------------------------------- --- 547,551 ---- ! Structure/union alignment and byte order ---------------------------------------- *************** *** 564,568 **** ! Bit Fields in Structures and Unions ----------------------------------- --- 564,568 ---- ! Bit fields in structures and unions ----------------------------------- *************** *** 772,777 **** ------------------ - (This example is too long, I should have used a shorter array) - ``ctypes`` allows to create C callable function pointers from Python callables. These are sometimes called *callback functions*. --- 772,775 ---- *************** *** 1052,1069 **** XXX Wrong - Bitfields are not implemented. - - Enumeration types are not implemented. You can do it easily - yourself, using ``c_int`` as the base class. - - ``long double`` is not implemented. ! .. no longer true: You cannot pass structures to functions as arguments, and you ! cannot set them as return type (only pointers). ! .. no longer true? Callback functions implemented in Python can *only* return integers. .. Local Variables: ! compile-command: "make_html" End: --- 1050,1061 ---- XXX Wrong ! Enumeration types are not implemented. You can do it easily yourself, ! using ``c_int`` as the base class. ! ``long double`` is not implemented. .. Local Variables: ! compile-command: "make.bat" End: |
From: Thomas H. <th...@us...> - 2006-04-19 18:35:37
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1734 Modified Files: tutorial.txt Log Message: Add some notes. Index: tutorial.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/tutorial.txt,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** tutorial.txt 19 Apr 2006 18:14:39 -0000 1.19 --- tutorial.txt 19 Apr 2006 18:35:30 -0000 1.20 *************** *** 5,10 **** This tutorial describes version 0.9.9 of ``ctypes``. ! Since older versions are quite common, I'll mention major differences ! when needed. Loading dynamic link libraries --- 5,18 ---- This tutorial describes version 0.9.9 of ``ctypes``. ! ! Note: The code samples in this tutorial uses ``doctest`` to make sure ! that they actually work. Since some code samples behave differently ! under Linux, Windows, or Mac OS X, they contain doctest directives in ! comments. ! ! Note: Quite some code samples references the ctypes ``c_int`` type. ! This type is an alias to the ``c_long`` type on 32-bit systems. So, ! you should not be confused if ``c_long`` is printed if you would ! expect ``c_int`` - they are actually the same type. Loading dynamic link libraries *************** *** 45,53 **** >>> cdll.LoadLibrary("libc.so.6") # doctest: +LINUX <CDLL 'libc.so.6', handle ... at ...> ! >>> libc = CDLL("libc.so.6") ! >>> libc <CDLL 'libc.so.6', handle ... at ...> >>> Accessing functions from loaded dlls --- 53,62 ---- >>> cdll.LoadLibrary("libc.so.6") # doctest: +LINUX <CDLL 'libc.so.6', handle ... at ...> ! >>> libc = CDLL("libc.so.6") # doctest: +LINUX ! >>> libc # doctest: +LINUX <CDLL 'libc.so.6', handle ... at ...> >>> + XXX Add section for Mac OS X. Accessing functions from loaded dlls *************** *** 101,106 **** >>> cdll.kernel32[1] # doctest: +WINDOWS ! <_FuncPtr object ar 0x...> >>> cdll.kernel32[0] # doctest: +WINDOWS >>> --- 110,120 ---- >>> cdll.kernel32[1] # doctest: +WINDOWS ! <_FuncPtr object at 0x...> >>> cdll.kernel32[0] # doctest: +WINDOWS + Traceback (most recent call last): + File "<stdin>", line 1, in ? + File "ctypes.py", line 310, in __getitem__ + func = _StdcallFuncPtr(name, self) + AttributeError: function ordinal 0 not found >>> |
From: Thomas H. <th...@us...> - 2006-04-19 18:14:45
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17323 Modified Files: tutorial.txt Log Message: LoadLibrary, CDLL, functions exported by ordinals. Index: tutorial.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/tutorial.txt,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** tutorial.txt 19 Apr 2006 17:43:15 -0000 1.18 --- tutorial.txt 19 Apr 2006 18:14:39 -0000 1.19 *************** *** 44,59 **** >>> cdll.LoadLibrary("libc.so.6") # doctest: +LINUX ! <CDLL '/lib/libc.so.6', handle ... at ...> ! >>> CDLL("libc.so.6") ! <CDLL '/lib/libc.so.6', handle ... at ...> >>> - **Note:** in older versions, the ``LoadLibrary`` method should be used - instead. - - This tutorial uses windows in its examples, however, functions from - the standard C library like ``strchr`` and ``printf`` should also work - on Linux and other systems. - Accessing functions from loaded dlls --- 44,53 ---- >>> cdll.LoadLibrary("libc.so.6") # doctest: +LINUX ! <CDLL 'libc.so.6', handle ... at ...> ! >>> libc = CDLL("libc.so.6") ! >>> libc ! <CDLL 'libc.so.6', handle ... at ...> >>> Accessing functions from loaded dlls *************** *** 73,77 **** func = _StdcallFuncPtr(name, self) AttributeError: function 'MyOwnFunction' not found ! Note that win32 system dlls like ``kernel32`` and ``user32`` often --- 67,71 ---- func = _StdcallFuncPtr(name, self) AttributeError: function 'MyOwnFunction' not found ! >>> Note that win32 system dlls like ``kernel32`` and ``user32`` often *************** *** 96,100 **** Sometimes, dlls export functions with names which aren't valid Python identifiers, like ``"??2@YAPAXI@Z"``. In this case you have to use ! ``getattr`` to retrieve the function (XXX Better example?):: >>> getattr(cdll.msvcrt, "??2@YAPAXI@Z") # doctest: +WINDOWS --- 90,94 ---- Sometimes, dlls export functions with names which aren't valid Python identifiers, like ``"??2@YAPAXI@Z"``. In this case you have to use ! ``getattr`` to retrieve the function:: >>> getattr(cdll.msvcrt, "??2@YAPAXI@Z") # doctest: +WINDOWS *************** *** 102,105 **** --- 96,107 ---- >>> + On Windows, some dlls export functions not by name but by ordinal. + These functions can be accessed by indexing the dll object with the + odinal number:: + + >>> cdll.kernel32[1] # doctest: +WINDOWS + <_FuncPtr object ar 0x...> + >>> cdll.kernel32[0] # doctest: +WINDOWS + >>> Calling functions |
From: Thomas H. <th...@us...> - 2006-04-19 17:43:20
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24463 Modified Files: tutorial.txt Log Message: Document cdll.LoadLibrary() and the CDLL constructor. Index: tutorial.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/tutorial.txt,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** tutorial.txt 19 Apr 2006 17:37:02 -0000 1.17 --- tutorial.txt 19 Apr 2006 17:43:15 -0000 1.18 *************** *** 35,46 **** >>> ! In principle the same way should work on Linux, but most of the time ! it seems required to specify the search path in this way. So this ! example shows also how to load libraries by specifying their ! filename:: ! >>> from ctypes import * ! >>> libc = cdll.LoadLibrary("/lib/libc.so.6") # doctest: +LINUX ! >>> print libc # doctest: +LINUX <CDLL '/lib/libc.so.6', handle ... at ...> >>> --- 35,49 ---- >>> ! Windows appends the usual '.dll' file suffix automatically. ! On Linux, it is required to specify the filename *including* the ! extension to load a library, so attribute access does not work. ! Either the ``LoadLibrary`` method of the dll loaders should be used, ! or you should load the library by creating an instance of CDLL by ! calling the constructor:: ! ! >>> cdll.LoadLibrary("libc.so.6") # doctest: +LINUX ! <CDLL '/lib/libc.so.6', handle ... at ...> ! >>> CDLL("libc.so.6") <CDLL '/lib/libc.so.6', handle ... at ...> >>> |
From: Thomas H. <th...@us...> - 2006-04-19 17:37:14
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19575 Modified Files: tutorial.txt Log Message: Fix test failures. Index: tutorial.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/tutorial.txt,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** tutorial.txt 19 Apr 2006 17:16:34 -0000 1.16 --- tutorial.txt 19 Apr 2006 17:37:02 -0000 1.17 *************** *** 522,528 **** >>> print POINT.x ! <Field type=c_int, ofs=0, size=4> >>> print POINT.y ! <Field type=c_int, ofs=4, size=4> >>> --- 522,528 ---- >>> print POINT.x ! <Field type=c_long, ofs=0, size=4> >>> print POINT.y ! <Field type=c_long, ofs=4, size=4> >>> *************** *** 557,563 **** ... >>> print Int.first_16 ! <Field type=c_int, ofs=0:0, bits=16> >>> print Int.second_16 ! <Field type=c_int, ofs=0:16, bits=16> >>> --- 557,563 ---- ... >>> print Int.first_16 ! <Field type=c_long, ofs=0:0, bits=16> >>> print Int.second_16 ! <Field type=c_long, ofs=0:16, bits=16> >>> |
From: Thomas H. <th...@us...> - 2006-04-19 17:35:02
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18093 Modified Files: ChangeLog Log Message: Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/ChangeLog,v retrieving revision 1.122 retrieving revision 1.123 diff -C2 -d -r1.122 -r1.123 *** ChangeLog 15 Apr 2006 20:21:22 -0000 1.122 --- ChangeLog 19 Apr 2006 17:34:56 -0000 1.123 *************** *** 1,2 **** --- 1,17 ---- + 2006-04-19 Thomas Heller <th...@py...> + + * When a 'source' object is casted to another object, the other + object keeps a reference to the source object to keep it alive. + + 2006-04-18 Thomas Heller <th...@py...> + + * Patch from Skip Montanaro, in Python SVN: C++ compiler cleanup: + the typical few casts, and ... C++ didn't like that the + StgDictObject's ffi_type member had the same name as its type. I + changed that to ffi_type_pointer. + + Fix refcount issues in CreateSwappedType - this removes the + refleak when reloading ctypes. + 2006-04-15 Thomas Heller <th...@py...> |
From: Thomas H. <th...@us...> - 2006-04-19 17:17:30
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4071 Added Files: mkpydoc.py Log Message: mkpydoc.py --- NEW FILE: mkpydoc.py --- #!/usr/bin/env 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 # python 2.3 if not hasattr(__builtins__,"set"): import sets set = sets.Set if not hasattr(__builtins__,"sorted"): def sorted(list): if hasattr(list,"sort"): return list.sort() # maybe it is sorted return list 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__) ] # TODO definitions get from latexwriter # TODO definitions must be guarded if multiple modules are included self.definitions = [ "\\newlength{\\locallinewidth}\n" "\\setlength{\\locallinewidth}{\\linewidth}\n" ] def astext(self): return ''.join(self.definitions + 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 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("tutorial.txt", "tutorial.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-04-19 17:16:38
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3286 Modified Files: tutorial.txt Removed Files: mkpydoc.py Log Message: mkpydoc.py Index: tutorial.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/tutorial.txt,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** tutorial.txt 13 Apr 2006 20:26:54 -0000 1.15 --- tutorial.txt 19 Apr 2006 17:16:34 -0000 1.16 *************** *** 1,4 **** ctypes tutorial ! +++++++++++++++ This tutorial describes version 0.9.9 of ``ctypes``. --- 1,6 ---- + ``ctypes`` is a foreign function library for Python. + ctypes tutorial ! =============== This tutorial describes version 0.9.9 of ``ctypes``. *************** *** 516,530 **** >>> r = RECT((1, 2), (3, 4)) ! XXX Fields descriptors can be retrieved from the *class*, they ! have readonly ``size`` and ``offset`` attributes describing the size ! in bytes and the offset of this field from the beginning of the ! internal memory buffer:: ! >>> print POINT.x.size, POINT.x.offset ! 4 0 ! >>> print POINT.y.size, POINT.y.offset ! 4 4 >>> By default, Structure and Union fields are aligned in the same way the C compiler does it. It is possible to override this behaviour be --- 518,534 ---- >>> r = RECT((1, 2), (3, 4)) ! Fields descriptors can be retrieved from the *class*, they are useful ! for debugging because they can provide useful information:: ! >>> print POINT.x ! <Field type=c_int, ofs=0, size=4> ! >>> print POINT.y ! <Field type=c_int, ofs=4, size=4> >>> + + Structure/Union Alignment and Byte Order + ---------------------------------------- + By default, Structure and Union fields are aligned in the same way the C compiler does it. It is possible to override this behaviour be *************** *** 534,539 **** also does in MSVC. ! **New in version 0.6.2**: Structures and unions can also be passed *by ! value* to function calls. Arrays --- 538,565 ---- also does in MSVC. ! ``ctypes`` uses the native byte order for Structures and Unions. To ! build structures with non-native byte order, you can use one of the ! BigEndianStructure, LittleEndianStructure, BigEndianUnion, and ! LittleEndianUnion base classes. These classes cannot contain pointer ! fields. ! ! ! Bit Fields in Structures and Unions ! ----------------------------------- ! ! It is possible to create structures and unions containing bit fields. ! Bit fields are only possible for integer fields, the bit width is ! specified as the third item in the ``_fields_`` tuples:: ! ! >>> class Int(Structure): ! ... _fields_ = [("first_16", c_int, 16), ! ... ("second_16", c_int, 16)] ! ... ! >>> print Int.first_16 ! <Field type=c_int, ofs=0:0, bits=16> ! >>> print Int.second_16 ! <Field type=c_int, ofs=0:16, bits=16> ! >>> ! Arrays --- mkpydoc.py DELETED --- |
From: Thomas H. <th...@us...> - 2006-04-13 21:29:13
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30521 Modified Files: mkpydoc.py Log Message: Patch from egr...@us.... Index: mkpydoc.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/mkpydoc.py,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** mkpydoc.py 5 Apr 2006 12:35:27 -0000 1.8 --- mkpydoc.py 13 Apr 2006 21:29:02 -0000 1.9 *************** *** 22,25 **** --- 22,36 ---- pass + # python 2.3 + if not hasattr(__builtins__,"set"): + import sets + set = sets.Set + if not hasattr(__builtins__,"sorted"): + def sorted(list): + if hasattr(list,"sort"): + return list.sort() + # maybe it is sorted + return list + from markup import codemarkup missing = set() *************** *** 72,78 **** % vars(self.__class__) ] ! def astext(self): ! return ''.join(self.head_prefix + self.head + self.body_prefix + --- 83,95 ---- % vars(self.__class__) ] ! # TODO definitions get from latexwriter ! # TODO definitions must be guarded if multiple modules are included ! self.definitions = [ ! "\\newlength{\\locallinewidth}\n" ! "\\setlength{\\locallinewidth}{\\linewidth}\n" ! ] def astext(self): ! return ''.join(self.definitions + ! self.head_prefix + self.head + self.body_prefix + *************** *** 204,213 **** 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'): --- 221,224 ---- *************** *** 282,286 **** def main(): ! convert("libctypes.txt", "../../../trunk/Doc/lib/libctypes.tex") if missing: mod = open("missing.py", "w") --- 293,298 ---- def main(): ! convert("tutorial.txt", "tutorial.tex") ! ## convert("libctypes.txt", "../../../trunk/Doc/lib/libctypes.tex") if missing: mod = open("missing.py", "w") |
From: Thomas H. <th...@us...> - 2006-04-13 20:26:58
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15424 Modified Files: tutorial.txt Log Message: final adjustments, for today Index: tutorial.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/tutorial.txt,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** tutorial.txt 13 Apr 2006 20:25:29 -0000 1.14 --- tutorial.txt 13 Apr 2006 20:26:54 -0000 1.15 *************** *** 787,791 **** And we're ready to go:: ! >>> qsort(ia, len(ia), sizeof(c_int), cmp_func) py_cmp_func <ctypes.LP_c_long object at 0x00...> <ctypes.LP_c_long object at 0x00...> py_cmp_func <ctypes.LP_c_long object at 0x00...> <ctypes.LP_c_long object at 0x00...> --- 787,791 ---- And we're ready to go:: ! >>> qsort(ia, len(ia), sizeof(c_int), cmp_func) # doctest: +WINDOWS py_cmp_func <ctypes.LP_c_long object at 0x00...> <ctypes.LP_c_long object at 0x00...> py_cmp_func <ctypes.LP_c_long object at 0x00...> <ctypes.LP_c_long object at 0x00...> |
From: Thomas H. <th...@us...> - 2006-04-13 20:25:34
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14513 Modified Files: tutorial.txt test-tutorial.py manual.html Log Message: doctest can now separate the output of the 'printf' function (which goes to C's stdout) from the Python output (which goes to sys.stdout). So there is no need to skip the printf tests anymore. Index: tutorial.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/tutorial.txt,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** tutorial.txt 13 Apr 2006 20:07:08 -0000 1.13 --- tutorial.txt 13 Apr 2006 20:25:29 -0000 1.14 *************** *** 273,286 **** >>> printf = libc.printf ! >>> printf("Hello, %s\n", "World!") # doctest: +SKIP Hello, World! 14 ! >>> printf("Hello, %S", u"World!") # doctest: +SKIP Hello, World! ! 14 ! >>> printf("%d bottles of beer\n", 42) # doctest: +SKIP 42 bottles of beer 19 ! >>> printf("%f bottles of beer\n", 42.5) # doctest: +SKIP Traceback (most recent call last): File "<stdin>", line 1, in ? --- 273,286 ---- >>> printf = libc.printf ! >>> printf("Hello, %s\n", "World!") Hello, World! 14 ! >>> printf("Hello, %S", u"World!") Hello, World! ! 13 ! >>> printf("%d bottles of beer\n", 42) 42 bottles of beer 19 ! >>> printf("%f bottles of beer\n", 42.5) Traceback (most recent call last): File "<stdin>", line 1, in ? *************** *** 293,299 **** type:: ! >>> printf("An int %d, a double %f\n", 1234, c_double(3.14)) # doctest: +SKIP Integer 1234, double 3.1400001049 ! 34 >>> --- 293,299 ---- type:: ! >>> printf("An int %d, a double %f\n", 1234, c_double(3.14)) Integer 1234, double 3.1400001049 ! 31 >>> *************** *** 312,316 **** ... >>> bottles = Bottles(42) ! >>> printf("%d bottles of beer\n", bottles) # doctest: +SKIP 42 bottles of beer 19 --- 312,316 ---- ... >>> bottles = Bottles(42) ! >>> printf("%d bottles of beer\n", bottles) 42 bottles of beer 19 *************** *** 334,339 **** >>> printf.argtypes = [c_char_p, c_char_p, c_int, c_double] ! >>> printf("String '%s', Int %d, Double %f\n", "Hi", 10, 2.2) # doctest: +SKIP String 'Hi', Int 10, Double 2.200000 Specifying a format protects against incompatible argument types (just --- 334,341 ---- >>> printf.argtypes = [c_char_p, c_char_p, c_int, c_double] ! >>> printf("String '%s', Int %d, Double %f\n", "Hi", 10, 2.2) String 'Hi', Int 10, Double 2.200000 + 37 + >>> Specifying a format protects against incompatible argument types (just *************** *** 341,350 **** to valid types:: ! >>> printf("%d %d %d", 1, 2, 3) # doctest: +SKIP Traceback (most recent call last): File "<stdin>", line 1, in ? ! TypeError: string expected instead of int instance ! >>> printf("%s %d %f", "X", 2, 3) # doctest: +SKIP X 2 3.00000012 >>> --- 343,353 ---- to valid types:: ! >>> printf("%d %d %d", 1, 2, 3) Traceback (most recent call last): File "<stdin>", line 1, in ? ! ArgumentError: argument 2: exceptions.TypeError: wrong type ! >>> printf("%s %d %f", "X", 2, 3) X 2 3.00000012 + 12 >>> Index: test-tutorial.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/test-tutorial.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** test-tutorial.py 13 Apr 2006 20:07:08 -0000 1.4 --- test-tutorial.py 13 Apr 2006 20:25:29 -0000 1.5 *************** *** 23,26 **** --- 23,35 ---- elif SKIP in ex.options: examples.remove(ex) + elif "printf(" in ex.source: + # handle that doctest doesn't catch printf's output + lines = ex.want.splitlines() + try: + int(lines[-1]) + except ValueError: + pass + else: + ex.want = "\n".join(lines[1:]) + "\n" else: ex.want = ex.want.replace("c_long", c_int_name) Index: manual.html =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/manual.html,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** manual.html 22 Mar 2006 07:09:10 -0000 1.4 --- manual.html 13 Apr 2006 20:25:29 -0000 1.5 *************** *** 224,229 **** pre.literal-block, pre.doctest-block { margin-left: 2em ; ! margin-right: 2em ; ! background-color: #eeeeee } span.classifier { --- 224,228 ---- pre.literal-block, pre.doctest-block { margin-left: 2em ; ! margin-right: 2em } span.classifier { *************** *** 282,288 **** font-size: 100% } - tt.docutils { - background-color: #eeeeee } - ul.auto-toc { list-style-type: none } --- 281,284 ---- *************** *** 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> --- 303,309 ---- <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> *************** *** 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 --- 588,594 ---- 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 *************** *** 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> --- 616,619 ---- *************** *** 632,636 **** <div class="section"> <h2><a class="toc-backref" href="#id11" id="class-attributes-of-simple-types" name="class-attributes-of-simple-types">Class attributes of simple types</a></h2> ! <p><tt class="docutils literal"><span class="pre">__ctype__be__</span></tt>, <tt class="docutils literal"><span class="pre">__ctype_le__</span></tt></p> <blockquote> If the type supports different byte order (pointer types do NOT --- 628,632 ---- <div class="section"> <h2><a class="toc-backref" href="#id11" id="class-attributes-of-simple-types" name="class-attributes-of-simple-types">Class attributes of simple types</a></h2> ! <p><tt class="docutils literal"><span class="pre">__ctype_be__</span></tt>, <tt class="docutils literal"><span class="pre">__ctype_le__</span></tt></p> <blockquote> If the type supports different byte order (pointer types do NOT *************** *** 660,671 **** <p><tt class="docutils literal"><span class="pre">from_param</span></tt></p> <blockquote> ! <p>This is a class method (an instance method of the metaclass, to be ! exact) that is used to adapt function parameters. If a ! <tt class="docutils literal"><span class="pre">c_int</span></tt> type is specified in a function's argtypes sequence, ! <tt class="docutils literal"><span class="pre">c_int.from_param(arg)</span></tt> will be called by ctypes and the result ! will be passed to the foreign function call as a parameter.</p> <p><tt class="docutils literal"><span class="pre">from_param</span></tt> usually returns an internal object that you cannot ! use in Python code - it only makes sense to pass this to foreign ! functions.</p> <p>On one hand, <tt class="docutils literal"><span class="pre">from_param</span></tt> is a performance optimization - it allows you to pass Python integers to function calls expecting a --- 656,667 ---- <p><tt class="docutils literal"><span class="pre">from_param</span></tt></p> <blockquote> ! <p>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 <tt class="docutils literal"><span class="pre">from_param(arg)</span></tt> method will be called with the actual ! argument, and the result will be passed to the foreign function ! call as a parameter.</p> <p><tt class="docutils literal"><span class="pre">from_param</span></tt> usually returns an internal object that you cannot ! use in Python code - it only makes sense to pass this object to ! foreign functions.</p> <p>On one hand, <tt class="docutils literal"><span class="pre">from_param</span></tt> is a performance optimization - it allows you to pass Python integers to function calls expecting a *************** *** 682,685 **** --- 678,686 ---- <div class="section"> <h2><a class="toc-backref" href="#id13" id="instance-attributes-of-simple-types" name="instance-attributes-of-simple-types">Instance attributes of simple types</a></h2> + <p><tt class="docutils literal"><span class="pre">value</span></tt></p> + <blockquote> + 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.</blockquote> <p><tt class="docutils literal"><span class="pre">_objects</span></tt> (never modify this)</p> <blockquote> *************** *** 695,703 **** Implementation artifact: does this object have to free its memory block on destruction.</blockquote> - <p><tt class="docutils literal"><span class="pre">value</span></tt></p> - <blockquote> - 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.</blockquote> <p><tt class="docutils literal"><span class="pre">_as_parameter_</span></tt> (readonly)</p> <blockquote> --- 696,699 ---- |
From: Thomas H. <th...@us...> - 2006-04-13 20:07:11
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1014 Modified Files: tutorial.txt test-tutorial.py Log Message: Adjustments for Windows. Index: tutorial.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/tutorial.txt,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** tutorial.txt 13 Apr 2006 19:58:08 -0000 1.12 --- tutorial.txt 13 Apr 2006 20:07:08 -0000 1.13 *************** *** 784,798 **** And we're ready to go:: ! >>> qsort(ia, len(ia), sizeof(c_int), cmp_func) # doctest: +WINDOWS ! 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> >>> --- 784,798 ---- And we're ready to go:: ! >>> qsort(ia, len(ia), sizeof(c_int), cmp_func) ! py_cmp_func <ctypes.LP_c_long object at 0x00...> <ctypes.LP_c_long object at 0x00...> ! py_cmp_func <ctypes.LP_c_long object at 0x00...> <ctypes.LP_c_long object at 0x00...> ! py_cmp_func <ctypes.LP_c_long object at 0x00...> <ctypes.LP_c_long object at 0x00...> ! py_cmp_func <ctypes.LP_c_long object at 0x00...> <ctypes.LP_c_long object at 0x00...> ! py_cmp_func <ctypes.LP_c_long object at 0x00...> <ctypes.LP_c_long object at 0x00...> ! py_cmp_func <ctypes.LP_c_long object at 0x00...> <ctypes.LP_c_long object at 0x00...> ! py_cmp_func <ctypes.LP_c_long object at 0x00...> <ctypes.LP_c_long object at 0x00...> ! py_cmp_func <ctypes.LP_c_long object at 0x00...> <ctypes.LP_c_long object at 0x00...> ! py_cmp_func <ctypes.LP_c_long object at 0x00...> <ctypes.LP_c_long object at 0x00...> ! py_cmp_func <ctypes.LP_c_long object at 0x00...> <ctypes.LP_c_long object at 0x00...> >>> *************** *** 853,857 **** py_cmp_func 1 7 py_cmp_func 5 1 - -1 >>> --- 853,856 ---- Index: test-tutorial.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/test-tutorial.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** test-tutorial.py 13 Apr 2006 19:58:08 -0000 1.3 --- test-tutorial.py 13 Apr 2006 20:07:08 -0000 1.4 *************** *** 2,9 **** --- 2,12 ---- import sys import doctest + + # handle platform specific issues WINDOWS = doctest.register_optionflag("WINDOWS") LINUX = doctest.register_optionflag("LINUX") SKIP = doctest.register_optionflag("SKIP") + # handle size specific issues import ctypes c_int_name = ctypes.c_int.__name__ *************** *** 21,27 **** examples.remove(ex) else: - ## print "REPLACE:" - ## print "\t", ex.want - ## print "\t", ex.want.replace("c_long", c_int_name) ex.want = ex.want.replace("c_long", c_int_name) test.examples = examples --- 24,27 ---- |
From: Thomas H. <th...@us...> - 2006-04-13 19:58:11
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26583 Modified Files: test-tutorial.py tutorial.txt Log Message: Update the tutorial, and ensure that it works on linux. Index: tutorial.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/tutorial.txt,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** tutorial.txt 27 Mar 2006 08:47:12 -0000 1.11 --- tutorial.txt 13 Apr 2006 19:58:08 -0000 1.12 *************** *** 26,33 **** >>> from ctypes import * ! >>> print windll.kernel32 ! <WinDLL 'kernel32', handle 7c800000 at ...> ! >>> print cdll.msvcrt ! <CDLL 'msvcrt', handle 77be0000 at ...> In principle the same way should work on Linux, but most of the time --- 26,35 ---- >>> from ctypes import * ! >>> print windll.kernel32 # doctest: +WINDOWS ! <WinDLL 'kernel32', handle ... at ...> ! >>> print cdll.msvcrt # doctest: +WINDOWS ! <CDLL 'msvcrt', handle ... at ...> ! >>> libc = cdll.msvcrt # doctest: +WINDOWS ! >>> In principle the same way should work on Linux, but most of the time *************** *** 37,42 **** >>> from ctypes import * ! >>> libc = cdll.load("/lib/libc.so.6") # doctest: +SKIP ! <CDLL '/lib/libc.so.6', handle 40018c28 at 4019978c> >>> --- 39,45 ---- >>> from ctypes import * ! >>> libc = cdll.LoadLibrary("/lib/libc.so.6") # doctest: +LINUX ! >>> print libc # doctest: +LINUX ! <CDLL '/lib/libc.so.6', handle ... at ...> >>> *************** *** 55,63 **** >>> from ctypes import * ! >>> print cdll.msvcrt.printf <_FuncPtr object at 0x...> ! >>> print windll.kernel32.GetModuleHandleA <_FuncPtr object at 0x...> ! >>> print windll.kernel32.MyOwnFunction Traceback (most recent call last): File "<stdin>", line 1, in ? --- 58,66 ---- >>> from ctypes import * ! >>> libc.printf <_FuncPtr object at 0x...> ! >>> print windll.kernel32.GetModuleHandleA # doctest: +WINDOWS <_FuncPtr object at 0x...> ! >>> print windll.kernel32.MyOwnFunction # doctest: +WINDOWS Traceback (most recent call last): File "<stdin>", line 1, in ? *************** *** 90,94 **** ``getattr`` to retrieve the function (XXX Better example?):: ! >>> getattr(cdll.msvcrt, "??2@YAPAXI@Z") <_FuncPtr object at 0x...> >>> --- 93,97 ---- ``getattr`` to retrieve the function (XXX Better example?):: ! >>> getattr(cdll.msvcrt, "??2@YAPAXI@Z") # doctest: +WINDOWS <_FuncPtr object at 0x...> >>> *************** *** 106,114 **** be used as the NULL pointer):: ! >>> from ctypes import * ! >>> print cdll.msvcrt.time(None) ! 1143... ! >>> print hex(windll.kernel32.GetModuleHandleA(None)) 0x1d000000 ``ctypes`` tries to protect you from calling functions with the wrong --- 109,117 ---- be used as the NULL pointer):: ! >>> print libc.time(None) ! 114... ! >>> print hex(windll.kernel32.GetModuleHandleA(None)) # doctest: +WINDOWS 0x1d000000 + >>> ``ctypes`` tries to protect you from calling functions with the wrong *************** *** 116,124 **** does this by examining the stack after the function returns:: ! >>> windll.kernel32.GetModuleHandleA() Traceback (most recent call last): File "<stdin>", line 1, in ? ValueError: Procedure probably called with not enough arguments (4 bytes missing) ! >>> windll.kernel32.GetModuleHandleA(0, 0) Traceback (most recent call last): File "<stdin>", line 1, in ? --- 119,127 ---- does this by examining the stack after the function returns:: ! >>> windll.kernel32.GetModuleHandleA() # doctest: +WINDOWS Traceback (most recent call last): File "<stdin>", line 1, in ? ValueError: Procedure probably called with not enough arguments (4 bytes missing) ! >>> windll.kernel32.GetModuleHandleA(0, 0) # doctest: +WINDOWS Traceback (most recent call last): File "<stdin>", line 1, in ? *************** *** 130,134 **** called with invalid argument values:: ! >>> windll.kernel32.GetModuleHandleA(32) Traceback (most recent call last): File "<stdin>", line 1, in ? --- 133,137 ---- called with invalid argument values:: ! >>> windll.kernel32.GetModuleHandleA(32) # doctest: +WINDOWS Traceback (most recent call last): File "<stdin>", line 1, in ? *************** *** 269,273 **** prompt, not from within *IDLE* or *PythonWin*:: ! >>> from ctypes import *; printf = cdll.msvcrt.printf >>> printf("Hello, %s\n", "World!") # doctest: +SKIP Hello, World! --- 272,276 ---- prompt, not from within *IDLE* or *PythonWin*:: ! >>> printf = libc.printf >>> printf("Hello, %s\n", "World!") # doctest: +SKIP Hello, World! *************** *** 290,295 **** type:: - >>> from ctypes import * - >>> printf = cdll.msvcrt.printf >>> printf("An int %d, a double %f\n", 1234, c_double(3.14)) # doctest: +SKIP Integer 1234, double 3.1400001049 --- 293,296 ---- *************** *** 311,316 **** ... >>> bottles = Bottles(42) - >>> from ctypes import * - >>> printf = cdll.msvcrt.printf >>> printf("%d bottles of beer\n", bottles) # doctest: +SKIP 42 bottles of beer --- 312,315 ---- *************** *** 334,339 **** with this feature):: - >>> from ctypes import * - >>> printf = cdll.msvcrt.printf >>> printf.argtypes = [c_char_p, c_char_p, c_int, c_double] >>> printf("String '%s', Int %d, Double %f\n", "Hi", 10, 2.2) # doctest: +SKIP --- 333,336 ---- *************** *** 375,380 **** string:: ! >>> from ctypes import * ! >>> strchr = cdll.msvcrt.strchr >>> strchr("abcdef", ord("d")) # doctest: +SKIP 8059983 --- 372,376 ---- string:: ! >>> strchr = libc.strchr >>> strchr("abcdef", ord("d")) # doctest: +SKIP 8059983 *************** *** 390,406 **** a single character Python string into a C char:: ! >>> from ctypes import * ! >>> msvcrt = cdll.msvcrt ! >>> msvcrt.strchr.restype = c_char_p ! >>> msvcrt.strchr.argtypes = [c_char_p, c_char] ! >>> msvcrt.strchr("abcdef", "d") 'def' ! >>> msvcrt.strchr("abcdef", "def") Traceback (most recent call last): File "<stdin>", line 1, in ? ArgumentError: argument 2: exceptions.TypeError: one character string expected ! >>> print msvcrt.strchr("abcdef", "x") None ! >>> msvcrt.strchr("abcdef", "d") 'def' >>> --- 386,400 ---- a single character Python string into a C char:: ! >>> strchr.restype = c_char_p ! >>> strchr.argtypes = [c_char_p, c_char] ! >>> strchr("abcdef", "d") 'def' ! >>> strchr("abcdef", "def") Traceback (most recent call last): File "<stdin>", line 1, in ? ArgumentError: argument 2: exceptions.TypeError: one character string expected ! >>> print strchr("abcdef", "x") None ! >>> strchr("abcdef", "d") 'def' >>> *************** *** 415,420 **** for error return values and automatically raise an exception:: ! >>> from ctypes import * ! >>> GetModuleHandle = windll.kernel32.GetModuleHandleA >>> def ValidHandle(value): ... if value == 0: --- 409,413 ---- for error return values and automatically raise an exception:: ! >>> GetModuleHandle = windll.kernel32.GetModuleHandleA # doctest: +WINDOWS >>> def ValidHandle(value): ... if value == 0: *************** *** 423,430 **** ... >>> ! >>> GetModuleHandle.restype = ValidHandle ! >>> GetModuleHandle(None) 486539264 ! >>> GetModuleHandle("something silly") # doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): File "<stdin>", line 1, in ? --- 416,423 ---- ... >>> ! >>> GetModuleHandle.restype = ValidHandle # doctest: +WINDOWS ! >>> GetModuleHandle(None) # doctest: +WINDOWS 486539264 ! >>> GetModuleHandle("something silly") # doctest: +WINDOWS +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): File "<stdin>", line 1, in ? *************** *** 452,457 **** if you don't need the pointer object in Python itself:: - >>> from ctypes import * - >>> msvcrt = cdll.msvcrt >>> i = c_int() >>> f = c_float() --- 445,448 ---- *************** *** 459,464 **** >>> print i.value, f.value, repr(s.value) 0 0.0 '' ! >>> msvcrt.sscanf("1 3.14 Hello", "%d %f %s", ! ... byref(i), byref(f), s) 3 >>> print i.value, f.value, repr(s.value) --- 450,455 ---- >>> print i.value, f.value, repr(s.value) 0 0.0 '' ! >>> libc.sscanf("1 3.14 Hello", "%d %f %s", ! ... byref(i), byref(f), s) 3 >>> print i.value, f.value, repr(s.value) *************** *** 651,659 **** ``ctypes`` type, and returns a new type:: - >>> from ctypes import * >>> PI = POINTER(c_int) >>> PI <class 'ctypes.LP_c_long'> ! >>> PI(42) Traceback (most recent call last): File "<stdin>", line 1, in ? --- 642,649 ---- ``ctypes`` type, and returns a new type:: >>> PI = POINTER(c_int) >>> PI <class 'ctypes.LP_c_long'> ! >>> PI(42) # doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): File "<stdin>", line 1, in ? *************** *** 758,765 **** integers:: - >>> from ctypes import * >>> IntArray5 = c_int * 5 >>> ia = IntArray5(5, 1, 7, 33, 99) ! >>> qsort = cdll.msvcrt.qsort >>> --- 748,755 ---- integers:: >>> IntArray5 = c_int * 5 >>> ia = IntArray5(5, 1, 7, 33, 99) ! >>> qsort = libc.qsort ! >>> qsort.restype = None >>> *************** *** 794,798 **** And we're ready to go:: ! >>> qsort(ia, len(ia), sizeof(c_int), cmp_func) 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> --- 784,788 ---- And we're ready to go:: ! >>> qsort(ia, len(ia), sizeof(c_int), cmp_func) # doctest: +WINDOWS 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> *************** *** 805,809 **** 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 >>> --- 795,798 ---- *************** *** 815,819 **** ... >>> 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 --- 804,812 ---- ... >>> cmp_func = CMPFUNC(py_cmp_func) ! >>> ! ! Here is what we get on Windows:: ! ! >>> qsort(ia, len(ia), sizeof(c_int), cmp_func) # doctest: +WINDOWS py_cmp_func 7 1 py_cmp_func 33 1 *************** *** 826,830 **** py_cmp_func 33 99 py_cmp_func 7 33 ! -1 >>> --- 819,833 ---- py_cmp_func 33 99 py_cmp_func 7 33 ! >>> ! ! It is funny to see that on linux the sort function seems to work much ! more efficient, it is doing less comparisons:: ! ! >>> qsort(ia, len(ia), sizeof(c_int), cmp_func) # doctest: +LINUX ! py_cmp_func 5 1 ! py_cmp_func 33 99 ! py_cmp_func 7 33 ! py_cmp_func 5 7 ! py_cmp_func 1 7 >>> *************** *** 835,839 **** ... 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 --- 838,846 ---- ... return a[0] - b[0] ... ! >>> ! ! Windows:: ! ! >>> qsort(ia, len(ia), sizeof(c_int), CMPFUNC(py_cmp_func)) # doctest: +WINDOWS py_cmp_func 33 7 py_cmp_func 99 33 *************** *** 849,852 **** --- 856,869 ---- >>> + Linux:: + + >>> qsort(ia, len(ia), sizeof(c_int), CMPFUNC(py_cmp_func)) # doctest: +LINUX + py_cmp_func 5 1 + py_cmp_func 33 99 + py_cmp_func 7 33 + py_cmp_func 1 7 + py_cmp_func 5 7 + >>> + So, is our array sorted now:: Index: test-tutorial.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/test-tutorial.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** test-tutorial.py 27 Mar 2006 08:44:36 -0000 1.2 --- test-tutorial.py 13 Apr 2006 19:58:08 -0000 1.3 *************** *** 1,6 **** --- 1,12 ---- #!/usr/bin/env python + import sys import doctest + WINDOWS = doctest.register_optionflag("WINDOWS") + LINUX = doctest.register_optionflag("LINUX") SKIP = doctest.register_optionflag("SKIP") + import ctypes + c_int_name = ctypes.c_int.__name__ + base = doctest.DocTestRunner class MyDocTestRunner(base): *************** *** 8,13 **** examples = test.examples[:] for ex in test.examples: ! if SKIP in ex.options: examples.remove(ex) test.examples = examples return base.run(self, test, compileflags, out, clear_globs) --- 14,28 ---- examples = test.examples[:] for ex in test.examples: ! if WINDOWS in ex.options and sys.platform != "win32": examples.remove(ex) + elif LINUX in ex.options and not sys.platform.startswith("linux"): + examples.remove(ex) + elif SKIP in ex.options: + examples.remove(ex) + else: + ## print "REPLACE:" + ## print "\t", ex.want + ## print "\t", ex.want.replace("c_long", c_int_name) + ex.want = ex.want.replace("c_long", c_int_name) test.examples = examples return base.run(self, test, compileflags, out, clear_globs) |
From: Thomas H. <th...@us...> - 2006-04-13 19:06:41
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18080 Modified Files: ChangeLog Log Message: Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/ChangeLog,v retrieving revision 1.120 retrieving revision 1.121 diff -C2 -d -r1.120 -r1.121 *** ChangeLog 13 Apr 2006 18:41:10 -0000 1.120 --- ChangeLog 13 Apr 2006 19:06:38 -0000 1.121 *************** *** 1,5 **** 2006-04-13 Thomas Heller <th...@py...> ! * Merged in changes made in the 'LoadLibrary_branch' branch: Restore the old way to load libraries again: --- 1,7 ---- 2006-04-13 Thomas Heller <th...@py...> ! * Changed version number to 0.9.9.6. ! ! * Merged in changes made in the 'LoadLibrary_branch' branch: Restore the old way to load libraries again: |