[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:15:10 +0100

mark commenting on Gordon commenting on Barry...

> If we are asking them to change their code, can we investigate whether
> asking them to insert a simple:
> if (!Py_IsInitialized())
>   Py_FatalError("Bad Python version"); /* Never returns */
> works OK?  I believe it will, as long as Python's fatal error handler
> doesnt make thread-state assumptions.

	I think this code will crash.

	1. Python20.dll loads and is initialised.
	2. python20.dll loads old_extension.pyd
	3. old_extension.pyd causes python15.dll to load

	At this point we have two copies of python in memory.

	4. old_extension.pyd calls Py_IsInitialized() which is bound
	   to the function in python15.dll.
	5. FALSE is return as python15.dll has not been initialised.
	6. Py_FatalError which is bound in python15.dll is called.
	   May well crash, certainly does not communicate to python20.dll

	You could just:

if (!Py_IsInitialized())

	Which prevents the module being created and hence gets an already
	implemented error message.

	The down side is that does not work for .PYD that have already been
	shipped for 1.5.

	Also if we wish to solve this class of problem for unix as well this
	does not work.