[Python-Dev] Improvements for Porting C Extension from 2 to 3
mal at egenix.com
Thu Mar 3 10:15:00 CET 2011
Sümer Cip wrote:
> While porting a C extension from 2 to 3, I realized that there are some
> general cases which can be automated. For example, for my specific
> application (yappi - http://code.google.com/p/yappi/), all I need to do is
> following things:
> 1) define PyModuleDef
> 2) change PyString_AS_STRING calls to _PyUnicode_AsString
Aside: Please don't use private APIs in Python extensions. Esp.
the above Unicode API is likely going to be phased out.
You're better off, using PyUnicode_AsUTF8String() instead and
then leaving the PyString_AS_STRING() macro in place.
> 3) change module init code a little.
> It occurred to me all these kind of standart changes can be automated via a
> Not sure on the usability of this however, because of my limited knowledge
> on the area.
> Does such a tool worth being implemented?
I'm not sure whether you can really automate this: The change from
8-bit strings to Unicode support usually requires reconsidering
whether you're dealing with plain text, encoded text data or
However, a guide of what to replace and how to change the code
would probably help a lot. Please share your thoughts on the
python-porting mailint list and/or add to these wiki pages:
Professional Python Services directly from the Source (#1, Mar 03 2011)
>>> 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
More information about the Python-Dev