Author: Armin Rigo <[email protected]> Branch: Changeset: r2216:0d2cff1af99f Date: 2015-07-06 19:38 +0200 http://bitbucket.org/cffi/cffi/changeset/0d2cff1af99f/
Log: Document ffi.new_allocator() diff --git a/doc/source/using.rst b/doc/source/using.rst --- a/doc/source/using.rst +++ b/doc/source/using.rst @@ -820,6 +820,28 @@ **ffi.RLTD_...**: constants: flags for ``ffi.dlopen()``. + +.. _`alternative allocators`: + +**ffi.new_allocator(alloc=None, free=None, should_clear_after_alloc=True)**: +returns a new allocator. An "allocator" is a callable that behaves like +``ffi.new()`` but uses the provided low-level ``alloc`` and ``free`` +functions. *New in version 1.2.* + +.. "versionadded:: 1.2" --- inlined in the previous paragraph + +``alloc()`` is invoked with the size as sole argument. If it returns +NULL, a MemoryError is raised. Later, if ``free`` is not None, it will +be called with the result of ``alloc()`` as argument. Both can be either +Python function or directly C functions. If only ``free`` is None, then no +free function is called. If both ``alloc`` and ``free`` are None, the +default alloc/free combination is used. (In other words, the call +``ffi.new(*args)`` is equivalent to ``ffi.new_allocator()(*args)``.) + +If ``should_clear_after_alloc`` is set to False, then the memory +returned by ``alloc()`` is assumed to be already cleared (or you are +fine with garbage); otherwise CFFI will clear it. + .. _`Preparing and Distributing modules`: cdef.html#loading-libraries diff --git a/doc/source/whatsnew.rst b/doc/source/whatsnew.rst --- a/doc/source/whatsnew.rst +++ b/doc/source/whatsnew.rst @@ -41,7 +41,7 @@ only for NULL: if you dereference random or dead pointers you might still get segfaults. -* Issue #152: callbacks: added an argument ``ffi.callback(..., +* Issue #152: callbacks__: added an argument ``ffi.callback(..., onerror=...)``. If the main callback function raises an exception and ``onerror`` is provided, then ``onerror(exception, exc_value, traceback)`` is called. This is similar to writing a ``try: @@ -49,6 +49,12 @@ signal) an exception can occur at the very start of the callback function---before it had time to enter the ``try: except:`` block. +* Issue #115: added ``ffi.new_allocator()``, which officializes + support for `alternative allocators`__. + +.. __: using.html#callbacks +.. __: using.html#alternative-allocators + 1.1.2 ===== _______________________________________________ pypy-commit mailing list [email protected] https://mail.python.org/mailman/listinfo/pypy-commit
