Skip to content

Commit d61d213

Browse files
committed
Partial back port from Embarcadero branch
Python interface fixes
1 parent 3e6a00a commit d61d213

File tree

4 files changed

+55
-49
lines changed

4 files changed

+55
-49
lines changed

Source/PythonEngine.pas

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ interface
9595
{$IF not Defined(FPC) and (CompilerVersion >= 23)}
9696
const
9797
{$IF CompilerVersion >= 33}
98-
pidSupportedPlatforms = pidWin32 or pidWin64 or pidOSX32 or pidOSX64 or pidLinux64;
98+
pidSupportedPlatforms = pidWin32 or pidWin64 or pidOSX32 or pidOSX64
99+
or pidLinux64 or pidAndroid32Arm or pidAndroid64Arm;
99100
{$ELSE}
100101
pidSupportedPlatforms = pidWin32 or pidWin64 or pidOSX32;
101102
{$IFEND}
@@ -402,7 +403,7 @@ TPythonVersionProp = record
402403
newfunc = function ( subtype: PPyTypeObject; args, kwds : PPyObject) : PPyObject; cdecl;
403404
allocfunc = function ( self: PPyTypeObject; nitems : NativeInt) : PPyObject; cdecl;
404405

405-
PyNumberMethods = {$IFNDEF CPUX64}packed{$ENDIF} record
406+
PyNumberMethods = {$IFDEF CPUX86}packed{$ENDIF} record
406407
nb_add : binaryfunc;
407408
nb_subtract : binaryfunc;
408409
nb_multiply : binaryfunc;
@@ -442,7 +443,7 @@ TPythonVersionProp = record
442443
end;
443444
PPyNumberMethods = ^PyNumberMethods;
444445

445-
PySequenceMethods = {$IFNDEF CPUX64}packed{$ENDIF} record
446+
PySequenceMethods = {$IFDEF CPUX86}packed{$ENDIF} record
446447
sq_length : lenfunc;
447448
sq_concat : binaryfunc;
448449
sq_repeat : ssizeargfunc;
@@ -456,37 +457,37 @@ TPythonVersionProp = record
456457
end;
457458
PPySequenceMethods = ^PySequenceMethods;
458459

459-
PyMappingMethods = {$IFNDEF CPUX64}packed{$ENDIF} record
460+
PyMappingMethods = {$IFDEF CPUX86}packed{$ENDIF} record
460461
mp_length : lenfunc;
461462
mp_subscript : binaryfunc;
462463
mp_ass_subscript : objobjargproc;
463464
end;
464465
PPyMappingMethods = ^PyMappingMethods;
465466

466-
Py_complex = {$IFNDEF CPUX64}packed{$ENDIF} record
467+
Py_complex = {$IFDEF CPUX86}packed{$ENDIF} record
467468
real : double;
468469
imag : double;
469470
end;
470471

471-
PyObject = {$IFNDEF CPUX64}packed{$ENDIF} record
472+
PyObject = {$IFDEF CPUX86}packed{$ENDIF} record
472473
ob_refcnt: NativeInt;
473474
ob_type: PPyTypeObject;
474475
end;
475476

476-
_frozen = {$IFNDEF CPUX64}packed{$ENDIF} record
477+
_frozen = {$IFDEF CPUX86}packed{$ENDIF} record
477478
name : PAnsiChar;
478479
code : PByte;
479480
size : Integer;
480481
end;
481482

482-
PySliceObject = {$IFNDEF CPUX64}packed{$ENDIF} record
483+
PySliceObject = {$IFDEF CPUX86}packed{$ENDIF} record
483484
ob_refcnt: NativeInt;
484485
ob_type: PPyTypeObject;
485486
start, stop, step: PPyObject;
486487
end;
487488

