Commit Graph

116 Commits

Author SHA1 Message Date
Thomas Heller b151f721a9 Prevent creation (followed by a segfault) of array types when the size
overflows the valid Py_ssize_t range.  Check return values of
PyMem_Malloc.

Backported from trunk.
2007-03-23 19:56:45 +00:00
Thomas Heller 50d1d0bad5 Explain the purpose of the b_needsfree flag. This answers Neals
question (well, two months too late).
2007-03-22 20:33:04 +00:00
Thomas Heller 02b8feea9f Back out "Patch #1643874: memory leak in ctypes fixed."
The code in this patch leaves no way to give up the ownership of a
BSTR instance.
2007-03-22 19:43:37 +00:00
Thomas Heller 8bf469ddc1 Merged revisions 54248 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk/Lib/ctypes

........
  r54248 | thomas.heller | 2007-03-09 21:39:22 +0100 (Fr, 09 Mär 2007) | 7 lines

  Bug #1651235: When a tuple was passed to a ctypes function call,
  Python would crash instead of raising an error.

  The crash was caused by a section of code that should have been
  removed long ago, at that time ctypes had other ways to pass
  parameters to function calls.
........
2007-03-09 20:48:57 +00:00
Thomas Heller f7eed5e2d1 Merged revisions 54244 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk/Lib/ctypes

........
  r54244 | thomas.heller | 2007-03-09 20:21:28 +0100 (Fr, 09 Mär 2007) | 3 lines

  Fix bug #1646630: ctypes.string_at(buf, 0) and ctypes.wstring_at(buf, 0)
  returned string up to the first NUL character.
........
2007-03-09 20:21:16 +00:00
Thomas Heller 817b489422 Merged revisions 53556 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk/Modules/_ctypes

........
  r53556 | thomas.heller | 2007-01-25 19:34:14 +0100 (Do, 25 Jan 2007) | 3 lines

  Fix for #1643874: When calling SysAllocString, create a PyCObject
  which will eventually call SysFreeString to free the BSTR resource.
........
2007-01-25 19:19:35 +00:00
Neal Norwitz e962300d0c Add a comment for some code I don't understand. Why would needsfree
be true if we didn't malloc the code?  Seems like the code is wrong
or could use comments.

Also verify if the buildbots are working properly for the 2.5 branch.
2007-01-18 07:16:31 +00:00
Thomas Heller 2a98c56c13 Merged revisions 53466 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk/Modules/_ctypes

........
  r53466 | thomas.heller | 2007-01-17 10:40:34 +0100 (Mi, 17 Jan 2007) | 2 lines

  Replace C++ comments with C comments.
........
2007-01-17 09:53:03 +00:00
Thomas Heller 3193763bdf Must update the version number on the extension module as well. 2007-01-10 20:44:21 +00:00
Thomas Heller 84a90cade5 Fix #1563807: _ctypes built on AIX fails with ld ffi error.
The contents of ffi_darwin.c must be compiled unless __APPLE__ is
defined and __ppc__ is not.

Backport from trunk.
2006-11-28 20:43:11 +00:00
Thomas Heller 558e56d599 Fix bug #1598620: A ctypes structure cannot contain itself.
Backport from trunk.
2006-11-24 19:00:39 +00:00
Martin v. Löwis 63a9b8b067 - Patch #1560695: Add .note.GNU-stack to ctypes' sysv.S so that
ctypes isn't considered as requiring executable stacks.
2006-10-22 10:55:25 +00:00
Thomas Heller dcbf64d34d ctypes callback functions only support 'fundamental' result types.
Check this and raise an error when something else is used - before
this change ctypes would hang or crash when such a callback was
called.  This is a partial fix for #1574584.

Backported from trunk.
2006-10-17 19:41:10 +00:00
Neal Norwitz 5728c27c74 Backport rev 51820 from Thomas Heller
The cast function did not accept c_char_p or c_wchar_p instances
as first argument, and failed with a 'bad argument to internal function'
error message.
2006-09-11 04:02:43 +00:00
Neal Norwitz 71e2aa0cc5 Backport rev 51819 from Thomas Heller
Anonymous structure fields that have a bit-width specified did not work,
and they gave a strange error message from PyArg_ParseTuple:
   function takes exactly 2 arguments (3 given).
