Comment 40 for bug 893091

Revision history for this message
In , Johnp-redhat (johnp-redhat) wrote :

(In reply to comment #33)
> (In reply to comment #31)
> > (In reply to comment #30)
>
> > After some research I came to learn PyCObject is deprecated in 2.7 and removed
> > in 3.2 in favour of PyCapsule (as its C code it can probably be fixed with
> > #if's, but its getting messy). I am just trying to learn what the changes
> > actually entail now.
>
> I tried the following in module.c:
>
> #if (PY_MAJOR_VERSION > 3) || ((PY_MAJOR_VERSION == 3) && (PY_MINOR_VERSION >=
> 2))
> c_api = PyCapsule_New((void *)dbus_bindings_API, "dbus._C_API", NULL);
> #else
> c_api = PyCObject_FromVoidPtr ((void *)dbus_bindings_API, NULL);
> #endif

This is sort of correct. See my patch for PyCairo - https://bugs.freedesktop.org/show_bug.cgi?id=30289

BTW you can apply PyCapsule to 3.0 and above since 3.0 will never be supported, and 3.1 introduced the API. You can also apply it to 2.7 and above if it doesn't appear in any header files (which would require other modules to recompile). I don't think any modules compile against the D-Bus python module so we are golden. This will ensure people don't get aborts if their warning level is set too high.

Note that the name you give has to conform to a certain standard which corresponds to where you add the attr to the object for any PyCapsule_Import call to work properly. I think your patch looks correct.

> it gets me further:
>
> >>> import dbus
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "/opt/Python-3.2a3/lib/python3.2/site-packages/dbus/__init__.py", line
> 78, in <module>
> import dbus.exceptions as exceptions
> AttributeError: 'module' object has no attribute 'exceptions'
>
> After several hours I haven't been able to work this one out, so at this stage
> getting d-bus python to work on 3.2a3 has defeated me :( Im happy to recut my
> patch using the construct given above instead of as, but without solving this
> issue it seems a moot point. Unless the line is drawn as 3.1? Personally as
> python "language" is stable between 3.1 and 3.2 I think there will be an
> expectation that stuff that works on 3.1 should also work on 3.2, even though
> the C api's have changed.

It needs to work on 3.2 since that is what we will ship in Fedora 15 in approx 6-8 months. Thanks for the extra work on this. Is there an exceptions.py in /opt/Python-3.2a3/lib/python3.2/site-packages/dbus/? Sounds like a path issue to me. Do you have commit access? Can you commit your patches (with the "as" issue fixed) to the py3k branch?