@@ -4063,7 +4063,7 @@ function TPythonInterface.PyByteArray_Check(obj: PPyObject): Boolean;
40634063
40644064function TPythonInterface.PyByteArray_CheckExact (obj: PPyObject): Boolean;
40654065begin
4066- Result := Assigned( obj ) and (obj^.ob_type = PPyTypeObject( PyByteArray_Type) );
4066+ Result := Assigned( obj ) and (obj^.ob_type = PyByteArray_Type);
40674067end ;
40684068
40694069function TPythonInterface.PyBytes_Check ( obj : PPyObject ) : Boolean;
@@ -4073,7 +4073,7 @@ function TPythonInterface.PyBytes_Check( obj : PPyObject ) : Boolean;
40734073
40744074function TPythonInterface.PyBytes_CheckExact (obj: PPyObject): Boolean;
40754075begin
4076- Result := Assigned( obj ) and (obj^.ob_type = PPyTypeObject( PyBytes_Type) );
4076+ Result := Assigned( obj ) and (obj^.ob_type = PyBytes_Type);
40774077end ;
40784078
40794079function TPythonInterface.PyFloat_Check ( obj : PPyObject ) : Boolean;
@@ -4083,7 +4083,7 @@ function TPythonInterface.PyFloat_Check( obj : PPyObject ) : Boolean;
40834083
40844084function TPythonInterface.PyFloat_CheckExact (obj: PPyObject): Boolean;
40854085begin
4086- Result := Assigned( obj ) and (obj^.ob_type = PPyTypeObject( PyFloat_Type) );
4086+ Result := Assigned( obj ) and (obj^.ob_type = PyFloat_Type);
40874087end ;
40884088
40894089function TPythonInterface.PyLong_Check ( obj : PPyObject ) : Boolean;
@@ -4093,7 +4093,7 @@ function TPythonInterface.PyLong_Check( obj : PPyObject ) : Boolean;
40934093
40944094function TPythonInterface.PyLong_CheckExact (obj: PPyObject): Boolean;
40954095begin
4096- Result := Assigned( obj ) and (obj^.ob_type = PPyTypeObject( PyLong_Type) );
4096+ Result := Assigned( obj ) and (obj^.ob_type = PyLong_Type);
40974097end ;
40984098
40994099function TPythonInterface.PyTuple_Check ( obj : PPyObject ) : Boolean;
@@ -4103,7 +4103,7 @@ function TPythonInterface.PyTuple_Check( obj : PPyObject ) : Boolean;
41034103
41044104function TPythonInterface.PyTuple_CheckExact (obj: PPyObject): Boolean;
41054105begin
4106- Result := Assigned( obj ) and (obj^.ob_type = PPyTypeObject( PyTuple_Type) );
4106+ Result := Assigned( obj ) and (obj^.ob_type = PyTuple_Type);
41074107end ;
41084108
41094109function TPythonInterface.PyClass_Check ( obj : PPyObject ) : Boolean;
@@ -4113,12 +4113,12 @@ function TPythonInterface.PyClass_Check( obj : PPyObject ) : Boolean;
41134113
41144114function TPythonInterface.PyType_CheckExact ( obj : PPyObject ) : Boolean;
41154115begin
4116- Result := Assigned( obj ) and (obj^.ob_type = PPyTypeObject( PyType_Type) );
4116+ Result := Assigned( obj ) and (obj^.ob_type = PyType_Type);
41174117end ;
41184118
41194119function TPythonInterface.PyMethod_Check ( obj : PPyObject ) : Boolean;
41204120begin
4121- Result := Assigned( obj ) and (obj^.ob_type = PPyTypeObject( PyMethod_Type) );
4121+ Result := Assigned( obj ) and (obj^.ob_type = PyMethod_Type);
41224122end ;
41234123
41244124function TPythonInterface.PyList_Check ( obj : PPyObject ) : Boolean;
@@ -4128,7 +4128,7 @@ function TPythonInterface.PyList_Check( obj : PPyObject ) : Boolean;
41284128
41294129function TPythonInterface.PyList_CheckExact (obj: PPyObject): Boolean;
41304130begin
4131- Result := Assigned( obj ) and (obj^.ob_type = PPyTypeObject( PyList_Type) );
4131+ Result := Assigned( obj ) and (obj^.ob_type = PyList_Type);
41324132end ;
41334133
41344134function TPythonInterface.PyDict_Check ( obj : PPyObject ) : Boolean;
@@ -4138,7 +4138,7 @@ function TPythonInterface.PyDict_Check( obj : PPyObject ) : Boolean;
41384138
41394139function TPythonInterface.PyDict_CheckExact (obj: PPyObject): Boolean;
41404140begin
4141- Result := Assigned( obj ) and (obj^.ob_type = PPyTypeObject( PyDict_Type) );
4141+ Result := Assigned( obj ) and (obj^.ob_type = PyDict_Type);
41424142end ;
41434143
41444144function TPythonInterface.PyModule_Check ( obj : PPyObject ) : Boolean;
@@ -4148,7 +4148,7 @@ function TPythonInterface.PyModule_Check( obj : PPyObject ) : Boolean;
41484148
41494149function TPythonInterface.PyModule_CheckExact (obj: PPyObject): Boolean;
41504150begin
4151- Result := Assigned( obj ) and (obj^.ob_type = PPyTypeObject( PyModule_Type) );
4151+ Result := Assigned( obj ) and (obj^.ob_type = PyModule_Type);
41524152end ;
41534153
41544154function TPythonInterface.PySlice_Check ( obj : PPyObject ) : Boolean;
@@ -4159,8 +4159,7 @@ function TPythonInterface.PySlice_Check( obj : PPyObject ) : Boolean;
41594159function TPythonInterface.PyFunction_Check ( obj : PPyObject ) : Boolean;
41604160begin
41614161 Result := Assigned( obj ) and
4162- ((obj^.ob_type = PPyTypeObject(PyCFunction_Type)) or
4163- (obj^.ob_type = PPyTypeObject(PyFunction_Type)));
4162+ ((obj^.ob_type = PyCFunction_Type) or (obj^.ob_type = PyFunction_Type));
41644163end ;
41654164
41664165function TPythonInterface.PyIter_Check (obj: PPyObject): Boolean;
@@ -4175,7 +4174,7 @@ function TPythonInterface.PyUnicode_Check( obj : PPyObject ) : Boolean;
41754174
41764175function TPythonInterface.PyUnicode_CheckExact (obj: PPyObject): Boolean;
41774176begin
4178- Result := Assigned( obj ) and (obj^.ob_type = PPyTypeObject( PyUnicode_Type) );
4177+ Result := Assigned( obj ) and (obj^.ob_type = PyUnicode_Type);
41794178end ;
41804179
41814180function TPythonInterface.PyType_IS_GC (t : PPyTypeObject ) : Boolean;
@@ -4216,10 +4215,12 @@ function TPythonInterface.PyEnum_Check( obj : PPyObject ) : Boolean;
42164215 Result := Assigned( obj ) and (obj^.ob_type = PPyTypeObject(PyEnum_Type));
42174216end ;
42184217
4219- function TPythonInterface.PyObject_TypeCheck (obj : PPyObject; t : PPyTypeObject) : Boolean;
4218+ function TPythonInterface.PyObject_TypeCheck (obj: PPyObject; t: PPyTypeObject): Boolean;
42204219begin
4221- Result := Assigned(obj) and (obj^.ob_type = t);
4222- if not Result and Assigned(obj) and Assigned(t) then
4220+ if not Assigned(obj) or not Assigned(t) then Exit(False);
4221+
4222+ Result := obj^.ob_type = t;
4223+ if not Result then
42234224 Result := PyType_IsSubtype(obj^.ob_type, t) = 1 ;
42244225end ;
42254226
@@ -4949,7 +4950,7 @@ procedure TPythonEngine.SetProgramName(const ProgramName: UnicodeString);
49494950
49504951function TPythonEngine.IsType (ob: PPyObject; obt: PPyTypeObject): Boolean;
49514952begin
4952- result := ob ^.ob_type = obt;
4953+ result := Assigned(ob) and (ob ^.ob_type = obt) ;
49534954end ;
49544955
49554956function TPythonEngine.EvalPyFunction (pyfunc, pyargs:PPyObject): Variant;
0 commit comments