Skip to content

Commit 8ddf2df

Browse files
author
pyscripter
committed
Support for Python 3.3
1 parent c93d3d8 commit 8ddf2df

File tree

2 files changed

+47
-17
lines changed

2 files changed

+47
-17
lines changed

PythonForDelphi/Components/Sources/Core/Definition.Inc

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
//{$DEFINE PYTHON30}
3434
//{$DEFINE PYTHON31}
3535
//{$DEFINE PYTHON32}
36+
//{$DEFINE PYTHON33}
3637

3738
/////////////////////////////////////////////////////////////////////////////
3839
// Python for Delphi settings. Comment out the setting you want to enable.
@@ -213,16 +214,18 @@
213214
// Note that the installer will let the user specify its default Python version, and
214215
// thus will edit this file.
215216

216-
{$IFNDEF PYTHON32}
217-
{$IFNDEF PYTHON31}
218-
{$IFNDEF PYTHON30}
219-
{$IFNDEF PYTHON26}
220-
{$IFNDEF PYTHON25}
221-
{$IFNDEF PYTHON24}
222-
{$IFNDEF PYTHON23}
223-
{---<START OF DEFAULT PYTHON VERSION>---}
224-
{$DEFINE PYTHON25}
225-
{---<END OF DEFAULT PYTHON VERSION>---}
217+
{$IFNDEF PYTHON33}
218+
{$IFNDEF PYTHON32}
219+
{$IFNDEF PYTHON31}
220+
{$IFNDEF PYTHON30}
221+
{$IFNDEF PYTHON26}
222+
{$IFNDEF PYTHON25}
223+
{$IFNDEF PYTHON24}
224+
{$IFNDEF PYTHON23}
225+
{---<START OF DEFAULT PYTHON VERSION>---}
226+
{$DEFINE PYTHON25}
227+
{---<END OF DEFAULT PYTHON VERSION>---}
228+
{$ENDIF}
226229
{$ENDIF}
227230
{$ENDIF}
228231
{$ENDIF}
@@ -231,6 +234,7 @@
231234
{$ENDIF}
232235
{$ENDIF}
233236

237+
234238
{$IFDEF PYTHON23}
235239
{$DEFINE PYTHON23_OR_HIGHER}
236240
{$ENDIF}
@@ -273,6 +277,16 @@
273277
{$DEFINE PYTHON31_OR_HIGHER}
274278
{$DEFINE PYTHON32_OR_HIGHER}
275279
{$ENDIF}
280+
{$IFDEF PYTHON33}
281+
{$DEFINE PYTHON23_OR_HIGHER}
282+
{$DEFINE PYTHON24_OR_HIGHER}
283+
{$DEFINE PYTHON25_OR_HIGHER}
284+
{$DEFINE PYTHON26_OR_HIGHER}
285+
{$DEFINE PYTHON30_OR_HIGHER}
286+
{$DEFINE PYTHON31_OR_HIGHER}
287+
{$DEFINE PYTHON32_OR_HIGHER}
288+
{$DEFINE PYTHON33_OR_HIGHER}
289+
{$ENDIF}
276290

277291
/////////////////////////////////////////////////////////////////////////////
278292
// Misc

PythonForDelphi/Components/Sources/Core/PythonEngine.pas

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,26 +126,28 @@ interface
126126
end;
127127
const
128128
{$IFDEF MSWINDOWS}
129-
PYTHON_KNOWN_VERSIONS: array[1..8] of TPythonVersionProp =
129+
PYTHON_KNOWN_VERSIONS: array[1..9] 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),
133133
(DllName: 'python26.dll'; RegVersion: '2.6'; APIVersion: 1013; CanUseLatest: True),
134134
(DllName: 'python27.dll'; RegVersion: '2.7'; APIVersion: 1013; CanUseLatest: True),
135135
(DllName: 'python30.dll'; RegVersion: '3.0'; APIVersion: 1013; CanUseLatest: True),
136136
(DllName: 'python31.dll'; RegVersion: '3.1'; APIVersion: 1013; CanUseLatest: True),
137-
(DllName: 'python32.dll'; RegVersion: '3.2'; APIVersion: 1013; CanUseLatest: True) );
137+
(DllName: 'python32.dll'; RegVersion: '3.2'; APIVersion: 1013; CanUseLatest: True),
138+
(DllName: 'python33.dll'; RegVersion: '3.3'; APIVersion: 1013; CanUseLatest: True) );
138139
{$ENDIF}
139140
{$IFDEF LINUX}
140-
PYTHON_KNOWN_VERSIONS: array[1..8] of TPythonVersionProp =
141+
PYTHON_KNOWN_VERSIONS: array[1..9] of TPythonVersionProp =
141142
( (DllName: 'libpython2.3.so'; RegVersion: '2.3'; APIVersion: 1012; CanUseLatest: True),
142143
(DllName: 'libpython2.4.so'; RegVersion: '2.4'; APIVersion: 1012; CanUseLatest: True),
143144
(DllName: 'libpython2.5.so'; RegVersion: '2.5'; APIVersion: 1013; CanUseLatest: True),
144145
(DllName: 'libpython2.6.so'; RegVersion: '2.6'; APIVersion: 1013; CanUseLatest: True),
145146
(DllName: 'libpython2.7.so'; RegVersion: '2.7'; APIVersion: 1013; CanUseLatest: True),
146147
(DllName: 'libpython3.0.so'; RegVersion: '3.0'; APIVersion: 1013; CanUseLatest: True),
147148
(DllName: 'libpython3.1.so'; RegVersion: '3.1'; APIVersion: 1013; CanUseLatest: True),
148-
(DllName: 'libpython3.2.so'; RegVersion: '3.2'; APIVersion: 1013; CanUseLatest: True) );
149+
(DllName: 'libpython3.2.so'; RegVersion: '3.2'; APIVersion: 1013; CanUseLatest: True),
150+
(DllName: 'libpython3.3.so'; RegVersion: '3.3'; APIVersion: 1013; CanUseLatest: True) );
149151
{$ENDIF}
150152
{$IFDEF PYTHON23}
151153
COMPILED_FOR_PYTHON_VERSION_INDEX = 1;
@@ -171,6 +173,9 @@ interface
171173
{$IFDEF PYTHON32}
172174
COMPILED_FOR_PYTHON_VERSION_INDEX = 8;
173175
{$ENDIF}
176+
{$IFDEF PYTHON33}
177+
COMPILED_FOR_PYTHON_VERSION_INDEX = 9;
178+
{$ENDIF}
174179

