Thread: Problem with python compile

Problem with python compile

From
Bruce Momjian
Date:
I am seeing the following warning message when compiling
interfaces/python:

---------------------------------------------------------------------------

gcc -O2 -pipe -m486 -Wall -Wmissing-prototypes -Wmissing-declarations -O0 -Wall 
-Wmissing-prototypes -Wmissing-declarations -Wpointer-arith -Wcast-align -fpic -
I../../../src/interfaces/libpq -I../../../src/include -I/usr/local/include/readl
ine -I/usr/contrib/include -I/usr/contrib/include/python1.5  -c -o pgmodule.o pg
module.c
pgmodule.c: In function `pgsource_dealloc':
pgmodule.c:346: warning: implicit declaration of function `PyObject_DEL'

---------------------------------------------------------------------------

This was introduced by the following patch:

---------------------------------------------------------------------------

Revision 1.35 / (download) - annotate - [select for diffs] , Wed Mar 20 14:36:06 2002 UTC (4 days, 11 hours ago) by
darcy
CVS Tags: HEAD
Changes since 1.34: +4 -4 lines
Diff to previous 1.34

PyGreSQL causes a segfault when used with a Python executable that was
compiled with --with-pymalloc.  This change fixes that.  Thanks to
Dave Wallace <dwallace@udel.edu>

---------------------------------------------------------------------------

The patch changes PyMem_DEL(self) to PyObject_DEL(self).

This is with python 1.5.  I suggest that we should reverse out this patch.
The fix for --with-pymalloc clearly is causing problems for regular
compiles.

--  Bruce Momjian                        |  http://candle.pha.pa.us pgman@candle.pha.pa.us               |  (610)
853-3000+  If your life is a hard drive,     |  830 Blythe Avenue +  Christ can be your backup.        |  Drexel Hill,
Pennsylvania19026
 


Re: Problem with python compile

From
Bernhard Herzog
Date:
Bruce Momjian <pgman@candle.pha.pa.us> writes:

> PyGreSQL causes a segfault when used with a Python executable that was
> compiled with --with-pymalloc.  This change fixes that.  Thanks to
> Dave Wallace <dwallace@udel.edu>
> 
> ---------------------------------------------------------------------------
> 
> The patch changes PyMem_DEL(self) to PyObject_DEL(self).
> 
> This is with python 1.5.  I suggest that we should reverse out this patch.
> The fix for --with-pymalloc clearly is causing problems for regular
> compiles.

This depends on the Python version. PyObject_DEL (which really should be
PyObject_Del, i.e. the function not the macro) is not defined in 1.5 but
it's defined in 2.x and the proper way to free memory allocated with
PyObject_New. In 1.5 PyMem_Del is OK. 

If you want compatibility from 1.5.2 up to 2.2 with pymalloc something
like this should work, I think:

#if PY_VERSION_HEX < 0x01060000
#define PyObject_Del(op) PyMem_Del((op))
#endif

This is basically what is done in Python's _sre.c.

Python's memory management API (which is a bit of a mess) and pymalloc
is currently a very actively discussed topic on python-dev.

  Bernhard

-- 
Intevation GmbH                                 http://intevation.de/
Sketch                                 http://sketch.sourceforge.net/
MapIt!                                           http://www.mapit.de/


Re: Problem with python compile

From
"D'Arcy J.M. Cain"
Date:
On March 24, 2002 08:49 pm, Bruce Momjian wrote:
> I am seeing the following warning message when compiling
> interfaces/python:
>
> ---------------------------------------------------------------------------
>
> gcc -O2 -pipe -m486 -Wall -Wmissing-prototypes -Wmissing-declarations -O0
> -Wall -Wmissing-prototypes -Wmissing-declarations -Wpointer-arith
> -Wcast-align -fpic - I../../../src/interfaces/libpq -I../../../src/include
> -I/usr/local/include/readl ine -I/usr/contrib/include
> -I/usr/contrib/include/python1.5  -c -o pgmodule.o pg module.c
> pgmodule.c: In function `pgsource_dealloc':
> pgmodule.c:346: warning: implicit declaration of function `PyObject_DEL'

