Commit graph

117 commits

Author SHA1 Message Date
Florent Xicluna
9e7a4c9738 Issue #7703: ctypes supports both buffer() and memoryview(). The former is deprecated.
Complement of r79288.
2010-03-22 16:07:38 +00:00
Florent Xicluna
f08a0176a7 Get rid of buffer() in test_ctypes: backport the 3.x tests. 2010-03-22 15:02:46 +00:00
Collin Winter
786431282b Avoid hardcoding refcounts in tests. 2010-03-17 17:36:16 +00:00
Ezio Melotti
d80b4bfd0b #7092: silence some more py3k warnings. 2010-03-17 13:52:48 +00:00
Florent Xicluna
1f3b4e12e8 Fix some py3k warnings in the standard library. 2010-03-07 12:14:25 +00:00
Gregory P. Smith
3c699d334a Adds c_ssize_t to ctypes. issue 6729. 2010-03-01 04:56:12 +00:00
Thomas Heller
92bd059c67 ctypes CThunkObject was not registered correctly with the cycle
garbage collector, leading to possible leaks when using callback
functions.
2010-02-23 20:11:44 +00:00
Ezio Melotti
dde5b94875 #7092: Silence more py3k warnings. Patch by Florent Xicluna. 2010-02-03 05:37:26 +00:00
Thomas Heller
6be522bfc2 Issue #4606: Passing 'None' if ctypes argtype is set to POINTER(...)
does now always result in NULL.
2009-09-18 20:05:44 +00:00
Thomas Heller
7a352c0ed8 Issue #5042: Structure sub-subclass does now initialize correctly with
base class positional arguments.
2009-09-18 18:55:17 +00:00
Thomas Heller
d8431ae3bd Revert rev 74134, as it does not completely fixx issue #6493. 2009-07-21 19:04:02 +00:00
Thomas Heller
6adda9641d Issue #6493: Fix a ctypes problem setting bitfields more than 31 bits
wide.
2009-07-21 06:27:14 +00:00
Benjamin Peterson
4d3f18f2ed fix a few cases where automated fail -> assert translation messed up
Thanks Joe Amenta
2009-07-01 00:36:41 +00:00
Benjamin Peterson
5c8da86f3a convert usage of fail* to assert* 2009-06-30 22:57:08 +00:00
Thomas Heller
ec21ccde12 Issue 5041: ctypes unwilling to allow pickling wide character. 2009-04-24 20:00:41 +00:00
Benjamin Peterson
164b0455b6 make tests fail if they can't be imported 2009-01-10 22:42:10 +00:00
Thomas Heller
e144873071 Fix issue #3547 for MingW, update comments. 2008-09-29 19:56:24 +00:00
Thomas Heller
a85c95d5e8 Fix issue #3547: ctypes is confused by bitfields of varying integer types
Reviewed by Fredrik Lundh and Skip Montanaro.
2008-09-24 18:26:05 +00:00
Thomas Heller
0ad5ae02af Fix a regression introduced by rev. 63792: ctypes function pointers
that are COM methods must have a boolean True value.
2008-08-19 19:25:04 +00:00
Thomas Heller
63d325e8c4 Disable the test until I have one that works. 2008-08-14 20:19:18 +00:00
Thomas Heller
6d2014ee59 Try to fix the test on 64-bit platforms. 2008-08-14 20:04:38 +00:00
Thomas Heller
57adf22f6e issue #3554: ctypes.string_at and ctypes.wstring_at must use the
pythonapi calling convention so that the GIL is held and error return
values are checked.
2008-08-14 19:10:48 +00:00
Nick Coghlan
48361f5cbf Issue 2235: Py3k warnings are now emitted for classes that will no longer inherit a__hash__ implementation from a parent class in Python 3.x. The standard library and test suite have been updated to not emit these warnings. 2008-08-11 15:45:58 +00:00
Thomas Heller
2affb40e70 Fix test on 64-bit platforms. 2008-07-15 20:18:46 +00:00
Thomas Heller
c0b2a807ff Issue #3258: Fix an assertion error (in debug build) and a crash (in
release build) when the format string of a pointer to an incomplete
structure is created.
2008-07-15 17:03:08 +00:00
Martin v. Löwis
06510b2213 Run svneol.py on all sources. 2008-06-13 22:38:33 +00:00
Thomas Heller
fbb9c0bf3c Issue #1798: Add ctypes calling convention that allows safe access of errno.
ctypes maintains thread-local storage that has space for two error
numbers: private copies of the system 'errno' value and, on Windows,
the system error code accessed by the GetLastError() and
SetLastError() api functions.

Foreign functions created with CDLL(..., use_errno=True), when called,
swap the system 'errno' value with the private copy just before the
actual function call, and swapped again immediately afterwards.  The
'use_errno' parameter defaults to False, in this case 'ctypes_errno'
is not touched.

On Windows, foreign functions created with CDLL(...,
use_last_error=True) or WinDLL(..., use_last_error=True) swap the
system LastError value with the ctypes private copy.

The values are also swapped immeditately before and after ctypes
callback functions are called, if the callbacks are constructed using
the new optional use_errno parameter set to True: CFUNCTYPE(...,
use_errno=TRUE) or WINFUNCTYPE(..., use_errno=True).

New ctypes functions are provided to access the ctypes private copies
from Python:

- ctypes.set_errno(value) and ctypes.set_last_error(value) store
  'value' in the private copy and returns the previous value.