488489
PPyMethodDef = ^PyMethodDef;
489-
PyMethodDef = {$IFNDEF CPUX64}packed{$ENDIF} record
490+
PyMethodDef = {$IFDEF CPUX86}packed{$ENDIF} record
490491
ml_name: PAnsiChar;
491492
ml_meth: PyCFunction;
492493
ml_flags: Integer;
@@ -495,11 +496,11 @@ TPythonVersionProp = record
495496

496497
// structmember.h
497498
PPyMemberDef = ^PyMemberDef;
498-
PyMemberDef = {$IFNDEF CPUX64}packed{$ENDIF} record
499+
PyMemberDef = {$IFDEF CPUX86}packed{$ENDIF} record
499500
name : PAnsiChar;
500501
_type : integer;
501502
offset : NativeInt;
502-
flags : integer;
503+
flags : Integer;
503504
doc : PAnsiChar;
504505
end;
505506

@@ -511,7 +512,7 @@ TPythonVersionProp = record
511512
setter = function ( obj, value : PPyObject; context : Pointer) : integer; cdecl;
512513

513514
PPyGetSetDef = ^PyGetSetDef;
514-
PyGetSetDef = {$IFNDEF CPUX64}packed{$ENDIF} record
515+
PyGetSetDef = {$IFDEF CPUX86}packed{$ENDIF} record
515516
name : PAnsiChar;
516517
get : getter;
517518
_set : setter;
@@ -522,7 +523,7 @@ TPythonVersionProp = record
522523
wrapperfunc = function (self, args: PPyObject; wrapped : Pointer) : PPyObject; cdecl;
523524

524525
pwrapperbase = ^wrapperbase;
525-
wrapperbase = {$IFNDEF CPUX64}packed{$ENDIF} record
526+
wrapperbase = {$IFDEF CPUX86}packed{$ENDIF} record
526527
name : PAnsiChar;
527528
wrapper : wrapperfunc;
528529
doc : PAnsiChar;
@@ -537,7 +538,7 @@ TPythonVersionProp = record
537538
}
538539

539540
PPyDescrObject = ^PyDescrObject;
540-
PyDescrObject = {$IFNDEF CPUX64}packed{$ENDIF} record
541+
PyDescrObject = {$IFDEF CPUX86}packed{$ENDIF} record
541542
// Start of the Head of an object
542543
ob_refcnt : NativeInt;
543544
ob_type : PPyTypeObject;
@@ -547,7 +548,7 @@ TPythonVersionProp = record
547548
end;
548549

549550
PPyMethodDescrObject = ^PyMethodDescrObject;
550-
PyMethodDescrObject = {$IFNDEF CPUX64}packed{$ENDIF} record
551+
PyMethodDescrObject = {$IFDEF CPUX86}packed{$ENDIF} record
551552
// Start of PyDescr_COMMON
552553
// Start of the Head of an object
553554
ob_refcnt : NativeInt;
@@ -560,7 +561,7 @@ TPythonVersionProp = record
560561
end;
561562

562563
PPyMemberDescrObject = ^PyMemberDescrObject;
563-
PyMemberDescrObject = {$IFNDEF CPUX64}packed{$ENDIF} record
564+
PyMemberDescrObject = {$IFDEF CPUX86}packed{$ENDIF} record
564565
// Start of PyDescr_COMMON
565566
// Start of the Head of an object
566567
ob_refcnt : NativeInt;
@@ -573,7 +574,7 @@ TPythonVersionProp = record
573574
end;
574575

575576
PPyGetSetDescrObject = ^PyGetSetDescrObject;
576-
PyGetSetDescrObject = {$IFNDEF CPUX64}packed{$ENDIF} record
577+
PyGetSetDescrObject = {$IFDEF CPUX86}packed{$ENDIF} record
577578
// Start of PyDescr_COMMON
578579
// Start of the Head of an object
579580
ob_refcnt : NativeInt;
@@ -586,7 +587,7 @@ TPythonVersionProp = record
586587
end;
587588