Let's not back it out just yet.  It works fine for me.  Perhaps is is a
Python version issue.  What version of Python are you running?

-- 
D'Arcy J.M. Cain <darcy@{druid|vex}.net>   |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.


Re: Problem with python compile

From
"D'Arcy J.M. Cain"
Date:
On March 25, 2002 06:18 am, Bernhard Herzog wrote:
> Bruce Momjian <pgman@candle.pha.pa.us> writes:
> > This is with python 1.5.  I suggest that we should reverse out this
> > patch. The fix for --with-pymalloc clearly is causing problems for
> > regular compiles.
>
> This depends on the Python version. PyObject_DEL (which really should be
> PyObject_Del, i.e. the function not the macro) is not defined in 1.5 but
> it's defined in 2.x and the proper way to free memory allocated with
> PyObject_New. In 1.5 PyMem_Del is OK.
>
> If you want compatibility from 1.5.2 up to 2.2 with pymalloc something
> like this should work, I think:
>
> #if PY_VERSION_HEX < 0x01060000
> #define PyObject_Del(op) PyMem_Del((op))
> #endif

I will do that but I wonder what is wrong with the macro?

I also note that the Python source was just changed a few days ago in this
area.  It looks like everything is going to effectively use the mem functions
anyway so this change may not matter eventually.  However, that won't apply
until the next release and we will still want to support 2.2 after that so
I will continue with the suggested change but please discuss this issue
between PyObject_DEL and PyObject_Del first.  I don't mind using the function
here but I just want to know your reasoning.

-- 
D'Arcy J.M. Cain <darcy@{druid|vex}.net>   |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.


Re: Problem with python compile

From
Bernhard Herzog
Date:
"D'Arcy J.M. Cain" <darcy@druid.net> writes:

> On March 25, 2002 06:18 am, Bernhard Herzog wrote:
> > #if PY_VERSION_HEX < 0x01060000
> > #define PyObject_Del(op) PyMem_Del((op))
> > #endif
> 
> I will do that but I wonder what is wrong with the macro?

Because the macros shouldn't be used in extension modules. From
http://python.org/doc/current/api/memoryInterface.html:
  In addition, the following macro sets are provided for calling the  Python memory allocator directly, without
involvingthe C API  functions listed above. However, note that their use does not  preserve binary compatibility
accrossPython versions and is  therefore deprecated in extension modules.
 
  PyMem_MALLOC(), PyMem_REALLOC(), PyMem_FREE(). 
  PyMem_NEW(), PyMem_RESIZE(), PyMem_DEL(). 

Apart from that the macros aren't really faster anyway, according to
some posts on python-dev.

> I also note that the Python source was just changed a few days ago in this
> area.  It looks like everything is going to effectively use the mem functions
> anyway so this change may not matter eventually.

AFAICT, there hasn't been any final decision on the changes to the
memory API. ISTM that they try to preserve backward compatibility as far
as possible and it does indeed seem that PyMem_Del will still work for
objects allocated with PyObject_New even when pymalloc is enabled, but I
haven't followed the python-dev discussion all that closely, so I may be
wrong. Of course, given that this won't work in current python versions
with pymalloc, switching to PyObject_Del would be better when compiling
with python versions that have it.
  Bernhard

-- 
Intevation GmbH                                 http://intevation.de/
Sketch                                 http://sketch.sourceforge.net/
MapIt!                                           http://www.mapit.de/


Re: Problem with python compile

From
"D'Arcy J.M. Cain"
Date:
On March 25, 2002 08:36 am, Bernhard Herzog wrote:
> "D'Arcy J.M. Cain" <darcy@druid.net> writes:
> > On March 25, 2002 06:18 am, Bernhard Herzog wrote:
> > > #if PY_VERSION_HEX < 0x01060000
> > > #define PyObject_Del(op) PyMem_Del((op))
> > > #endif
> >
> > I will do that but I wonder what is wrong with the macro?
>
> Because the macros shouldn't be used in extension modules. From
> http://python.org/doc/current/api/memoryInterface.html:

Right you are.  Changes submitted.

-- 
D'Arcy J.M. Cain <darcy@{druid|vex}.net>   |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.