schnullerbacke / python4delphi

Automatically exported from code.google.com/p/python4delphi
0 stars 0 forks source link

Compatibility with Python 3.0 #1

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The code in SVN is mostly compatible with Python 3.0.  That is it works OK,
but on exit or when you run programs you get Access Violations.

What steps will reproduce the problem?
1. Load the Demo 1 program
2. Change the Engine properties
   UseLastKnownVersion to False
   APIVersion to 1013
   DLLName to python30.dll

3. Run the program. 

Executing statements works fine.  But even if you exit without executing
any statements you get an Access Violation at exit.

With the release of Python 3.0 this issue is critical.

Please use labels and text to provide additional information.

Original issue reported on code.google.com by pyscripter on 10 Dec 2008 at 12:40

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
The Access appears to happenning during the call to Py_Finalize.
The debugger shows that Python calls
PyGC_Collect
which calls Py_AddPendingCall in which the error occurs.

So it appears that there is a problem during garbage collection.

Original comment by pyscripter on 10 Dec 2008 at 12:59

GoogleCodeExporter commented 9 years ago
Still with the Demo01, if I disconnect the redirection there is no error 
occurring
even if I execute code.  So the issue might be the pyio module creation.

I had to modify Py_InitModule since Py_InitModule4 was removed in Python 3000.  
Here
is the version in SVN. Is anything wrong with this? (redirection works fine).

function TPythonInterface.Py_InitModule( const AName : PChar; md : 
PPyMethodDef) :
PPyObject;
Var
  moduledef : PyModuleDef;
  modules  : PPyObject;
begin
  CheckPython;
  if IsPython3000 then begin
    FillChar(moduledef, SizeOf(moduledef), 0);
    moduledef.m_base.ob_refcnt := 1;
    moduledef.m_name := AName;
    moduledef.m_methods := md;
    moduledef.m_size := -1;
    Result:= PyModule_Create2(@moduledef, APIVersion);
    if not Assigned(Result) then
      GetPythonEngine.CheckError;
    // To emulate Py_InitModule4 we need to add the module to sys.modules
    modules := PyImport_GetModuleDict;
    if PyDict_SetItemString(modules, AName, Result) <> 0 then
      GetPythonEngine.CheckError;
  end else
    Result := Py_InitModule4( AName, md, nil, nil, APIVersion );
end;

Original comment by pyscripter on 10 Dec 2008 at 9:48

GoogleCodeExporter commented 9 years ago
The problem actually was in the above function.  
Fixed in todays commit.

At long last...

Original comment by pyscripter on 13 Feb 2009 at 12:36