65
65
{ $ENDIF}
66
66
67
67
{ $IF defined(LINUX) or (defined(BSD) and not defined(DARWIN)) or defined(SOLARIS) or defined(HAIKU)}
68
- { $define _so_files}
69
- { $ENDIF}
68
+ { $define _so_files}
69
+ { $ENDIF}
70
70
71
71
interface
72
72
@@ -2190,14 +2190,18 @@ TPythonEngine = class(TPythonInterface)
2190
2190
procedure Finalize ;
2191
2191
procedure Lock ;
2192
2192
procedure Unlock ;
2193
- procedure SetPythonHome (const PythonHome: string );
2194
- procedure SetProgramName (const ProgramName: string );
2193
+ procedure SetPythonHome (const PythonHome: UnicodeString );
2194
+ procedure SetProgramName (const ProgramName: UnicodeString );
2195
2195
function IsType (ob: PPyObject; obt: PPyTypeObject): Boolean;
2196
2196
function GetAttrString (obj: PPyObject; AName: PAnsiChar):PAnsiChar;
2197
2197
function Run_CommandAsString (const command : AnsiString; mode : Integer) : string;
2198
2198
function Run_CommandAsObject (const command : AnsiString; mode : Integer) : PPyObject;
2199
2199
function Run_CommandAsObjectWithDict (const command : AnsiString; mode : Integer; locals, globals : PPyObject) : PPyObject;
2200
- function EncodeString (const str: string): AnsiString;
2200
+ function EncodeString (const str: UnicodeString): AnsiString; { $IFDEF FPC} overload;{ $ENDIF}
2201
+ { $IFDEF FPC}
2202
+ overload;
2203
+ function EncodeString (const str: AnsiString): AnsiString; overload;
2204
+ { $ENDIF}
2201
2205
function EncodeWindowsFilePath (const str: string): AnsiString;
2202
2206
procedure ExecString (const command : AnsiString); overload;
2203
2207
procedure ExecStrings ( strings : TStrings ); overload;
@@ -2353,7 +2357,7 @@ TEventDef = class(TCollectionItem)
2353
2357
FTmpDocString: AnsiString;
2354
2358
FOnExecute: TPythonEvent;
2355
2359
FDocString: TStringList;
2356
- procedure SetDocString (const Value : TStringList);
2360
+ procedure SetDocString (const Value : TStringList);
2357
2361
protected
2358
2362
function GetDisplayName : string; override;
2359
2363
procedure SetDisplayName (const Value : string); override;
@@ -3238,7 +3242,7 @@ procedure TPythonInputOutput.WriteLine( const str : IOString );
3238
3242
3239
3243
procedure TPythonInputOutput.AddWrite ( const str : IOString );
3240
3244
begin
3241
- FQueue.Add( str );
3245
+ FQueue.Add( string( str) );
3242
3246
if FQueue.Count > FMaxLines then
3243
3247
FQueue.Delete(0 )
3244
3248
else
@@ -3292,12 +3296,12 @@ function TPythonInputOutput.GetCurrentThreadSlotIdx : Integer;
3292
3296
3293
3297
function TPythonInputOutput.GetCurrentThreadLine : IOString;
3294
3298
begin
3295
- Result := FLinesPerThread.Strings[ GetCurrentThreadSlotIdx ];
3299
+ Result := IOString( FLinesPerThread.Strings[ GetCurrentThreadSlotIdx ]) ;
3296
3300
end ;
3297
3301
3298
3302
procedure TPythonInputOutput.UpdateCurrentThreadLine ;
3299
3303
begin
3300
- FLinesPerThread.Strings[ GetCurrentThreadSlotIdx ] := FLine_Buffer;
3304
+ FLinesPerThread.Strings[ GetCurrentThreadSlotIdx ] := string( FLine_Buffer) ;
3301
3305
end ;
3302
3306
3303
3307
(* ******************************************************)
@@ -3311,12 +3315,18 @@ procedure TDynamicDll.DoOpenDll(const aDllName : string);
3311
3315
if not IsHandleValid then
3312
3316
begin
3313
3317
FDllName := aDllName;
3318
+ { $IFDEF MSWINDOWS}
3314
3319
FDLLHandle := SafeLoadLibrary(
3315
3320
{ $IFDEF FPC}
3316
- PAnsiChar(AnsiString(GetDllPath+DllName))
3321
+ PAnsiChar(AnsiString(GetDllPath+DllName))
3317
3322
{ $ELSE}
3318
- GetDllPath+DllName
3323
+ GetDllPath+DllName
3319
3324
{ $ENDIF}
3325
+ { $ELSE}
3326
+ // Linux: need here RTLD_GLOBAL, so Python can do "import ctypes"
3327
+ FDLLHandle := THandle(dlopen(PAnsiChar(AnsiString(GetDllPath+DllName)),
3328
+ RTLD_LAZY+RTLD_GLOBAL));
3329
+ { $ENDIF}
3320
3330
);
3321
3331
end ;
3322
3332
end ;
@@ -3469,11 +3479,7 @@ procedure TDynamicDll.Quit;
3469
3479
ExitProcess( 1 );
3470
3480
{ $ELSE}
3471
3481
WriteLn(ErrOutput, GetQuitMessage);
3472
- { $IFDEF FPC}
3473
3482
Halt( 1 );
3474
- { $ELSE}
3475
- __exit(1 );
3476
- { $ENDIF}
3477
3483
{ $ENDIF}
3478
3484
end ;
3479
3485
end ;
@@ -4716,7 +4722,7 @@ procedure TPythonEngine.DoOpenDll(const aDllName : string);
4716
4722
for i:= Integer(COMPILED_FOR_PYTHON_VERSION_INDEX) downto 1 do
4717
4723
begin
4718
4724
RegVersion := PYTHON_KNOWN_VERSIONS[i].RegVersion;
4719
- FDLLHandle := SafeLoadLibrary(GetDllPath+ PYTHON_KNOWN_VERSIONS[i].DllName);
4725
+ inherited DoOpenDll( PYTHON_KNOWN_VERSIONS[i].DllName);
4720
4726
if IsHandleValid then
4721
4727
begin
4722
4728
DllName := PYTHON_KNOWN_VERSIONS[i].DllName;
@@ -4848,7 +4854,7 @@ procedure TPythonEngine.Initialize;
4848
4854
if Assigned(Py_SetProgramName3000) then
4849
4855
begin
4850
4856
if FProgramNameW = ' ' then
4851
- FProgramNameW := ParamStr(0 );
4857
+ FProgramNameW := UnicodeString( ParamStr(0 ) );
4852
4858
Py_SetProgramName3000(PWideChar(FProgramNameW));
4853
4859
end
4854
4860
end else begin
@@ -5050,7 +5056,7 @@ procedure TPythonEngine.SetProgramArgs;
5050
5056
// get the strings
5051
5057
// build the PAnsiChar array
5052
5058
for i := 0 to argc do begin
5053
- WL[i] := ParamStr(i);
5059
+ WL[i] := UnicodeString( ParamStr(i) );
5054
5060
wargv^[i] := PWideChar(WL[i]);
5055
5061
end ;
5056
5062
// set the argv list of the sys module with the application arguments
@@ -5123,13 +5129,13 @@ procedure TPythonEngine.SetPyFlags(const Value: TPythonFlags);
5123
5129
end ; // of if
5124
5130
end ;
5125
5131
5126
- procedure TPythonEngine.SetPythonHome (const PythonHome: string );
5132
+ procedure TPythonEngine.SetPythonHome (const PythonHome: UnicodeString );
5127
5133
begin
5128
5134
FPythonHomeW := PythonHome;
5129
5135
FPythonHome := EncodeString(PythonHome);
5130
5136
end ;
5131
5137
5132
- procedure TPythonEngine.SetProgramName (const ProgramName: string );
5138
+ procedure TPythonEngine.SetProgramName (const ProgramName: UnicodeString );
5133
5139
begin
5134
5140
FProgramNameW := ProgramName;
5135
5141
FProgramName := EncodeString(ProgramName);
@@ -5287,12 +5293,12 @@ function TPythonEngine.Run_CommandAsObjectWithDict(const command : AnsiString; m
5287
5293
5288
5294
procedure TPythonEngine.ExecStrings ( strings : TStrings );
5289
5295
begin
5290
- Py_XDecRef( Run_CommandAsObject( EncodeString(strings.Text) , file_input ) );
5296
+ Py_XDecRef( Run_CommandAsObject( EncodeString(strings.Text) , file_input ) );
5291
5297
end ;
5292
5298
5293
5299
function TPythonEngine.EvalStrings ( strings : TStrings ) : PPyObject;
5294
5300
begin
5295
- Result := Run_CommandAsObject( EncodeString(strings.Text) , eval_input );
5301
+ Result := Run_CommandAsObject( EncodeString(strings.Text) , eval_input );
5296
5302
end ;
5297
5303
5298
5304
procedure TPythonEngine.ExecString (const command : AnsiString; locals, globals : PPyObject );
@@ -5302,7 +5308,7 @@ procedure TPythonEngine.ExecString(const command : AnsiString; locals, globals :
5302
5308
5303
5309
procedure TPythonEngine.ExecStrings ( strings : TStrings; locals, globals : PPyObject );
5304
5310
begin
5305
- Py_XDecRef( Run_CommandAsObjectWithDict( EncodeString(strings.Text), file_input, locals, globals ) );
5311
+ Py_XDecRef( Run_CommandAsObjectWithDict( EncodeString(strings.Text), file_input, locals, globals ) );
5306
5312
end ;
5307
5313
5308
5314
function TPythonEngine.EvalString ( const command : AnsiString; locals, globals : PPyObject ) : PPyObject;
@@ -5312,12 +5318,12 @@ function TPythonEngine.EvalString( const command : AnsiString; locals, globals :
5312
5318
5313
5319
function TPythonEngine.EvalStrings ( strings : TStrings; locals, globals : PPyObject ) : PPyObject;
5314
5320
begin
5315
- Result := Run_CommandAsObjectWithDict( EncodeString(strings.Text), eval_input, locals, globals );
5321
+ Result := Run_CommandAsObjectWithDict( EncodeString(strings.Text), eval_input, locals, globals );
5316
5322
end ;
5317
5323
5318
5324
function TPythonEngine.EvalStringsAsStr ( strings : TStrings ) : string;
5319
5325
begin
5320
- Result := Run_CommandAsString( EncodeString(strings.Text), eval_input );
5326
+ Result := Run_CommandAsString( EncodeString(strings.Text), eval_input );
5321
5327
end ;
5322
5328
5323
5329
function TPythonEngine.CheckEvalSyntax ( const str : AnsiString ) : Boolean;
@@ -5570,7 +5576,7 @@ function TPythonEngine.PyObjectAsString( obj : PPyObject ) : string;
5570
5576
if PyUnicode_Check(obj) then
5571
5577
begin
5572
5578
w := PyUnicode_AsWideString(obj);
5573
- Result := w ;
5579
+ Result := string(w) ;
5574
5580
Exit;
5575
5581
end ;
5576
5582
s := PyObject_Str( obj );
@@ -5656,14 +5662,21 @@ function TPythonEngine.FindClient( const aName : string ) : TEngineClient;
5656
5662
end ;
5657
5663
end ;
5658
5664
5659
- function TPythonEngine.EncodeString (const str: string ): AnsiString;
5665
+ function TPythonEngine.EncodeString (const str: UnicodeString ): AnsiString; { $IFDEF FPC } overload; { $ENDIF }
5660
5666
begin
5661
5667
if IsPython3000 then
5662
5668
Result := UTF8Encode(str)
5663
5669
else
5664
5670
Result := AnsiString(str);
5665
5671
end ;
5666
5672
5673
+ { $IFDEF FPC}
5674
+ function TPythonEngine.EncodeString (const str: AnsiString): AnsiString; overload;
5675
+ begin
5676
+ Result := str;
5677
+ end ;
5678
+ { $ENDIF}
5679
+
5667
5680
function TPythonEngine.EncodeWindowsFilePath (const str: string): AnsiString;
5668
5681
{ PEP 529}
5669
5682
begin
@@ -6558,7 +6571,7 @@ function TPythonEngine.PyString_FromDelphiString(str: string): PPyObject;
6558
6571
begin
6559
6572
if IsPython3000 then
6560
6573
begin
6561
- Result := PyUnicode_FromWideString(str);
6574
+ Result := PyUnicode_FromWideString(UnicodeString( str) );
6562
6575
end
6563
6576
else
6564
6577
Result := DLL_PyString_FromString(PAnsiChar(AnsiString(str)));
@@ -9526,7 +9539,7 @@ function pyio_write(self, args : PPyObject) : PPyObject;
9526
9539
IO.Write(PyUnicode_AsWideString(a1))
9527
9540
else
9528
9541
if PyString_Check(a1) then
9529
- IO.Write(PyObjectAsString(a1));
9542
+ IO.Write(IOString( PyObjectAsString(a1) ));
9530
9543
end ;
9531
9544
Result := ReturnNone;
9532
9545
end
@@ -9773,7 +9786,11 @@ function CleanString(const s : AnsiString; AppendLF : Boolean) : AnsiString;
9773
9786
9774
9787
function CleanString (const s : UnicodeString; AppendLF : Boolean) : UnicodeString;
9775
9788
begin
9789
+ { $IFDEF FPC}
9790
+ Result := UnicodeString(AdjustLineBreaks(AnsiString(s), tlbsLF));
9791
+ { $ELSE}
9776
9792
Result := AdjustLineBreaks(s, tlbsLF);
9793
+ { $ENDIF}
9777
9794
if AppendLF and (result[length(result)] <> LF) then
9778
9795
Result := Result + LF;
9779
9796
end ;
0 commit comments