- ctypes.get_errno() and ctypes.get_last_error() returns the current
  ctypes private copies value.
2008-06-06 08:33:46 +00:00
Thomas Heller
2e75c450d2 Backport from py3k: Implement the new buffer interface from pep3118
for ctypes instances.  Closes issue #2404.
2008-06-05 17:51:15 +00:00
Thomas Heller
d5bb9215c9 Revert revisions 63943 and 63942 (Issue #1798: Add ctypes calling
convention that allows safe access to errno)

This code does not yet work on OS X (__thread storage specifier not
available), so i needs a configure check plus a more portable
solution.
2008-06-04 20:22:05 +00:00
Thomas Heller
e70c3378c0 Issue #1798: Add ctypes calling convention that allows safe access to
errno (and LastError, on Windows).

ctypes maintains a module-global, but thread-local, variable that
contains an error number; called 'ctypes_errno' for this discussion.
This variable is a private copy of the systems 'errno' value; the copy
is swapped with the 'errno' variable on several occasions.

Foreign functions created with CDLL(..., use_errno=True), when called,
swap the values just before the actual function call, and swapped
again immediately afterwards.  The 'use_errno' parameter defaults to
False, in this case 'ctypes_errno' is not touched.

The values are also swapped immeditately before and after ctypes
callback functions are called, if the callbacks are constructed using
the new optional use_errno parameter set to True: CFUNCTYPE(..., use_errno=TRUE)
or WINFUNCTYPE(..., use_errno=True).

Two new ctypes functions are provided to access the 'ctypes_errno'
value from Python:

- ctypes.set_errno(value) sets ctypes_errno to 'value', the previous
  ctypes_errno value is returned.

- ctypes.get_errno() returns the current ctypes_errno value.

---

On Windows, the same scheme is implemented for the error value which
is managed by the GetLastError() and SetLastError() windows api calls.

The ctypes functions are 'ctypes.set_last_error(value)' and
'ctypes.get_last_error()', the CDLL and WinDLL optional parameter is
named 'use_last_error', defaults to False.

---

On Windows, TlsSetValue and TlsGetValue calls are used to provide
thread local storage for the variables; ctypes compiled with __GNUC__
uses __thread variables.
2008-06-04 18:59:03 +00:00
Thomas Heller
261b136321 Fix the -x flag so that is does work. 2008-06-02 20:07:46 +00:00
Thomas Heller
9287acf83d ctypes NULL function pointers have a boolean False value now. 2008-05-29 19:42:34 +00:00
Thomas Heller
6c78f553ae Oops, get_tests may be called with 3 arguments. 2008-05-21 19:47:44 +00:00
Thomas Heller
7d9e721586 The -x <test1[,test2...]> flag allows to exclude tests. 2008-05-21 18:47:02 +00:00
Thomas Heller
ee130b72f8 Very simple test for ctypes.util.find_library on Windows. 2008-05-16 20:19:07 +00:00
Thomas Heller
6ad5fbb7ea Add from_buffer and from_buffer_copy class methods to ctypes types. 2008-04-25 15:44:16 +00:00
Thomas Heller
8e8ba151dd Issue #2543: Make ctypes compatible (again) with Python 2.3, 2.4, and 2.5. 2008-04-04 08:35:44 +00:00
Christian Heimes
c5f05e45cf Patch #2167 from calvin: Remove unused imports 2008-02-23 17:40:11 +00:00
Thomas Heller
8982cf5484 Replace 'has_key()' with 'in'.
Replace 'raise Error, stuff' with 'raise Error(stuff)'.
2008-02-21 18:52:20 +00:00
Thomas Heller
4516451aec Make the test somewhat clearer (I hope). 2008-02-13 20:36:51 +00:00
Thomas Heller
a06a1a88ee Add pickle support to ctypes types. 2008-02-13 20:21:53 +00:00
Thomas Heller
99120c4f7e Revert rev. 59925, it breaks comtypes (I need to further examine this). 2008-01-28 08:44:13 +00:00
Thomas Heller
5ca924038d Invert the checks in get_[u]long and get_[u]longlong. The intent was
to not accept float types; the result was that integer-like objects
were not accepted.

Ported from release25-maint.
2008-01-24 19:15:02 +00:00
Thomas Heller
415c1e36a9 Raise a TypeError instead of a ValueError when too many initializers
are used in a Structure or Union constructor.
2008-01-16 19:45:51 +00:00
Thomas Heller
02ec289f3e Raise a TypeError if conflicting positional and named arguments are
passed to a Structure or Union constructor.
2008-01-16 19:37:33 +00:00
Thomas Heller
902d30752f Convert the internal ctypes array type cache to a WeakValueDict so
that array types do not live longer than needed.
2008-01-16 19:16:27 +00:00
Thomas Heller
c682614df0 Raise an error instead of crashing with a segfault when a NULL
function pointer is called.

Will backport to release25-maint.
2008-01-11 19:34:06 +00:00
Thomas Heller
153038efa4 Issue #1642: Fix segfault in ctypes when trying to delete attributes. 2007-12-18 19:00:34 +00:00
Thomas Heller
03fd077482 Enable the full ctypes c_longdouble tests again. 2007-11-02 19:11:23 +00:00
Thomas Heller
e7becc5007 Added unittest for calling a function with paramflags (backport from py3k branch). 2007-10-24 19:50:45 +00:00