2006-09-11 04:01:57 +00:00
Thomas Heller 291a1b89c6 Backport of r51379 from trunk:
Add asserts to check for 'impossible' NULL values, with comments.
In one place where I'm not 1000% sure about the non-NULL, raise
a RuntimeError for safety.

This should fix the klocwork issues that Neal sent me.  If so,
it should be applied to the release25-maint branch also.
2006-09-06 17:48:56 +00:00
Neal Norwitz 03ee62c352 Move assert to after NULL check, otherwise we deref NULL in the assert.
Klocwork #307
2006-08-19 04:18:39 +00:00
Thomas Heller b4a0cf17c4 Remove the special casing of Py_None when converting the return value
of the Python part of a callback function to C.  If it cannot be
converted, call PyErr_WriteUnraisable with the exception we got.
Before, arbitrary data has been passed to the calling C code in this
case.

(I'm not really sure the NEWS entry is understandable, but I cannot
find better words)
2006-08-16 15:10:12 +00:00
Thomas Heller b0aa98fd4f The __repr__ method of a NULL py_object does no longer raise an
exception.  Remove a stray '?' character from the exception text
when the value is retrieved of such an object.

Includes tests.
2006-08-16 14:07:44 +00:00
Thomas Heller d32e616722 Add commented assert statements to check that the result of
PyObject_stgdict() and PyType_stgdict() calls are non-NULL before
dereferencing the result.  Hopefully this fixes what klocwork is
complaining about.

Fix a few other nits as well.
2006-08-16 13:03:11 +00:00
Thomas Heller 4dc5dd1f3b Check for NULL return value from new_CArgObject calls. 2006-08-15 13:07:21 +00:00
Thomas Heller ef8d513d62 Patch #1536908: Add support for AMD64 / OpenBSD.
Remove the -no-stack-protector compiler flag for OpenBSD
as it has been reported to be unneeded.
2006-08-14 16:17:41 +00:00
Thomas Heller 867200483b Apply the patch #1532975 plus ideas from the patch #1533481.
ctypes instances no longer have the internal and undocumented
'_as_parameter_' attribute which was used to adapt them to foreign
function calls; this mechanism is replaced by a function pointer in
the type's stgdict.

In the 'from_param' class methods, try the _as_parameter_ attribute if
other conversions are not possible.

This makes the documented _as_parameter_ mechanism work as intended.

Change the ctypes version number to 1.0.1.
2006-08-14 11:17:48 +00:00
Thomas Heller e6dd31c50b Revert the change that tries to zero out a closure's result storage
area because the size if unknown in source/callproc.c.
2006-08-14 10:02:24 +00:00
Thomas Heller dca703fbda Check for NULL return value of GenericCData_new().
Fixes klockwork issues #188, #189.
2006-08-14 07:50:14 +00:00
Thomas Heller efa2727334 Check for NULL return value from new_CArgObject().
Fixes klockwork issues #183, #184, #185.
2006-08-14 07:14:09 +00:00
Thomas Heller acdedfbf0a Remove unused, buggy test function.
Fixes klockwork issue #207.
2006-08-14 07:13:05 +00:00
Neal Norwitz 93bf902242 Handle alloca failures.
Klocwork 225-228
2006-08-13 18:40:39 +00:00
Neal Norwitz 6b4953fd3d Check returned pointer is valid.
Klocwork #233
2006-08-12 02:06:34 +00:00
Thomas Heller 2a899c8b76 When a ctypes C callback function is called, zero out the result
storage before converting the result to C data.  See the comment in
the code for details.

Provide a better context for errors when the conversion of a callback
function's result cannot be converted.
2006-08-11 19:55:35 +00:00
Thomas Heller d61d0733cb Speed up PyType_stgdict and PyObject_stgdict. 2006-08-01 19:14:15 +00:00
Thomas Heller 11d68a6ac4 Minimal useful docstring for CopyComPointer. 2006-08-01 17:46:10 +00:00
Thomas Heller 3de83e9b61 Fix a potential segfault and various potentail refcount leaks
in the cast() function.
2006-08-01 16:54:43 +00:00
Thomas Heller 1393d6a4ca Patch #1529514: More openbsd platforms for ctypes.
Regenerated Modules/_ctypes/libffi/configure with autoconf 2.59.

