[Python-Dev] PyMem_Malloc() vs PyObject_Malloc() (original) (raw)

M.-A. Lemburg mal at egenix.com
Fri Sep 4 11:27:58 CEST 2009


Kristján Valur Jónsson wrote:

I noticed something (in 2.5) yesterday, which may be a feature, but is more likely a bug. In tokenizer.c, tok->encoding is allocated using PyMemMALLOC(). However, this then gets handed to a node->rstr in parsetok.c, and then released in node.c using PyObjectFree(). Now, by coincidence, PyObjectFree() will default to free() for objects that it doesn't recognize, so this works. But is this documented behavior? The reason I ran into this was that I had redirect the PyMem* API to a different allocator, but left the PyObject* one alone. My feeling Is that these two APIs shouldn't be interchangeable. Especially since you can't hand a PyObjectMalloc'd object to PyMemFree() so the inverse shouldn't be expected to work. Any thoughts?

This is a bug. Please file a bug report for this.

In general, either PyObject_* xor PyMem_* memory API should used.

-- Marc-Andre Lemburg eGenix.com

Professional Python Services directly from the Source (#1, Sep 04 2009)

Python/Zope Consulting and Support ... http://www.egenix.com/ mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/


::: Try our new mxODBC.Connect Python Database Interface for free ! ::::

eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/



More information about the Python-Dev mailing list