Skip to content

Commit ba6f513

Browse files
committed
Reversed making TPyObject.PythonType a class var. Bad idea!
1 parent 0117d7d commit ba6f513

File tree

2 files changed

+35
-34
lines changed

2 files changed

+35
-34
lines changed

Source/PythonEngine.pas

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2387,9 +2387,9 @@ TPyObject = class
23872387
procedure Set_ob_refcnt(const Value: NativeInt);
23882388
procedure Set_ob_type(const Value: PPyTypeObject);
23892389
public
2390-
IsSubtype: Boolean;
2391-
PythonAlloc: Boolean;
2392-
class var PythonType: TPythonType;
2390+
PythonType : TPythonType;
2391+
IsSubtype : Boolean;
2392+
PythonAlloc : Boolean;
23932393

23942394
// Constructors & Destructors
23952395
constructor Create(APythonType: TPythonType); virtual;
@@ -7987,7 +7987,6 @@ procedure TPythonType.SetPyObjectClass( val : TPyObjectClass );
79877987
if Assigned(val) then
79887988
begin
79897989
FType.tp_basicsize := val.InstanceSize + Sizeof(PyObject);
7990-
val.PythonType := Self;
79917990
val.RegisterMethods( Self );
79927991
val.RegisterMembers( Self );
79937992
val.RegisterGetSets( Self );

Source/WrapDelphi.pas

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ TPyDelphiObject = class (TPyInterfacedObject, IFreeNotificationSubscriber)
550550
// implementation of interface IFreeNotificationSubscriber
551551
procedure Notify(ADeletedObject : TObject);
552552
{$IFDEF EXTENDED_RTTI}
553-
class function ExcludedExposedMembers: TArray<string>; virtual;
553+
class function ExcludedExposedMembers(APythonType: TPythonType): TArray<string>; virtual;
554554
class procedure ExposeMethods(AClass: TClass; NearestAncestorClass: TClass;
555555
APythonType: TPythonType; APyDelphiWrapper: TPyDelphiWrapper;
556556
AExcludedMethodNames: TArray<string> = []);
@@ -587,7 +587,7 @@ TPyDelphiObject = class (TPyInterfacedObject, IFreeNotificationSubscriber)
587587
class function DelphiObjectClass : TClass; virtual;
588588
class procedure RegisterMethods( PythonType : TPythonType ); override;
589589
class procedure RegisterGetSets( PythonType : TPythonType ); override;
590-
class procedure SetupType( PythonType : TPythonType ); override;
590+
class procedure SetupType(APythonType: TPythonType ); override;
591591
// if the class is a container (TStrings, TComponent, TCollection...),
592592
// then return the class implementing the access to the contained items.
593593
class function GetContainerAccessClass : TContainerAccessClass; virtual;
@@ -3564,7 +3564,7 @@ function TPyDelphiObject.SetProps(args, keywords: PPyObject): PPyObject;
35643564
Result := SetProperties(GetSelf, keywords);
35653565
end;
35663566

3567-
class procedure TPyDelphiObject.SetupType(PythonType: TPythonType);
3567+
class procedure TPyDelphiObject.SetupType(APythonType: TPythonType);
35683568
var
35693569
_ContainerAccessClass : TContainerAccessClass;
35703570
PyWrapper: TPyDelphiWrapper;
@@ -3573,34 +3573,35 @@ class procedure TPyDelphiObject.SetupType(PythonType: TPythonType);
35733573
Index: Integer;
35743574
{$IFDEF EXTENDED_RTTI}
35753575
LDocStr: string;
3576+
ExcludedMembers: TArray<string>;
35763577
{$ENDIF EXTENDED_RTTI}
35773578
begin
35783579
inherited;
3579-
PythonType.TypeName := AnsiString(GetTypeName);
3580-
PythonType.Name := string(PythonType.TypeName) + TPythonType.TYPE_COMP_NAME_SUFFIX;
3581-
PythonType.GenerateCreateFunction := False;
3582-
PythonType.DocString.Text := 'Wrapper for Delphi ' + DelphiObjectClass.ClassName;
3583-
PythonType.Services.Basic := [bsGetAttrO, bsSetAttrO, bsRepr, bsStr, bsRichCompare];
3580+
APythonType.TypeName := AnsiString(GetTypeName);
3581+
APythonType.Name := string(APythonType.TypeName) + TPythonType.TYPE_COMP_NAME_SUFFIX;
3582+
APythonType.GenerateCreateFunction := False;
3583+
APythonType.DocString.Text := 'Wrapper for Pascal class ' + DelphiObjectClass.ClassName;
3584+
APythonType.Services.Basic := [bsGetAttrO, bsSetAttrO, bsRepr, bsStr, bsRichCompare];
35843585
_ContainerAccessClass := GetContainerAccessClass;
35853586
if Assigned(_ContainerAccessClass) then
35863587
begin
3587-
PythonType.Services.Basic := PythonType.Services.Basic + [bsIter];
3588-
PythonType.Services.Sequence := PythonType.Services.Sequence + [ssLength, ssItem];
3588+
APythonType.Services.Basic := APythonType.Services.Basic + [bsIter];
3589+
APythonType.Services.Sequence := APythonType.Services.Sequence + [ssLength, ssItem];
35893590
if _ContainerAccessClass.SupportsWrite then
3590-
PythonType.Services.Sequence := PythonType.Services.Sequence + [ssAssItem];
3591+
APythonType.Services.Sequence := APythonType.Services.Sequence + [ssAssItem];
35913592
if _ContainerAccessClass.SupportsIndexOf then
3592-
PythonType.Services.Sequence := PythonType.Services.Sequence + [ssContains];
3593+
APythonType.Services.Sequence := APythonType.Services.Sequence + [ssContains];
35933594
end;
35943595

