Bug 623857 - numpy uses PyCObject API (deprecated in Python 2.7)
Summary: numpy uses PyCObject API (deprecated in Python 2.7)
Alias: None
Product: Fedora
Classification: Fedora
Component: numpy   
(Show other bugs)
Version: 19
Hardware: All
OS: Linux
Target Milestone: ---
Assignee: Gwyn Ciesla
QA Contact: Fedora Extras Quality Assurance
Keywords: Reopened
Depends On:
Blocks: PyCObject
TreeView+ depends on / blocked
Reported: 2010-08-13 01:04 UTC by Dave Malcolm
Modified: 2015-02-18 13:28 UTC (History)
6 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2015-02-18 13:28:58 UTC
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

Description Dave Malcolm 2010-08-13 01:04:23 UTC
Description of problem:
Python 2.7 deprecated the PyCObject API in favor of a new "capsule" API.

The deprecations are set to "ignore" by default, so in theory the API still works.

However the deprecation has caused at least one app to fail (virt-manager, see bug 620216, due to it modifying the warning settings), so I've been doublechecking the scope of usage of the PyCObject API, and am filing bugs against components that are possibly affected.

You can trigger a hard failure of the API via:
>>> import warnings
>>> warnings.filterwarnings('error')
>>> import numpy
python: /root/rpmbuild/BUILD/Python-2.7/Objects/dictobject.c:759: PyDict_SetItem: Assertion `value' failed.

I'm not yet sure what the best approach is to fixing this, but this is a "heads up" to warn about changes to the default warning settings.  Not touching the default warning settings may be one workaround.

Version-Release number of selected component (if applicable):

Grepping through the source tree finds numerous uses of the API:
./numpy-1.4.1/doc/source/reference/arrays.interface.rst:200:   A :ctype:`PyCObject` whose :cdata:`voidptr` member contains a
./numpy-1.4.1/doc/source/reference/arrays.interface.rst:202:   for the structure is dynamically created and the :ctype:`PyCObject`
./numpy-1.4.1/doc/source/reference/arrays.interface.rst:242:   :ctype:`PyCObject` itself (do not confuse this with the "descr" member of
./numpy-1.4.1/doc/source/reference/arrays.interface.rst:246:   reference to the object when the :ctype:`PyCObject` is created using
./numpy-1.4.1/doc/source/reference/arrays.interface.rst:247:   :ctype:`PyCObject_FromVoidPtrAndDesc`.
./numpy-1.4.1/doc/source/reference/arrays.interface.rst:315:2. The desc member of the PyCObject returned from __array_struct__ was
./numpy-1.4.1/doc/source/reference/c-api.types-and-structures.rst:556:        wrapped in a :ctype:`PyCObject *` and keyed by the data-type number.
./numpy-1.4.1/doc/source/reference/c-api.types-and-structures.rst:1066:   :ctype:`PyCObject` that contains a pointer to a :ctype:`PyArrayInterface`
./numpy-1.4.1/numpy/numarray/_capi.c:3356:    c_api_object = PyCObject_FromVoidPtr((void *)libnumarray_API, NULL);
./numpy-1.4.1/numpy/numarray/numpy/libnumarray.h:50:          if (c_api_object && PyCObject_Check(c_api_object)) {              \
./numpy-1.4.1/numpy/numarray/numpy/libnumarray.h:51:            libnumarray_API = (void **)PyCObject_AsVoidPtr(c_api_object);      \
./numpy-1.4.1/numpy/core/code_generators/generate_numpy_api.py:57:  if (PyCObject_Check(c_api)) {
./numpy-1.4.1/numpy/core/code_generators/generate_numpy_api.py:58:      PyArray_API = (void **)PyCObject_AsVoidPtr(c_api);
./numpy-1.4.1/numpy/core/code_generators/generate_ufunc_api.py:47:  if (PyCObject_Check(c_api)) {
./numpy-1.4.1/numpy/core/code_generators/generate_ufunc_api.py:48:      PyUFunc_API = (void **)PyCObject_AsVoidPtr(c_api);
./numpy-1.4.1/numpy/core/src/umath/ufunc_object.c:370:    funcdata = (PyUFunc_Loop1d *)PyCObject_AsVoidPtr(obj);
./numpy-1.4.1/numpy/core/src/umath/ufunc_object.c:515:        funcdata = (PyUFunc_Loop1d *)PyCObject_AsVoidPtr(obj);
./numpy-1.4.1/numpy/core/src/umath/ufunc_object.c:3926:        cobj = PyCObject_FromVoidPtr((void *)funcdata, _loop1d_list_free);
./numpy-1.4.1/numpy/core/src/umath/ufunc_object.c:3944:        current = (PyUFunc_Loop1d *)PyCObject_AsVoidPtr(cobj);
./numpy-1.4.1/numpy/core/src/umath/umathmodule.c.src:271:    c_api = PyCObject_FromVoidPtr((void *)PyUFunc_API, NULL);
./numpy-1.4.1/numpy/core/src/multiarray/multiarraymodule.c:2942:    c_api = PyCObject_FromVoidPtr((void *)PyArray_API, NULL);
./numpy-1.4.1/numpy/core/src/multiarray/convert_datatype.c:103:            if (PyCObject_Check(cobj)) {
./numpy-1.4.1/numpy/core/src/multiarray/convert_datatype.c:104:                castfunc = PyCObject_AsVoidPtr(cobj);
./numpy-1.4.1/numpy/core/src/multiarray/scalartypes.c.src:756:    return PyCObject_FromVoidPtrAndDesc(inter, arr, gentype_struct_free);
./numpy-1.4.1/numpy/core/src/multiarray/getset.c:548:    return PyCObject_FromVoidPtrAndDesc(inter, self, gentype_struct_free);
./numpy-1.4.1/numpy/core/src/multiarray/common.c:213:        if (PyCObject_Check(ip)) {
./numpy-1.4.1/numpy/core/src/multiarray/common.c:214:            inter=(PyArrayInterface *)PyCObject_AsVoidPtr(ip);
./numpy-1.4.1/numpy/core/src/multiarray/usertypes.c:207:    cobj = PyCObject_FromVoidPtr((void *)castfunc, NULL);
./numpy-1.4.1/numpy/core/src/multiarray/ctors.c:1107:        if (PyCObject_Check(e)) {
./numpy-1.4.1/numpy/core/src/multiarray/ctors.c:1109:            inter = (PyArrayInterface *)PyCObject_AsVoidPtr(e);
./numpy-1.4.1/numpy/core/src/multiarray/ctors.c:1530:            if PyCObject_Check(func) {
./numpy-1.4.1/numpy/core/src/multiarray/ctors.c:1533:                cfunc = PyCObject_AsVoidPtr(func);
./numpy-1.4.1/numpy/core/src/multiarray/ctors.c:1968:    if (!PyCObject_Check(attr)) {
./numpy-1.4.1/numpy/core/src/multiarray/ctors.c:1971:    inter = PyCObject_AsVoidPtr(attr);
./numpy-1.4.1/numpy/core/include/numpy/ndarrayobject.h:576:#define PyDataType_GetDatetimeMetaData(descr) ((descr->metadata == NULL) ? NULL : ((PyArray_DatetimeMetaData *)(PyCObject_AsVoidPtr(PyDict_GetItemString(descr->metadata, NPY_METADATA_DTSTR)))))
./numpy-1.4.1/numpy/core/include/numpy/ndarrayobject.h:1209:   PyCObject attribute of an array __array_struct__. See
./numpy-1.4.1/numpy/f2py/src/fortranobject.c:232:        PyObject *cobj = PyCObject_FromVoidPtr((void *)(fp->defs[0].data),NULL);
./numpy-1.4.1/numpy/f2py/cb_rules.py:64:\tif (PyCObject_Check(#name#_capi)) {
./numpy-1.4.1/numpy/f2py/cb_rules.py:66:\t#name#_cptr = PyCObject_AsVoidPtr(#name#_capi);
./numpy-1.4.1/numpy/f2py/cfuncs.py:1002:\t\telse if (PyCObject_Check(fun)) {
./numpy-1.4.1/numpy/f2py/rules.py:395:      PyObject_SetAttrString(o,"_cpointer", PyCObject_FromVoidPtr((void*)#F_FUNC#(#name_lower#,#NAME#),NULL));
./numpy-1.4.1/numpy/f2py/rules.py:689:if(PyCObject_Check(#varname#_capi)) {
./numpy-1.4.1/numpy/f2py/rules.py:690:  #varname#_cptr = PyCObject_AsVoidPtr(#varname#_capi);
./numpy-1.4.1/numpy/lib/type_check.py:621:    func = ctypes.pythonapi.PyCObject_AsVoidPtr
./numpy-1.4.1/numpy/random/mtrand/Python.pxi:34:    int PyCObject_Check(object p)
./numpy-1.4.1/numpy/random/mtrand/Python.pxi:35:    object PyCObject_FromVoidPtr(void* cobj, destructor1 destr)
./numpy-1.4.1/numpy/random/mtrand/Python.pxi:36:    object PyCObject_FromVoidPtrAndDesc(void* cobj, void* desc, 
./numpy-1.4.1/numpy/random/mtrand/Python.pxi:38:    void* PyCObject_AsVoidPtr(object self)
./numpy-1.4.1/numpy/random/mtrand/Python.pxi:39:    void* PyCObject_GetDesc(object self)
./numpy-1.4.1/numpy/random/mtrand/Python.pxi:40:    int PyCObject_SetVoidPtr(object self, void* cobj)  
./numpy-1.4.1/numpy/random/mtrand/mtrand.c:244:#define __Pyx_ImportRefcountAPI(name)   (__Pyx_RefnannyAPIStruct *) PyCObject_Import((char *)name, (char *)"RefnannyAPI")

Comment 1 Thomas Spura 2010-10-26 10:35:32 UTC
The new version of numpy claims to work on python3, so that would solve this issue...

Comment 2 Dave Malcolm 2010-10-26 18:05:35 UTC
There seems to be some upstream discussion about this:

In http://www.mail-archive.com/numpy-discussion@scipy.org/msg26669.html , Charles R Harris said:
> ...I believe the Python devs reversed the full
> deprecation before the final 2.7 release.
> So I think we should just stick with PyCObject on 2.x, as we have done so
> far. I'll just bump the version checks so that PyCapsule is used only on
> 3.x.

My understanding is that although there was python-dev discussion of removing the deprecation warning, I don't think it's actually been removed in the upstream 2.7 branch yet.

(In reply to comment #1)
> The new version of numpy claims to work on python3, so that would solve this
> issue...

Not necessarily: python 3.0.*, 3.1.* and 3.2 releases prior to 3.2a2 (iirc) contain the PyCObject API.

IIRC, it was removed altogether in 3.2a2

Comment 3 charles harris 2010-11-05 01:42:06 UTC
Numpy 1.5.x uses PyCapsule when compiled for Python > 3.0. However, we decided to stick with PyCObject for the Python 2.x series to maintain backward compatibility with other projects that depend on numpy. Modifying the codebase to use PyCObject for 2.7 isn't much work, you just need to change a couple of versions checks.

Comment 4 Gwyn Ciesla 2012-02-02 14:35:16 UTC
Fedora 14 is End-of-Life, please reopen against a current release if this bug is still occurring.  Thank you!

Comment 5 Dave Malcolm 2012-02-02 20:30:42 UTC
Reopening, and updating version to "rawhide": I checked in numpy-1.6.1, and it still uses PyCObject for Python 2.x

As noted in comment #3, we could port this for our Python 2.7

[BTW, why was closed with the resolution "ERRATA"?  Surely "DEFERRED" would have been more appropriate for autoclosing bugs based on the reported version]

Comment 6 Gwyn Ciesla 2012-02-03 15:25:41 UTC
I'm not clear what changes need to be made.

You're right, I should have used DEFERRED.

Comment 7 Dave Malcolm 2012-02-03 15:48:11 UTC
(In reply to comment #6)
> I'm not clear what changes need to be made.
> You're right, I should have used DEFERRED.

[Sorry if I came across as picky.  I'm hoping to do a sweep through all of the remaining PyCObject code and actually port them at some point, but swamped with other stuff ATM]

Comment 8 Gwyn Ciesla 2012-02-03 15:56:28 UTC
No worries. :)  If there's anything I can do, let me know.

Comment 9 Fedora End Of Life 2013-04-03 20:08:44 UTC
This bug appears to have been reported against 'rawhide' during the Fedora 19 development cycle.
Changing version to '19'.

(As we did not run this process for some time, it could affect also pre-Fedora 19 development
cycle bugs. We are very sorry. It will help us with cleanup during Fedora 19 End Of Life. Thank you.)

More information and reason for this action is here:

Comment 10 Fedora End Of Life 2015-01-09 21:45:03 UTC
This message is a notice that Fedora 19 is now at end of life. Fedora 
has stopped maintaining and issuing updates for Fedora 19. It is 
Fedora's policy to close all bug reports from releases that are no 
longer maintained. Approximately 4 (four) weeks from now this bug will
be closed as EOL if it remains open with a Fedora 'version' of '19'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version' 
to a later Fedora version.

Thank you for reporting this issue and we are sorry that we were not 
able to fix it before Fedora 19 is end of life. If you would still like 
to see this bug fixed and are able to reproduce it against a later version 
of Fedora, you are encouraged  change the 'version' to a later Fedora 
version prior this bug is closed as described in the policy above.

Although we aim to fix as many bugs as possible during every release's 
lifetime, sometimes those efforts are overtaken by events. Often a 
more recent Fedora release includes newer upstream software that fixes 
bugs or makes them obsolete.

Comment 11 Fedora End Of Life 2015-02-18 13:28:58 UTC
Fedora 19 changed to end-of-life (EOL) status on 2015-01-06. Fedora 19 is
no longer maintained, which means that it will not receive any further
security or bug fix updates. As a result we are closing this bug.

If you can reproduce this bug against a currently maintained version of
Fedora please feel free to reopen this bug against that version. If you
are unable to reopen this bug, please file a new report against the
current release. If you experience problems, please add a comment to this

Thank you for reporting this bug and we are sorry it could not be fixed.

Note You need to log in before you can comment on or make changes to this bug.