Lists: | pgsql-hackers |
---|
From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | pgsql-hackers(at)postgreSQL(dot)org |
Subject: | Python 2.7 deprecated the PyCObject API? |
Date: | 2010-08-14 00:20:19 |
Message-ID: | 26161.1281745219@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
According to a discussion over in Fedora-land, $subject is true:
http://lists.fedoraproject.org/pipermail/devel/2010-August/140995.html
I see several calls in plpython.c that seem to refer to PyCObject stuff.
Anybody have any idea if we need to do something about this?
regards, tom lane
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 02:16:27 |
Message-ID: | 4A8655F9-54BC-44C0-BC90-575B1E536104@jwp.name |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On Aug 13, 2010, at 5:20 PM, Tom Lane wrote:
> According to a discussion over in Fedora-land, $subject is true:
> http://lists.fedoraproject.org/pipermail/devel/2010-August/140995.html
>
> I see several calls in plpython.c that seem to refer to PyCObject stuff.
> Anybody have any idea if we need to do something about this?
Well, we should at least be checking for an exception here anyways:
proc->me = PyCObject_FromVoidPtr(proc, NULL);
PyDict_SetItemString(PLy_procedure_cache, key, proc->me);
if (proc->me == NULL) complain();
That is, with those warnings adjustments, proc->me will be NULL and then explode in PyDict_SetItemString:
[David Malcolm]
However, if someone overrides the process-wide warnings settings, then
the API can fail altogether, raising a PendingDeprecationWarning
exception (which in CPython terms means setting a thread-specific error
state and returning NULL).
./
AFA a better fix is concerned, the shortest route would seem to be to use the new capsule stuff iff Python >= 2.7.
From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | James William Pye <lists(at)jwp(dot)name> |
Cc: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: Python 2.7 deprecated the PyCObject API? |
Date: | 2010-08-14 16:08:41 |
Message-ID: | 29560.1281802121@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
James William Pye <lists(at)jwp(dot)name> writes:
> On Aug 13, 2010, at 5:20 PM, Tom Lane wrote:
>> I see several calls in plpython.c that seem to refer to PyCObject stuff.
>> Anybody have any idea if we need to do something about this?
> Well, we should at least be checking for an exception here anyways:
> proc->me = PyCObject_FromVoidPtr(proc, NULL);
> PyDict_SetItemString(PLy_procedure_cache, key, proc->me);
> if (proc->me == NULL) complain();
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...)
> AFA a better fix is concerned, the shortest route would seem to be to
> use the new capsule stuff iff Python >= 2.7.
Yeah, and since we'll have to back-patch it, a fairly noninvasive patch
would be nice. Will you work on that?
regards, tom lane
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 |
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?
From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | James William Pye <lists(at)jwp(dot)name> |
Cc: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: Python 2.7 deprecated the PyCObject API? |
Date: | 2010-08-15 18:25:03 |
Message-ID: | 2536.1281896703@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
James William Pye <lists(at)jwp(dot)name> writes:
> 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.
Ah, right, I guess that should be PLy_elog() not just elog().
>> 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..
> ...
> yay? nay?
Damifino, I don't hack Python. Peter?
regards, tom lane
From: | Peter Eisentraut <peter_e(at)gmx(dot)net> |
---|---|
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-17 17:55:58 |
Message-ID: | 1282067758.25113.4.camel@vanquo.pezone.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On fre, 2010-08-13 at 20:20 -0400, Tom Lane wrote:
> According to a discussion over in Fedora-land, $subject is true:
> http://lists.fedoraproject.org/pipermail/devel/2010-August/140995.html
>
> I see several calls in plpython.c that seem to refer to PyCObject
> stuff.
> Anybody have any idea if we need to do something about this?
Some exception handling might be good, but I think we don't need to
abandon the API yet. It's only "pending deprecation".
From: | Peter Eisentraut <peter_e(at)gmx(dot)net> |
---|---|
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-17 18:48:55 |
Message-ID: | 1282070935.25113.10.camel@vanquo.pezone.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On tis, 2010-08-17 at 20:55 +0300, Peter Eisentraut wrote:
> On fre, 2010-08-13 at 20:20 -0400, Tom Lane wrote:
> > According to a discussion over in Fedora-land, $subject is true:
> > http://lists.fedoraproject.org/pipermail/devel/2010-August/140995.html
> >
> > I see several calls in plpython.c that seem to refer to PyCObject
> > stuff.
> > Anybody have any idea if we need to do something about this?
>
> Some exception handling might be good, but I think we don't need to
> abandon the API yet. It's only "pending deprecation".
Here is a patch. The crash is reproducible, if warnings are turned into
errors.
Attachment | Content-Type | Size |
---|---|---|
plpython-warn.patch | text/x-patch | 987 bytes |
From: | Peter Eisentraut <peter_e(at)gmx(dot)net> |
---|---|
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-25 19:39:19 |
Message-ID: | 1282765159.6146.0.camel@vanquo.pezone.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On tis, 2010-08-17 at 21:48 +0300, Peter Eisentraut wrote:
> On tis, 2010-08-17 at 20:55 +0300, Peter Eisentraut wrote:
> > On fre, 2010-08-13 at 20:20 -0400, Tom Lane wrote:
> > > According to a discussion over in Fedora-land, $subject is true:
> > > http://lists.fedoraproject.org/pipermail/devel/2010-August/140995.html
> > >
> > > I see several calls in plpython.c that seem to refer to PyCObject
> > > stuff.
> > > Anybody have any idea if we need to do something about this?
> >
> > Some exception handling might be good, but I think we don't need to
> > abandon the API yet. It's only "pending deprecation".
>
> Here is a patch. The crash is reproducible, if warnings are turned into
> errors.
I have applied this patch back to 8.0. 7.4's plpython crashes with
Python >= 2.5; it's probably not worth rescuing.