588589
PPyWrapperDescrObject = ^PyWrapperDescrObject;
589-
PyWrapperDescrObject = {$IFNDEF CPUX64}packed{$ENDIF} record
590+
PyWrapperDescrObject = {$IFDEF CPUX86}packed{$ENDIF} record
590591
// Start of PyDescr_COMMON
591592
// Start of the Head of an object
592593
ob_refcnt : NativeInt;
@@ -600,7 +601,7 @@ TPythonVersionProp = record
600601
end;
601602

602603
PPyModuleDef_Base = ^PyModuleDef_Base;
603-
PyModuleDef_Base = {$IFNDEF CPUX64}packed{$ENDIF} record
604+
PyModuleDef_Base = {$IFDEF CPUX86}packed{$ENDIF} record
604605
// Start of the Head of an object
605606
ob_refcnt : NativeInt;
606607
ob_type : PPyTypeObject;
@@ -611,7 +612,7 @@ TPythonVersionProp = record
611612
end;
612613

613614
PPyModuleDef = ^PyModuleDef;
614-
PyModuleDef = {$IFNDEF CPUX64}packed{$ENDIF} record
615+
PyModuleDef = {$IFDEF CPUX86}packed{$ENDIF} record
615616
m_base : PyModuleDef_Base;
616617
m_name : PAnsiChar;
617618
m_doc : PAnsiChar;
@@ -625,7 +626,7 @@ TPythonVersionProp = record
625626

626627

627628
// object.h
628-
PyTypeObject = {$IFNDEF CPUX64}packed{$ENDIF} record
629+
PyTypeObject = {$IFDEF CPUX86}packed{$ENDIF} record
629630
ob_refcnt: NativeInt;
630631
ob_type: PPyTypeObject;
631632
ob_size: NativeInt; // Number of items in variable part
@@ -724,7 +725,7 @@ TPythonVersionProp = record
724725
// Parse tree node interface
725726

726727
PNode = ^node;
727-
node = {$IFNDEF CPUX64}packed{$ENDIF} record
728+
node = {$IFDEF CPUX86}packed{$ENDIF} record
728729
n_type : smallint;
729730
n_str : PAnsiChar;
730731
n_lineno : integer;
@@ -734,7 +735,7 @@ TPythonVersionProp = record
734735
end;
735736

736737
PPyCompilerFlags = ^PyCompilerFlags;
737-
PyCompilerFlags = {$IFNDEF CPUX64}packed{$ENDIF} record
738+
PyCompilerFlags = {$IFDEF CPUX86}packed{$ENDIF} record
738739
flags : integer;
739740
cf_feature_version : integer; //added in Python 3.8
740741
end;
@@ -765,11 +766,9 @@ TPythonVersionProp = record
765766

766767
{ # of bytes for year, month, day, hour, minute, second, and usecond. }
767768
_PyDateTime_DATETIME_DATASIZE = 10;
768-
PyGILState_LOCKED = 0;
769-
PyGILState_UNLOCKED = 1;
770769

771770
type
772-
PyDateTime_Delta = {$IFNDEF CPUX64}packed{$ENDIF} record
771+
PyDateTime_Delta = {$IFDEF CPUX86}packed{$ENDIF} record
773772
// Start of the Head of an object
774773
ob_refcnt : NativeInt;
775774
ob_type : PPyTypeObject;
@@ -781,7 +780,7 @@ TPythonVersionProp = record
781780
end;
782781
PPyDateTime_Delta = ^PyDateTime_Delta;
783782

784-
PyDateTime_TZInfo = {$IFNDEF CPUX64}packed{$ENDIF} record // a pure abstract base clase
783+
PyDateTime_TZInfo = {$IFDEF CPUX86}packed{$ENDIF} record // a pure abstract base clase
785784
// Start of the Head of an object
786785
ob_refcnt : NativeInt;
787786
ob_type : PPyTypeObject;
@@ -803,7 +802,7 @@ TPythonVersionProp = record
803802
* convenient to cast to, when getting at the hastzinfo member of objects
804803
* starting with _PyTZINFO_HEAD.
805804
*}
806-
_PyDateTime_BaseTZInfo = {$IFNDEF CPUX64}packed{$ENDIF} record
805+
_PyDateTime_BaseTZInfo = {$IFDEF CPUX86}packed{$ENDIF} record
807806
// Start of _PyTZINFO_HEAD
808807
// Start of the Head of an object
809808
ob_refcnt : NativeInt;
@@ -826,7 +825,7 @@ TPythonVersionProp = record
826825
unsigned char data[_PyDateTime_TIME_DATASIZE];
827826
}
828827

