@@ -1968,6 +1968,10 @@ TPythonInterface=class(TDynamicDll)
1968
1968
Py_GetCopyright : function : PAnsiChar; cdecl;
1969
1969
Py_GetExecPrefix : function : PAnsiChar; cdecl;
1970
1970
Py_GetPath : function : PAnsiChar; cdecl;
1971
+ Py_SetPythonHome : procedure (home : PAnsiChar); cdecl;
1972
+ Py_GetPythonHome : function : PAnsiChar; cdecl;
1973
+ Py_SetPythonHome3000 : procedure (home : PWideChar); cdecl;
1974
+ Py_GetPythonHome3000 : function : PWideChar; cdecl;
1971
1975
Py_GetPrefix : function : PAnsiChar; cdecl;
1972
1976
Py_GetProgramName : function : PAnsiChar; cdecl;
1973
1977
@@ -2187,6 +2191,8 @@ TPythonEngine = class(TPythonInterface)
2187
2191
FAutoFinalize: Boolean;
2188
2192
FProgramName: AnsiString;
2189
2193
FProgramNameW: UnicodeString;
2194
+ FPythonHome: AnsiString;
2195
+ FPythonHomeW: UnicodeString;
2190
2196
FInitThreads: Boolean;
2191
2197
FOnPathInitialization: TPathInitializationEvent;
2192
2198
FOnSysPathInit: TSysPathInitEvent;
@@ -2240,12 +2246,14 @@ TPythonEngine = class(TPythonInterface)
2240
2246
procedure Finalize ;
2241
2247
procedure Lock ;
2242
2248
procedure Unlock ;
2249
+ procedure SetPythonHome (PythonHome: String);
2243
2250
function IsType (ob: PPyObject; obt: PPyTypeObject): Boolean;
2244
2251
function GetAttrString (obj: PPyObject; AName: PAnsiChar):PAnsiChar;
2245
2252
function CleanString (const s : AnsiString) : AnsiString;
2246
2253
function Run_CommandAsString (const command : AnsiString; mode : Integer) : String;
2247
2254
function Run_CommandAsObject (const command : AnsiString; mode : Integer) : PPyObject;
2248
2255
function Run_CommandAsObjectWithDict (const command : AnsiString; mode : Integer; locals, globals : PPyObject) : PPyObject;
2256
+ function ToPythonRawString (str: String): AnsiString;
2249
2257
procedure ExecString (const command : AnsiString); overload;
2250
2258
procedure ExecStrings ( strings : TStrings ); overload;
2251
2259
function EvalString (const command : AnsiString) : PPyObject; overload;
@@ -4056,6 +4064,14 @@ procedure TPythonInterface.MapDll;
4056
4064
Py_GetCopyright :=Import (' Py_GetCopyright' );
4057
4065
Py_GetExecPrefix :=Import (' Py_GetExecPrefix' );
4058
4066
Py_GetPath :=Import (' Py_GetPath' );
4067
+ if IsPython3000 then
4068
+ Py_SetPythonHome3000 :=Import (' Py_SetPythonHome' )
4069
+ else
4070
+ Py_SetPythonHome :=Import (' Py_SetPythonHome' );
4071
+ if IsPython3000 then
4072
+ Py_GetPythonHome3000 :=Import (' Py_GetPythonHome' )
4073
+ else
4074
+ Py_GetPythonHome :=Import (' Py_GetPythonHome' );
4059
4075
Py_GetPrefix :=Import (' Py_GetPrefix' );
4060
4076
Py_GetProgramName :=Import (' Py_GetProgramName' );
4061
4077
PyParser_SimpleParseString :=Import (' PyParser_SimpleParseString' );
@@ -4850,6 +4866,12 @@ procedure TPythonEngine.Initialize;
4850
4866
end
4851
4867
end ;
4852
4868
AssignPyFlags;
4869
+ if FPythonHomeW<>' ' then begin
4870
+ if IsPython3000 then
4871
+ Py_SetPythonHome3000(PChar(FPythonHomeW))
4872
+ else
4873
+ Py_SetPythonHome(PAnsiChar(FPythonHome));
4874
+ end ;
4853
4875
Py_Initialize;
4854
4876
FInitialized := True;
4855
4877
FIORedirected := False;
@@ -5111,6 +5133,12 @@ procedure TPythonEngine.SetPyFlags(const Value: TPythonFlags);
5111
5133
end ; // of if
5112
5134
end ;
5113
5135
5136
+ procedure TPythonEngine.SetPythonHome (PythonHome: String);
5137
+ begin
5138
+ FPythonHomeW := PythonHome;
5139
+ FPythonHome := ToPythonRawString(PythonHome);
5140
+ end ;
5141
+
5114
5142
function TPythonEngine.IsType (ob: PPyObject; obt: PPyTypeObject): Boolean;
5115
5143
begin
5116
5144
result := ob^.ob_type = obt;
@@ -5280,12 +5308,12 @@ function TPythonEngine.Run_CommandAsObjectWithDict(const command : AnsiString; m
5280
5308
5281
5309
procedure TPythonEngine.ExecStrings ( strings : TStrings );
5282
5310
begin
5283
- Py_XDecRef( Run_CommandAsObject( CleanString( AnsiString (strings.Text) ), file_input ) );
5311
+ Py_XDecRef( Run_CommandAsObject( CleanString( ToPythonRawString (strings.Text) ), file_input ) );
5284
5312
end ;
5285
5313
5286
5314
function TPythonEngine.EvalStrings ( strings : TStrings ) : PPyObject;
5287
5315
begin
5288
- Result := Run_CommandAsObject( CleanString( AnsiString (strings.Text) ), eval_input );
5316
+ Result := Run_CommandAsObject( CleanString( ToPythonRawString (strings.Text) ), eval_input );
5289
5317
end ;
5290
5318
5291
5319
procedure TPythonEngine.ExecString (const command : AnsiString; locals, globals : PPyObject );
@@ -5295,7 +5323,7 @@ procedure TPythonEngine.ExecString(const command : AnsiString; locals, globals :
5295
5323
5296
5324
procedure TPythonEngine.ExecStrings ( strings : TStrings; locals, globals : PPyObject );
5297
5325
begin
5298
- Py_XDecRef( Run_CommandAsObjectWithDict( CleanString( AnsiString (strings.Text) ), file_input, locals, globals ) );
5326
+ Py_XDecRef( Run_CommandAsObjectWithDict( CleanString( ToPythonRawString (strings.Text) ), file_input, locals, globals ) );
5299
5327
end ;
5300
5328
5301
5329
function TPythonEngine.EvalString ( const command : AnsiString; locals, globals : PPyObject ) : PPyObject;
@@ -5305,12 +5333,12 @@ function TPythonEngine.EvalString( const command : AnsiString; locals, globals :
5305
5333
5306
5334
function TPythonEngine.EvalStrings ( strings : TStrings; locals, globals : PPyObject ) : PPyObject;
5307
5335
begin
5308
- Result := Run_CommandAsObjectWithDict( CleanString( AnsiString (strings.Text) ), eval_input, locals, globals );
5336
+ Result := Run_CommandAsObjectWithDict( CleanString( ToPythonRawString (strings.Text) ), eval_input, locals, globals );
5309
5337
end ;
5310
5338
5311
5339
function TPythonEngine.EvalStringsAsStr ( strings : TStrings ) : String;
5312
5340
begin
5313
- Result := Run_CommandAsString( CleanString( AnsiString (strings.Text) ), eval_input );
5341
+ Result := Run_CommandAsString( CleanString( ToPythonRawString (strings.Text) ), eval_input );
5314
5342
end ;
5315
5343
5316
5344
function TPythonEngine.CheckEvalSyntax ( const str : AnsiString ) : Boolean;
@@ -5658,6 +5686,14 @@ function TPythonEngine.FindClient( const aName : string ) : TEngineClient;
5658
5686
end ;
5659
5687
end ;
5660
5688
5689
+ function TPythonEngine.ToPythonRawString (str: String): AnsiString;
5690
+ begin
5691
+ if IsPython3000 then
5692
+ Result := UTF8Encode(str)
5693
+ else
5694
+ Result := AnsiString(str);
5695
+ end ;
5696
+
5661
5697
function TPythonEngine.TypeByName ( const aTypeName : AnsiString ) : PPyTypeObject;
5662
5698
var
5663
5699
i : Integer;
@@ -9726,12 +9762,12 @@ procedure MaskFPUExceptions(ExceptionsMasked : boolean;
9726
9762
exOverflow, exUnderflow, exPrecision])
9727
9763
else
9728
9764
SetExceptionMask([exDenormalized, exUnderflow, exPrecision]);
9729
- { $IFNDEF NEXTGEN}
9765
+ { $IFNDEF NEXTGEN}{ $WARN SYMBOL_PLATFORM OFF }
9730
9766
if MatchPythonPrecision then
9731
9767
SetPrecisionMode(pmDouble)
9732
9768
else
9733
9769
SetPrecisionMode(pmExtended);
9734
- { $ENDIF !NEXTGEN}
9770
+ { $ENDIF !NEXTGEN}{ $WARN SYMBOL_PLATFORM ON }
9735
9771
end ;
9736
9772
9737
9773
{ $IFDEF MSWINDOWS}
0 commit comments