Re: Python 2.7 deprecated the PyCObject API? - Mailing list pgsql-hackers

From James William Pye
Subject Re: Python 2.7 deprecated the PyCObject API?
Date
Msg-id 0FFDAC97-DF15-457E-A455-9C0BBF4BBA84@jwp.name
Whole thread Raw
In response to Re: Python 2.7 deprecated the PyCObject API?  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Python 2.7 deprecated the PyCObject API?
List pgsql-hackers
On Aug 14, 2010, at 9:08 AM, Tom Lane wrote:
> Just to clarify, you're recommending something like
>
>         proc->me = PyCObject_FromVoidPtr(proc, NULL);
> +        if (proc->me == NULL)
> +            elog(ERROR, "could not create PyCObject for function");
>         PyDict_SetItemString(PLy_procedure_cache, key, proc->me);
>
> correct?  (Hm, and it looks like we'd better move the pfree just above that...)

Almost, there's still a Python exception to report and/or clear.
I only glanced at this and didn't recall what the plpython mechanisms were for that, thus the ambiguous "complain()".

> Yeah, and since we'll have to back-patch it, a fairly noninvasive patch
> would be nice.  Will you work on that?

I was hoping that Peter would pop in with a patch, but I think a few lines of CPP may suffice..
(warning: untested =)

#ifdef Py_CAPSULE_H
/** Python.h (2.7 and up) includes pycapsule.h, so rely on the header* define to detect the API's existence.*/
#define PyCObject_FromVoidPtr(POINTER, IGNORED) PyCapsule_New(POINTER, NULL, NULL)
#undef PyCObject_Check
#define PyCObject_Check(OBJ) PyCapsule_CheckExact(OBJ)
#define PyCObject_AsVoidPtr(OBJ) PyCapsule_GetPointer(OBJ, NULL)
#endif /* Py_CAPSULE_H */

http://svn.python.org/view/python/branches/release27-maint/Include/pycapsule.h?view=markup

yay? nay?

pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Python 2.7 deprecated the PyCObject API?
Next
From: Heikki Linnakangas
Date:
Subject: Re: MERGE Specification