829-
_PyDateTime_BaseTime = {$IFNDEF CPUX64}packed{$ENDIF} record // hastzinfo false
828+
_PyDateTime_BaseTime = {$IFDEF CPUX86}packed{$ENDIF} record // hastzinfo false
830829
// Start of _PyDateTime_TIMEHEAD
831830
// Start of _PyTZINFO_HEAD
832831
// Start of the Head of an object
@@ -841,7 +840,7 @@ TPythonVersionProp = record
841840
end;
842841
_PPyDateTime_BaseTime = ^_PyDateTime_BaseTime;
843842

844-
PyDateTime_Time = {$IFNDEF CPUX64}packed{$ENDIF} record // hastzinfo true
843+
PyDateTime_Time = {$IFDEF CPUX86}packed{$ENDIF} record // hastzinfo true
845844
// Start of _PyDateTime_TIMEHEAD
846845
// Start of _PyTZINFO_HEAD
847846
// Start of the Head of an object
@@ -864,7 +863,7 @@ TPythonVersionProp = record
864863
* the plain date type is a base class for datetime, so it must also have
865864
* a hastzinfo member (although it's unused there).
866865
*}
867-
PyDateTime_Date = {$IFNDEF CPUX64}packed{$ENDIF} record
866+
PyDateTime_Date = {$IFDEF CPUX86}packed{$ENDIF} record
868867
// Start of _PyTZINFO_HEAD
869868
// Start of the Head of an object
870869
ob_refcnt : NativeInt;
@@ -883,7 +882,7 @@ TPythonVersionProp = record
883882
unsigned char data[_PyDateTime_DATETIME_DATASIZE];
884883
}
885884

886-
_PyDateTime_BaseDateTime = {$IFNDEF CPUX64}packed{$ENDIF} record // hastzinfo false
885+
_PyDateTime_BaseDateTime = {$IFDEF CPUX86}packed{$ENDIF} record // hastzinfo false
887886
// Start of _PyTZINFO_HEAD
888887
// Start of the Head of an object
889888
ob_refcnt : NativeInt;
@@ -896,7 +895,7 @@ TPythonVersionProp = record
896895
end;
897896
_PPyDateTime_BaseDateTime = ^_PyDateTime_BaseDateTime;
898897

899-
PyDateTime_DateTime = {$IFNDEF CPUX64}packed{$ENDIF} record // hastzinfo true
898+
PyDateTime_DateTime = {$IFDEF CPUX86}packed{$ENDIF} record // hastzinfo true
900899
// Start of _PyDateTime_DATETIMEHEAD
901900
// Start of _PyTZINFO_HEAD
902901
// Start of the Head of an object
@@ -917,6 +916,10 @@ TPythonVersionProp = record
917916
//## GIL state ##
918917
//## ##
919918
//#######################################################
919+
const
920+
PyGILState_LOCKED = 0;
921+
PyGILState_UNLOCKED = 1;
922+
type
920923
PyGILState_STATE = type Integer; // (PyGILState_LOCKED, PyGILState_UNLOCKED);
921924

