Skip to content

Commit

Permalink
Merge pull request numpy#22421 from HaoZeke/cobjToCapsule
Browse files Browse the repository at this point in the history
DOC: Replace CObject with Capsule consistently
  • Loading branch information
mattip authored Oct 10, 2022
2 parents c6f8fb2 + 6d8670a commit 1ed87fa
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
13 changes: 7 additions & 6 deletions doc/source/f2py/python-usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ Routine wrappers are callable ``fortran`` type objects while wrappers to Fortran
data have attributes referring to data objects.

All ``fortran`` type objects have an attribute ``_cpointer`` that contains a
``CObject`` referring to the C pointer of the corresponding Fortran/C function
or variable at the C level. Such ``CObjects`` can be used as callback arguments
for F2PY generated functions to bypass the Python C/API layer for calling Python
functions from Fortran or C. This can be useful when the computational aspects
of such functions are implemented in C or Fortran and wrapped with F2PY (or any
other tool capable of providing the ``CObject`` of a function).
:c:type:`PyCapsule` referring to the C pointer of the corresponding Fortran/C function
or variable at the C level. Such ``PyCapsule`` objects can be used as callback
arguments for F2PY generated functions to bypass the Python C/API layer for
calling Python functions from Fortran or C. This can be useful when the
computational aspects of such functions are implemented in C or Fortran and
wrapped with F2PY (or any other tool capable of providing the ``PyCapsule``
containing a function).

Consider a Fortran 77 file ```ftype.f``:

Expand Down
2 changes: 1 addition & 1 deletion doc/source/reference/c-api/array.rst
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ and its sub-types).
.. c:function:: int PyArray_FinalizeFunc(PyArrayObject* arr, PyObject* obj)
The function pointed to by the CObject
The function pointed to by the :c:type:`PyCapsule`
:obj:`~numpy.class.__array_finalize__`.
The first argument is the newly created sub-type. The second argument
(if not NULL) is the "parent" array (if the array was created using
Expand Down
19 changes: 10 additions & 9 deletions doc/source/user/c-info.beyond-basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -470,13 +470,14 @@ The __array_finalize\__ method
__new_\_ method nor the __init\__ method gets called. Instead, the
sub-type is allocated and the appropriate instance-structure
members are filled in. Finally, the :obj:`~numpy.class.__array_finalize__`
attribute is looked-up in the object dictionary. If it is present
and not None, then it can be either a CObject containing a pointer
to a :c:func:`PyArray_FinalizeFunc` or it can be a method taking a
single argument (which could be None)
attribute is looked-up in the object dictionary. If it is present and not
None, then it can be either a :c:type:`PyCapsule` containing a pointer to a
:c:func:`PyArray_FinalizeFunc` or it can be a method taking a single argument
(which could be None)
If the :obj:`~numpy.class.__array_finalize__` attribute is a CObject, then the pointer
must be a pointer to a function with the signature:
If the :obj:`~numpy.class.__array_finalize__` attribute is a
:c:type:`PyCapsule`, then the pointer must be a pointer to a function with
the signature:
.. code-block:: c
Expand All @@ -488,9 +489,9 @@ The __array_finalize\__ method
is present). This routine can do anything it wants to. It should
return a -1 on error and 0 otherwise.
If the :obj:`~numpy.class.__array_finalize__` attribute is not None nor a CObject,
then it must be a Python method that takes the parent array as an
argument (which could be None if there is no parent), and returns
If the :obj:`~numpy.class.__array_finalize__` attribute is not None nor a
:c:type:`PyCapsule`, then it must be a Python method that takes the parent
array as an argument (which could be None if there is no parent), and returns
nothing. Errors in this method will be caught and handled.
Expand Down
2 changes: 1 addition & 1 deletion numpy/f2py/cfuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1324,7 +1324,7 @@
if (xa != NULL)
ext = PyTuple_Size((PyObject *)xa);
if(ext>0) {
fprintf(stderr,\"extra arguments tuple cannot be used with CObject call-back\\n\");
fprintf(stderr,\"extra arguments tuple cannot be used with PyCapsule call-back\\n\");
goto capi_fail;
}
tmp_fun = fun;
Expand Down

0 comments on commit 1ed87fa

Please sign in to comment.