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

Barry Scott barry@scottb.demon.co.uk
Tue, 18 Jul 2000 23:36:15 +0100

Mark's comment about what I'd come up with being too complex
inspired this simpler solution.

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.