922925
//#######################################################
@@ -1586,12 +1589,13 @@ TPythonInterface=class(TDynamicDll)
15861589
PyEval_EvalCode : function ( co : PPyObject; globals, locals : PPyObject) : PPyObject; cdecl;
15871590
Py_GetVersion : function : PAnsiChar; cdecl;
15881591
Py_GetCopyright : function : PAnsiChar; cdecl;
1589-
Py_GetExecPrefix : function : PAnsiChar; cdecl;
1590-
Py_GetPath : function : PAnsiChar; cdecl;
1592+
Py_GetExecPrefix : function : PWCharT; cdecl;
1593+
Py_GetPath : function : PWCharT; cdecl;
1594+
Py_SetPath : procedure (path: PWCharT); cdecl;
15911595
Py_SetPythonHome : procedure (home : PWCharT); cdecl;
15921596
Py_GetPythonHome : function : PWCharT; cdecl;
1593-
Py_GetPrefix : function : PAnsiChar; cdecl;
1594-
Py_GetProgramName : function : PAnsiChar; cdecl;
1597+
Py_GetPrefix : function : PWCharT; cdecl;
1598+
Py_GetProgramName : function : PWCharT; cdecl;
15951599

15961600
PyParser_SimpleParseStringFlags : function ( str : PAnsiChar; start, flags : Integer) : PNode; cdecl;
15971601
PyNode_Free : procedure( n : PNode ); cdecl;
@@ -2534,7 +2538,8 @@ TPythonType = class(TGetSetContainer)
25342538
// methods
25352539
///////////////////////////////////////
25362540
function NewSubtypeInst( aType: PPyTypeObject; args, kwds : PPyObject) : PPyObject; cdecl;
2537-
2541+
public
2542+
const TYPE_COMP_NAME_SUFFIX = 'Type';
25382543
public
25392544
constructor Create( AOwner : TComponent ); override;
25402545
destructor Destroy; override;
@@ -3560,6 +3565,7 @@ procedure TPythonInterface.MapDll;
35603565
Py_GetCopyright := Import('Py_GetCopyright');
35613566
Py_GetExecPrefix := Import('Py_GetExecPrefix');
35623567
Py_GetPath := Import('Py_GetPath');
3568+
Py_SetPath := Import('Py_SetPath');
35633569
Py_SetPythonHome := Import('Py_SetPythonHome');
35643570
Py_GetPythonHome := Import('Py_GetPythonHome');
35653571
Py_GetPrefix := Import('Py_GetPrefix');
@@ -5043,7 +5049,7 @@ function TPythonEngine.EncodeWindowsFilePath(const str: string): AnsiString;
50435049
Result := AnsiString(str);
50445050
end;
50455051

5046-
function TPythonEngine.TypeByName( const aTypeName : AnsiString ) : PPyTypeObject;
5052+
function TPythonEngine.TypeByName( const aTypeName : AnsiString ) : PPyTypeObject;
50475053
var
50485054
i : Integer;
50495055
begin

Source/WrapDelphi.pas

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2140,7 +2140,7 @@ class procedure TPyRttiObject.SetupType(PythonType: TPythonType);
21402140
begin
21412141
inherited;
21422142
PythonType.TypeName := 'RttiObject';
2143-
PythonType.Name := string(PythonType.TypeName) + 'Type';
2143+
PythonType.Name := string(PythonType.TypeName) + TPythonType.TYPE_COMP_NAME_SUFFIX;
21442144
PythonType.GenerateCreateFunction := False;
21452145
PythonType.DocString.Text := 'Wrapper of a Pascal record';
21462146
PythonType.Services.Basic := [bsGetAttrO, bsSetAttrO, bsRepr, bsStr];
@@ -2165,7 +2165,7 @@ class procedure TPyPascalRecord.SetupType(PythonType: TPythonType);
21652165
begin
21662166
inherited;
21672167
PythonType.TypeName := 'PascalRecord';
2168-
PythonType.Name := string(PythonType.TypeName) + 'Type';
2168+
PythonType.Name := string(PythonType.TypeName) + TPythonType.TYPE_COMP_NAME_SUFFIX;
21692169
end;
21702170