175180
PYT_METHOD_BUFFER_INCREASE = 10;
176181
PYT_MEMBER_BUFFER_INCREASE = 10;
@@ -1504,6 +1509,8 @@ TPythonInterface=class(TDynamicDll)
15041509
FInitialized: Boolean;
15051510
FFinalizing: Boolean;
15061511
FIsPython3000: Boolean;
1512+
FMajorVersion: integer;
1513+
FMinorVersion: integer;
15071514
FBuiltInModuleName: String;
15081515
function GetInitialized: Boolean;
15091516

@@ -2050,6 +2057,8 @@ TPythonInterface=class(TDynamicDll)
20502057
property Initialized : Boolean read GetInitialized;
20512058
property Finalizing : Boolean read FFinalizing;
20522059
property IsPython3000 : Boolean read FIsPython3000;
2060+
property MajorVersion : integer read FMajorVersion;
2061+
property MinorVersion : integer read FMinorVersion;
20532062
property BuiltInModuleName: String read FBuiltInModuleName write FBuiltInModuleName;
20542063

20552064
end;
@@ -3478,6 +3487,10 @@ procedure TPythonInterface.AfterLoad;
34783487
begin
34793488
inherited;
34803489
FIsPython3000 := Pos('PYTHON3', UpperCase(DLLName)) = 1;
3490+
FMajorVersion := StrToInt(DLLName[7 {$IFDEF LINUX}+3{$ENDIF}]);
3491+
FMinorVersion := StrToInt(DLLName[8{$IFDEF LINUX}+3{$ENDIF}]);
3492+
3493+
34813494
if FIsPython3000 then
34823495
FBuiltInModuleName := 'builtins'
34833496
else
@@ -3520,7 +3533,9 @@ procedure TPythonInterface.CheckPython;
35203533

35213534
function TPythonInterface.GetUnicodeTypeSuffix : String;
35223535
begin
3523-
if APIVersion >= 1011 then
3536+
if (fMajorVersion > 3) or ((fMajorVersion = 3) and (fMinorVersion >= 3)) then
3537+
Result := ''
3538+
else if APIVersion >= 1011 then
35243539
Result := 'UCS2'
35253540
else
35263541
Result := '';
@@ -3538,9 +3553,9 @@ procedure TPythonInterface.MapDll;
35383553
if not IsPython3000 then begin
35393554
Py_TabcheckFlag := Import('Py_TabcheckFlag');
35403555
Py_UnicodeFlag := Import('Py_UnicodeFlag');
3556+
Py_DivisionWarningFlag := Import('Py_DivisionWarningFlag');
35413557
end;
35423558
Py_IgnoreEnvironmentFlag := Import('Py_IgnoreEnvironmentFlag');
3543-
Py_DivisionWarningFlag := Import('Py_DivisionWarningFlag');
35443559

35453560
//_PySys_TraceFunc := Import('_PySys_TraceFunc');
35463561
//_PySys_ProfileFunc := Import('_PySys_ProfileFunc');
@@ -4670,7 +4685,8 @@ procedure TPythonEngine.AssignPyFlags;
46704685
SetFlag(Py_TabcheckFlag, pfTabcheck in FPyFlags);
46714686
end;
46724687
SetFlag(Py_IgnoreEnvironmentFlag, pfIgnoreEnvironmentFlag in FPyFlags);
4673-
SetFlag(Py_DivisionWarningFlag, pfDivisionWarningFlag in FPyFlags);
4688+
if Assigned(Py_DivisionWarningFlag) then
4689+
SetFlag(Py_DivisionWarningFlag, pfDivisionWarningFlag in FPyFlags);
46744690
end;
46754691

46764692
procedure TPythonEngine.Initialize;

0 commit comments

Comments
 (0)