Approved by Neal.
2006-07-28 21:43:20 +00:00
Thomas Heller 944f3b6ecb Remove a useless XXX comment.
Cosmetic changes to the code so that the #ifdef _UNICODE block
doesn't mess emacs code formatting.
2006-07-28 19:42:40 +00:00
Neal Norwitz 93f2ca1f85 Check the allocation of b_objects and return if there was a failure.
Also fix a few memory leaks in other failure scenarios.

It seems that if b_objects == Py_None, we will have an extra ref to
b_objects.  Add XXX comment so hopefully someone documents why the
else isn't necessary or adds it in.

Reported by Klocwork #20
2006-07-23 07:55:55 +00:00
Thomas Heller 100a4e944b Make sure the _ctypes extension can be compiled when WITH_THREAD is
not defined on Windows, even if that configuration is probably not
supported at all.
2006-07-19 09:09:32 +00:00
Neal Norwitz 109f91414f proto was dereffed above and is known to be good. No need for X.
Reported by Klocwork, #39.
2006-07-16 02:05:35 +00:00
Thomas Heller ce049a0aef Patch #1521817: The index range checking on ctypes arrays containing
exactly one element is enabled again.
2006-07-14 17:51:14 +00:00
Thomas Heller 9f902470da Make the prototypes of our private PyUnicode_FromWideChar and
PyUnicode_AsWideChar replacement functions compatible to the official
functions by using Py_ssize_t instead of int.
2006-07-14 15:01:05 +00:00
Thomas Heller b4dc2ef5da A misspelled preprocessor symbol caused ctypes to be always compiled
without thread support.  Replaced WITH_THREADS with WITH_THREAD.
2006-07-13 09:53:47 +00:00
Thomas Heller 3b9be2ae6f Change the ctypes version number to 1.0.0. 2006-07-11 18:40:50 +00:00
Thomas Heller 7644262aa5 Assigning None to pointer type structure fields possible overwrote
wrong fields.
2006-07-10 11:11:10 +00:00
Thomas Heller 7b1da513fd Fixed a segfault when ctypes.wintypes were imported on
non-Windows machines.
2006-07-10 09:31:06 +00:00
Thomas Heller dda068dee1 Fix bug #1518190: accept any integer or long value in the
ctypes.c_void_p constructor.
2006-07-10 09:10:28 +00:00
Thomas Heller 5becdbee96 Patch #1517790: It is now possible to use custom objects in the ctypes
foreign function argtypes sequence as long as they provide a
from_param method, no longer is it required that the object is a
ctypes type.
2006-07-06 08:48:35 +00:00
Thomas Heller 43d9a58dfd Revert the change done in svn revision 47206:
Add a new function uses_seh() to the _ctypes extension module.  This
will return True if Windows Structured Exception handling (SEH) is
used when calling functions, False otherwise.
2006-07-06 07:50:18 +00:00
Thomas Heller 9ba7ca8229 Fix the bitfield test when _ctypes is compiled with MingW. Structures
containing bitfields may have different layout on MSVC and MingW .
2006-07-05 09:13:56 +00:00
Ronald Oussoren b4a6a566ff Sync the darwin/x86 port libffi with the copy in PyObjC. This fixes a number
of bugs in that port. The most annoying ones were due to some subtle differences
between the document ABI and the actual implementation :-(

(there are no python unittests that fail without this patch, but without it
 some of libffi's unittests fail).
2006-07-04 12:30:22 +00:00
Thomas Heller f780be4239 Add a new function uses_seh() to the _ctypes extension module. This
will return True if Windows Structured Exception handling (SEH) is
used when calling functions, False otherwise.

Currently, only MSVC supports SEH.

Fix the test so that it doesn't crash when run with MingW compiled
_ctypes.  Note that two tests are still failing when mingw is used, I
suspect structure layout differences and function calling conventions
between MSVC and MingW.
2006-07-03 08:08:14 +00:00