@@ -1452,6 +1452,8 @@ TPythonInterface=class(TDynamicDll)
14521452 _PyWeakref_CallableProxyType: PPyTypeObject;
14531453 PyBool_Type: PPyTypeObject;
14541454 PyEnum_Type: PPyTypeObject;
1455+ PySet_Type: PPyTypeObject;
1456+ PyFrozenSet_Type: PPyTypeObject;
14551457
14561458 Py_GetBuildInfo: function : PAnsiChar; cdecl;
14571459 PyImport_ExecCodeModule: function ( const name : AnsiString; codeobject : PPyObject) : PPyObject; cdecl;
@@ -1684,6 +1686,14 @@ TPythonInterface=class(TDynamicDll)
16841686 PyByteArray_FromObject: function(ob:PPyObject): PPyObject; cdecl;
16851687 PyByteArray_FromStringAndSize: function(s: PAnsiChar; i: Py_ssize_t): PPyObject; cdecl;
16861688 PyByteArray_Size: function(ob: PPyObject): Py_ssize_t; cdecl;
1689+ PyFrozenSet_New: function(iterable: PPyObject): PPyObject; cdecl;
1690+ PySet_New: function(iterable: PPyObject): PPyObject; cdecl;
1691+ PySet_Add: function(aset, key: PPyObject): Integer; cdecl;
1692+ PySet_Clear: function(aset: PPyObject): Integer; cdecl;
1693+ PySet_Contains: function(anyset, key: PPyObject): Integer; cdecl;
1694+ PySet_Discard: function(aset, key: PPyObject): Integer; cdecl;
1695+ PySet_Pop: function(aset: PPyObject): PPyObject; cdecl;
1696+ PySet_Size: function(anyset: PPyObject): Py_ssize_t; cdecl;
16871697 PySys_GetObject:function (s:PAnsiChar):PPyObject; cdecl;
16881698 PySys_SetObject:function (s:PAnsiChar;ob:PPyObject):integer; cdecl;
16891699 PySys_SetPath:procedure(path:PAnsiChar); cdecl;
@@ -1841,9 +1851,13 @@ TPythonInterface=class(TDynamicDll)
18411851 function PyWeakref_CheckProxy ( obj : PPyObject ) : Boolean;
18421852 function PyBool_Check ( obj : PPyObject ) : Boolean;
18431853 function PyEnum_Check ( obj : PPyObject ) : Boolean;
1844- function PyObject_TypeCheck (obj:PPyObject; t:PPyTypeObject) : Boolean;
18451854 function Py_InitModule ( const md : PyModuleDef) : PPyObject;
18461855
1856+ // The following are defined as non-exported inline functions in object.h
1857+ function Py_Type (ob: PPyObject): PPyTypeObject; inline;
1858+ function IsType (ob: PPyObject; obt: PPyTypeObject): Boolean; inline;
1859+ function PyObject_TypeCheck (obj:PPyObject; t:PPyTypeObject) : Boolean; inline;
1860+
18471861 // Constructors & Destructors
18481862 constructor Create(AOwner: TComponent); override;
18491863
@@ -1977,7 +1991,6 @@ TPythonEngine = class(TPythonInterface)
19771991 // Public methods
19781992 procedure SetPythonHome (const PythonHome: UnicodeString);
19791993 procedure SetProgramName (const ProgramName: UnicodeString);
1980- function IsType (ob: PPyObject; obt: PPyTypeObject): Boolean;
19811994 function Run_CommandAsString (const command: AnsiString; mode: Integer; const FileName: string = ' <string>' ): string;
19821995 function Run_CommandAsObject (const command: AnsiString; mode: Integer; const FileName: string = ' <string>' ): PPyObject;
19831996 function Run_CommandAsObjectWithDict (const command: AnsiString; mode: Integer; locals, globals: PPyObject; const FileName: string = ' <string>' ): PPyObject;
@@ -3699,6 +3712,8 @@ procedure TPythonInterface.MapDll;
36993712 _PyWeakref_CallableProxyType:=Import (' _PyWeakref_CallableProxyType' );
37003713 PyBool_Type := Import (' PyBool_Type' );
37013714 PyEnum_Type := Import (' PyEnum_Type' );
3715+ PySet_Type := Import (' PySet_Type' );
3716+ PyFrozenSet_Type := Import (' PyFrozenSet_Type' );
37023717
37033718 PyComplex_FromCComplex := Import (' PyComplex_FromCComplex' );
37043719 PyComplex_FromDoubles := Import (' PyComplex_FromDoubles' );
@@ -3921,6 +3936,14 @@ procedure TPythonInterface.MapDll;
39213936 PyByteArray_FromObject := Import (' PyByteArray_FromObject' );
39223937 PyByteArray_FromStringAndSize := Import (' PyByteArray_FromStringAndSize' );
39233938 PyByteArray_Size := Import (' PyByteArray_Size' );
3939+ PyFrozenSet_New := Import (' PyFrozenSet_New' );
3940+ PySet_New := Import (' PySet_New' );
3941+ PySet_Add := Import (' PySet_Add' );
3942+ PySet_Clear := Import (' PySet_Clear' );
3943+ PySet_Contains := Import (' PySet_Contains' );
3944+ PySet_Discard := Import (' PySet_Discard' );
3945+ PySet_Pop := Import (' PySet_Pop' );
3946+ PySet_Size := Import (' PySet_Size' );
39243947 PySys_GetObject := Import (' PySys_GetObject' );
39253948 PySys_SetObject := Import (' PySys_SetObject' );
39263949 PySys_SetPath := Import (' PySys_SetPath' );
@@ -4083,7 +4106,7 @@ function TPythonInterface.PyFloat_Check( obj : PPyObject ) : Boolean;
40834106
40844107function TPythonInterface.PyFloat_CheckExact (obj: PPyObject): Boolean;
40854108begin
4086- Result := Assigned( obj ) and (obj^.ob_type = PyFloat_Type);
4109+ Result := IsType( obj, PyFloat_Type);
40874110end ;
40884111
40894112function TPythonInterface.PyLong_Check ( obj : PPyObject ) : Boolean;
@@ -4093,7 +4116,7 @@ function TPythonInterface.PyLong_Check( obj : PPyObject ) : Boolean;
40934116
40944117function TPythonInterface.PyLong_CheckExact (obj: PPyObject): Boolean;
40954118begin
4096- Result := Assigned( obj ) and (obj^.ob_type = PyLong_Type);
4119+ Result := IsType( obj, PyLong_Type);
40974120end ;
40984121
40994122function TPythonInterface.PyTuple_Check ( obj : PPyObject ) : Boolean;
@@ -4103,7 +4126,7 @@ function TPythonInterface.PyTuple_Check( obj : PPyObject ) : Boolean;
41034126
41044127function TPythonInterface.PyTuple_CheckExact (obj: PPyObject): Boolean;
41054128begin
4106- Result := Assigned( obj ) and (obj^.ob_type = PyTuple_Type);
4129+ Result := IsType( obj, PyTuple_Type);
41074130end ;
41084131
41094132function TPythonInterface.PyClass_Check ( obj : PPyObject ) : Boolean;
@@ -4113,7 +4136,7 @@ function TPythonInterface.PyClass_Check( obj : PPyObject ) : Boolean;
41134136
41144137function TPythonInterface.PyType_CheckExact ( obj : PPyObject ) : Boolean;
41154138begin
4116- Result := Assigned( obj ) and (obj^.ob_type = PyType_Type);
4139+ Result := IsType( obj, PyType_Type);
41174140end ;
41184141
41194142function TPythonInterface.PyMethod_Check ( obj : PPyObject ) : Boolean;
@@ -4128,7 +4151,7 @@ function TPythonInterface.PyList_Check( obj : PPyObject ) : Boolean;
41284151
41294152function TPythonInterface.PyList_CheckExact (obj: PPyObject): Boolean;
41304153begin
4131- Result := Assigned( obj ) and (obj^.ob_type = PyList_Type);
4154+ Result := IsType( obj, PyList_Type);
41324155end ;
41334156
41344157function TPythonInterface.PyDict_Check ( obj : PPyObject ) : Boolean;
@@ -4138,7 +4161,7 @@ function TPythonInterface.PyDict_Check( obj : PPyObject ) : Boolean;
41384161
41394162function TPythonInterface.PyDict_CheckExact (obj: PPyObject): Boolean;
41404163begin
4141- Result := Assigned( obj ) and (obj^.ob_type = PyDict_Type);
4164+ Result := IsType( obj, PyDict_Type);
41424165end ;
41434166
41444167function TPythonInterface.PyModule_Check ( obj : PPyObject ) : Boolean;
@@ -4148,7 +4171,7 @@ function TPythonInterface.PyModule_Check( obj : PPyObject ) : Boolean;
41484171
41494172function TPythonInterface.PyModule_CheckExact (obj: PPyObject): Boolean;
41504173begin
4151- Result := Assigned( obj ) and (obj^.ob_type = PyModule_Type);
4174+ Result := IsType( obj, PyModule_Type);
41524175end ;
41534176
41544177function TPythonInterface.PySlice_Check ( obj : PPyObject ) : Boolean;
@@ -4174,7 +4197,7 @@ function TPythonInterface.PyUnicode_Check( obj : PPyObject ) : Boolean;
41744197
41754198function TPythonInterface.PyUnicode_CheckExact (obj: PPyObject): Boolean;
41764199begin
4177- Result := Assigned( obj ) and (obj^.ob_type = PyUnicode_Type);
4200+ Result := IsType( obj, PyUnicode_Type);
41784201end ;
41794202
41804203function TPythonInterface.PyType_IS_GC (t : PPyTypeObject ) : Boolean;
@@ -4215,13 +4238,19 @@ function TPythonInterface.PyEnum_Check( obj : PPyObject ) : Boolean;
42154238 Result := Assigned( obj ) and (obj^.ob_type = PPyTypeObject(PyEnum_Type));
42164239end ;
42174240
4218- function TPythonInterface.PyObject_TypeCheck (obj : PPyObject; t: PPyTypeObject ): Boolean ;
4241+ function TPythonInterface.Py_Type (ob : PPyObject): PPyTypeObject ;
42194242begin
4220- if not Assigned(obj) or not Assigned(t) then Exit(False);
4243+ Result := ob^.ob_type;
4244+ end ;
42214245
4222- Result := obj^.ob_type = t;
4223- if not Result then
4224- Result := PyType_IsSubtype(obj^.ob_type, t) = 1 ;
4246+ function TPythonInterface.IsType (ob: PPyObject; obt: PPyTypeObject): Boolean;
4247+ begin
4248+ Result := ob^.ob_type = obt;
4249+ end ;
4250+
4251+ function TPythonInterface.PyObject_TypeCheck (obj: PPyObject; t: PPyTypeObject): Boolean;
4252+ begin
4253+ Result := IsType(obj, t) or (PyType_IsSubtype(obj^.ob_type, t) = 1 );
42254254end ;
42264255
42274256function TPythonInterface.Py_InitModule (const md: PyModuleDef): PPyObject;
@@ -4948,11 +4977,6 @@ procedure TPythonEngine.SetProgramName(const ProgramName: UnicodeString);
49484977{ $ENDIF}
49494978end ;
49504979
4951- function TPythonEngine.IsType (ob: PPyObject; obt: PPyTypeObject): Boolean;
4952- begin
4953- result := Assigned(ob) and (ob^.ob_type = obt);
4954- end ;
4955-
49564980function TPythonEngine.EvalPyFunction (pyfunc, pyargs:PPyObject): Variant;
49574981var presult :PPyObject;
49584982begin
0 commit comments