Skip to content

Commit 5a50360

Browse files
author
pyscripter
committed
Python 3.4 compatibility
1 parent 4a886db commit 5a50360

File tree

8 files changed

+366
-291
lines changed

8 files changed

+366
-291
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package Python_XE7;
2+
3+
{$R *.res}
4+
{$R 'Sources\Core\PythonEngine.dcr'}
5+
{$IFDEF IMPLICITBUILDING This IFDEF should not be used by users}
6+
{$ALIGN 8}
7+
{$ASSERTIONS ON}
8+
{$BOOLEVAL OFF}
9+
{$DEBUGINFO ON}
10+
{$EXTENDEDSYNTAX ON}
11+
{$IMPORTEDDATA ON}
12+
{$IOCHECKS ON}
13+
{$LOCALSYMBOLS ON}
14+
{$LONGSTRINGS ON}
15+
{$OPENSTRINGS ON}
16+
{$OPTIMIZATION OFF}
17+
{$OVERFLOWCHECKS OFF}
18+
{$RANGECHECKS OFF}
19+
{$REFERENCEINFO ON}
20+
{$SAFEDIVIDE OFF}
21+
{$STACKFRAMES ON}
22+
{$TYPEDADDRESS OFF}
23+
{$VARSTRINGCHECKS ON}
24+
{$WRITEABLECONST OFF}
25+
{$MINENUMSIZE 1}
26+
{$IMAGEBASE $400000}
27+
{$DEFINE DEBUG}
28+
{$ENDIF IMPLICITBUILDING}
29+
{$DESCRIPTION 'Components for Python'}
30+
{$IMPLICITBUILD OFF}
31+
32+
requires
33+
rtl,
34+
vcl;
35+
36+
contains
37+
MethodCallBack in 'Sources\Core\MethodCallBack.pas',
38+
PythonEngine in 'Sources\Core\PythonEngine.pas',
39+
PythonGUIInputOutput in 'Sources\Core\PythonGUIInputOutput.pas',
40+
WrapDelphi in 'Sources\Core\WrapDelphi.pas';
41+
42+
end.

PythonForDelphi/Components/Sources/Core/PythonEngine.pas

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ interface
126126
end;
127127
const
128128
{$IFDEF MSWINDOWS}
129-
PYTHON_KNOWN_VERSIONS: array[1..9] of TPythonVersionProp =
129+
PYTHON_KNOWN_VERSIONS: array[1..10] of TPythonVersionProp =
130130
( (DllName: 'python23.dll'; RegVersion: '2.3'; APIVersion: 1012; CanUseLatest: True),
131131
(DllName: 'python24.dll'; RegVersion: '2.4'; APIVersion: 1012; CanUseLatest: True),
132132
(DllName: 'python25.dll'; RegVersion: '2.5'; APIVersion: 1013; CanUseLatest: True),
@@ -135,10 +135,11 @@ interface
135135
(DllName: 'python30.dll'; RegVersion: '3.0'; APIVersion: 1013; CanUseLatest: True),
136136
(DllName: 'python31.dll'; RegVersion: '3.1'; APIVersion: 1013; CanUseLatest: True),
137137
(DllName: 'python32.dll'; RegVersion: '3.2'; APIVersion: 1013; CanUseLatest: True),
138-
(DllName: 'python33.dll'; RegVersion: '3.3'; APIVersion: 1013; CanUseLatest: True) );
138+
(DllName: 'python33.dll'; RegVersion: '3.3'; APIVersion: 1013; CanUseLatest: True),
139+
(DllName: 'python34.dll'; RegVersion: '3.4'; APIVersion: 1013; CanUseLatest: True) );
139140
{$ENDIF}
140141
{$IFDEF LINUX}
141-
PYTHON_KNOWN_VERSIONS: array[1..9] of TPythonVersionProp =
142+
PYTHON_KNOWN_VERSIONS: array[1..10] of TPythonVersionProp =
142143
( (DllName: 'libpython2.3.so'; RegVersion: '2.3'; APIVersion: 1012; CanUseLatest: True),
143144
(DllName: 'libpython2.4.so'; RegVersion: '2.4'; APIVersion: 1012; CanUseLatest: True),
144145
(DllName: 'libpython2.5.so'; RegVersion: '2.5'; APIVersion: 1013; CanUseLatest: True),
@@ -147,7 +148,8 @@ interface
147148
(DllName: 'libpython3.0.so'; RegVersion: '3.0'; APIVersion: 1013; CanUseLatest: True),
148149
(DllName: 'libpython3.1.so'; RegVersion: '3.1'; APIVersion: 1013; CanUseLatest: True),
149150
(DllName: 'libpython3.2.so'; RegVersion: '3.2'; APIVersion: 1013; CanUseLatest: True),
150-
(DllName: 'libpython3.3.so'; RegVersion: '3.3'; APIVersion: 1013; CanUseLatest: True) );
151+
(DllName: 'libpython3.3.so'; RegVersion: '3.3'; APIVersion: 1013; CanUseLatest: True),
152+
(DllName: 'libpython3.4.so'; RegVersion: '3.4'; APIVersion: 1013; CanUseLatest: True) );
151153
{$ENDIF}
152154
{$IFDEF PYTHON23}
153155
COMPILED_FOR_PYTHON_VERSION_INDEX = 1;
@@ -176,7 +178,9 @@ interface
176178
{$IFDEF PYTHON33}
177179
COMPILED_FOR_PYTHON_VERSION_INDEX = 9;
178180
{$ENDIF}
179-
181+
{$IFDEF PYTHON34}
182+
COMPILED_FOR_PYTHON_VERSION_INDEX = 10;
183+
{$ENDIF}
180184
PYT_METHOD_BUFFER_INCREASE = 10;
181185
PYT_MEMBER_BUFFER_INCREASE = 10;
182186
PYT_GETSET_BUFFER_INCREASE = 10;
@@ -1704,6 +1708,7 @@ TPythonInterface=class(TDynamicDll)
17041708
PySys_SetArgv3000: procedure( argc: Integer; argv: PPWideChar); cdecl;
17051709