21712171
{ TPyPascalInterface }
@@ -2179,7 +2179,7 @@ class procedure TPyPascalInterface.SetupType(PythonType: TPythonType);
21792179
begin
21802180
inherited;
21812181
PythonType.TypeName := 'PascalInterface';
2182-
PythonType.Name := string(PythonType.TypeName) + 'Type';
2182+
PythonType.Name := string(PythonType.TypeName) + TPythonType.TYPE_COMP_NAME_SUFFIX;
21832183
end;
21842184

21852185
{$ENDIF}
@@ -2675,7 +2675,7 @@ class procedure TPyDelphiObject.SetupType(PythonType: TPythonType);
26752675
begin
26762676
inherited;
26772677
PythonType.TypeName := AnsiString(GetTypeName);
2678-
PythonType.Name := string(PythonType.TypeName) + 'Type';
2678+
PythonType.Name := string(PythonType.TypeName) + TPythonType.TYPE_COMP_NAME_SUFFIX;
26792679
PythonType.GenerateCreateFunction := False;
26802680
PythonType.DocString.Text := 'Wrapper for Delphi ' + DelphiObjectClass.ClassName;
26812681
PythonType.Services.Basic := [bsGetAttrO, bsSetAttrO, bsRepr, bsStr, bsRichCompare];
@@ -3140,7 +3140,7 @@ class procedure TPyDelphiVarParameter.SetupType(PythonType: TPythonType);
31403140
begin
31413141
inherited;
31423142
PythonType.TypeName := 'VarParameter';
3143-
PythonType.Name := string(PythonType.TypeName) + 'Type';
3143+
PythonType.Name := string(PythonType.TypeName) + TPythonType.TYPE_COMP_NAME_SUFFIX;
31443144
PythonType.GenerateCreateFunction := False;
31453145
PythonType.DocString.Text := 'Container object allowing modification of Delphi var parameters from Python';
31463146
PythonType.Services.Basic := [bsGetAttrO, bsSetAttrO, bsRepr, bsStr, bsRichCompare];

Source/WrapDelphiTypes.pas

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ class procedure TPyDelphiPoint.SetupType(PythonType: TPythonType);
282282
begin
283283
inherited;
284284
PythonType.TypeName := 'Point';
285-
PythonType.Name := string(PythonType.TypeName) + 'Type';
285+
PythonType.Name := string(PythonType.TypeName) + TPythonType.TYPE_COMP_NAME_SUFFIX;
286286
PythonType.TypeFlags := PythonType.TypeFlags + [tpfBaseType];
287287
PythonType.GenerateCreateFunction := False;
288288
PythonType.DocString.Text := 'wrapper for Delphi TPoint type';
@@ -503,7 +503,7 @@ class procedure TPyDelphiRect.SetupType(PythonType: TPythonType);
503503
begin
504504
inherited;
505505
PythonType.TypeName := 'Rect';
506-
PythonType.Name := string(PythonType.TypeName) + 'Type';
506+
PythonType.Name := string(PythonType.TypeName) + TPythonType.TYPE_COMP_NAME_SUFFIX;
507507
PythonType.TypeFlags := PythonType.TypeFlags + [tpfBaseType];
508508
PythonType.GenerateCreateFunction := False;
509509
PythonType.DocString.Text := 'wrapper for Delphi TRect type';
@@ -575,7 +575,7 @@ class procedure TPyDelphiSize.SetupType(PythonType: TPythonType);
575575
begin
576576
inherited;
577577
PythonType.TypeName := 'Size';
578-
PythonType.Name := string(PythonType.TypeName) + 'Type';
578+
PythonType.Name := string(PythonType.TypeName) + TPythonType.TYPE_COMP_NAME_SUFFIX;
579579
PythonType.TypeFlags := PythonType.TypeFlags + [tpfBaseType];
580580
PythonType.GenerateCreateFunction := False;
581581
PythonType.DocString.Text := 'wrapper for Delphi TSize type';

0 commit comments

Comments
 (0)