summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArmin Rigo <arigo@tunes.org>2015-11-30 16:41:06 +0100
committerArmin Rigo <arigo@tunes.org>2015-11-30 16:41:06 +0100
commit3bfbf9a79e0d5f8c88ea8fad0cc054ccd6f0bd90 (patch)
treed566f2b556a0c6fd966e11e0e9148d1acf9f632f
parentc81e07bef968407e0f3fb8310bc4a7e9d4d07f87 (diff)
parent550ffa4ba3023dabbec58923729c8ded70168a39 (diff)
downloadcffi-3bfbf9a79e0d5f8c88ea8fad0cc054ccd6f0bd90.tar.gz
hg merge default
-rw-r--r--c/_cffi_backend.c4
-rw-r--r--cffi/parse_c_type.h3
-rw-r--r--doc/source/using.rst26
-rw-r--r--doc/source/whatsnew.rst8
4 files changed, 31 insertions, 10 deletions
diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
index 0dd412d..604f68d 100644
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -5822,6 +5822,10 @@ static PyObject *direct_from_buffer(CTypeDescrObject *ct, PyObject *x)
}
view = PyObject_Malloc(sizeof(Py_buffer));
+ if (view == NULL) {
+ PyErr_NoMemory();
+ return NULL;
+ }
if (_my_PyObject_GetContiguousBuffer(x, view, 0) < 0)
goto error1;
diff --git a/cffi/parse_c_type.h b/cffi/parse_c_type.h
index 2303879..a01d89e 100644
--- a/cffi/parse_c_type.h
+++ b/cffi/parse_c_type.h
@@ -1,5 +1,6 @@
-/* See doc/misc/parse_c_type.rst in the source of CFFI for more information */
+/* This part is from file 'cffi/parse_c_type.h'. It is copied at the
+ beginning of C sources generated by CFFI's ffi.set_source(). */
typedef void *_cffi_opcode_t;
diff --git a/doc/source/using.rst b/doc/source/using.rst
index 85bbfa8..7d8f7b6 100644
--- a/doc/source/using.rst
+++ b/doc/source/using.rst
@@ -365,8 +365,9 @@ function expecting a function pointer argument. Only ``ffi.typeof()``
works on them. To get a cdata containing a regular function pointer,
use ``ffi.addressof(lib, "name")`` (new in version 1.1).
-Before version 1.1, if you really need a cdata pointer to the function,
-use the following workaround:
+Before version 1.1 (or with the deprecated ``ffi.verify()``), if you
+really need a cdata pointer to the function, use the following
+workaround:
.. code-block:: python
@@ -1055,9 +1056,7 @@ like this:
* ``new_handle()`` returns cdata objects that contains references to
the Python objects; we call them collectively the "handle" cdata
objects. The ``void *`` value in these handle cdata objects are
- random but unique. *New in version 1.4:* two calls to
- ``new_handle(x)`` are guaranteed to return cdata objects with
- different ``void *`` values, even with the same ``x``.
+ random but unique.
* ``from_handle(p)`` searches all live "handle" cdata objects for the
one that has the same value ``p`` as its ``void *`` value. It then
@@ -1070,6 +1069,16 @@ alive. If the handle cdata object *itself* is not alive any more,
then the association ``void * -> python_object`` is dead and
``from_handle()`` will crash.
+*New in version 1.4:* two calls to ``new_handle(x)`` are guaranteed to
+return cdata objects with different ``void *`` values, even with the
+same ``x``. This is a useful feature that avoids issues with unexpected
+duplicates in the following trick: if you need to keep alive the
+"handle" until explicitly asked to free it, but don't have a natural
+Python-side place to attach it to, then the easiest is to ``add()`` it
+to a global set. It can later be removed from the set by
+``global_set.discard(p)``, with ``p`` any cdata object whose ``void *``
+value compares equal.
+
.. _`ffi.addressof()`:
@@ -1232,7 +1241,12 @@ allowed.
Note that we assume that the called functions are *not* using the
Python API from Python.h. For example, we don't check afterwards
if they set a Python exception. You may work around it, but mixing
- CFFI with ``Python.h`` is not recommended.
+ CFFI with ``Python.h`` is not recommended. (If you do that, on
+ PyPy and on some platforms like Windows, you may need to explicitly
+ link to ``libpypy-c.dll`` to access the CPython C API compatibility
+ layer; indeed, CFFI-generated modules on PyPy don't link to
+ ``libpypy-c.dll`` on their own. But really, don't do that in the
+ first place.)
`(***)` ``long double`` support:
diff --git a/doc/source/whatsnew.rst b/doc/source/whatsnew.rst
index cdf215a..44b4e23 100644
--- a/doc/source/whatsnew.rst
+++ b/doc/source/whatsnew.rst
@@ -8,11 +8,13 @@ v1.4.0
* ``ffi.new_handle()`` is now guaranteed to return unique ``void *``
values, even if called twice on the same object. Previously, in
- that case, CPython (but not PyPy) would return different ``cdata``
- objects with the same ``void *`` value. This is useful to add and
- remove handles from a global set without worrying about duplicates.
+ that case, CPython (but not PyPy) would return two ``cdata`` objects
+ with the same ``void *`` value. This change is useful to add and
+ remove handles from a global dict or set without worrying about
+ duplicates.
* ``ffi.init_once()`` XXX
+ https://bitbucket.org/cffi/cffi/issues/233/
v1.3.1