17061710
PyCFunction_New: function(md:PPyMethodDef;ob:PPyObject):PPyObject; cdecl;
1711+
PyCFunction_NewEx: function(md:PPyMethodDef;self, ob:PPyObject):PPyObject; cdecl;
17071712
// Removed. Use PyEval_CallObjectWithKeywords with third argument nil
17081713
// PyEval_CallObject: function(callable_obj, args:PPyObject):PPyObject; cdecl;
17091714
PyEval_CallObjectWithKeywords:function (callable_obj, args, kw:PPyObject):PPyObject; cdecl;
@@ -3752,7 +3757,12 @@ procedure TPythonInterface.MapDll;
37523757
PySys_SetArgv3000 := Import('PySys_SetArgv');
37533758
Py_Exit := Import('Py_Exit');
37543759

3755-
PyCFunction_New :=Import('PyCFunction_New');
3760+
if IsPython3000 then
3761+
PyCFunction_NewEx :=Import('PyCFunction_NewEx')
3762+
else
3763+
PyCFunction_New :=Import('PyCFunction_New');
3764+
3765+
37563766
PyEval_CallObjectWithKeywords:=Import('PyEval_CallObjectWithKeywords');
37573767
PyEval_GetFrame :=Import('PyEval_GetFrame');
37583768
PyEval_GetGlobals :=Import('PyEval_GetGlobals');
@@ -8915,7 +8925,10 @@ procedure TPythonType.AddTypeVar;
89158925
FCreateFuncDef.ml_meth := GetOfObjectCallBack( TCallBack(meth), 2, ctCDECL);
89168926
FCreateFuncDef.ml_flags := METH_VARARGS;
89178927
FCreateFuncDef.ml_doc := PAnsiChar(FCreateFuncDoc);
8918-
FCreateFunc := Engine.PyCFunction_New(@FCreateFuncDef, nil);
8928+
if GetPythonEngine.IsPython3000 then
8929+
FCreateFunc := Engine.PyCFunction_NewEx(@FCreateFuncDef, nil, nil)
8930+
else
8931+
FCreateFunc := Engine.PyCFunction_New(@FCreateFuncDef, nil);
89198932
end;
89208933
Assert(Assigned(FCreateFunc));
89218934
end;

PythonForDelphi/Components/Sources/Core/WrapDelphi.pas

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2689,7 +2689,10 @@ procedure TPyDelphiWrapper.CreatePyFunc(AModule: TPythonModule; AMethodDef: PPyM
26892689
begin
26902690
d := PyModule_GetDict(FModule.Module);
26912691
Assert(Assigned(d));
2692-
PyDict_SetItemString( d, AMethodDef^.ml_name, PyCFunction_New(AMethodDef, nil));
2692+
if IsPython3000 then
2693+
PyDict_SetItemString( d, AMethodDef^.ml_name, PyCFunction_NewEx(AMethodDef, nil, nil))
2694+
else
2695+
PyDict_SetItemString( d, AMethodDef^.ml_name, PyCFunction_New(AMethodDef, nil));
26932696
end;
26942697
end;
26952698

0 commit comments

Comments
 (0)