[Python-Dev] Preventing 1.5 extensions crashing under 1.6/2.0 Python

M.-A. Lemburg mal@lemburg.com
Thu, 03 Aug 2000 11:55:57 +0200


Guido van Rossum wrote:
> 
> > Change the init function name to a new name PythonExtensionInit_ say.
> > Pass in the API version for the extension writer to check. If the
> > version is bad for this extension returns without calling any python
> > functions. Add a return code that is true if compatible, false if not.
> > If compatible the extension can use python functions and report and
> > problems it wishes.
> >
> > int PythonExtensionInit_XXX( int invoking_python_api_version )
> >       {
> >       if( invoking_python_api_version != PYTHON_API_VERSION )
> >               {
> >               /* python will report that the module is incompatible */
> >               return 0;
> >               }
> >
> >       /* setup module for XXX ... */
> >
> >       /* say this extension is compatible with the invoking python */
> >       return 1;
> >       }
> >
> > All 1.5 extensions fail to load on later python 2.0 and later.
> > All 2.0 extensions fail to load on python 1.5.
> >
> > All new extensions work only with python of the same API version.
> >
> > Document that failure to setup a module could mean the extension is
> > incompatible with this version of python.
> >
> > Small code change in python core. But need to tell extension writers
> > what the new interface is and update all extensions within the python
> > CVS tree.
> 
> I sort-of like this idea -- at least at the +0 level.

I sort of dislike the idea ;-)

It introduces needless work for hundreds of extension writers
and effectively prevents binary compatibility for future
versions of Python: not all platforms have the problems of the
Windows platform and extensions which were compiled against a
different API version may very well still work with the
new Python version -- e.g. the dynamic loader on Linux is
very well capable of linking the new Python version against
an extension compiled for the previous Python version.

If all this is really necessary, I'd at least suggest adding macros
emulating the old Py_InitModule() APIs, so that extension writers
don't have to edit their code just to get it recompiled.

BTW, the subject line doesn't have anything to do with the
proposed solutions in this thread... they all crash Python
or the extensions in some way, some nicer, some not so nice ;-)

-- 
Marc-Andre Lemburg
______________________________________________________________________
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/