Re: Python 2.7 deprecated the PyCObject API?

From: James William Pye <lists(at)jwp(dot)name>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Python 2.7 deprecated the PyCObject API?
Date: 2010-08-14 18:14:26
Message-ID: 0FFDAC97-DF15-457E-A455-9C0BBF4BBA84@jwp.name
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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?

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Heikki Linnakangas 2010-08-14 20:05:49 Re: MERGE Specification
Previous Message Tom Lane 2010-08-14 16:08:41 Re: Python 2.7 deprecated the PyCObject API?