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

Guido van Rossum guido@beopen.com
Wed, 02 Aug 2000 18:18:04 -0500


> > But-I-doubt-anyone-will-release-extension-modules-for-1.6-anyway ly,
> 
> 	Yes indeed once the story of 1.6 and 2.0 is out I expect folks
> 	will skip 1.6. For example, if your win32 stuff is not ported
> 	then Python 1.6 is not usable on Windows/NT.

I expect to be releasing a 1.6 Windows installer -- but I can't
control Mark Hammond.  Yet, it shouldn't be hard for him to create a
1.6 version of win32all, should it?

> 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 would choose a shorter name: PyExtInit_XXX().

Could you (or someone else) prepare a patch that changes this?  It
would be great if the patch were relative to the 1.6 branch of the
source tree; unfortunately this is different because of the
ANSIfication.

Unfortunately we only have two days to get this done for 1.6 -- I plan
to release 1.6b1 this Friday!  If you don't get to it, prepare a patch
for 2.0 would be the next best thing.

--Guido van Rossum (home page: http://www.pythonlabs.com/~guido/)