35953596
// Find nearest registered ancestor class and set it as base
3596-
PyWrapper := PythonType.Owner as TPyDelphiWrapper;
3597+
PyWrapper := APythonType.Owner as TPyDelphiWrapper;
35973598
NearestAncestorClass := nil;
35983599
for Index := PyWrapper.fClassRegister.Count - 1 downto 0 do
35993600
begin
36003601
RegisteredClass := PyWrapper.fClassRegister[Index] as TRegisteredClass;
36013602
if DelphiObjectClass.InheritsFrom(RegisteredClass.DelphiClass) then
36023603
begin
3603-
PythonType.BaseType := RegisteredClass.PythonType;
3604+
APythonType.BaseType := RegisteredClass.PythonType;
36043605
NearestAncestorClass := RegisteredClass.DelphiClass;
36053606
Break;
36063607
end;
@@ -3610,32 +3611,33 @@ class procedure TPyDelphiObject.SetupType(PythonType: TPythonType);
36103611
if Assigned(PyDocServer) and PyDocServer.Initialized and
36113612
PyDocServer.ReadTypeDocStr(DelphiObjectClass.ClassInfo, LDocStr)
36123613
then
3613-
PythonType.DocString.Text := LDocStr;
3614-
3615-
ExposeMethods(DelphiObjectClass, NearestAncestorClass, PythonType,
3616-
PyWrapper, ExcludedExposedMembers);
3617-
ExposeFields(DelphiObjectClass, NearestAncestorClass, PythonType,
3618-
PyWrapper, ExcludedExposedMembers);
3619-
ExposeProperties(DelphiObjectClass, NearestAncestorClass, PythonType,
3620-
PyWrapper, ExcludedExposedMembers);
3621-
ExposeIndexedProperties(DelphiObjectClass, NearestAncestorClass, PythonType,
3622-
PyWrapper, ExcludedExposedMembers);
3614+
APythonType.DocString.Text := LDocStr;
3615+
3616+
ExcludedMembers := ExcludedExposedMembers(APythonType);
3617+
ExposeMethods(DelphiObjectClass, NearestAncestorClass, APythonType,
3618+
PyWrapper, ExcludedMembers);
3619+
ExposeFields(DelphiObjectClass, NearestAncestorClass, APythonType,
3620+
PyWrapper, ExcludedMembers);
3621+
ExposeProperties(DelphiObjectClass, NearestAncestorClass, APythonType,
3622+
PyWrapper, ExcludedMembers);
3623+
ExposeIndexedProperties(DelphiObjectClass, NearestAncestorClass, APythonType,
3624+
PyWrapper, ExcludedMembers);
36233625
{$ENDIF EXTENDED_RTTI}
36243626
end;
36253627

36263628
{$IFDEF EXTENDED_RTTI}
3627-
class function TPyDelphiObject.ExcludedExposedMembers: TArray<string>;
3629+
class function TPyDelphiObject.ExcludedExposedMembers(APythonType: TPythonType): TArray<string>;
36283630
var
36293631
I, MethodCount: Integer;
36303632
begin
3631-
MethodCount := PythonType.MethodCount;
3632-
SetLength(Result, MethodCount + PythonType.GetSetCount);
3633+
MethodCount := APythonType.MethodCount;
3634+
SetLength(Result, MethodCount + APythonType.GetSetCount);
36333635

36343636
for I := 0 to MethodCount - 1 do
3635-
Result[I] := string(PythonType.Methods[I].ml_name);
3637+
Result[I] := string(APythonType.Methods[I].ml_name);
36363638

3637-
for I := 0 to PythonType.GetSetCount - 1 do
3638-
Result[MethodCount + I] := string(PythonType.GetSet[I].name);
3639+
for I := 0 to APythonType.GetSetCount - 1 do
3640+
Result[MethodCount + I] := string(APythonType.GetSet[I].name);
36393641
end;
36403642

36413643
class procedure TPyDelphiObject.ExposeMethods(AClass: TClass;

0 commit comments

Comments
 (0)