Skip to content

Commit 85a2374

Browse files
committed
PyByteArray added.
1 parent da1bfe2 commit 85a2374

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

Source/PythonEngine.pas

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ TPythonVersionProp = record
230230
WCharTString = UnicodeString;
231231
{$ENDIF}
232232

233+
Py_ssize_t = NativeInt;
233234

234235
const
235236
{
@@ -940,6 +941,27 @@ TPythonVersionProp = record
940941
end;
941942
PPyDateTime_DateTime = ^PyDateTime_DateTime;
942943

944+
//bytearrayobject.h
945+
946+
//typedef struct {
947+
// PyObject_VAR_HEAD
948+
// Py_ssize_t ob_alloc; /* How many bytes allocated in ob_bytes */
949+
// char *ob_bytes; /* Physical backing buffer */
950+
// char *ob_start; /* Logical start inside ob_bytes */
951+
// Py_ssize_t ob_exports; /* How many buffer exports */
952+
//} PyByteArrayObject;
953+
954+
PyByteArrayObject = {$IFDEF CPUX86}packed{$ENDIF} record
955+
// Start of PyObject_VAR_HEAD
956+
// Start of the Head of an object
957+
ob_base: PyObject;
958+
ob_size: Py_ssize_t;
959+
// End of the Head of an object
960+
ob_bytes: PAnsiChar;
961+
ob_start: PAnsiChar;
962+
ob_exports: Py_ssize_t;
963+
end;
964+
943965
//#######################################################
944966
//## ##
945967
//## GIL state ##
@@ -1361,6 +1383,7 @@ TPythonInterface=class(TDynamicDll)
13611383
PyRange_Type: PPyTypeObject;
13621384
PySlice_Type: PPyTypeObject;
13631385
PyBytes_Type: PPyTypeObject;
1386+
PyByteArray_Type: PPyTypeObject;
13641387
PyTuple_Type: PPyTypeObject;
13651388
PyBaseObject_Type: PPyTypeObject;
13661389
PyCallIter_Type: PPyTypeObject;
@@ -1440,6 +1463,7 @@ TPythonInterface=class(TDynamicDll)
14401463
PyRun_SimpleString: function( str: PAnsiChar): Integer; cdecl;
14411464
PyBytes_AsString: function( ob: PPyObject): PAnsiChar; cdecl;
14421465
PyBytes_AsStringAndSize: function( ob: PPyObject; var buffer: PAnsiChar; var size: NativeInt): integer; cdecl;
1466+
PyByteArray_AsString: function(ob: PPyObject): PAnsiChar; cdecl;
14431467
PySys_SetArgv: procedure( argc: Integer; argv: PPWCharT); cdecl;
14441468

14451469
PyCFunction_NewEx: function(md:PPyMethodDef;self, ob:PPyObject):PPyObject; cdecl;
@@ -1588,6 +1612,11 @@ TPythonInterface=class(TDynamicDll)
15881612
PyBytes_Size:function (ob:PPyObject):NativeInt; cdecl;
15891613
PyBytes_DecodeEscape:function(s:PAnsiChar; len:NativeInt; errors:PAnsiChar; unicode:NativeInt; recode_encoding:PAnsiChar):PPyObject; cdecl;
15901614
PyBytes_Repr:function(ob:PPyObject; smartquotes:integer):PPyObject; cdecl;
1615+
PyByteArray_Concat: procedure(var ob1: PPyObject; ob2: PPyObject); cdecl;
1616+
PyByteArray_Resize: procedure(var ob1: PPyObject; len: Py_ssize_t); cdecl;
1617+
PyByteArray_FromObject: function(ob:PPyObject): PPyObject; cdecl;
1618+
PyByteArray_FromStringAndSize: function(s: PAnsiChar; i: Py_ssize_t): PPyObject; cdecl;
1619+
PyByteArray_Size: function(ob: PPyObject): Py_ssize_t; cdecl;
15911620
PySys_GetObject:function (s:PAnsiChar):PPyObject; cdecl;
15921621
PySys_SetObject:function (s:PAnsiChar;ob:PPyObject):integer; cdecl;
15931622
PySys_SetPath:procedure(path:PAnsiChar); cdecl;
@@ -1715,6 +1744,8 @@ TPythonInterface=class(TDynamicDll)
17151744

17161745
function PyBytes_Check( obj : PPyObject ) : Boolean;
17171746
function PyBytes_CheckExact( obj : PPyObject ) : Boolean;
1747+
function PyByteArray_Check(obj: PPyObject): Boolean;
1748+
function PyByteArray_CheckExact(obj: PPyObject): Boolean;
17181749
function PyFloat_Check( obj : PPyObject ) : Boolean;
17191750
function PyFloat_CheckExact( obj : PPyObject ) : Boolean;
17201751
function PyLong_Check( obj : PPyObject ) : Boolean;
@@ -3557,6 +3588,7 @@ procedure TPythonInterface.MapDll;
35573588
PyRange_Type := Import('PyRange_Type');
35583589
PySlice_Type := Import('PySlice_Type');
35593590
PyBytes_Type := Import('PyBytes_Type');
3591+
PyByteArray_Type := Import('PyByteArray_Type');
35603592
PyTuple_Type := Import('PyTuple_Type');
35613593
PyUnicode_Type := Import('PyUnicode_Type');
35623594
PyBaseObject_Type := Import('PyBaseObject_Type');
@@ -3776,6 +3808,12 @@ procedure TPythonInterface.MapDll;
37763808
PyBytes_DecodeEscape := Import('PyBytes_DecodeEscape');
37773809
PyBytes_Repr := Import('PyBytes_Repr');
37783810
_PyBytes_Resize := Import('_PyBytes_Resize');
3811+
PyByteArray_AsString := Import('PyByteArray_AsString');
3812+
PyByteArray_Concat := Import('PyByteArray_Concat');
3813+
PyByteArray_Resize := Import('PyByteArray_Resize');
3814+
PyByteArray_FromObject := Import('PyByteArray_FromObject');
3815+
PyByteArray_FromStringAndSize := Import('PyByteArray_FromStringAndSize');
3816+
PyByteArray_Size := Import('PyByteArray_Size');
37793817
PySys_GetObject := Import('PySys_GetObject');
37803818
PySys_SetObject := Import('PySys_SetObject');
37813819
PySys_SetPath := Import('PySys_SetPath');
@@ -3909,6 +3947,16 @@ class procedure TPythonInterface.Py_CLEAR(var op: PPyObject);
39093947
end;
39103948
end;
39113949

3950+
function TPythonInterface.PyByteArray_Check(obj: PPyObject): Boolean;
3951+
begin
3952+
Result := PyObject_TypeCheck(obj, PyByteArray_Type);
3953+
end;
3954+
3955+
function TPythonInterface.PyByteArray_CheckExact(obj: PPyObject): Boolean;
3956+
begin
3957+
Result := Assigned( obj ) and (obj^.ob_type = PPyTypeObject(PyByteArray_Type));
3958+
end;
3959+
39123960
function TPythonInterface.PyBytes_Check( obj : PPyObject ) : Boolean;
39133961
begin
39143962
Result := PyObject_TypeCheck(obj, PyBytes_Type);

0 commit comments

Comments
 (0)