diff --git a/Demos/Demo06/Unit1.dfm b/Demos/Demo06/Unit1.dfm
index 48010fa7..19538b07 100644
--- a/Demos/Demo06/Unit1.dfm
+++ b/Demos/Demo06/Unit1.dfm
@@ -1,175 +1,175 @@
-object Form1: TForm1
- Left = 233
- Top = 175
- Caption = 'Demo of Python'
- ClientHeight = 337
- ClientWidth = 528
- Color = clBtnFace
- Font.Charset = DEFAULT_CHARSET
- Font.Color = clWindowText
- Font.Height = -11
- Font.Name = 'MS Sans Serif'
- Font.Style = []
- OldCreateOrder = True
- PixelsPerInch = 96
- TextHeight = 13
- object Splitter1: TSplitter
- Left = 0
- Top = 145
- Width = 528
- Height = 3
- Cursor = crVSplit
- Align = alTop
- ExplicitWidth = 536
- end
- object Memo1: TMemo
- Left = 0
- Top = 148
- Width = 528
- Height = 121
- Align = alClient
- Font.Charset = DEFAULT_CHARSET
- Font.Color = clWindowText
- Font.Height = -13
- Font.Name = 'Consolas'
- Font.Style = []
- Lines.Strings = (
- 'import sys'
- 'import spam'
- 'print (spam.foo('#39'hello world'#39', 1))'
- 'p = spam.CreatePoint( 10, 25 )'
- 'print ("Point:", p)'
- 'p.x = 58'
- 'print (p.x, p)'
- 'p.OffsetBy( 5, 5 )'
- 'print (p)'
- 'print ("Current value of var test is: ", test)'
- 'test.Value = "New value set by Python"'
- 'print ("getdouble: ", spam.getdouble())')
- ParentFont = False
- ScrollBars = ssVertical
- TabOrder = 1
- end
- object Panel1: TPanel
- Left = 0
- Top = 269
- Width = 528
- Height = 68
- Align = alBottom
- BevelOuter = bvNone
- TabOrder = 0
- object Button1: TButton
- Left = 6
- Top = 8
- Width = 115
- Height = 25
- Caption = 'Execute script'
- TabOrder = 0
- OnClick = Button1Click
- end
- object Button2: TButton
- Left = 168
- Top = 8
- Width = 91
- Height = 25
- Caption = 'Load script...'
- TabOrder = 1
- OnClick = Button2Click
- end
- object Button3: TButton
- Left = 264
- Top = 8
- Width = 89
- Height = 25
- Caption = 'Save script...'
- TabOrder = 2
- OnClick = Button3Click
- end
- object Button4: TButton
- Left = 368
- Top = 8
- Width = 89
- Height = 25
- Caption = 'Show var test'
- TabOrder = 3
- OnClick = Button4Click
- end
- object Edit1: TEdit
- Left = 368
- Top = 32
- Width = 161
- Height = 21
- TabOrder = 4
- Text = 'Edit1'
- end
- end
- object Memo2: TMemo
- Left = 0
- Top = 0
- Width = 528
- Height = 145
- Align = alTop
- Font.Charset = DEFAULT_CHARSET
- Font.Color = clWindowText
- Font.Height = -13
- Font.Name = 'Consolas'
- Font.Style = []
- Lines.Strings = (
- 'Memo2')
- ParentFont = False
- TabOrder = 2
- end
- object PythonEngine1: TPythonEngine
- InitScript.Strings = (
- 'import sys'
- 'print ("Python Dll: ", sys.version)'
- 'print (sys.copyright)'
- 'print')
- IO = PythonGUIInputOutput1
- Left = 8
- end
- object PythonType1: TPythonType
- Engine = PythonEngine1
- OnInitialization = PythonType1Initialization
- TypeName = 'Point'
- Prefix = 'Create'
- Services.Basic = [bsGetAttr, bsSetAttr, bsRepr, bsStr]
- Services.InplaceNumber = []
- Services.Number = []
- Services.Sequence = []
- Services.Mapping = []
- Left = 72
- end
- object PythonModule1: TPythonModule
- Engine = PythonEngine1
- OnInitialization = PythonModule1Initialization
- ModuleName = 'spam'
- Errors = <>
- Left = 104
- end
- object OpenDialog1: TOpenDialog
- DefaultExt = '*.py'
- Filter = 'Python files|*.py|Text files|*.txt|All files|*.*'
- Left = 176
- end
- object SaveDialog1: TSaveDialog
- DefaultExt = '*.py'
- Filter = 'Python files|*.py|Text files|*.txt|All files|*.*'
- Left = 208
- end
- object PythonDelphiVar1: TPythonDelphiVar
- Engine = PythonEngine1
- Module = '__main__'
- VarName = 'test'
- OnGetData = PythonDelphiVar1GetData
- OnSetData = PythonDelphiVar1SetData
- OnChange = PythonDelphiVar1Change
- Left = 136
- end
- object PythonGUIInputOutput1: TPythonGUIInputOutput
- UnicodeIO = True
- RawOutput = False
- Output = Memo2
- Left = 40
- end
-end
+object Form1: TForm1
+ Left = 233
+ Top = 175
+ Caption = 'Demo of Python'
+ ClientHeight = 337
+ ClientWidth = 528
+ Color = clBtnFace
+ Font.Charset = DEFAULT_CHARSET
+ Font.Color = clWindowText
+ Font.Height = -11
+ Font.Name = 'MS Sans Serif'
+ Font.Style = []
+ OldCreateOrder = True
+ PixelsPerInch = 96
+ TextHeight = 13
+ object Splitter1: TSplitter
+ Left = 0
+ Top = 145
+ Width = 528
+ Height = 3
+ Cursor = crVSplit
+ Align = alTop
+ ExplicitWidth = 536
+ end
+ object Memo1: TMemo
+ Left = 0
+ Top = 148
+ Width = 528
+ Height = 121
+ Align = alClient
+ Font.Charset = DEFAULT_CHARSET
+ Font.Color = clWindowText
+ Font.Height = -13
+ Font.Name = 'Consolas'
+ Font.Style = []
+ Lines.Strings = (
+ 'import sys'
+ 'import spam'
+ 'print (spam.foo('#39'hello world'#39', 1))'
+ 'p = spam.CreatePoint( 10, 25 )'
+ 'print ("Point:", p)'
+ 'p.x = 58'
+ 'print (p.x, p)'
+ 'p.OffsetBy( 5, 5 )'
+ 'print (p)'
+ 'print ("Current value of var test is: ", test)'
+ 'test.Value = "New value set by Python"'
+ 'print ("getdouble: ", spam.getdouble())')
+ ParentFont = False
+ ScrollBars = ssVertical
+ TabOrder = 1
+ end
+ object Panel1: TPanel
+ Left = 0
+ Top = 269
+ Width = 528
+ Height = 68
+ Align = alBottom
+ BevelOuter = bvNone
+ TabOrder = 0
+ object Button1: TButton
+ Left = 6
+ Top = 8
+ Width = 115
+ Height = 25
+ Caption = 'Execute script'
+ TabOrder = 0
+ OnClick = Button1Click
+ end
+ object Button2: TButton
+ Left = 168
+ Top = 8
+ Width = 91
+ Height = 25
+ Caption = 'Load script...'
+ TabOrder = 1
+ OnClick = Button2Click
+ end
+ object Button3: TButton
+ Left = 264
+ Top = 8
+ Width = 89
+ Height = 25
+ Caption = 'Save script...'
+ TabOrder = 2
+ OnClick = Button3Click
+ end
+ object Button4: TButton
+ Left = 368
+ Top = 8
+ Width = 89
+ Height = 25
+ Caption = 'Show var test'
+ TabOrder = 3
+ OnClick = Button4Click
+ end
+ object Edit1: TEdit
+ Left = 368
+ Top = 32
+ Width = 161
+ Height = 21
+ TabOrder = 4
+ Text = 'Edit1'
+ end
+ end
+ object Memo2: TMemo
+ Left = 0
+ Top = 0
+ Width = 528
+ Height = 145
+ Align = alTop
+ Font.Charset = DEFAULT_CHARSET
+ Font.Color = clWindowText
+ Font.Height = -13
+ Font.Name = 'Consolas'
+ Font.Style = []
+ Lines.Strings = (
+ 'Memo2')
+ ParentFont = False
+ TabOrder = 2
+ end
+ object PythonEngine1: TPythonEngine
+ InitScript.Strings = (
+ 'import sys'
+ 'print ("Python Dll: ", sys.version)'
+ 'print (sys.copyright)'
+ 'print')
+ IO = PythonGUIInputOutput1
+ Left = 8
+ end
+ object PythonType1: TPythonType
+ Engine = PythonEngine1
+ OnInitialization = PythonType1Initialization
+ TypeName = 'Point'
+ Prefix = 'Create'
+ Services.Basic = [bsGetAttr, bsSetAttr, bsRepr, bsStr]
+ Services.InplaceNumber = []
+ Services.Number = []
+ Services.Sequence = []
+ Services.Mapping = []
+ Left = 72
+ end
+ object PythonModule1: TPythonModule
+ Engine = PythonEngine1
+ OnInitialization = PythonModule1Initialization
+ ModuleName = 'spam'
+ Errors = <>
+ Left = 104
+ end
+ object OpenDialog1: TOpenDialog
+ DefaultExt = '*.py'
+ Filter = 'Python files|*.py|Text files|*.txt|All files|*.*'
+ Left = 176
+ end
+ object SaveDialog1: TSaveDialog
+ DefaultExt = '*.py'
+ Filter = 'Python files|*.py|Text files|*.txt|All files|*.*'
+ Left = 208
+ end
+ object PythonDelphiVar1: TPythonDelphiVar
+ Engine = PythonEngine1
+ Module = '__main__'
+ VarName = 'test'
+ OnGetData = PythonDelphiVar1GetData
+ OnSetData = PythonDelphiVar1SetData
+ OnChange = PythonDelphiVar1Change
+ Left = 136
+ end
+ object PythonGUIInputOutput1: TPythonGUIInputOutput
+ UnicodeIO = True
+ RawOutput = False
+ Output = Memo2
+ Left = 40
+ end
+end
diff --git a/Demos/Demo06/Unit1.pas b/Demos/Demo06/Unit1.pas
index a228acf6..b12181bd 100644
--- a/Demos/Demo06/Unit1.pas
+++ b/Demos/Demo06/Unit1.pas
@@ -156,14 +156,14 @@ function PyPoint_getattr(obj : PPyObject; key : PAnsiChar) : PPyObject; cdecl;
begin
// Check for attribute x
if key = 'x' then
- Result := PyInt_FromLong( po_x )
+ Result := PyLong_FromLong( po_x )
// Check for attribute y
else if key = 'y' then
- Result := PyInt_FromLong( po_y )
+ Result := PyLong_FromLong( po_y )
else
begin
// Else check for a method
- Result := PyObject_GenericGetAttr(obj, PyString_FromString(key));
+ Result := PyObject_GenericGetAttr(obj, PyUnicode_FromAnsiString(key));
if not Assigned(Result) then
PyErr_SetString (PyExc_AttributeError^, PAnsiChar(Format('Unknown attribute "%s"',[key])));
end;
@@ -180,18 +180,18 @@ function PyPoint_setattrfunc(obj : PPyObject; key : PAnsiChar; value : PPyObjec
begin
// Check for attribute x
if key = 'x' then begin
- if PyInt_Check(value) then
+ if PyLong_Check(value) then
begin
- po_x := PyInt_AsLong(value);
+ po_x := PyLong_AsLong(value);
Result := 0;
end
else
PyErr_SetString (PyExc_AttributeError^, PAnsiChar(Format('Attribute "%s" needs an integer',[key])));
// Check for attribute y
end else if key = 'y' then begin
- if PyInt_Check(value) then
+ if PyLong_Check(value) then
begin
- po_y := PyInt_AsLong(value);
+ po_y := PyLong_AsLong(value);
Result := 0;
end
else
@@ -206,7 +206,7 @@ function PyPoint_repr(obj : PPyObject) : PPyObject; cdecl;
begin
with GetPythonEngine, PPyPoint(obj)^ do
begin
- Result := PyString_FromString( PAnsiChar(Format('(%d, %d)',[po_x, po_y]) ) );
+ Result := PyUnicode_FromAnsiString(Format('(%d, %d)',[po_x, po_y]));
end;
end;
diff --git a/Demos/Demo07/Unit1.dfm b/Demos/Demo07/Unit1.dfm
index a35a2209..514f0914 100644
--- a/Demos/Demo07/Unit1.dfm
+++ b/Demos/Demo07/Unit1.dfm
@@ -1,182 +1,182 @@
-object Form1: TForm1
- Left = 245
- Top = 175
- Width = 544
- Height = 375
- VertScrollBar.Range = 200
- ActiveControl = Button1
- Caption = 'Demo of Python'
- Color = clBtnFace
- Font.Charset = DEFAULT_CHARSET
- Font.Color = clWindowText
- Font.Height = 11
- Font.Name = 'MS Sans Serif'
- Font.Pitch = fpVariable
- Font.Style = []
- OldCreateOrder = True
- PixelsPerInch = 96
- TextHeight = 13
- object Splitter1: TSplitter
- Left = 0
- Top = 129
- Width = 528
- Height = 3
- Cursor = crVSplit
- Align = alTop
- ExplicitWidth = 536
- end
- object Memo1: TMemo
- Left = 0
- Top = 132
- Width = 528
- Height = 136
- Align = alClient
- Font.Charset = DEFAULT_CHARSET
- Font.Color = clWindowText
- Font.Height = -13
- Font.Name = 'Consolas'
- Font.Pitch = fpVariable
- Font.Style = []
- Lines.Strings = (
- 'import sys'
- 'print ("Version:", sys.version)'
- 'import spam'
- 'print (spam.foo('#39'hello world'#39', 1))'
- 'p = spam.CreatePoint( 10, 25 )'
- 'print ("Point:", p)'
- 'p.x = 58'
- 'print (p.x, p)'
- 'p.OffsetBy( 5, 5 )'
- 'print (p)'
- 'print ("Current value of var test is: ", test)'
- 'test.Value = "New value set by Python"'
- 'print (spam.getdouble())'
- 'print (spam.getdouble2())')
- ParentFont = False
- ScrollBars = ssBoth
- TabOrder = 1
- end
- object Panel1: TPanel
- Left = 0
- Top = 268
- Width = 528
- Height = 68
- Align = alBottom
- BevelOuter = bvNone
- TabOrder = 0
- object Button1: TButton
- Left = 6
- Top = 8
- Width = 115
- Height = 25
- Caption = 'Execute script'
- TabOrder = 0
- OnClick = Button1Click
- end
- object Button2: TButton
- Left = 168
- Top = 8
- Width = 91
- Height = 25
- Caption = 'Load script...'
- TabOrder = 1
- OnClick = Button2Click
- end
- object Button3: TButton
- Left = 264
- Top = 8
- Width = 89
- Height = 25
- Caption = 'Save script...'
- TabOrder = 2
- OnClick = Button3Click
- end
- object Button4: TButton
- Left = 368
- Top = 8
- Width = 89
- Height = 25
- Caption = 'Show var test'
- TabOrder = 3
- OnClick = Button4Click
- end
- object Edit1: TEdit
- Left = 368
- Top = 32
- Width = 161
- Height = 21
- TabOrder = 4
- Text = 'Edit1'
- end
- end
- object Memo2: TMemo
- Left = 0
- Top = 0
- Width = 528
- Height = 129
- Align = alTop
- Font.Charset = DEFAULT_CHARSET
- Font.Color = clWindowText
- Font.Height = -13
- Font.Name = 'Consolas'
- Font.Pitch = fpVariable
- Font.Style = []
- ParentFont = False
- TabOrder = 2
- end
- object PythonEngine1: TPythonEngine
- InitScript.Strings = (
- 'import sys'
- 'print ("Python Dll: ", sys.version)'
- 'print (sys.copyright)'
- 'print')
- IO = PythonGUIInputOutput1
- Left = 8
- end
- object PythonType1: TPythonType
- Engine = PythonEngine1
- OnInitialization = PythonType1Initialization
- TypeName = 'Point'
- Prefix = 'Create'
- Services.Basic = [bsGetAttr, bsSetAttr, bsRepr, bsStr]
- Services.InplaceNumber = []
- Services.Number = []
- Services.Sequence = []
- Services.Mapping = []
- Left = 72
- end
- object PythonModule1: TPythonModule
- Engine = PythonEngine1
- OnInitialization = PythonModule1Initialization
- ModuleName = 'spam'
- Errors = <>
- Left = 104
- end
- object OpenDialog1: TOpenDialog
- DefaultExt = '*.py'
- Filter = 'Python files|*.py|Text files|*.txt|All files|*.*'
- Title = 'Open'
- Left = 176
- end
- object SaveDialog1: TSaveDialog
- DefaultExt = '*.py'
- Filter = 'Python files|*.py|Text files|*.txt|All files|*.*'
- Title = 'Save As'
- Left = 208
- end
- object PythonDelphiVar1: TPythonDelphiVar
- Engine = PythonEngine1
- Module = '__main__'
- VarName = 'test'
- OnGetData = PythonDelphiVar1GetData
- OnSetData = PythonDelphiVar1SetData
- OnChange = PythonDelphiVar1Change
- Left = 136
- end
- object PythonGUIInputOutput1: TPythonGUIInputOutput
- UnicodeIO = True
- RawOutput = False
- Output = Memo2
- Left = 40
- end
-end
+object Form1: TForm1
+ Left = 245
+ Top = 175
+ Width = 544
+ Height = 375
+ VertScrollBar.Range = 200
+ ActiveControl = Button1
+ Caption = 'Demo of Python'
+ Color = clBtnFace
+ Font.Charset = DEFAULT_CHARSET
+ Font.Color = clWindowText
+ Font.Height = 11
+ Font.Name = 'MS Sans Serif'
+ Font.Pitch = fpVariable
+ Font.Style = []
+ OldCreateOrder = True
+ PixelsPerInch = 96
+ TextHeight = 13
+ object Splitter1: TSplitter
+ Left = 0
+ Top = 129
+ Width = 528
+ Height = 3
+ Cursor = crVSplit
+ Align = alTop
+ ExplicitWidth = 536
+ end
+ object Memo1: TMemo
+ Left = 0
+ Top = 132
+ Width = 528
+ Height = 136
+ Align = alClient
+ Font.Charset = DEFAULT_CHARSET
+ Font.Color = clWindowText
+ Font.Height = -13
+ Font.Name = 'Consolas'
+ Font.Pitch = fpVariable
+ Font.Style = []
+ Lines.Strings = (
+ 'import sys'
+ 'print ("Version:", sys.version)'
+ 'import spam'
+ 'print (spam.foo('#39'hello world'#39', 1))'
+ 'p = spam.CreatePoint( 10, 25 )'
+ 'print ("Point:", p)'
+ 'p.x = 58'
+ 'print (p.x, p)'
+ 'p.OffsetBy( 5, 5 )'
+ 'print (p)'
+ 'print ("Current value of var test is: ", test)'
+ 'test.Value = "New value set by Python"'
+ 'print (spam.getdouble())'
+ 'print (spam.getdouble2())')
+ ParentFont = False
+ ScrollBars = ssBoth
+ TabOrder = 1
+ end
+ object Panel1: TPanel
+ Left = 0
+ Top = 268
+ Width = 528
+ Height = 68
+ Align = alBottom
+ BevelOuter = bvNone
+ TabOrder = 0
+ object Button1: TButton
+ Left = 6
+ Top = 8
+ Width = 115
+ Height = 25
+ Caption = 'Execute script'
+ TabOrder = 0
+ OnClick = Button1Click
+ end
+ object Button2: TButton
+ Left = 168
+ Top = 8
+ Width = 91
+ Height = 25
+ Caption = 'Load script...'
+ TabOrder = 1
+ OnClick = Button2Click
+ end
+ object Button3: TButton
+ Left = 264
+ Top = 8
+ Width = 89
+ Height = 25
+ Caption = 'Save script...'
+ TabOrder = 2
+ OnClick = Button3Click
+ end
+ object Button4: TButton
+ Left = 368
+ Top = 8
+ Width = 89
+ Height = 25
+ Caption = 'Show var test'
+ TabOrder = 3
+ OnClick = Button4Click
+ end
+ object Edit1: TEdit
+ Left = 368
+ Top = 32
+ Width = 161
+ Height = 21
+ TabOrder = 4
+ Text = 'Edit1'
+ end
+ end
+ object Memo2: TMemo
+ Left = 0
+ Top = 0
+ Width = 528
+ Height = 129
+ Align = alTop
+ Font.Charset = DEFAULT_CHARSET
+ Font.Color = clWindowText
+ Font.Height = -13
+ Font.Name = 'Consolas'
+ Font.Pitch = fpVariable
+ Font.Style = []
+ ParentFont = False
+ TabOrder = 2
+ end
+ object PythonEngine1: TPythonEngine
+ InitScript.Strings = (
+ 'import sys'
+ 'print ("Python Dll: ", sys.version)'
+ 'print (sys.copyright)'
+ 'print')
+ IO = PythonGUIInputOutput1
+ Left = 8
+ end
+ object PythonType1: TPythonType
+ Engine = PythonEngine1
+ OnInitialization = PythonType1Initialization
+ TypeName = 'Point'
+ Prefix = 'Create'
+ Services.Basic = [bsGetAttr, bsSetAttr, bsRepr, bsStr]
+ Services.InplaceNumber = []
+ Services.Number = []
+ Services.Sequence = []
+ Services.Mapping = []
+ Left = 72
+ end
+ object PythonModule1: TPythonModule
+ Engine = PythonEngine1
+ OnInitialization = PythonModule1Initialization
+ ModuleName = 'spam'
+ Errors = <>
+ Left = 104
+ end
+ object OpenDialog1: TOpenDialog
+ DefaultExt = '*.py'
+ Filter = 'Python files|*.py|Text files|*.txt|All files|*.*'
+ Title = 'Open'
+ Left = 176
+ end
+ object SaveDialog1: TSaveDialog
+ DefaultExt = '*.py'
+ Filter = 'Python files|*.py|Text files|*.txt|All files|*.*'
+ Title = 'Save As'
+ Left = 208
+ end
+ object PythonDelphiVar1: TPythonDelphiVar
+ Engine = PythonEngine1
+ Module = '__main__'
+ VarName = 'test'
+ OnGetData = PythonDelphiVar1GetData
+ OnSetData = PythonDelphiVar1SetData
+ OnChange = PythonDelphiVar1Change
+ Left = 136
+ end
+ object PythonGUIInputOutput1: TPythonGUIInputOutput
+ UnicodeIO = True
+ RawOutput = False
+ Output = Memo2
+ Left = 40
+ end
+end
diff --git a/Demos/Demo07/Unit1.pas b/Demos/Demo07/Unit1.pas
index f8cbcb35..b18d2124 100644
--- a/Demos/Demo07/Unit1.pas
+++ b/Demos/Demo07/Unit1.pas
@@ -1,4 +1,4 @@
-unit Unit1;
+unit Unit1;
{$I Definition.Inc}
@@ -149,7 +149,7 @@ function TForm1.spam_getdouble2( pself, args : PPyObject ) : PPyObject; cdecl;
y := 42.0;
i := 42;
s := 'Hallo';
- Result := ArrayToPyTuple( [ s,x,y,i,815,2.7172,3.14159,4711,1.2e-12, PyInt_FromLong(333) ] );
+ Result := ArrayToPyTuple( [ s,x,y,i,815,2.7172,3.14159,4711,1.2e-12, PyLong_FromLong(333) ] );
end;
end;
@@ -196,14 +196,14 @@ function PyPoint_getattr(obj : PPyObject; key : PAnsiChar) : PPyObject; cdecl;
begin
// Check for attribute x
if key = 'x' then
- Result := PyInt_FromLong( po_x )
+ Result := PyLong_FromLong( po_x )
// Check for attribute y
else if key = 'y' then
- Result := PyInt_FromLong( po_y )
+ Result := PyLong_FromLong( po_y )
else
begin
// Else check for a method
- Result := PyObject_GenericGetAttr(obj, PyString_FromString(key));
+ Result := PyObject_GenericGetAttr(obj, PyUnicode_FromAnsiString(key));
if not Assigned(Result) then
PyErr_SetString (PyExc_AttributeError^, PAnsiChar(Format('Unknown attribute "%s"',[key])));
end;
@@ -220,18 +220,18 @@ function PyPoint_setattrfunc(obj : PPyObject; key : PAnsiChar; value : PPyObjec
begin
// Check for attribute x
if key = 'x' then begin
- if PyInt_Check(value) then
+ if PyLong_Check(value) then
begin
- po_x := PyInt_AsLong(value);
+ po_x := PyLong_AsLong(value);
Result := 0;
end
else
PyErr_SetString (PyExc_AttributeError^, PAnsiChar(Format('Attribute "%s" needs an integer',[key])));
// Check for attribute y
end else if key = 'y' then begin
- if PyInt_Check(value) then
+ if PyLong_Check(value) then
begin
- po_y := PyInt_AsLong(value);
+ po_y := PyLong_AsLong(value);
Result := 0;
end
else
@@ -246,7 +246,7 @@ function PyPoint_repr(obj : PPyObject) : PPyObject; cdecl;
begin
with GetPythonEngine, PPyPoint(obj)^ do
begin
- Result := PyString_FromString( PAnsiChar(Format('(%d, %d)',[po_x, po_y]) ) );
+ Result := PyUnicode_FromAnsiString(Format('(%d, %d)',[po_x, po_y]));
end;
end;
diff --git a/Demos/Demo08/Unit1.dfm b/Demos/Demo08/Unit1.dfm
index 99938114..ec7b9906 100644
--- a/Demos/Demo08/Unit1.dfm
+++ b/Demos/Demo08/Unit1.dfm
@@ -1,179 +1,179 @@
-object Form1: TForm1
- Left = 214
- Top = 174
- Width = 592
- Height = 422
- VertScrollBar.Range = 210
- ActiveControl = Memo1
- Caption = 'Form1'
- Color = clBtnFace
- Font.Charset = DEFAULT_CHARSET
- Font.Color = clWindowText
- Font.Height = 11
- Font.Name = 'MS Sans Serif'
- Font.Pitch = fpVariable
- Font.Style = []
- OldCreateOrder = True
- PixelsPerInch = 96
- TextHeight = 13
- object Splitter1: TSplitter
- Left = 0
- Top = 169
- Width = 576
- Height = 3
- Cursor = crVSplit
- Align = alTop
- ExplicitWidth = 584
- end
- object Memo1: TMemo
- Left = 0
- Top = 172
- Width = 576
- Height = 170
- Align = alClient
- Font.Charset = DEFAULT_CHARSET
- Font.Color = clWindowText
- Font.Height = -13
- Font.Name = 'Consolas'
- Font.Pitch = fpVariable
- Font.Style = []
- Lines.Strings = (
- 'import spam'
- 'p = spam.CreatePoint(2, 5)'
- 'print (p)'
- 'p.OffsetBy( 3, 3 )'
- 'print (p.x, p.y)'
- 'print (dir(spam))'
- 'print (spam.Point)'
- 'print ("p = ", p, " --> ",)'
- 'if type(p) is spam.Point:'
- ' print ("p is a Point")'
- 'else:'
- ' print ("p is not a point")'
- 'p = 2'
- 'print ("p = ", p, " --> ",)'
- 'if type(p) is spam.Point:'
- ' print ("p is a Point")'
- 'else:'
- ' print ("p is not a point")'
- 'p = spam.CreatePoint(2, 5)'
- 'try:'
- ' print ("raising an error of class EBadPoint")'
- ' p.RaiseError() # it will raise spam.EBadPoint'
-
- 'except spam.PointError as what: #it shows you that you can inter' +
- 'cept a parent class'
- ' print ("Caught an error derived from PointError")'
-
- ' print ("Error class = ", what.__class__, " a =", what.a, "' +
- ' b =", what.b, " c =", what.c)'
- ''
- '# You can raise errors from a Python script too!'
-
- 'print ("--------------------------------------------------------' +
- '----------")'
- 'print ("Errors in a Python script")'
- 'try:'
- ' raise spam.EBadPoint("this is a test !")'
- 'except:'
- ' pass'
- ''
- 'try:'
- ' err = spam.EBadPoint()'
- ' err.a = 1'
- ' err.b = 2'
- ' err.c = 3'
- ' raise err'
-
- 'except spam.PointError as what: #it shows you that you can inter' +
- 'cept a parent class'
- ' print ("Caught an error derived from PointError")'
-
- ' print ("Error class = ", what.__class__, " a =", what.a, "' +
- ' b =", what.b, " c =", what.c)'
- ''
- 'if p == spam.CreatePoint(2, 5):'
- ' print ("Equal")'
- 'else:'
- ' print ("Not equal")')
- ParentFont = False
- ScrollBars = ssVertical
- TabOrder = 0
- WordWrap = False
- end
- object Panel1: TPanel
- Left = 0
- Top = 342
- Width = 576
- Height = 41
- Align = alBottom
- BevelOuter = bvNone
- TabOrder = 1
- object Button1: TButton
- Left = 8
- Top = 8
- Width = 75
- Height = 25
- Caption = 'Execute'
- TabOrder = 0
- OnClick = Button1Click
- end
- end
- object Memo2: TMemo
- Left = 0
- Top = 0
- Width = 576
- Height = 169
- Align = alTop
- Font.Charset = DEFAULT_CHARSET
- Font.Color = clWindowText
- Font.Height = -13
- Font.Name = 'Consolas'
- Font.Pitch = fpVariable
- Font.Style = []
- ParentFont = False
- TabOrder = 2
- end
- object PythonEngine1: TPythonEngine
- IO = PythonGUIInputOutput1
- Left = 16
- Top = 16
- end
- object PythonModule1: TPythonModule
- Engine = PythonEngine1
- ModuleName = 'spam'
- Errors = <
- item
- Name = 'PointError'
- ErrorType = etClass
- end
- item
- Name = 'EBadPoint'
- ErrorType = etClass
- ParentClass.Name = 'PointError'
- end>
- Left = 56
- Top = 16
- end
- object PythonType1: TPythonType
- Engine = PythonEngine1
- OnInitialization = PythonType1Initialization
- TypeName = 'Point'
- Prefix = 'Create'
- Module = PythonModule1
- Services.Basic = [bsGetAttr, bsSetAttr, bsRepr, bsStr, bsRichCompare]
- Services.InplaceNumber = []
- Services.Number = []
- Services.Sequence = []
- Services.Mapping = []
- Left = 96
- Top = 16
- end
- object PythonGUIInputOutput1: TPythonGUIInputOutput
- UnicodeIO = True
- RawOutput = False
- Output = Memo2
- Left = 136
- Top = 16
- end
-end
+object Form1: TForm1
+ Left = 214
+ Top = 174
+ Width = 592
+ Height = 422
+ VertScrollBar.Range = 210
+ ActiveControl = Memo1
+ Caption = 'Form1'
+ Color = clBtnFace
+ Font.Charset = DEFAULT_CHARSET
+ Font.Color = clWindowText
+ Font.Height = 11
+ Font.Name = 'MS Sans Serif'
+ Font.Pitch = fpVariable
+ Font.Style = []
+ OldCreateOrder = True
+ PixelsPerInch = 96
+ TextHeight = 13
+ object Splitter1: TSplitter
+ Left = 0
+ Top = 169
+ Width = 576
+ Height = 3
+ Cursor = crVSplit
+ Align = alTop
+ ExplicitWidth = 584
+ end
+ object Memo1: TMemo
+ Left = 0
+ Top = 172
+ Width = 576
+ Height = 170
+ Align = alClient
+ Font.Charset = DEFAULT_CHARSET
+ Font.Color = clWindowText
+ Font.Height = -13
+ Font.Name = 'Consolas'
+ Font.Pitch = fpVariable
+ Font.Style = []
+ Lines.Strings = (
+ 'import spam'
+ 'p = spam.CreatePoint(2, 5)'
+ 'print (p)'
+ 'p.OffsetBy( 3, 3 )'
+ 'print (p.x, p.y)'
+ 'print (dir(spam))'
+ 'print (spam.Point)'
+ 'print ("p = ", p, " --> ",)'
+ 'if type(p) is spam.Point:'
+ ' print ("p is a Point")'
+ 'else:'
+ ' print ("p is not a point")'
+ 'p = 2'
+ 'print ("p = ", p, " --> ",)'
+ 'if type(p) is spam.Point:'
+ ' print ("p is a Point")'
+ 'else:'
+ ' print ("p is not a point")'
+ 'p = spam.CreatePoint(2, 5)'
+ 'try:'
+ ' print ("raising an error of class EBadPoint")'
+ ' p.RaiseError() # it will raise spam.EBadPoint'
+
+ 'except spam.PointError as what: #it shows you that you can inter' +
+ 'cept a parent class'
+ ' print ("Caught an error derived from PointError")'
+
+ ' print ("Error class = ", what.__class__, " a =", what.a, "' +
+ ' b =", what.b, " c =", what.c)'
+ ''
+ '# You can raise errors from a Python script too!'
+
+ 'print ("--------------------------------------------------------' +
+ '----------")'
+ 'print ("Errors in a Python script")'
+ 'try:'
+ ' raise spam.EBadPoint("this is a test !")'
+ 'except:'
+ ' pass'
+ ''
+ 'try:'
+ ' err = spam.EBadPoint()'
+ ' err.a = 1'
+ ' err.b = 2'
+ ' err.c = 3'
+ ' raise err'
+
+ 'except spam.PointError as what: #it shows you that you can inter' +
+ 'cept a parent class'
+ ' print ("Caught an error derived from PointError")'
+
+ ' print ("Error class = ", what.__class__, " a =", what.a, "' +
+ ' b =", what.b, " c =", what.c)'
+ ''
+ 'if p == spam.CreatePoint(2, 5):'
+ ' print ("Equal")'
+ 'else:'
+ ' print ("Not equal")')
+ ParentFont = False
+ ScrollBars = ssVertical
+ TabOrder = 0
+ WordWrap = False
+ end
+ object Panel1: TPanel
+ Left = 0
+ Top = 342
+ Width = 576
+ Height = 41
+ Align = alBottom
+ BevelOuter = bvNone
+ TabOrder = 1
+ object Button1: TButton
+ Left = 8
+ Top = 8
+ Width = 75
+ Height = 25
+ Caption = 'Execute'
+ TabOrder = 0
+ OnClick = Button1Click
+ end
+ end
+ object Memo2: TMemo
+ Left = 0
+ Top = 0
+ Width = 576
+ Height = 169
+ Align = alTop
+ Font.Charset = DEFAULT_CHARSET
+ Font.Color = clWindowText
+ Font.Height = -13
+ Font.Name = 'Consolas'
+ Font.Pitch = fpVariable
+ Font.Style = []
+ ParentFont = False
+ TabOrder = 2
+ end
+ object PythonEngine1: TPythonEngine
+ IO = PythonGUIInputOutput1
+ Left = 16
+ Top = 16
+ end
+ object PythonModule1: TPythonModule
+ Engine = PythonEngine1
+ ModuleName = 'spam'
+ Errors = <
+ item
+ Name = 'PointError'
+ ErrorType = etClass
+ end
+ item
+ Name = 'EBadPoint'
+ ErrorType = etClass
+ ParentClass.Name = 'PointError'
+ end>
+ Left = 56
+ Top = 16
+ end
+ object PythonType1: TPythonType
+ Engine = PythonEngine1
+ OnInitialization = PythonType1Initialization
+ TypeName = 'Point'
+ Prefix = 'Create'
+ Module = PythonModule1
+ Services.Basic = [bsGetAttr, bsSetAttr, bsRepr, bsStr, bsRichCompare]
+ Services.InplaceNumber = []
+ Services.Number = []
+ Services.Sequence = []
+ Services.Mapping = []
+ Left = 96
+ Top = 16
+ end
+ object PythonGUIInputOutput1: TPythonGUIInputOutput
+ UnicodeIO = True
+ RawOutput = False
+ Output = Memo2
+ Left = 136
+ Top = 16
+ end
+end
diff --git a/Demos/Demo08/Unit1.pas b/Demos/Demo08/Unit1.pas
index a544e55d..e5fb7ec6 100644
--- a/Demos/Demo08/Unit1.pas
+++ b/Demos/Demo08/Unit1.pas
@@ -1,4 +1,4 @@
-unit Unit1;
+unit Unit1;
{$I Definition.Inc}
@@ -106,10 +106,10 @@ function TPyPoint.GetAttr(key : PAnsiChar) : PPyObject;
begin
if key = 'x' then
Result := VariantAsPyObject( x )
- // Or Result := PyInt_FromLong( x )
+ // Or Result := PyLong_FromLong( x )
else if key = 'y' then
- Result := PyInt_FromLong( y )
- // or Result := PyInt_FromLong( y )
+ Result := PyLong_FromLong( y )
+ // or Result := PyLong_FromLong( y )
else
Result := inherited GetAttr(key);
end;
@@ -139,13 +139,12 @@ function TPyPoint.Repr : PPyObject;
begin
with GetPythonEngine do
Result := VariantAsPyObject(Format('(%d, %d)',[x, y]));
- // or Result := PyString_FromString( PAnsiChar(Format('(%d, %d)',[x, y])) );
end;
function TPyPoint.RichCompare( obj : PPyObject; Op : TRichComparisonOpcode) : PPyObject;
begin
with GetPythonEngine do
- Result := PyInt_FromLong(1); // Return True by default, just for testing the API.
+ Result := PyLong_FromLong(1); // Return True by default, just for testing the API.
end;
// Class methods
diff --git a/Demos/Demo09/module.pas b/Demos/Demo09/module.pas
index 38e880ea..1255cd55 100644
--- a/Demos/Demo09/module.pas
+++ b/Demos/Demo09/module.pas
@@ -22,7 +22,7 @@ function Add( Self, Args : PPyObject ) : PPyObject; far; cdecl;
begin
if PyArg_ParseTuple( args, 'ii:Add',@a, @b ) <> 0 then
begin
- Result := PyInt_FromLong( a + b );
+ Result := PyLong_FromLong( a + b );
end
else
Result := nil;
diff --git a/Demos/Demo11/ThSort.pas b/Demos/Demo11/ThSort.pas
index 6066f700..c766f910 100644
--- a/Demos/Demo11/ThSort.pas
+++ b/Demos/Demo11/ThSort.pas
@@ -188,7 +188,7 @@ function TThreadSortForm.SortModule_GetValue( pself, args : PPyObject ) : PPyObj
begin
if PyArg_ParseTuple( args, 'ii',@psort, @index) <> 0 then
begin
- Result := PyInt_FromLong(TSortThread(psort)[index]);
+ Result := PyLong_FromLong(TSortThread(psort)[index]);
end else
Result := nil;
end;
diff --git a/Demos/Demo16/Example2/Unit1.pas b/Demos/Demo16/Example2/Unit1.pas
index 1c597e16..a9afced9 100644
--- a/Demos/Demo16/Example2/Unit1.pas
+++ b/Demos/Demo16/Example2/Unit1.pas
@@ -149,12 +149,12 @@ function TForm1.GetPropertyList(pSelf, Args : PPyObject) : PPyObject; cdecl;
with GetPythonEngine do
begin
Result := PyList_New(6);
- PyList_SetItem(Result, 0, PyString_FromString('Title'));
- PyList_SetItem(Result, 1, PyString_FromString('Name'));
- PyList_SetItem(Result, 2, PyString_FromString('Informatician'));
- PyList_SetItem(Result, 3, PyString_FromString('PythonUser'));
- PyList_SetItem(Result, 4, PyString_FromString('Age'));
- PyList_SetItem(Result, 5, PyString_FromString('Sex'));
+ PyList_SetItem(Result, 0, PyUnicode_FromAnsiString('Title'));
+ PyList_SetItem(Result, 1, PyUnicode_FromAnsiString('Name'));
+ PyList_SetItem(Result, 2, PyUnicode_FromAnsiString('Informatician'));
+ PyList_SetItem(Result, 3, PyUnicode_FromAnsiString('PythonUser'));
+ PyList_SetItem(Result, 4, PyUnicode_FromAnsiString('Age'));
+ PyList_SetItem(Result, 5, PyUnicode_FromAnsiString('Sex'));
end;
end;
diff --git a/Demos/Demo21/Unit1.dfm b/Demos/Demo21/Unit1.dfm
index bb536e8b..2a4fe041 100644
--- a/Demos/Demo21/Unit1.dfm
+++ b/Demos/Demo21/Unit1.dfm
@@ -1,158 +1,156 @@
-object Form1: TForm1
- Left = 237
- Top = 135
- Caption = 'Demo of Python'
- ClientHeight = 337
- ClientWidth = 528
- Color = clBtnFace
- Font.Charset = DEFAULT_CHARSET
- Font.Color = clWindowText
- Font.Height = -11
- Font.Name = 'MS Sans Serif'
- Font.Style = []
- OldCreateOrder = True
- PixelsPerInch = 96
- TextHeight = 13
- object Splitter1: TSplitter
- Left = 0
- Top = 140
- Width = 528
- Height = 3
- Cursor = crVSplit
- Align = alTop
- ExplicitTop = 153
- ExplicitWidth = 536
- end
- object Memo1: TMemo
- Left = 0
- Top = 143
- Width = 528
- Height = 150
- Align = alClient
- Font.Charset = DEFAULT_CHARSET
- Font.Color = clWindowText
- Font.Height = -13
- Font.Name = 'Consolas'
- Font.Style = []
- Lines.Strings = (
- 'import spam'
- 'print (spam.foo())'
- 'print (spam.foo.__doc__)'
- ''
- 'P = spam.CreatePoint(2,3)'
- 'print (P)'
- 'P.OffsetBy(2, 2)'
- 'print (P)')
- ParentFont = False
- ScrollBars = ssBoth
- TabOrder = 1
- ExplicitTop = 156
- ExplicitHeight = 137
- end
- object Panel1: TPanel
- Left = 0
- Top = 293
- Width = 528
- Height = 44
- Align = alBottom
- BevelOuter = bvNone
- TabOrder = 0
- object Button1: TButton
- Left = 6
- Top = 8
- Width = 115
- Height = 25
- Caption = 'Execute script'
- TabOrder = 0
- OnClick = Button1Click
- end
- object Button2: TButton
- Left = 168
- Top = 8
- Width = 91
- Height = 25
- Caption = 'Load script...'
- TabOrder = 1
- OnClick = Button2Click
- end
- object Button3: TButton
- Left = 264
- Top = 8
- Width = 89
- Height = 25
- Caption = 'Save script...'
- TabOrder = 2
- OnClick = Button3Click
- end
- end
- object Memo2: TMemo
- Left = 0
- Top = 0
- Width = 528
- Height = 140
- Align = alTop
- Font.Charset = DEFAULT_CHARSET
- Font.Color = clWindowText
- Font.Height = -13
- Font.Name = 'Consolas'
- Font.Style = []
- ParentFont = False
- ScrollBars = ssBoth
- TabOrder = 2
- end
- object PythonEngine1: TPythonEngine
- IO = PythonGUIInputOutput1
- Left = 32
- end
- object OpenDialog1: TOpenDialog
- DefaultExt = '*.py'
- Filter = 'Python files|*.py|Text files|*.txt|All files|*.*'
- Left = 176
- end
- object SaveDialog1: TSaveDialog
- DefaultExt = '*.py'
- Filter = 'Python files|*.py|Text files|*.txt|All files|*.*'
- Left = 208
- end
- object PythonGUIInputOutput1: TPythonGUIInputOutput
- UnicodeIO = True
- RawOutput = False
- Output = Memo2
- Left = 64
- end
- object PythonModule1: TPythonModule
- Engine = PythonEngine1
- Events = <
- item
- Name = 'foo'
- OnExecute = PythonModule1Events0Execute
- DocString.Strings = (
- 'Hello !'
- 'This is a doc string'
- 'of several lines...')
- end>
- ModuleName = 'spam'
- Errors = <>
- Left = 112
- Top = 64
- end
- object PythonType1: TPythonType
- Engine = PythonEngine1
- OnInitialization = PythonType1Initialization
- Events = <
- item
- Name = 'OffsetBy'
- OnExecute = PythonType1Events0Execute
- end>
- TypeName = 'Point'
- Prefix = 'Create'
- Module = PythonModule1
- Services.Basic = [bsGetAttr, bsSetAttr, bsRepr, bsStr]
- Services.InplaceNumber = []
- Services.Number = []
- Services.Sequence = []
- Services.Mapping = []
- Left = 192
- Top = 64
- end
-end
+object Form1: TForm1
+ Left = 237
+ Top = 135
+ Caption = 'Demo of Python'
+ ClientHeight = 337
+ ClientWidth = 528
+ Color = clBtnFace
+ Font.Charset = DEFAULT_CHARSET
+ Font.Color = clWindowText
+ Font.Height = -11
+ Font.Name = 'MS Sans Serif'
+ Font.Style = []
+ OldCreateOrder = True
+ PixelsPerInch = 96
+ TextHeight = 13
+ object Splitter1: TSplitter
+ Left = 0
+ Top = 140
+ Width = 528
+ Height = 3
+ Cursor = crVSplit
+ Align = alTop
+ ExplicitTop = 153
+ ExplicitWidth = 536
+ end
+ object Memo1: TMemo
+ Left = 0
+ Top = 143
+ Width = 528
+ Height = 150
+ Align = alClient
+ Font.Charset = DEFAULT_CHARSET
+ Font.Color = clWindowText
+ Font.Height = -13
+ Font.Name = 'Consolas'
+ Font.Style = []
+ Lines.Strings = (
+ 'import spam'
+ 'print (spam.foo())'
+ 'print (spam.foo.__doc__)'
+ ''
+ 'P = spam.CreatePoint(2,3)'
+ 'print (P)'
+ 'P.OffsetBy(2, 2)'
+ 'print (P)')
+ ParentFont = False
+ ScrollBars = ssBoth
+ TabOrder = 1
+ end
+ object Panel1: TPanel
+ Left = 0
+ Top = 293
+ Width = 528
+ Height = 44
+ Align = alBottom
+ BevelOuter = bvNone
+ TabOrder = 0
+ object Button1: TButton
+ Left = 6
+ Top = 8
+ Width = 115
+ Height = 25
+ Caption = 'Execute script'
+ TabOrder = 0
+ OnClick = Button1Click
+ end
+ object Button2: TButton
+ Left = 168
+ Top = 8
+ Width = 91
+ Height = 25
+ Caption = 'Load script...'
+ TabOrder = 1
+ OnClick = Button2Click
+ end
+ object Button3: TButton
+ Left = 264
+ Top = 8
+ Width = 89
+ Height = 25
+ Caption = 'Save script...'
+ TabOrder = 2
+ OnClick = Button3Click
+ end
+ end
+ object Memo2: TMemo
+ Left = 0
+ Top = 0
+ Width = 528
+ Height = 140
+ Align = alTop
+ Font.Charset = DEFAULT_CHARSET
+ Font.Color = clWindowText
+ Font.Height = -13
+ Font.Name = 'Consolas'
+ Font.Style = []
+ ParentFont = False
+ ScrollBars = ssBoth
+ TabOrder = 2
+ end
+ object PythonEngine1: TPythonEngine
+ IO = PythonGUIInputOutput1
+ Left = 32
+ end
+ object OpenDialog1: TOpenDialog
+ DefaultExt = '*.py'
+ Filter = 'Python files|*.py|Text files|*.txt|All files|*.*'
+ Left = 176
+ end
+ object SaveDialog1: TSaveDialog
+ DefaultExt = '*.py'
+ Filter = 'Python files|*.py|Text files|*.txt|All files|*.*'
+ Left = 208
+ end
+ object PythonGUIInputOutput1: TPythonGUIInputOutput
+ UnicodeIO = True
+ RawOutput = False
+ Output = Memo2
+ Left = 64
+ end
+ object PythonModule1: TPythonModule
+ Engine = PythonEngine1
+ Events = <
+ item
+ Name = 'foo'
+ OnExecute = PythonModule1Events0Execute
+ DocString.Strings = (
+ 'Hello !'
+ 'This is a doc string'
+ 'of several lines...')
+ end>
+ ModuleName = 'spam'
+ Errors = <>
+ Left = 112
+ Top = 64
+ end
+ object PythonType1: TPythonType
+ Engine = PythonEngine1
+ OnInitialization = PythonType1Initialization
+ Events = <
+ item
+ Name = 'OffsetBy'
+ OnExecute = PythonType1Events0Execute
+ end>
+ TypeName = 'Point'
+ Prefix = 'Create'
+ Module = PythonModule1
+ Services.Basic = [bsGetAttr, bsSetAttr, bsRepr, bsStr]
+ Services.InplaceNumber = []
+ Services.Number = []
+ Services.Sequence = []
+ Services.Mapping = []
+ Left = 192
+ Top = 64
+ end
+end
diff --git a/Demos/Demo21/Unit1.pas b/Demos/Demo21/Unit1.pas
index 340d6750..ad628f89 100644
--- a/Demos/Demo21/Unit1.pas
+++ b/Demos/Demo21/Unit1.pas
@@ -99,10 +99,10 @@ function TPyPoint.GetAttr(key : PAnsiChar) : PPyObject;
begin
if key = 'x' then
Result := VariantAsPyObject( x )
- // Or Result := PyInt_FromLong( x )
+ // Or Result := PyLong_FromLong( x )
else if key = 'y' then
- Result := PyInt_FromLong( y )
- // or Result := PyInt_FromLong( y )
+ Result := PyLong_FromLong( y )
+ // or Result := PyLong_FromLong( y )
else
Result := inherited GetAttr(key);
end;
@@ -132,7 +132,7 @@ function TPyPoint.Repr : PPyObject;
begin
with GetPythonEngine do
Result := VariantAsPyObject(Format('(%d, %d)',[x, y]));
- // or Result := PyString_FromString( PAnsiChar(Format('(%d, %d)',[x, y])) );
+ // or Result := PyUnicode_FromAnsiString(Format('(%d, %d)',[x, y]));
end;
// Methods of TPyPoint
@@ -178,7 +178,7 @@ procedure TForm1.PythonModule1Events0Execute(Sender: TObject; PSelf,
begin
with GetPythonEngine do
begin
- Result := PyString_FromString('Hello world !');
+ Result := PyUnicode_FromAnsiString('Hello world !');
end;
end;
diff --git a/Demos/Demo26/Unit1.dfm b/Demos/Demo26/Unit1.dfm
index b5efc57b..23663ec7 100644
--- a/Demos/Demo26/Unit1.dfm
+++ b/Demos/Demo26/Unit1.dfm
@@ -1,203 +1,203 @@
-object Form1: TForm1
- Left = 214
- Top = 174
- Width = 592
- Height = 422
- VertScrollBar.Range = 210
- ActiveControl = Memo1
- Caption = 'Form1'
- Color = clBtnFace
- Font.Charset = DEFAULT_CHARSET
- Font.Color = clWindowText
- Font.Height = 11
- Font.Name = 'MS Sans Serif'
- Font.Pitch = fpVariable
- Font.Style = []
- OldCreateOrder = True
- PixelsPerInch = 96
- TextHeight = 13
- object Splitter1: TSplitter
- Left = 0
- Top = 169
- Width = 576
- Height = 3
- Cursor = crVSplit
- Align = alTop
- ExplicitWidth = 584
- end
- object Memo1: TMemo
- Left = 0
- Top = 172
- Width = 576
- Height = 170
- Align = alClient
- Font.Charset = DEFAULT_CHARSET
- Font.Color = clWindowText
- Font.Height = -13
- Font.Name = 'Consolas'
- Font.Pitch = fpVariable
- Font.Style = []
- Lines.Strings = (
- 'import spam'
- ''
- 'class MyPoint(spam.Point):'
- ' def Foo(Self, v):'
- ' Self.OffsetBy(v, v)'
- ''
- '# old way to create a type instance'
- 'p = spam.CreatePoint(2, 5)'
- 'print (p, type(p))'
- 'p.OffsetBy( 3, 3 )'
- 'print (p.x, p.y)'
- 'print ("Name =", p.Name)'
- 'p.Name = '#39'Hello world!'#39
- 'print ("Name =", p.Name)'
- ''
- '# new way to create a type instance'
- 'p = spam.Point(2, 5) # no need to use CreateXXX anymore'
- 'print (p, type(p))'
- 'p.OffsetBy( 3, 3 )'
- 'print (p.x, p.y)'
- ''
- '# create a subtype instance'
- 'p = MyPoint(2, 5)'
- 'print (p, type(p))'
- 'p.OffsetBy( 3, 3 )'
- 'print (p.x, p.y)'
- 'p.Foo( 4 )'
- 'print (p.x, p.y)'
- 'print (dir(spam))'
- 'print (spam.Point)'
- 'print ("p = ", p, " --> ",)'
- 'if type(p) is spam.Point:'
- ' print ("p is a Point")'
- 'else:'
- ' print ("p is not a point")'
- 'p = 2'
- 'print ("p = ", p, " --> ",)'
- 'if type(p) is spam.Point:'
- ' print ("p is a Point")'
- 'else:'
- ' print ("p is not a point")'
- 'p = spam.CreatePoint(2, 5)'
- 'try:'
- ' print ("raising an error of class EBadPoint")'
- ' p.RaiseError() # it will raise spam.EBadPoint'
-
- 'except spam.PointError as what: # this shows you that you can in' +
- 'tercept a parent class'
- ' print ("Caught an error derived from PointError")'
-
- ' print ("Error class = ", what.__class__, " a =", what.a, "' +
- ' b =", what.b, " c =", what.c)'
- ''
- '# You can raise errors from a Python script too!'
-
- 'print ("--------------------------------------------------------' +
- '----------")'
- 'print ("Errors in a Python script")'
- 'try:'
- ' raise spam.EBadPoint("this is a test!")'
- 'except:'
- ' pass'
- ''
- 'try:'
- ' err = spam.EBadPoint()'
- ' err.a = 1'
- ' err.b = 2'
- ' err.c = 3'
- ' raise err'
-
- 'except spam.PointError as what: # this shows you that you can in' +
- 'tercept a parent class'
- ' print ("Caught an error derived from PointError")'
-
- ' print ("Error class = ", what.__class__, " a =", what.a, "' +
- ' b =", what.b, " c =", what.c)'
- ''
- 'if p == spam.CreatePoint(2, 5):'
- ' print ("Equal")'
- 'else:'
- ' print ("Not equal")')
- ParentFont = False
- ScrollBars = ssBoth
- TabOrder = 0
- WordWrap = False
- end
- object Panel1: TPanel
- Left = 0
- Top = 342
- Width = 576
- Height = 41
- Align = alBottom
- BevelOuter = bvNone
- TabOrder = 1
- object Button1: TButton
- Left = 8
- Top = 8
- Width = 75
- Height = 25
- Caption = 'Execute'
- TabOrder = 0
- OnClick = Button1Click
- end
- end
- object Memo2: TMemo
- Left = 0
- Top = 0
- Width = 576
- Height = 169
- Align = alTop
- Font.Charset = DEFAULT_CHARSET
- Font.Color = clWindowText
- Font.Height = -13
- Font.Name = 'Consolas'
- Font.Pitch = fpVariable
- Font.Style = []
- ParentFont = False
- ScrollBars = ssBoth
- TabOrder = 2
- end
- object PythonEngine1: TPythonEngine
- IO = PythonGUIInputOutput1
- Left = 16
- Top = 16
- end
- object PythonModule1: TPythonModule
- Engine = PythonEngine1
- ModuleName = 'spam'
- Errors = <
- item
- Name = 'PointError'
- ErrorType = etClass
- end
- item
- Name = 'EBadPoint'
- ErrorType = etClass
- ParentClass.Name = 'PointError'
- end>
- Left = 56
- Top = 16
- end
- object PythonType1: TPythonType
- Engine = PythonEngine1
- OnInitialization = PythonType1Initialization
- TypeName = 'Point'
- Prefix = 'Create'
- Module = PythonModule1
- Services.Basic = [bsRepr, bsStr, bsGetAttrO, bsSetAttrO]
- Services.InplaceNumber = []
- Services.Number = []
- Services.Sequence = []
- Services.Mapping = []
- Left = 96
- Top = 16
- end
- object PythonGUIInputOutput1: TPythonGUIInputOutput
- UnicodeIO = True
- RawOutput = False
- Output = Memo2
- Left = 136
- Top = 16
- end
-end
+object Form1: TForm1
+ Left = 214
+ Top = 174
+ Width = 592
+ Height = 422
+ VertScrollBar.Range = 210
+ ActiveControl = Memo1
+ Caption = 'Form1'
+ Color = clBtnFace
+ Font.Charset = DEFAULT_CHARSET
+ Font.Color = clWindowText
+ Font.Height = 11
+ Font.Name = 'MS Sans Serif'
+ Font.Pitch = fpVariable
+ Font.Style = []
+ OldCreateOrder = True
+ PixelsPerInch = 96
+ TextHeight = 13
+ object Splitter1: TSplitter
+ Left = 0
+ Top = 169
+ Width = 576
+ Height = 3
+ Cursor = crVSplit
+ Align = alTop
+ ExplicitWidth = 584
+ end
+ object Memo1: TMemo
+ Left = 0
+ Top = 172
+ Width = 576
+ Height = 170
+ Align = alClient
+ Font.Charset = DEFAULT_CHARSET
+ Font.Color = clWindowText
+ Font.Height = -13
+ Font.Name = 'Consolas'
+ Font.Pitch = fpVariable
+ Font.Style = []
+ Lines.Strings = (
+ 'import spam'
+ ''
+ 'class MyPoint(spam.Point):'
+ ' def Foo(Self, v):'
+ ' Self.OffsetBy(v, v)'
+ ''
+ '# old way to create a type instance'
+ 'p = spam.CreatePoint(2, 5)'
+ 'print (p, type(p))'
+ 'p.OffsetBy( 3, 3 )'
+ 'print (p.x, p.y)'
+ 'print ("Name =", p.Name)'
+ 'p.Name = '#39'Hello world!'#39
+ 'print ("Name =", p.Name)'
+ ''
+ '# new way to create a type instance'
+ 'p = spam.Point(2, 5) # no need to use CreateXXX anymore'
+ 'print (p, type(p))'
+ 'p.OffsetBy( 3, 3 )'
+ 'print (p.x, p.y)'
+ ''
+ '# create a subtype instance'
+ 'p = MyPoint(2, 5)'
+ 'print (p, type(p))'
+ 'p.OffsetBy( 3, 3 )'
+ 'print (p.x, p.y)'
+ 'p.Foo( 4 )'
+ 'print (p.x, p.y)'
+ 'print (dir(spam))'
+ 'print (spam.Point)'
+ 'print ("p = ", p, " --> ",)'
+ 'if type(p) is spam.Point:'
+ ' print ("p is a Point")'
+ 'else:'
+ ' print ("p is not a point")'
+ 'p = 2'
+ 'print ("p = ", p, " --> ",)'
+ 'if type(p) is spam.Point:'
+ ' print ("p is a Point")'
+ 'else:'
+ ' print ("p is not a point")'
+ 'p = spam.CreatePoint(2, 5)'
+ 'try:'
+ ' print ("raising an error of class EBadPoint")'
+ ' p.RaiseError() # it will raise spam.EBadPoint'
+
+ 'except spam.PointError as what: # this shows you that you can in' +
+ 'tercept a parent class'
+ ' print ("Caught an error derived from PointError")'
+
+ ' print ("Error class = ", what.__class__, " a =", what.a, "' +
+ ' b =", what.b, " c =", what.c)'
+ ''
+ '# You can raise errors from a Python script too!'
+
+ 'print ("--------------------------------------------------------' +
+ '----------")'
+ 'print ("Errors in a Python script")'
+ 'try:'
+ ' raise spam.EBadPoint("this is a test!")'
+ 'except:'
+ ' pass'
+ ''
+ 'try:'
+ ' err = spam.EBadPoint()'
+ ' err.a = 1'
+ ' err.b = 2'
+ ' err.c = 3'
+ ' raise err'
+
+ 'except spam.PointError as what: # this shows you that you can in' +
+ 'tercept a parent class'
+ ' print ("Caught an error derived from PointError")'
+
+ ' print ("Error class = ", what.__class__, " a =", what.a, "' +
+ ' b =", what.b, " c =", what.c)'
+ ''
+ 'if p == spam.CreatePoint(2, 5):'
+ ' print ("Equal")'
+ 'else:'
+ ' print ("Not equal")')
+ ParentFont = False
+ ScrollBars = ssBoth
+ TabOrder = 0
+ WordWrap = False
+ end
+ object Panel1: TPanel
+ Left = 0
+ Top = 342
+ Width = 576
+ Height = 41
+ Align = alBottom
+ BevelOuter = bvNone
+ TabOrder = 1
+ object Button1: TButton
+ Left = 8
+ Top = 8
+ Width = 75
+ Height = 25
+ Caption = 'Execute'
+ TabOrder = 0
+ OnClick = Button1Click
+ end
+ end
+ object Memo2: TMemo
+ Left = 0
+ Top = 0
+ Width = 576
+ Height = 169
+ Align = alTop
+ Font.Charset = DEFAULT_CHARSET
+ Font.Color = clWindowText
+ Font.Height = -13
+ Font.Name = 'Consolas'
+ Font.Pitch = fpVariable
+ Font.Style = []
+ ParentFont = False
+ ScrollBars = ssBoth
+ TabOrder = 2
+ end
+ object PythonEngine1: TPythonEngine
+ IO = PythonGUIInputOutput1
+ Left = 16
+ Top = 16
+ end
+ object PythonModule1: TPythonModule
+ Engine = PythonEngine1
+ ModuleName = 'spam'
+ Errors = <
+ item
+ Name = 'PointError'
+ ErrorType = etClass
+ end
+ item
+ Name = 'EBadPoint'
+ ErrorType = etClass
+ ParentClass.Name = 'PointError'
+ end>
+ Left = 56
+ Top = 16
+ end
+ object PythonType1: TPythonType
+ Engine = PythonEngine1
+ OnInitialization = PythonType1Initialization
+ TypeName = 'Point'
+ Prefix = 'Create'
+ Module = PythonModule1
+ Services.Basic = [bsRepr, bsStr, bsGetAttrO, bsSetAttrO]
+ Services.InplaceNumber = []
+ Services.Number = []
+ Services.Sequence = []
+ Services.Mapping = []
+ Left = 96
+ Top = 16
+ end
+ object PythonGUIInputOutput1: TPythonGUIInputOutput
+ UnicodeIO = True
+ RawOutput = False
+ Output = Memo2
+ Left = 136
+ Top = 16
+ end
+end
diff --git a/Demos/Demo26/Unit1.pas b/Demos/Demo26/Unit1.pas
index f08d9d46..c83501fd 100644
--- a/Demos/Demo26/Unit1.pas
+++ b/Demos/Demo26/Unit1.pas
@@ -31,7 +31,7 @@ TForm1 = class(TForm)
// the RegisterMethods and the type services' virtual methods.
TPyPoint = class(TPyObject)
x, y : Integer;
- Name : String;
+ Name : string;
// Constructors & Destructors
constructor Create( APythonType : TPythonType ); override;
@@ -100,23 +100,23 @@ function TPyPoint.Repr : PPyObject;
begin
with GetPythonEngine do
Result := VariantAsPyObject(Format('(%d, %d)',[x, y]));
- // or Result := PyString_FromString( PAnsiChar(Format('(%d, %d)',[x, y])) );
+ // or Result := PyUnicode_FromAnsiString(Format('(%d, %d)',[x, y]));
end;
// get/set functions
function TPyPoint_GetName( obj : PPyObject; context : Pointer) : PPyObject; cdecl;
begin
with GetPythonEngine do
- Result := PyString_FromString(PAnsiChar(AnsiString(TPyPoint(PythonToDelphi(obj)).Name)));
+ Result := PyUnicode_FromAnsiString(AnsiString(TPyPoint(PythonToDelphi(obj)).Name));
end;
function TPyPoint_SetName( obj, value : PPyObject; context : Pointer) : integer; cdecl;
begin
with GetPythonEngine do
begin
- if PyString_Check(value) then
+ if PyUnicode_Check(value) then
begin
- TPyPoint(PythonToDelphi(obj)).Name := PyObjectAsVariant(value);
+ TPyPoint(PythonToDelphi(obj)).Name := PyUnicode_AsWideString(value);
Result := 0;
end
else
diff --git a/Demos/Demo28/Unit1.dfm b/Demos/Demo28/Unit1.dfm
index 429153b6..4a848199 100644
--- a/Demos/Demo28/Unit1.dfm
+++ b/Demos/Demo28/Unit1.dfm
@@ -1,175 +1,175 @@
-object Form1: TForm1
- Left = 241
- Top = 155
- Width = 597
- Height = 557
- VertScrollBar.Range = 200
- ActiveControl = Button1
- Caption = 'Demo of Python'
- Color = clBackground
- Font.Charset = DEFAULT_CHARSET
- Font.Color = clWindowText
- Font.Height = 11
- Font.Name = 'MS Sans Serif'
- Font.Pitch = fpVariable
- Font.Style = []
- OldCreateOrder = True
- PixelsPerInch = 96
- TextHeight = 13
- object Splitter1: TSplitter
- Left = 0
- Top = 209
- Width = 581
- Height = 3
- Cursor = crVSplit
- Align = alTop
- Color = clBtnFace
- ParentColor = False
- ExplicitWidth = 589
- end
- object Memo1: TMemo
- Left = 0
- Top = 212
- Width = 581
- Height = 262
- Align = alClient
- Font.Charset = DEFAULT_CHARSET
- Font.Color = clWindowText
- Font.Height = -13
- Font.Name = 'Consolas'
- Font.Pitch = fpVariable
- Font.Style = []
- Lines.Strings = (
- 'import p4d'
- 'L = p4d.CreateTStringList(1, 2, 3, 4)'
- 'print (L)'
- 'for i in L:'
- ' print (i, type(i))'
- ''
- 'i = iter(L)'
- 'print (i)'
- 'try:'
- ' while True:'
- ' print (i.next())'
- 'except StopIteration:'
- ' print ("Done")'
- ''
- 'print (L[2])'
- 'L[2] = int(L[2]) * 2'
- 'print (L[2], type(L[2]))'
- 'print (L[ L.add(10) ])')
- ParentFont = False
- ScrollBars = ssBoth
- TabOrder = 1
- end
- object Panel1: TPanel
- Left = 0
- Top = 474
- Width = 581
- Height = 44
- Align = alBottom
- BevelOuter = bvNone
- TabOrder = 0
- object Button1: TButton
- Left = 6
- Top = 8
- Width = 115
- Height = 25
- Caption = 'Execute script'
- TabOrder = 0
- OnClick = Button1Click
- end
- object Button2: TButton
- Left = 168
- Top = 8
- Width = 91
- Height = 25
- Caption = 'Load script...'
- TabOrder = 1
- OnClick = Button2Click
- end
- object Button3: TButton
- Left = 264
- Top = 8
- Width = 89
- Height = 25
- Caption = 'Save script...'
- TabOrder = 2
- OnClick = Button3Click
- end
- end
- object Memo2: TMemo
- Left = 0
- Top = 0
- Width = 581
- Height = 209
- Align = alTop
- Font.Charset = DEFAULT_CHARSET
- Font.Color = clWindowText
- Font.Height = -13
- Font.Name = 'Consolas'
- Font.Pitch = fpVariable
- Font.Style = []
- ParentFont = False
- ScrollBars = ssBoth
- TabOrder = 2
- end
- object PythonEngine1: TPythonEngine
- IO = PythonGUIInputOutput1
- Left = 32
- end
- object OpenDialog1: TOpenDialog
- DefaultExt = '*.py'
- Filter = 'Python files|*.py|Text files|*.txt|All files|*.*'
- Title = 'Open'
- Left = 176
- end
- object SaveDialog1: TSaveDialog
- DefaultExt = '*.py'
- Filter = 'Python files|*.py|Text files|*.txt|All files|*.*'
- Title = 'Save As'
- Left = 208
- end
- object PythonGUIInputOutput1: TPythonGUIInputOutput
- UnicodeIO = True
- RawOutput = False
- Output = Memo2
- Left = 64
- end
- object ptStringList: TPythonType
- Engine = PythonEngine1
- OnCreate = ptStringListCreate
- TypeName = 'TStringList'
- TypeFlags = [tpfHaveGetCharBuffer, tpfHaveSequenceIn, tpfHaveInplaceOps, tpfHaveRichCompare, tpfHaveWeakRefs, tpfHaveIter, tpfHaveClass, tpfBaseType]
- Prefix = 'Create'
- Module = pmP4D
- Services.Basic = [bsGetAttr, bsSetAttr, bsRepr, bsStr, bsIter]
- Services.InplaceNumber = []
- Services.Number = []
- Services.Sequence = [ssLength, ssItem, ssAssItem]
- Services.Mapping = []
- Left = 64
- Top = 48
- end
- object pmP4D: TPythonModule
- Engine = PythonEngine1
- ModuleName = 'p4d'
- Errors = <>
- Left = 32
- Top = 48
- end
- object ptStringListIterator: TPythonType
- Engine = PythonEngine1
- OnCreate = ptStringListIteratorCreate
- TypeName = 'TStringListIterator'
- Prefix = 'Create'
- Module = pmP4D
- Services.Basic = [bsGetAttr, bsSetAttr, bsRepr, bsStr, bsIter, bsIterNext]
- Services.InplaceNumber = []
- Services.Number = []
- Services.Sequence = []
- Services.Mapping = []
- Left = 64
- Top = 80
- end
-end
+object Form1: TForm1
+ Left = 241
+ Top = 155
+ Width = 597
+ Height = 557
+ VertScrollBar.Range = 200
+ ActiveControl = Button1
+ Caption = 'Demo of Python'
+ Color = clBackground
+ Font.Charset = DEFAULT_CHARSET
+ Font.Color = clWindowText
+ Font.Height = 11
+ Font.Name = 'MS Sans Serif'
+ Font.Pitch = fpVariable
+ Font.Style = []
+ OldCreateOrder = True
+ PixelsPerInch = 96
+ TextHeight = 13
+ object Splitter1: TSplitter
+ Left = 0
+ Top = 209
+ Width = 581
+ Height = 3
+ Cursor = crVSplit
+ Align = alTop
+ Color = clBtnFace
+ ParentColor = False
+ ExplicitWidth = 589
+ end
+ object Memo1: TMemo
+ Left = 0
+ Top = 212
+ Width = 581
+ Height = 262
+ Align = alClient
+ Font.Charset = DEFAULT_CHARSET
+ Font.Color = clWindowText
+ Font.Height = -13
+ Font.Name = 'Consolas'
+ Font.Pitch = fpVariable
+ Font.Style = []
+ Lines.Strings = (
+ 'import p4d'
+ 'L = p4d.CreateTStringList(1, 2, 3, 4)'
+ 'print (L)'
+ 'for i in L:'
+ ' print (i, type(i))'
+ ''
+ 'i = iter(L)'
+ 'print (i)'
+ 'try:'
+ ' while True:'
+ ' print (i.next())'
+ 'except StopIteration:'
+ ' print ("Done")'
+ ''
+ 'print (L[2])'
+ 'L[2] = int(L[2]) * 2'
+ 'print (L[2], type(L[2]))'
+ 'print (L[ L.add(10) ])')
+ ParentFont = False
+ ScrollBars = ssBoth
+ TabOrder = 1
+ end
+ object Panel1: TPanel
+ Left = 0
+ Top = 474
+ Width = 581
+ Height = 44
+ Align = alBottom
+ BevelOuter = bvNone
+ TabOrder = 0
+ object Button1: TButton
+ Left = 6
+ Top = 8
+ Width = 115
+ Height = 25
+ Caption = 'Execute script'
+ TabOrder = 0
+ OnClick = Button1Click
+ end
+ object Button2: TButton
+ Left = 168
+ Top = 8
+ Width = 91
+ Height = 25
+ Caption = 'Load script...'
+ TabOrder = 1
+ OnClick = Button2Click
+ end
+ object Button3: TButton
+ Left = 264
+ Top = 8
+ Width = 89
+ Height = 25
+ Caption = 'Save script...'
+ TabOrder = 2
+ OnClick = Button3Click
+ end
+ end
+ object Memo2: TMemo
+ Left = 0
+ Top = 0
+ Width = 581
+ Height = 209
+ Align = alTop
+ Font.Charset = DEFAULT_CHARSET
+ Font.Color = clWindowText
+ Font.Height = -13
+ Font.Name = 'Consolas'
+ Font.Pitch = fpVariable
+ Font.Style = []
+ ParentFont = False
+ ScrollBars = ssBoth
+ TabOrder = 2
+ end
+ object PythonEngine1: TPythonEngine
+ IO = PythonGUIInputOutput1
+ Left = 32
+ end
+ object OpenDialog1: TOpenDialog
+ DefaultExt = '*.py'
+ Filter = 'Python files|*.py|Text files|*.txt|All files|*.*'
+ Title = 'Open'
+ Left = 176
+ end
+ object SaveDialog1: TSaveDialog
+ DefaultExt = '*.py'
+ Filter = 'Python files|*.py|Text files|*.txt|All files|*.*'
+ Title = 'Save As'
+ Left = 208
+ end
+ object PythonGUIInputOutput1: TPythonGUIInputOutput
+ UnicodeIO = True
+ RawOutput = False
+ Output = Memo2
+ Left = 64
+ end
+ object ptStringList: TPythonType
+ Engine = PythonEngine1
+ OnCreate = ptStringListCreate
+ TypeName = 'TStringList'
+ TypeFlags = [tpfHaveGetCharBuffer, tpfHaveSequenceIn, tpfHaveInplaceOps, tpfHaveRichCompare, tpfHaveWeakRefs, tpfHaveIter, tpfHaveClass, tpfBaseType]
+ Prefix = 'Create'
+ Module = pmP4D
+ Services.Basic = [bsGetAttr, bsSetAttr, bsRepr, bsStr, bsIter]
+ Services.InplaceNumber = []
+ Services.Number = []
+ Services.Sequence = [ssLength, ssItem, ssAssItem]
+ Services.Mapping = []
+ Left = 64
+ Top = 48
+ end
+ object pmP4D: TPythonModule
+ Engine = PythonEngine1
+ ModuleName = 'p4d'
+ Errors = <>
+ Left = 32
+ Top = 48
+ end
+ object ptStringListIterator: TPythonType
+ Engine = PythonEngine1
+ OnCreate = ptStringListIteratorCreate
+ TypeName = 'TStringListIterator'
+ Prefix = 'Create'
+ Module = pmP4D
+ Services.Basic = [bsGetAttr, bsSetAttr, bsRepr, bsStr, bsIter, bsIterNext]
+ Services.InplaceNumber = []
+ Services.Number = []
+ Services.Sequence = []
+ Services.Mapping = []
+ Left = 64
+ Top = 80
+ end
+end
diff --git a/Demos/Demo28/Unit1.pas b/Demos/Demo28/Unit1.pas
index d1662d8c..5a74df3f 100644
--- a/Demos/Demo28/Unit1.pas
+++ b/Demos/Demo28/Unit1.pas
@@ -131,7 +131,7 @@ function TPyStringList.add(args: PPyObject): PPyObject;
Adjust(@Self);
if PyArg_ParseTuple( args, 'O:add',@_obj ) <> 0 then
begin
- Result := PyInt_FromLong(Strings.Add(PyObjectAsString(_obj)));
+ Result := PyLong_FromLong(Strings.Add(PyObjectAsString(_obj)));
end
else
Result := nil;
@@ -218,7 +218,7 @@ function TPyStringList.SqItem(idx: NativeInt): PPyObject;
with GetPythonEngine do
begin
if idx < Strings.Count then
- Result := PyString_FromString(PAnsiChar(AnsiString(Strings[idx])))
+ Result := PyUnicode_FromAnsiString(AnsiString(Strings[idx]))
else
begin
PyErr_SetString(PyExc_IndexError^, 'list index out of range');
@@ -280,7 +280,7 @@ function TPyStringListIterator.IterNext: PPyObject;
end
else
begin
- Result := PyString_FromString(PAnsiChar(AnsiString(StringList.Strings[fCurrentIndex])));
+ Result := PyUnicode_FromAnsiString(AnsiString(StringList.Strings[fCurrentIndex]));
end;
end;
end;
diff --git a/Demos/Demo29/Unit1.dfm b/Demos/Demo29/Unit1.dfm
index 2bdf8619..6cb32951 100644
--- a/Demos/Demo29/Unit1.dfm
+++ b/Demos/Demo29/Unit1.dfm
@@ -2,7 +2,7 @@ object Form1: TForm1
Left = 218
Top = 18
Caption = 'Form1'
- ClientHeight = 809
+ ClientHeight = 701
ClientWidth = 668
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
@@ -11,6 +11,9 @@ object Form1: TForm1
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
+ DesignSize = (
+ 668
+ 701)
PixelsPerInch = 96
TextHeight = 13
object Image1: TImage
@@ -39,10 +42,11 @@ object Form1: TForm1
OnClick = Button2Click
end
object Memo1: TMemo
- Left = 8
- Top = 471
- Width = 657
- Height = 330
+ Left = 0
+ Top = 472
+ Width = 668
+ Height = 229
+ Align = alBottom
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
@@ -69,7 +73,7 @@ object Form1: TForm1
' new_im.format = im.format'
' return new_im'
' '
- 'def ImageToString(image):'
+ 'def ImageToBytes(image):'
' stream = BytesIO()'
' image.save(stream, image.format)'
' return stream.getvalue()')
@@ -77,12 +81,15 @@ object Form1: TForm1
ScrollBars = ssBoth
TabOrder = 2
WordWrap = False
+ ExplicitLeft = 16
+ ExplicitTop = 352
end
object Memo2: TMemo
Left = 8
Top = 352
Width = 657
- Height = 113
+ Height = 114
+ Anchors = [akLeft, akTop, akRight]
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
diff --git a/Demos/Demo29/Unit1.pas b/Demos/Demo29/Unit1.pas
index 57cd85d6..b17184f8 100644
--- a/Demos/Demo29/Unit1.pas
+++ b/Demos/Demo29/Unit1.pas
@@ -43,41 +43,17 @@ implementation
{$R *.dfm}
-// Old code not compatible with Unicode
-//
-//function ImageToString(AGraphic : TGraphic) : String;
-//var
-// _stream : TStringStream;
-//begin
-// _stream := TStringStream.Create('');
-// try
-// AGraphic.SaveToStream(_stream);
-// Result := _stream.DataString;
-// finally
-// _stream.Free;
-// end;
-//end;
-//
-//function BinStrToPyStr(const AString : String) : Variant;
-//var
-// _str : PPyObject;
-//begin
-// _str := GetPythonEngine.PyString_FromStringAndSize(PAnsiChar(AString), Length(AString)*SizeOf(Char));
-// Result := VarPythonCreate(_str);
-// GetPythonEngine.Py_DECREF(_str);
-//end;
-
-function ImageToPyStr(AGraphic : TGraphic) : Variant;
+function ImageToPyBytes(AGraphic : TGraphic) : Variant;
var
_stream : TMemoryStream;
- _str : PPyObject;
+ _bytes : PPyObject;
begin
_stream := TMemoryStream.Create();
try
AGraphic.SaveToStream(_stream);
- _str := GetPythonEngine.PyString_FromStringAndSize(_stream.Memory, _stream.Size);
- Result := VarPythonCreate(_str);
- GetPythonEngine.Py_DECREF(_str);
+ _bytes := GetPythonEngine.PyBytes_FromStringAndSize(_stream.Memory, _stream.Size);
+ Result := VarPythonCreate(_bytes);
+ GetPythonEngine.Py_DECREF(_bytes);
finally
_stream.Free;
end;
@@ -102,17 +78,17 @@ procedure TForm1.Button2Click(Sender: TObject);
if (Image1.Picture.Graphic = nil) or Image1.Picture.Graphic.Empty then
raise Exception.Create('You must first select an image');
PythonEngine1.ExecStrings(Memo1.Lines);
- _im := MainModule.ProcessImage(ImageToPyStr(Image1.Picture.Graphic));
+ _im := MainModule.ProcessImage(ImageToPyBytes(Image1.Picture.Graphic));
if not chkUseDC.Checked then
begin
// We have to call PyString_AsStringAndSize because the image may contain zeros
with GetPythonEngine do begin
pargs := MakePyTuple([ExtractPythonObjectFrom(_im)]);
try
+ presult := PyEval_CallObjectWithKeywords(
+ ExtractPythonObjectFrom(MainModule.ImageToBytes), pargs, nil);
try
- presult := PyEval_CallObjectWithKeywords(
- ExtractPythonObjectFrom(MainModule.ImageToString), pargs, nil);
- if (PyString_AsStringAndSize(presult, P, Len) < 0) or (P = nil) then begin
+ if (P = nil) or (PyBytes_AsStringAndSize(presult, P, Len) < 0) then begin
ShowMessage('This does not work and needs fixing');
Abort;
end;
diff --git a/Demos/Demo31/Unit1.pas b/Demos/Demo31/Unit1.pas
index 540569cc..e090e56f 100644
--- a/Demos/Demo31/Unit1.pas
+++ b/Demos/Demo31/Unit1.pas
@@ -206,7 +206,7 @@ procedure TForm1.Button1Click(Sender: TObject);
PyEngine.Py_DecRef(p);
{$ENDIF}
- p := PyEngine.PyInt_FromLong(Trunc(System.CompilerVersion));
+ p := PyEngine.PyLong_FromLong(Trunc(System.CompilerVersion));
PythonModule.SetVar( 'DelphiVersion', p );
PyEngine.Py_DecRef(p);
diff --git a/Demos/Demo32/Unit1.pas b/Demos/Demo32/Unit1.pas
index 14df2bbf..a76eb0b9 100644
--- a/Demos/Demo32/Unit1.pas
+++ b/Demos/Demo32/Unit1.pas
@@ -127,7 +127,7 @@ function TPyPoint.Repr : PPyObject;
begin
with GetPythonEngine, DelphiObject as TPoint do
Result := VariantAsPyObject(Format('(%d, %d)',[x, y]));
- // or Result := PyString_FromString( PAnsiChar(Format('(%d, %d)',[x, y])) );
+ // or Result := PyUnicode_FromAnsiString(Format('(%d, %d)',[x, y]));
end;
/////////////////////////////////////////////////
diff --git a/Demos/Demo33/ThSort.pas b/Demos/Demo33/ThSort.pas
index 3979c0aa..876af12f 100644
--- a/Demos/Demo33/ThSort.pas
+++ b/Demos/Demo33/ThSort.pas
@@ -203,7 +203,7 @@ function TThreadSortForm.SortModule_GetValue( pself, args : PPyObject ) : PPyObj
begin
if (PyErr_Occurred() = nil) and (PyArg_ParseTuple( args, 'ii',@psort, @index) <> 0) then
begin
- Result := PyInt_FromLong(TSortThread(psort)[index]);
+ Result := PyLong_FromLong(TSortThread(psort)[index]);
end else
Result := nil;
end;
diff --git a/Demos/Demo34/Unit1.dfm b/Demos/Demo34/Unit1.dfm
index d69d10f4..5fed44b7 100644
--- a/Demos/Demo34/Unit1.dfm
+++ b/Demos/Demo34/Unit1.dfm
@@ -1,188 +1,188 @@
-object Form1: TForm1
- Left = 214
- Top = 174
- Width = 592
- Height = 422
- VertScrollBar.Range = 210
- ActiveControl = Memo1
- Caption = 'Form1'
- Color = clBtnFace
- Font.Charset = DEFAULT_CHARSET
- Font.Color = clWindowText
- Font.Height = 11
- Font.Name = 'MS Sans Serif'
- Font.Pitch = fpVariable
- Font.Style = []
- OldCreateOrder = True
- OnCreate = FormCreate
- PixelsPerInch = 96
- TextHeight = 13
- object Splitter1: TSplitter
- Left = 0
- Top = 169
- Width = 576
- Height = 3
- Cursor = crVSplit
- Align = alTop
- ExplicitWidth = 584
- end
- object Memo1: TMemo
- Left = 0
- Top = 172
- Width = 576
- Height = 170
- Align = alClient
- Font.Charset = DEFAULT_CHARSET
- Font.Color = clWindowText
- Font.Height = -13
- Font.Name = 'Consolas'
- Font.Pitch = fpVariable
- Font.Style = []
- Lines.Strings = (
- 'import sys'
- 'print (sys.version)'
- ''
- 'import spam'
- ''
- 'class MyPoint(spam.Point):'
- ' def Foo(Self, v):'
- ' Self.OffsetBy(v, v)'
- ''
- '# old way to create a type instance'
- 'p = spam.CreatePoint(2, 5)'
- 'print (p, type(p))'
- 'p.OffsetBy( 3, 3 )'
- 'print (p.x, p.y)'
- 'print ("Name =", p.Name)'
- 'p.Name = '#39'Hello world!'#39
- 'print ("Name =", p.Name)'
- ''
- '# new way to create a type instance'
- 'p = spam.Point(2, 5) # no need to use CreateXXX anymore'
- 'print (p, type(p))'
- 'p.OffsetBy( 3, 3 )'
- 'print (p.x, p.y)'
- ''
- '# create a subtype instance'
- 'p = MyPoint(2, 5)'
- 'print (p, type(p))'
- 'p.OffsetBy( 3, 3 )'
- 'print (p.x, p.y)'
- 'p.Foo( 4 )'
- 'print (p.x, p.y)'
- 'print (dir(spam))'
- 'print (spam.Point)'
- 'print ("p = ", p, " --> ",)'
- 'if type(p) is spam.Point:'
- ' print ("p is a Point")'
- 'else:'
- ' print ("p is not a point")'
- 'p = 2'
- 'print ("p = ", p, " --> ",)'
- 'if type(p) is spam.Point:'
- ' print ("p is a Point")'
- 'else:'
- ' print ("p is not a point")'
- 'p = spam.CreatePoint(2, 5)'
- 'try:'
- ' print ("raising an error of class EBadPoint")'
- ' p.RaiseError() # it will raise spam.EBadPoint'
-
- 'except spam.PointError as what: # this shows that you can interc' +
- 'ept a parent class'
- ' print ("Caught an error derived from PointError")'
-
- ' print ("Error class = ", what.__class__, " a =", what.a,' +
- ' " b =", what.b, " c =", what.c)'
- ''
- '# You can raise error from a Python script to !'
-
- 'print ("--------------------------------------------------------' +
- '----------")'
- 'print ("Errors in a Python script")'
- 'try:'
- ' raise spam.EBadPoint("this is a test !")'
- 'except:'
- ' pass'
- ''
- 'try:'
- ' err = spam.EBadPoint()'
- ' err.a = 1'
- ' err.b = 2'
- ' err.c = 3'
- ' raise err'
-
- 'except spam.PointError as what: # this shows that you can interc' +
- 'ept a parent class'
- ' print ("Caught an error derived from PointError")'
-
- ' print ("Error class = ", what.__class__, " a =", what.a,' +
- ' " b =", what.b, " c =", what.c)'
- ''
- 'if p == spam.CreatePoint(2, 5):'
- ' print ("Equal")'
- 'else:'
- ' print ("Not equal")')
- ParentFont = False
- ScrollBars = ssVertical
- TabOrder = 0
- WordWrap = False
- end
- object Panel1: TPanel
- Left = 0
- Top = 342
- Width = 576
- Height = 41
- Align = alBottom
- BevelOuter = bvNone
- TabOrder = 1
- object Label1: TLabel
- Left = 16
- Top = 6
- Width = 109
- Height = 13
- Caption = 'Select Python version :'
- end
- object Button1: TButton
- Left = 336
- Top = 6
- Width = 75
- Height = 25
- Caption = 'Execute'
- TabOrder = 0
- OnClick = Button1Click
- end
- object cbPyVersions: TComboBox
- Left = 144
- Top = 6
- Width = 161
- Height = 21
- Style = csDropDownList
- TabOrder = 1
- OnSelect = cbPyVersionsSelect
- end
- end
- object Memo2: TMemo
- Left = 0
- Top = 0
- Width = 576
- Height = 169
- Align = alTop
- Font.Charset = DEFAULT_CHARSET
- Font.Color = clWindowText
- Font.Height = -13
- Font.Name = 'Consolas'
- Font.Pitch = fpVariable
- Font.Style = []
- ParentFont = False
- ScrollBars = ssBoth
- TabOrder = 2
- end
- object PythonGUIInputOutput1: TPythonGUIInputOutput
- UnicodeIO = True
- RawOutput = False
- Output = Memo2
- Left = 136
- Top = 16
- end
-end
+object Form1: TForm1
+ Left = 214
+ Top = 174
+ Width = 592
+ Height = 422
+ VertScrollBar.Range = 210
+ ActiveControl = Memo1
+ Caption = 'Form1'
+ Color = clBtnFace
+ Font.Charset = DEFAULT_CHARSET
+ Font.Color = clWindowText
+ Font.Height = 11
+ Font.Name = 'MS Sans Serif'
+ Font.Pitch = fpVariable
+ Font.Style = []
+ OldCreateOrder = True
+ OnCreate = FormCreate
+ PixelsPerInch = 96
+ TextHeight = 13
+ object Splitter1: TSplitter
+ Left = 0
+ Top = 169
+ Width = 576
+ Height = 3
+ Cursor = crVSplit
+ Align = alTop
+ ExplicitWidth = 584
+ end
+ object Memo1: TMemo
+ Left = 0
+ Top = 172
+ Width = 576
+ Height = 170
+ Align = alClient
+ Font.Charset = DEFAULT_CHARSET
+ Font.Color = clWindowText
+ Font.Height = -13
+ Font.Name = 'Consolas'
+ Font.Pitch = fpVariable
+ Font.Style = []
+ Lines.Strings = (
+ 'import sys'
+ 'print (sys.version)'
+ ''
+ 'import spam'
+ ''
+ 'class MyPoint(spam.Point):'
+ ' def Foo(Self, v):'
+ ' Self.OffsetBy(v, v)'
+ ''
+ '# old way to create a type instance'
+ 'p = spam.CreatePoint(2, 5)'
+ 'print (p, type(p))'
+ 'p.OffsetBy( 3, 3 )'
+ 'print (p.x, p.y)'
+ 'print ("Name =", p.Name)'
+ 'p.Name = '#39'Hello world!'#39
+ 'print ("Name =", p.Name)'
+ ''
+ '# new way to create a type instance'
+ 'p = spam.Point(2, 5) # no need to use CreateXXX anymore'
+ 'print (p, type(p))'
+ 'p.OffsetBy( 3, 3 )'
+ 'print (p.x, p.y)'
+ ''
+ '# create a subtype instance'
+ 'p = MyPoint(2, 5)'
+ 'print (p, type(p))'
+ 'p.OffsetBy( 3, 3 )'
+ 'print (p.x, p.y)'
+ 'p.Foo( 4 )'
+ 'print (p.x, p.y)'
+ 'print (dir(spam))'
+ 'print (spam.Point)'
+ 'print ("p = ", p, " --> ",)'
+ 'if type(p) is spam.Point:'
+ ' print ("p is a Point")'
+ 'else:'
+ ' print ("p is not a point")'
+ 'p = 2'
+ 'print ("p = ", p, " --> ",)'
+ 'if type(p) is spam.Point:'
+ ' print ("p is a Point")'
+ 'else:'
+ ' print ("p is not a point")'
+ 'p = spam.CreatePoint(2, 5)'
+ 'try:'
+ ' print ("raising an error of class EBadPoint")'
+ ' p.RaiseError() # it will raise spam.EBadPoint'
+
+ 'except spam.PointError as what: # this shows that you can interc' +
+ 'ept a parent class'
+ ' print ("Caught an error derived from PointError")'
+
+ ' print ("Error class = ", what.__class__, " a =", what.a,' +
+ ' " b =", what.b, " c =", what.c)'
+ ''
+ '# You can raise error from a Python script to !'
+
+ 'print ("--------------------------------------------------------' +
+ '----------")'
+ 'print ("Errors in a Python script")'
+ 'try:'
+ ' raise spam.EBadPoint("this is a test !")'
+ 'except:'
+ ' pass'
+ ''
+ 'try:'
+ ' err = spam.EBadPoint()'
+ ' err.a = 1'
+ ' err.b = 2'
+ ' err.c = 3'
+ ' raise err'
+
+ 'except spam.PointError as what: # this shows that you can interc' +
+ 'ept a parent class'
+ ' print ("Caught an error derived from PointError")'
+
+ ' print ("Error class = ", what.__class__, " a =", what.a,' +
+ ' " b =", what.b, " c =", what.c)'
+ ''
+ 'if p == spam.CreatePoint(2, 5):'
+ ' print ("Equal")'
+ 'else:'
+ ' print ("Not equal")')
+ ParentFont = False
+ ScrollBars = ssVertical
+ TabOrder = 0
+ WordWrap = False
+ end
+ object Panel1: TPanel
+ Left = 0
+ Top = 342
+ Width = 576
+ Height = 41
+ Align = alBottom
+ BevelOuter = bvNone
+ TabOrder = 1
+ object Label1: TLabel
+ Left = 16
+ Top = 6
+ Width = 109
+ Height = 13
+ Caption = 'Select Python version :'
+ end
+ object Button1: TButton
+ Left = 336
+ Top = 6
+ Width = 75
+ Height = 25
+ Caption = 'Execute'
+ TabOrder = 0
+ OnClick = Button1Click
+ end
+ object cbPyVersions: TComboBox
+ Left = 144
+ Top = 6
+ Width = 161
+ Height = 21
+ Style = csDropDownList
+ TabOrder = 1
+ OnSelect = cbPyVersionsSelect
+ end
+ end
+ object Memo2: TMemo
+ Left = 0
+ Top = 0
+ Width = 576
+ Height = 169
+ Align = alTop
+ Font.Charset = DEFAULT_CHARSET
+ Font.Color = clWindowText
+ Font.Height = -13
+ Font.Name = 'Consolas'
+ Font.Pitch = fpVariable
+ Font.Style = []
+ ParentFont = False
+ ScrollBars = ssBoth
+ TabOrder = 2
+ end
+ object PythonGUIInputOutput1: TPythonGUIInputOutput
+ UnicodeIO = True
+ RawOutput = False
+ Output = Memo2
+ Left = 136
+ Top = 16
+ end
+end
diff --git a/Demos/Demo34/Unit1.pas b/Demos/Demo34/Unit1.pas
index ae34a4a4..460ae16c 100644
--- a/Demos/Demo34/Unit1.pas
+++ b/Demos/Demo34/Unit1.pas
@@ -177,23 +177,23 @@ function TPyPoint.Repr : PPyObject;
begin
with GetPythonEngine do
Result := VariantAsPyObject(Format('(%d, %d)',[x, y]));
- // or Result := PyString_FromString( PAnsiChar(Format('(%d, %d)',[x, y])) );
+ // or Result := PyUnicode_FromAnsiString(Format('(%d, %d)',[x, y]));
end;
// get/set functions
function TPyPoint_GetName( obj : PPyObject; context : Pointer) : PPyObject; cdecl;
begin
with GetPythonEngine do
- Result := PyString_FromString(PAnsiChar(AnsiString(TPyPoint(PythonToDelphi(obj)).Name)));
+ Result := PyUnicode_FromAnsiString(AnsiString(TPyPoint(PythonToDelphi(obj)).Name));
end;
function TPyPoint_SetName( obj, value : PPyObject; context : Pointer) : integer; cdecl;
begin
with GetPythonEngine do
begin
- if PyString_Check(value) then
+ if PyUnicode_Check(value) then
begin
- TPyPoint(PythonToDelphi(obj)).Name := PyObjectAsVariant(value);
+ TPyPoint(PythonToDelphi(obj)).Name := PyUnicode_AsWideString(value);
Result := 0;
end
else
diff --git a/Demos/FPC/Demo06/Unit1.pas b/Demos/FPC/Demo06/Unit1.pas
index a41cc1d9..c21167a7 100644
--- a/Demos/FPC/Demo06/Unit1.pas
+++ b/Demos/FPC/Demo06/Unit1.pas
@@ -1,4 +1,4 @@
-unit Unit1;
+unit Unit1;
{$I Definition.Inc}
@@ -161,14 +161,14 @@ function PyPoint_getattr(obj : PPyObject; key : PAnsiChar) : PPyObject; cdecl;
begin
// Check for attribute x
if key = 'x' then
- Result := PyInt_FromLong( po_x )
+ Result := PyLong_FromLong( po_x )
// Check for attribute y
else if key = 'y' then
- Result := PyInt_FromLong( po_y )
+ Result := PyLong_FromLong( po_y )
else
begin
// Else check for a method
- Result := PyObject_GenericGetAttr(obj, PyString_FromString(key));
+ Result := PyObject_GenericGetAttr(obj, PyUnicode_FromAnsiString(key));
if not Assigned(Result) then
PyErr_SetString (PyExc_AttributeError^, PAnsiChar(Format('Unknown attribute "%s"',[key])));
end;
@@ -185,18 +185,18 @@ function PyPoint_setattrfunc(obj : PPyObject; key : PAnsiChar; value : PPyObjec
begin
// Check for attribute x
if key = 'x' then begin
- if PyInt_Check(value) then
+ if PyLong_Check(value) then
begin
- po_x := PyInt_AsLong(value);
+ po_x := PyLong_AsLong(value);
Result := 0;
end
else
PyErr_SetString (PyExc_AttributeError^, PAnsiChar(Format('Attribute "%s" needs an integer',[key])));
// Check for attribute y
end else if key = 'y' then begin
- if PyInt_Check(value) then
+ if PyLong_Check(value) then
begin
- po_y := PyInt_AsLong(value);
+ po_y := PyLong_AsLong(value);
Result := 0;
end
else
@@ -211,7 +211,7 @@ function PyPoint_repr(obj : PPyObject) : PPyObject; cdecl;
begin
with GetPythonEngine, PPyPoint(obj)^ do
begin
- Result := PyString_FromString( PAnsiChar(Format('(%d, %d)',[po_x, po_y]) ) );
+ Result := PyUnicode_FromAnsiString(Format('(%d, %d)',[po_x, po_y]));
end;
end;
diff --git a/Demos/FPC/Demo31/Unit1.pas b/Demos/FPC/Demo31/Unit1.pas
index e3ce24bf..c28ad7b1 100644
--- a/Demos/FPC/Demo31/Unit1.pas
+++ b/Demos/FPC/Demo31/Unit1.pas
@@ -168,9 +168,9 @@ procedure TForm1.Button1Click(Sender: TObject);
PyEngine.Py_DecRef(p);
{$IF DEFINED(FPC_VER) and (FPC_VER >= 5)}
- p := PyEngine.PyInt_FromLong(FPC_VER);
+ p := PyEngine.PyLong_FromLong(FPC_VER);
{ELSE}
- p := PyEngine.PyInt_FromLong(4);
+ p := PyEngine.PyLong_FromLong(4);
{$IFEND}
PythonModule.SetVar( 'DelphiVersion', p );
PyEngine.Py_DecRef(p);
diff --git a/Modules/Delphi/Delphi.dpr b/Modules/Delphi/Delphi.dpr
deleted file mode 100644
index 7ad17385..00000000
--- a/Modules/Delphi/Delphi.dpr
+++ /dev/null
@@ -1,32 +0,0 @@
-library Delphi;
-
-{ Important note about DLL memory management: ShareMem must be the
- first unit in your library's USES clause AND your project's (select
- Project-View Source) USES clause if your DLL exports any procedures or
- functions that pass strings as parameters or function results. This
- applies to all strings passed to and from your DLL--even those that
- are nested in records and classes. ShareMem is the interface unit to
- the BORLNDMM.DLL shared memory manager, which must be deployed along
- with your DLL. To avoid using BORLNDMM.DLL, pass string information
- using PChar or ShortString parameters. }
-
-uses
- SysUtils,
- Classes,
- uMain in 'uMain.pas';
-
-{$I Definition.Inc}
-
-exports
- PyInit_Delphi;
-{$IFDEF MSWINDOWS}
-{$E pyd}
-{$ENDIF}
-{$IFDEF LINUX}
-{$SONAME 'Delphi'}
-
-{$ENDIF}
-
-begin
-end.
-
diff --git a/Modules/Delphi/Delphi.dproj b/Modules/Delphi/Delphi.dproj
deleted file mode 100644
index 42373ec5..00000000
--- a/Modules/Delphi/Delphi.dproj
+++ /dev/null
@@ -1,108 +0,0 @@
-
-
- True
- Library
- Debug
- None
- Delphi.dpr
- Win64
- {7E56095C-46B8-4F28-87A2-EEA8D9D2448D}
- 19.1
- 3
-
-
- true
-
-
- true
- Base
- true
-
-
- true
- Base
- true
-
-
- true
- Base
- true
-
-
- true
- Base
- true
-
-
- true
- Cfg_2
- true
- true
-
-
- Delphi
- 00400000
- System;Xml;Data;Datasnap;Web;Soap;Vcl;$(DCC_Namespace)
- true
- CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=;CFBundleName=
- 1033
-
-
- Debug
- Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace)
-
-
- Debug
- Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;$(DCC_Namespace)
-
-
- 0
- RELEASE;$(DCC_Define)
- false
- 0
-
-
- DEBUG;$(DCC_Define)
- true
- false
-
-
- (None)
-
-
-
- MainSource
-
-
-
- Base
-
-
- Cfg_1
- Base
-
-
- Cfg_2
- Base
-
-
-
- Delphi.Personality.12
-
-
-
-
- Delphi.dpr
-
-
-
-
- True
- True
-
-
- 12
-
-
-
-
diff --git a/Modules/Delphi/TestApp.py b/Modules/Delphi/TestApp.py
deleted file mode 100644
index 1986ebcc..00000000
--- a/Modules/Delphi/TestApp.py
+++ /dev/null
@@ -1,25 +0,0 @@
-from Delphi import *
-
-class MainForm(Form):
-
- def __init__(self, Owner):
- self.Caption = "A Delphi Form..."
- self.SetBounds(10, 10, 500, 400)
- self.lblHello = Label(self)
- self.lblHello.SetProps(Parent=self, Caption="Hello World")
- self.lblHello.SetBounds(10, 10, 300, 24)
- self.OnClose = self.MainFormClose
-
- def MainFormClose(self, Sender, Action):
- Action.Value = caFree
-
-def main():
- Application.Initialize()
- Application.Title = "MyDelphiApp"
- f = MainForm(Application)
- f.Show()
- FreeConsole()
- Application.Run()
-
-main()
-
diff --git a/Modules/DelphiVCL/DelphiVCL.dpr b/Modules/DelphiVCL/DelphiVCL.dpr
new file mode 100644
index 00000000..857e5b83
--- /dev/null
+++ b/Modules/DelphiVCL/DelphiVCL.dpr
@@ -0,0 +1,25 @@
+library DelphiVCL;
+
+uses
+ SysUtils,
+ Classes,
+ uMain in 'uMain.pas';
+
+{$I Definition.Inc}
+
+exports
+ // This must match the pattern "PyInit_[ProjectName]"
+ // So if the project is named DelphiVCL then
+ // the export must be PyInit_DelphiVCL
+ PyInit_DelphiVCL;
+{$IFDEF MSWINDOWS}
+{$E pyd}
+{$ENDIF}
+{$IFDEF LINUX}
+{$SONAME 'DelphiVCL'}
+
+{$ENDIF}
+
+begin
+end.
+
diff --git a/Modules/DelphiVCL/DelphiVCL.dproj b/Modules/DelphiVCL/DelphiVCL.dproj
new file mode 100644
index 00000000..a83e4c47
--- /dev/null
+++ b/Modules/DelphiVCL/DelphiVCL.dproj
@@ -0,0 +1,814 @@
+
+
+ True
+ Library
+ Release
+ None
+ DelphiVCL.dpr
+ Win64
+ {7E56095C-46B8-4F28-87A2-EEA8D9D2448D}
+ 19.1
+ 3
+
+
+ true
+
+
+ true
+ Base
+ true
+
+
+ true
+ Base
+ true
+
+
+ true
+ Base
+ true
+
+
+ true
+ Base
+ true
+
+
+ true
+ Cfg_2
+ true
+ true
+
+
+ DelphiVCL
+ 00400000
+ System;Xml;Data;Datasnap;Web;Soap;Vcl;$(DCC_Namespace)
+ true
+ CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=;CFBundleName=
+ 1033
+
+
+ Debug
+ Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace)
+
+
+ Debug
+ Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;$(DCC_Namespace)
+
+
+ 0
+ RELEASE;$(DCC_Define)
+ false
+ 0
+
+
+ DEBUG;$(DCC_Define)
+ true
+ false
+
+
+ (None)
+
+
+
+ MainSource
+
+
+
+ Base
+
+
+ Cfg_1
+ Base
+
+
+ Cfg_2
+ Base
+
+
+
+ Delphi.Personality.12
+
+
+
+
+ DelphiVCL.dpr
+
+
+
+
+
+
+ true
+
+
+
+
+ true
+
+
+
+
+ true
+
+
+
+
+ DelphiVCL.dll
+ true
+
+
+
+
+ 1
+
+
+ 0
+
+
+
+
+ classes
+ 1
+
+
+ classes
+ 1
+
+
+
+
+ res\xml
+ 1
+
+
+ res\xml
+ 1
+
+
+
+
+ library\lib\armeabi-v7a
+ 1
+
+
+
+
+ library\lib\armeabi
+ 1
+
+
+ library\lib\armeabi
+ 1
+
+
+
+
+ library\lib\armeabi-v7a
+ 1
+
+
+
+
+ library\lib\mips
+ 1
+
+
+ library\lib\mips
+ 1
+
+
+
+
+ library\lib\armeabi-v7a
+ 1
+
+
+ library\lib\arm64-v8a
+ 1
+
+
+
+
+ library\lib\armeabi-v7a
+ 1
+
+
+
+
+ res\drawable
+ 1
+
+
+ res\drawable
+ 1
+
+
+
+
+ res\values
+ 1
+
+
+ res\values
+ 1
+
+
+
+
+ res\values-v21
+ 1
+
+
+ res\values-v21
+ 1
+
+
+
+
+ res\values
+ 1
+
+
+ res\values
+ 1
+
+
+
+
+ res\drawable
+ 1
+
+
+ res\drawable
+ 1
+
+
+
+
+ res\drawable-xxhdpi
+ 1
+
+
+ res\drawable-xxhdpi
+ 1
+
+
+
+
+ res\drawable-ldpi
+ 1
+
+
+ res\drawable-ldpi
+ 1
+
+
+
+
+ res\drawable-mdpi
+ 1
+
+
+ res\drawable-mdpi
+ 1
+
+
+
+
+ res\drawable-hdpi
+ 1
+
+
+ res\drawable-hdpi
+ 1
+
+
+
+
+ res\drawable-xhdpi
+ 1
+
+
+ res\drawable-xhdpi
+ 1
+
+
+
+
+ res\drawable-mdpi
+ 1
+
+
+ res\drawable-mdpi
+ 1
+
+
+
+
+ res\drawable-hdpi
+ 1
+
+
+ res\drawable-hdpi
+ 1
+
+
+
+
+ res\drawable-xhdpi
+ 1
+
+
+ res\drawable-xhdpi
+ 1
+
+
+
+
+ res\drawable-xxhdpi
+ 1
+
+
+ res\drawable-xxhdpi
+ 1
+
+
+
+
+ res\drawable-xxxhdpi
+ 1
+
+
+ res\drawable-xxxhdpi
+ 1
+
+
+
+
+ res\drawable-small
+ 1
+
+
+ res\drawable-small
+ 1
+
+
+
+
+ res\drawable-normal
+ 1
+
+
+ res\drawable-normal
+ 1
+
+
+
+
+ res\drawable-large
+ 1
+
+
+ res\drawable-large
+ 1
+
+
+
+
+ res\drawable-xlarge
+ 1
+
+
+ res\drawable-xlarge
+ 1
+
+
+
+
+ res\values
+ 1
+
+
+ res\values
+ 1
+
+
+
+
+ 1
+
+
+ 1
+
+
+ 0
+
+
+
+
+ 1
+ .framework
+
+
+ 1
+ .framework
+
+
+ 0
+
+
+
+
+ 1
+ .dylib
+
+
+ 1
+ .dylib
+
+
+ 0
+ .dll;.bpl
+
+
+
+
+ 1
+ .dylib
+
+
+ 1
+ .dylib
+
+
+ 1
+ .dylib
+
+
+ 1
+ .dylib
+
+
+ 1
+ .dylib
+
+
+ 0
+ .bpl
+
+
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+
+
+ 1
+
+
+ 1
+
+
+
+
+
+
+
+ Contents\Resources
+ 1
+
+
+ Contents\Resources
+ 1
+
+
+
+
+ library\lib\armeabi-v7a
+ 1
+
+
+ library\lib\arm64-v8a
+ 1
+
+
+ 1
+
+
+ 1
+
+
+ 1
+
+
+ 1
+
+
+ 1
+
+
+ 1
+
+
+ 0
+
+
+
+
+ library\lib\armeabi-v7a
+ 1
+
+
+
+
+ 1
+
+
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF
+ 1
+
+
+ ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF
+ 1
+
+
+
+
+
+
+
+ 1
+
+
+ 1
+
+
+ 1
+
+
+
+
+ Assets
+ 1
+
+
+ Assets
+ 1
+
+
+
+
+ Assets
+ 1
+
+
+ Assets
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ True
+ True
+
+
+ 12
+
+
+
+
+
diff --git a/Modules/DelphiVCL/TestVCL.py b/Modules/DelphiVCL/TestVCL.py
new file mode 100644
index 00000000..fba8f36a
--- /dev/null
+++ b/Modules/DelphiVCL/TestVCL.py
@@ -0,0 +1,45 @@
+from DelphiVCL import *
+
+class MainForm(Form):
+
+ def __init__(self, Owner):
+ self.Caption = "A VCL Form..."
+ self.SetBounds(10, 10, 500, 400)
+
+ self.lblHello = Label(self)
+ self.lblHello.SetProps(Parent=self, Caption="Hello Python")
+ self.lblHello.SetBounds(10, 10, 300, 24)
+
+ self.edit1 = Edit(self)
+ self.edit1.SetProps(Parent=self)
+ self.edit1.SetBounds(10, 30, 250, 24)
+
+ self.button1 = Button(self)
+ self.button1.Parent = self
+ self.button1.SetBounds(270,24,100,30)
+ self.button1.Caption = "Add"
+ self.button1.OnClick = self.Button1Click
+
+ self.lb1 = ListBox(self)
+ self.lb1.Parent = self
+ self.lb1.SetBounds(10,60,300,300)
+
+ self.OnClose = self.MainFormClose
+
+ def MainFormClose(self, Sender, Action):
+ Action.Value = caFree
+
+ def Button1Click(self, Sender):
+ self.lb1.Items.Add(self.edit1.Text)
+ self.edit1.Text = ""
+
+def main():
+ Application.Initialize()
+ Application.Title = "MyDelphiApp"
+ f = MainForm(Application)
+ f.Show()
+ FreeConsole()
+ Application.Run()
+
+main()
+
diff --git a/Modules/Delphi/uMain.pas b/Modules/DelphiVCL/uMain.pas
similarity index 55%
rename from Modules/Delphi/uMain.pas
rename to Modules/DelphiVCL/uMain.pas
index 96186301..06d82d7a 100644
--- a/Modules/Delphi/uMain.pas
+++ b/Modules/DelphiVCL/uMain.pas
@@ -1,49 +1,56 @@
-unit uMain;
-
-interface
-
-uses PythonEngine;
-
-function PyInit_Delphi: PPyObject; cdecl;
-
-implementation
-
-uses WrapDelphi, WrapDelphiVCL;
-
-var
- gEngine : TPythonEngine;
- gModule : TPythonModule;
- gDelphiWrapper : TPyDelphiWrapper;
-
-function PyInit_Delphi: PPyObject;
-begin
- try
- gEngine := TPythonEngine.Create(nil);
- gEngine.AutoFinalize := False;
- gEngine.UseLastKnownVersion := False;
- // Adapt to the desired python version
- gEngine.RegVersion := '3.8';
- gEngine.DllName := 'python38.dll';
-
- gModule := TPythonModule.Create(nil);
- gModule.Engine := gEngine;
- gModule.ModuleName := 'Delphi';
-
- gDelphiWrapper := TPyDelphiWrapper.Create(nil);
- gDelphiWrapper.Engine := gEngine;
- gDelphiWrapper.Module := gModule;
-
- gEngine.LoadDll;
- except
- end;
- Result := gModule.Module;
-end;
-
-initialization
-finalization
- gEngine.Free;
- gModule.Free;
- gDelphiWrapper.Free;
-end.
-
-
+unit uMain;
+
+interface
+
+uses PythonEngine;
+
+function PyInit_DelphiVCL: PPyObject; cdecl;
+
+implementation
+
+uses WrapDelphi, WrapDelphiVCL;
+
+var
+ gEngine : TPythonEngine;
+ gModule : TPythonModule;
+ gDelphiWrapper : TPyDelphiWrapper;
+
+// This must match the pattern "PyInit_[ProjectName]"
+// So if the project is named DelphiVCL then
+// the function must be PyInit_DelphiVCL
+function PyInit_DelphiVCL: PPyObject;
+begin
+ try
+ gEngine := TPythonEngine.Create(nil);
+ gEngine.AutoFinalize := False;
+ gEngine.UseLastKnownVersion := False;
+ // Adapt to the desired python version - Will only work with this version
+ gEngine.RegVersion := '3.9';
+ gEngine.DllName := 'python39.dll';
+
+ gModule := TPythonModule.Create(nil);
+ gModule.Engine := gEngine;
+ // This must match the ProjectName and the function name pattern
+ gModule.ModuleName := 'DelphiVCL';
+
+ gDelphiWrapper := TPyDelphiWrapper.Create(nil);
+ gDelphiWrapper.Engine := gEngine;
+ gDelphiWrapper.Module := gModule;
+
+ gEngine.LoadDll;
+ except
+ end;
+ Result := gModule.Module;
+end;
+
+initialization
+ gEngine := nil;
+ gModule := nil;
+ gDelphiWrapper := nil;
+finalization
+ gEngine.Free;
+ gModule.Free;
+ gDelphiWrapper.Free;
+end.
+
+
diff --git a/Source/PythonAction.pas b/Source/PythonAction.pas
index 749f768e..c1532fab 100644
--- a/Source/PythonAction.pas
+++ b/Source/PythonAction.pas
@@ -124,7 +124,7 @@ function TPythonAction.PythonClear(pself, args: PPyObject): PPyObject;
ClearMethods;
with GetPythonEngine, RegisteredMethods do
begin
- Result := PyInt_FromLong(Count);
+ Result := PyLong_FromLong(Count);
end;
end;
@@ -146,7 +146,7 @@ function TPythonAction.PythonRegister(pself, args: PPyObject): PPyObject;
begin
Py_XINCREF(func);
Add(func);
- Result := PyInt_FromLong(Count);
+ Result := PyLong_FromLong(Count);
end;
end;
@@ -168,7 +168,7 @@ function TPythonAction.PythonUnregister(pself, args: PPyObject): PPyObject;
begin
Py_XDECREF(func);
Remove(func);
- Result := PyInt_FromLong(Count);
+ Result := PyLong_FromLong(Count);
end;
end;
diff --git a/Source/PythonEngine.pas b/Source/PythonEngine.pas
index 54a8fc9b..dc7136aa 100644
--- a/Source/PythonEngine.pas
+++ b/Source/PythonEngine.pas
@@ -116,9 +116,8 @@ TPythonVersionProp = record
end;
const
{$IFDEF MSWINDOWS}
- PYTHON_KNOWN_VERSIONS: array[1..9] of TPythonVersionProp =
+ PYTHON_KNOWN_VERSIONS: array[1..8] of TPythonVersionProp =
(
- (DllName: 'python27.dll'; RegVersion: '2.7'; APIVersion: 1013),
(DllName: 'python32.dll'; RegVersion: '3.2'; APIVersion: 1013),
(DllName: 'python33.dll'; RegVersion: '3.3'; APIVersion: 1013),
(DllName: 'python34.dll'; RegVersion: '3.4'; APIVersion: 1013),
@@ -130,9 +129,8 @@ TPythonVersionProp = record
);
{$ENDIF}
{$IFDEF _so_files}
- PYTHON_KNOWN_VERSIONS: array[1..9] of TPythonVersionProp =
+ PYTHON_KNOWN_VERSIONS: array[1..8] of TPythonVersionProp =
(
- (DllName: 'libpython2.7.so'; RegVersion: '2.7'; APIVersion: 1013),
(DllName: 'libpython3.2m.so'; RegVersion: '3.2'; APIVersion: 1013),
(DllName: 'libpython3.3m.so'; RegVersion: '3.3'; APIVersion: 1013),
(DllName: 'libpython3.4m.so'; RegVersion: '3.4'; APIVersion: 1013),
@@ -144,9 +142,8 @@ TPythonVersionProp = record
);
{$ENDIF}
{$IFDEF DARWIN}
- PYTHON_KNOWN_VERSIONS: array[1..9] of TPythonVersionProp =
+ PYTHON_KNOWN_VERSIONS: array[1..8] of TPythonVersionProp =
(
- (DllName: 'libpython2.7.dylib'; RegVersion: '2.7'; APIVersion: 1013),
(DllName: 'libpython3.2.dylib'; RegVersion: '3.2'; APIVersion: 1013),
(DllName: 'libpython3.3.dylib'; RegVersion: '3.3'; APIVersion: 1013),
(DllName: 'libpython3.4.dylib'; RegVersion: '3.4'; APIVersion: 1013),
@@ -184,19 +181,19 @@ TPythonVersionProp = record
// Delphi equivalent used by TPyObject
TRichComparisonOpcode = (pyLT, pyLE, pyEQ, pyNE, pyGT, pyGE);
const
-{Type flags (tp_flags) introduced in version 2.0
+{
+Type flags (tp_flags)
-These flags are used to extend the type structure in a backwards-compatible
-fashion. Extensions can use the flags to indicate (and test) when a given
-type structure contains a new feature. The Python core will use these when
-introducing new functionality between major revisions (to avoid mid-version
-changes in the PYTHON_API_VERSION).
+These flags are used to change expected features and behavior for a
+particular type.
Arbitration of the flag bit positions will need to be coordinated among
-all extension writers who publically release their extensions (this will
-be fewer than you might expect!)..
+all extension writers who publicly release their extensions (this will
+be fewer than you might expect!).
-Python 1.5.2 introduced the bf_getcharbuffer slot into PyBufferProcs.
+Most flags were removed as of Python 3.0 to make room for new flags. (Some
+flags are not for backwards compatibility but to indicate the presence of an
+optional feature; these flags remain of course.)
Type definitions should use Py_TPFLAGS_DEFAULT for their tp_flags value.
@@ -204,35 +201,6 @@ TPythonVersionProp = record
given type object has a specified feature.
}
-// PyBufferProcs contains bf_getcharbuffer
- Py_TPFLAGS_HAVE_GETCHARBUFFER = (1 shl 0);
-
-// PySequenceMethods contains sq_contains
- Py_TPFLAGS_HAVE_SEQUENCE_IN = (1 shl 1);
-
-// Objects which participate in garbage collection (see objimp.h)
- Py_TPFLAGS_GC = (1 shl 2);
-
-// PySequenceMethods and PyNumberMethods contain in-place operators
- Py_TPFLAGS_HAVE_INPLACEOPS = (1 shl 3);
-
-// PyNumberMethods do their own coercion */
- Py_TPFLAGS_CHECKTYPES = (1 shl 4);
-
- Py_TPFLAGS_HAVE_RICHCOMPARE = (1 shl 5);
-
-// Objects which are weakly referencable if their tp_weaklistoffset is >0
-// XXX Should this have the same value as Py_TPFLAGS_HAVE_RICHCOMPARE?
-// These both indicate a feature that appeared in the same alpha release.
-
- Py_TPFLAGS_HAVE_WEAKREFS = (1 shl 6);
-
-// tp_iter is defined
- Py_TPFLAGS_HAVE_ITER = (1 shl 7);
-
-// New members introduced by Python 2.2 exist
- Py_TPFLAGS_HAVE_CLASS = (1 shl 8);
-
// Set if the type object is dynamically allocated
Py_TPFLAGS_HEAPTYPE = (1 shl 9);
@@ -248,96 +216,50 @@ TPythonVersionProp = record
// Objects support garbage collection (see objimp.h)
Py_TPFLAGS_HAVE_GC = (1 shl 14);
- Py_TPFLAGS_DEFAULT = Py_TPFLAGS_HAVE_GETCHARBUFFER
- or Py_TPFLAGS_HAVE_SEQUENCE_IN
- or Py_TPFLAGS_HAVE_INPLACEOPS
- or Py_TPFLAGS_HAVE_RICHCOMPARE
- or Py_TPFLAGS_HAVE_WEAKREFS
- or Py_TPFLAGS_HAVE_ITER
- or Py_TPFLAGS_HAVE_CLASS
- or Py_TPFLAGS_BASETYPE
- ;
+// Set if the type implements the vectorcall protocol (PEP 590) */
+ _Py_TPFLAGS_HAVE_VECTORCALL = (1 shl 11);
+
+// Objects behave like an unbound method
+ Py_TPFLAGS_METHOD_DESCRIPTOR = (1 shl 17);
+
+// Objects support type attribute cache
+ Py_TPFLAGS_HAVE_VERSION_TAG = (1 shl 18);
+ Py_TPFLAGS_VALID_VERSION_TAG = (1 shl 19);
+
+// Type is abstract and cannot be instantiated
+ Py_TPFLAGS_IS_ABSTRACT = (1 shl 20);
+
+// These flags are used to determine if a type is a subclass.
+ Py_TPFLAGS_LONG_SUBCLASS = (1 shl 24);
+ Py_TPFLAGS_LIST_SUBCLASS = (1 shl 25);
+ Py_TPFLAGS_TUPLE_SUBCLASS = (1 shl 26);
+ Py_TPFLAGS_BYTES_SUBCLASS = (1 shl 27);
+ Py_TPFLAGS_UNICODE_SUBCLASS = (1 shl 28);
+ Py_TPFLAGS_DICT_SUBCLASS = (1 shl 29);
+ Py_TPFLAGS_BASE_EXC_SUBCLASS = (1 shl 30);
+ Py_TPFLAGS_TYPE_SUBCLASS = (1 shl 31);
+
+ Py_TPFLAGS_DEFAULT = Py_TPFLAGS_BASETYPE or Py_TPFLAGS_HAVE_VERSION_TAG;
// See function PyType_HasFeature below for testing the flags.
// Delphi equivalent used by TPythonType
type
- TPFlag = (tpfHaveGetCharBuffer, tpfHaveSequenceIn, tpfGC, tpfHaveInplaceOps,
- tpfCheckTypes, tpfHaveRichCompare, tpfHaveWeakRefs
- ,tpfHaveIter, tpfHaveClass, tpfHeapType, tpfBaseType, tpfReady, tpfReadying, tpfHaveGC
- );
+ TPFlag = (tpfHeapType, tpfBaseType, tpfReady, tpfReadying, tpfHaveGC,
+ tpVectorCall, tpMethodDescriptor, tpHaveVersionTag,
+ tpValidVersionTag, tpIsAbstract, tpLongSubclass,
+ tpListSubClass, tpTupleSubclass, tpBytesSubclass,
+ tpBaseExcSubclass, tpTypeSubclass);
TPFlags = set of TPFlag;
+
const
- TPFLAGS_DEFAULT = [tpfHaveSequenceIn, tpfHaveInplaceOps,
- tpfHaveRichCompare, tpfHaveIter,
- tpfHaveClass, tpfBaseType
- ];
+ TPFLAGS_DEFAULT = [tpfBaseType, tpHaveVersionTag];
+
//------- Python opcodes ----------//
Const
single_input = 256;
file_input = 257;
eval_input = 258;
- p4d_funcdef = 259;
- p4d_parameters = 260;
- p4d_varargslist = 261;
- p4d_fpdef = 262;
- p4d_fplist = 263;
- p4d_stmt = 264;
- p4d_simple_stmt = 265;
- p4d_small_stmt = 266;
- p4d_expr_stmt = 267;
- p4d_augassign = 268;
- p4d_print_stmt = 269;
- p4d_del_stmt = 270;
- p4d_pass_stmt = 271;
- p4d_flow_stmt = 272;
- p4d_break_stmt = 273;
- p4d_continue_stmt = 274;
- p4d_return_stmt = 275;
- p4d_raise_stmt = 276;
- p4d_import_stmt = 277;
- p4d_import_as_name = 278;
- p4d_dotted_as_name = 279;
- p4d_dotted_name = 280;
- p4d_global_stmt = 281;
- p4d_exec_stmt = 282;
- p4d_assert_stmt = 283;
- p4d_compound_stmt = 284;
- p4d_if_stmt = 285;
- p4d_while_stmt = 286;
- p4d_for_stmt = 287;
- p4d_try_stmt = 288;
- p4d_except_clause = 289;
- p4d_suite = 290;
- p4d_test = 291;
- p4d_and_test = 291;
- p4d_not_test = 293;
- p4d_comparison = 294;
- p4d_comp_op = 295;
- p4d_expr = 296;
- p4d_xor_expr = 297;
- p4d_and_expr = 298;
- p4d_shift_expr = 299;
- p4d_arith_expr = 300;
- p4d_term = 301;
- p4d_factor = 302;
- p4d_power = 303;
- p4d_atom = 304;
- p4d_listmaker = 305;
- p4d_lambdef = 306;
- p4d_trailer = 307;
- p4d_subscriptlist = 308;
- p4d_subscript = 309;
- p4d_sliceop = 310;
- p4d_exprlist = 311;
- p4d_testlist = 312;
- p4d_dictmaker = 313;
- p4d_classdef = 314;
- p4d_arglist = 315;
- p4d_argument = 316;
- p4d_list_iter = 317;
- p4d_list_for = 318;
- p4d_list_if = 319;
// structmember.h
const
@@ -384,14 +306,11 @@ TPythonVersionProp = record
//#######################################################
const
- ErrInit = -300;
CR = #13;
LF = #10;
TAB = #09;
CRLF = CR+LF;
-
-
//#######################################################
//## ##
//## Python specific interface ##
@@ -419,28 +338,18 @@ TPythonVersionProp = record
lenfunc = function( ob1 : PPyObject): NativeInt; cdecl;
coercion = function( ob1,ob2 : PPPyObject): integer; cdecl;
ssizeargfunc = function( ob1 : PPyObject; i: NativeInt): PPyObject; cdecl;
- ssizessizeargfunc = function( ob1 : PPyObject; i1, i2: NativeInt):
- PPyObject; cdecl;
ssizeobjargproc = function( ob1 : PPyObject; i: NativeInt; ob2 : PPyObject):
integer; cdecl;
- ssizessizeobjargproc = function( ob1: PPyObject; i1, i2: NativeInt;
- ob2: PPyObject): integer; cdecl;
objobjargproc = function( ob1,ob2,ob3 : PPyObject): integer; cdecl;
pydestructor = procedure(ob: PPyObject); cdecl;
- printfunc = function( ob: PPyObject; var f: file; i: integer): integer; cdecl;
getattrfunc = function( ob1: PPyObject; name: PAnsiChar): PPyObject; cdecl;
setattrfunc = function( ob1: PPyObject; name: PAnsiChar; ob2: PPyObject): integer; cdecl;
- cmpfunc = function( ob1,ob2: PPyObject): integer; cdecl;
reprfunc = function( ob: PPyObject): PPyObject; cdecl;
hashfunc = function( ob: PPyObject): NativeInt; cdecl; // !! in 2.x it is still a LongInt
getattrofunc = function( ob1,ob2: PPyObject): PPyObject; cdecl;
setattrofunc = function( ob1,ob2,ob3: PPyObject): integer; cdecl;
- getreadbufferproc = function ( ob1: PPyObject; i: NativeInt; ptr: Pointer): NativeInt; cdecl;
- getwritebufferproc= function ( ob1: PPyObject; i: NativeInt; ptr: Pointer): NativeInt; cdecl;
- getsegcountproc = function ( ob1: PPyObject; i: NativeInt): NativeInt; cdecl;
- getcharbufferproc = function ( ob1: PPyObject; i: NativeInt; const pstr: PAnsiChar): NativeInt; cdecl;
objobjproc = function ( ob1, ob2: PPyObject): integer; cdecl;
visitproc = function ( ob1: PPyObject; ptr: Pointer): integer; cdecl;
traverseproc = function ( ob1: PPyObject; proc: visitproc; ptr: Pointer): integer; cdecl;
@@ -454,50 +363,7 @@ TPythonVersionProp = record
newfunc = function ( subtype: PPyTypeObject; args, kwds : PPyObject) : PPyObject; cdecl;
allocfunc = function ( self: PPyTypeObject; nitems : NativeInt) : PPyObject; cdecl;
- PyNumberMethods200 = {$IFNDEF CPUX64}packed{$ENDIF} record
- nb_add : binaryfunc;
- nb_subtract : binaryfunc;
- nb_multiply : binaryfunc;
- nb_divide : binaryfunc;
- nb_remainder : binaryfunc;
- nb_divmod : binaryfunc;
- nb_power : ternaryfunc;
- nb_negative : unaryfunc;
- nb_positive : unaryfunc;
- nb_absolute : unaryfunc;
- nb_nonzero : inquiry;
- nb_invert : unaryfunc;
- nb_lshift : binaryfunc;
- nb_rshift : binaryfunc;
- nb_and : binaryfunc;
- nb_xor : binaryfunc;
- nb_or : binaryfunc;
- nb_coerce : coercion;
- nb_int : unaryfunc;
- nb_long : unaryfunc;
- nb_float : unaryfunc;
- nb_oct : unaryfunc;
- nb_hex : unaryfunc;
- nb_inplace_add : binaryfunc;
- nb_inplace_subtract : binaryfunc;
- nb_inplace_multiply : binaryfunc;
- nb_inplace_divide : binaryfunc;
- nb_inplace_remainder : binaryfunc;
- nb_inplace_power : ternaryfunc;
- nb_inplace_lshift : binaryfunc;
- nb_inplace_rshift : binaryfunc;
- nb_inplace_and : binaryfunc;
- nb_inplace_xor : binaryfunc;
- nb_inplace_or : binaryfunc;
- nb_floor_divide : binaryfunc;
- nb_true_divide : binaryfunc;
- nb_inplace_floor_divide : binaryfunc;
- nb_inplace_true_divide : binaryfunc;
- nb_index : unaryfunc;
- end;
- PPyNumberMethods200 = ^PyNumberMethods200;
-
- PyNumberMethods300 = {$IFNDEF CPUX64}packed{$ENDIF} record
+ PyNumberMethods = {$IFNDEF CPUX64}packed{$ENDIF} record
nb_add : binaryfunc;
nb_subtract : binaryfunc;
nb_multiply : binaryfunc;
@@ -535,19 +401,19 @@ TPythonVersionProp = record
nb_matrix_multiply : binaryfunc; // new in python 3.5
nb_inplace_matrix_multiply : binaryfunc; // new in python 3.5
end;
- PPyNumberMethods300 = ^PyNumberMethods300;
+ PPyNumberMethods = ^PyNumberMethods;
PySequenceMethods = {$IFNDEF CPUX64}packed{$ENDIF} record
sq_length : lenfunc;
sq_concat : binaryfunc;
sq_repeat : ssizeargfunc;
sq_item : ssizeargfunc;
- sq_slice : ssizessizeargfunc; // empty slot in python 3.x
+ was_sq_slice : Pointer; // empty slot in python 3.x
sq_ass_item : ssizeobjargproc;
- sq_ass_slice : ssizessizeobjargproc; // empty slot in python 3.x
- sq_contains : objobjproc;
- sq_inplace_concat : binaryfunc;
- sq_inplace_repeat : ssizeargfunc;
+ was_sq_ass_slice : Pointer; // empty slot in python 3.x
+ sq_contains : objobjproc;
+ sq_inplace_concat : binaryfunc;
+ sq_inplace_repeat : ssizeargfunc;
end;
PPySequenceMethods = ^PySequenceMethods;
@@ -558,16 +424,6 @@ TPythonVersionProp = record
end;
PPyMappingMethods = ^PyMappingMethods;
- // PyBufferProcs has changed drastiacally in Python 3.0 but since
- // it is currently not implemented it does not matter
- PyBufferProcs = {$IFNDEF CPUX64}packed{$ENDIF} record
- bf_getreadbuffer : getreadbufferproc;
- bf_getwritebuffer : getwritebufferproc;
- bf_getsegcount : getsegcountproc;
- bf_getcharbuffer : getcharbufferproc;
- end;
- PPyBufferProcs = ^PyBufferProcs;
-
Py_complex = {$IFNDEF CPUX64}packed{$ENDIF} record
real : double;
imag : double;
@@ -740,21 +596,21 @@ TPythonVersionProp = record
ob_refcnt: NativeInt;
ob_type: PPyTypeObject;
ob_size: NativeInt; // Number of items in variable part
- tp_name: PAnsiChar; // For printing
+ tp_name: PAnsiChar; // For printing
tp_basicsize, tp_itemsize: NativeInt; // For allocation
// Methods to implement standard operations
- tp_dealloc: pydestructor;
- tp_print: printfunc; // not available and replaced in Python 3.x
- tp_getattr: getattrfunc;
- tp_setattr: setattrfunc;
- tp_compare: cmpfunc; // not available and replaced in Python 3.x
- tp_repr: reprfunc;
+ tp_dealloc: pydestructor;
+ tp_vectorcall_offset: NativeInt;
+ tp_getattr: getattrfunc;
+ tp_setattr: setattrfunc;
+ tp_as_async: Pointer; // not implemented
+ tp_repr: reprfunc;
// Method suites for standard classes
- tp_as_number: Pointer; //PPyNumberMethods
+ tp_as_number: PPyNumberMethods;
tp_as_sequence: PPySequenceMethods;
tp_as_mapping: PPyMappingMethods;
@@ -767,7 +623,7 @@ TPythonVersionProp = record
tp_setattro: setattrofunc;
// Functions to access object as input/output buffer
- tp_as_buffer: PPyBufferProcs;
+ tp_as_buffer: Pointer; // PPyBufferProcs - not implemented
// Flags to define presence of optional/expanded features
tp_flags: LongInt;
@@ -810,6 +666,7 @@ TPythonVersionProp = record
tp_del : PyDestructor;
tp_version_tag : Cardinal; // Type attribute cache version tag. Added in version 2.6
tp_finalize : PyDestructor;
+ tp_vectorcall : Pointer; // not implemented
//More spares
tp_xxx1 : NativeInt;
tp_xxx2 : NativeInt;
@@ -823,212 +680,12 @@ TPythonVersionProp = record
tp_xxx10 : NativeInt;
end;
- PPyMethodChain = ^PyMethodChain;
- PyMethodChain = {$IFNDEF CPUX64}packed{$ENDIF} record
- methods: PPyMethodDef;
- link: PPyMethodChain;
- end;
-
- PPyClassObject = ^PyClassObject;
- PyClassObject = {$IFNDEF CPUX64}packed{$ENDIF} record
- // Start of the Head of an object
- ob_refcnt : NativeInt;
- ob_type : PPyTypeObject;
- // End of the Head of an object
- cl_bases : PPyObject; // A tuple of class objects
- cl_dict : PPyObject; // A dictionary
- cl_name : PPyObject; // A string
- // The following three are functions or NULL
- cl_getattr : PPyObject;
- cl_setattr : PPyObject;
- cl_delattr : PPyObject;
- end;
-
- PPyInstanceObject = ^PyInstanceObject;
- PyInstanceObject = {$IFNDEF CPUX64}packed{$ENDIF} record
- // Start of the Head of an object
- ob_refcnt : NativeInt;
- ob_type : PPyTypeObject;
- // End of the Head of an object
- in_class : PPyClassObject; // The class object
- in_dict : PPyObject; // A dictionary
- end;
-
-{ Instance method objects are used for two purposes:
- (a) as bound instance methods (returned by instancename.methodname)
- (b) as unbound methods (returned by ClassName.methodname)
- In case (b), im_self is NULL
-}
-
- PPyMethodObject = ^PyMethodObject;
- PyMethodObject = {$IFNDEF CPUX64}packed{$ENDIF} record
- // Start of the Head of an object
- ob_refcnt : NativeInt;
- ob_type : PPyTypeObject;
- // End of the Head of an object
- im_func : PPyObject; // The function implementing the method
- im_self : PPyObject; // The instance it is bound to, or NULL
- im_class : PPyObject; // The class that defined the method
- end;
-
-
- // Bytecode object, compile.h
- PPyCodeObject = ^PyCodeObject;
- PyCodeObject = {$IFNDEF CPUX64}packed{$ENDIF} record
- ob_refcnt : NativeInt;
- ob_type : PPyTypeObject;
- co_argcount : Integer; // #arguments, except *args
- co_nlocals : Integer; // #local variables
- co_stacksize : Integer; // #entries needed for evaluation stack
- co_flags : Integer; // CO_..., see below
- co_code : PPyObject; // instruction opcodes (it hides a PyStringObject)
- co_consts : PPyObject; // list (constants used)
- co_names : PPyObject; // list of strings (names used)
- co_varnames : PPyObject; // tuple of strings (local variable names)
- co_freevars : PPyObject; // tuple of strings (free variable names)
- co_cellvars : PPyObject; // tuple of strings (cell variable names)
- // The rest doesn't count for hash/cmp
- co_filename : PPyObject; // string (where it was loaded from)
- co_name : PPyObject; // string (name, for reference)
- co_firstlineno : Integer; // first source line number
- co_lnotab : PPyObject; // string (encoding addr<->lineno mapping)
- end;
-
-
// from pystate.h
- PPyInterpreterState = ^PyInterpreterState;
- PPyThreadState = ^PyThreadState;
- PPyFrameObject = ^PyFrameObject;
-
- // Interpreter environments
- PyInterpreterState = {$IFNDEF CPUX64}packed{$ENDIF} record
- next : PPyInterpreterState;
- tstate_head : PPyThreadState;
-
-// The strucure has changed between versions beyond this point.
-// Not safe to use members
-// modules : PPyObject;
-// sysdict : PPyObject;
-// builtins : PPyObject;
-
- //Spares
- is_xxx1 : NativeInt;
- is_xxx2 : NativeInt;
- is_xxx3 : NativeInt;
- is_xxx4 : NativeInt;
- is_xxx5 : NativeInt;
- is_xxx6 : NativeInt;
- is_xxx7 : NativeInt;
- is_xxx8 : NativeInt;
- is_xxx9 : NativeInt;
- end;
-
- // Thread specific information
- PyThreadState = {$IFNDEF CPUX64}packed{$ENDIF} record
- {prev : PPyThreadState; introduced in python 3.4}
- next : PPyThreadState;
- interp : PPyInterpreterState;
- interp34 : PPyInterpreterState;
-
-// The strucure has changed between versions beyond this point.
-// Not safe to use members
-//
-// frame : PPyFrameObject;
-// recursion_depth: integer;
-// ticker : integer;
-// tracing : integer;
-//
-// sys_profilefn : Pointer; // c-functions for profile/trace
-// sys_tracefn : Pointer;
-// sys_profilefunc: PPyObject;
-// sys_tracefunc : PPyObject;
-//
-// curexc_type : PPyObject;
-// curexc_value : PPyObject;
-// curexc_traceback: PPyObject;
-//
-// exc_type : PPyObject;
-// exc_value : PPyObject;
-// exc_traceback : PPyObject;
-//
-// dict : PPyObject;
-// tick_counter :Integer;
-// gilstate_counter :Integer;
-//
-// async_exc :PPyObject; { Asynchronous exception to raise }
-// thread_id :LongInt; { Thread id where this tstate was created }
- //Spares
- ts_xxx1 : NativeInt;
- ts_xxx2 : NativeInt;
- ts_xxx3 : NativeInt;
- ts_xxx4 : NativeInt;
- ts_xxx5 : NativeInt;
- ts_xxx6 : NativeInt;
- ts_xxx7 : NativeInt;
- ts_xxx8 : NativeInt;
- ts_xxx9 : NativeInt;
- ts_xxx10 : NativeInt;
- ts_xxx11 : NativeInt;
- ts_xxx12 : NativeInt;
- ts_xxx13 : NativeInt;
- ts_xxx14 : NativeInt;
- ts_xxx15 : NativeInt;
- ts_xxx16 : NativeInt;
- ts_xxx17 : NativeInt;
- ts_xxx18 : NativeInt;
- ts_xxx19 : NativeInt;
-
- { XXX signal handlers should also be here }
- end;
-
- // from frameobject.h
-
- PPyTryBlock = ^PyTryBlock;
- PyTryBlock = {$IFNDEF CPUX64}packed{$ENDIF} record
- b_type : Integer; // what kind of block this is
- b_handler : Integer; // where to jump to find handler
- b_level : Integer; // value stack level to pop to
- end;
-
- CO_MAXBLOCKS = 0..19;
- PyFrameObject = {$IFNDEF CPUX64}packed{$ENDIF} record
- // Start of the VAR_HEAD of an object.
- ob_refcnt : NativeInt;
- ob_type : PPyTypeObject;
- ob_size : NativeInt; // Number of items in variable part
- // End of the Head of an object
- f_back : PPyFrameObject; // previous frame, or NULL
- f_code : PPyCodeObject; // code segment
- f_builtins : PPyObject; // builtin symbol table (PyDictObject)
- f_globals : PPyObject; // global symbol table (PyDictObject)
- f_locals : PPyObject; // local symbol table (PyDictObject)
- f_valuestack : PPPyObject; // points after the last local
- (* Next free slot in f_valuestack. Frame creation sets to f_valuestack.
- Frame evaluation usually NULLs it, but a frame that yields sets it
- to the current stack top. *)
- f_stacktop : PPPyObject;
- f_trace : PPyObject; // Trace function
- f_exc_type, f_exc_value, f_exc_traceback: PPyObject;
- f_tstate : PPyThreadState;
- f_lasti : Integer; // Last instruction if called
- f_lineno : Integer; // Current line number
- f_iblock : Integer; // index in f_blockstack
- f_blockstack : array[CO_MAXBLOCKS] of PyTryBlock; // for try and loop blocks
- f_localsplus : array[0..0] of PPyObject; // locals+stack, dynamically sized
- end;
-
- // From traceback.c
- PPyTraceBackObject = ^PyTraceBackObject;
- PyTraceBackObject = {$IFNDEF CPUX64}packed{$ENDIF} record
- // Start of the Head of an object
- ob_refcnt : NativeInt;
- ob_type : PPyTypeObject;
- // End of the Head of an object
- tb_next : PPyTraceBackObject;
- tb_frame : PPyFrameObject;
- tb_lasti : Integer;
- tb_lineno : Integer;
- end;
+ // the structure of PyInterpreterState and PyThreadState is considered
+ // an implementation detail. It has been changing between python versions
+ // and there is no real use of accessing these structures directly.
+ PPyInterpreterState = Pointer;
+ PPyThreadState = Pointer;
// Parse tree node interface
@@ -1045,21 +702,7 @@ TPythonVersionProp = record
PPyCompilerFlags = ^PyCompilerFlags;
PyCompilerFlags = {$IFNDEF CPUX64}packed{$ENDIF} record
flags : integer;
- end;
-
- // From weakrefobject.h
-
- PPyWeakReference = ^PyWeakReference;
- PyWeakReference = {$IFNDEF CPUX64}packed{$ENDIF} record
- // Start of the Head of an object
- ob_refcnt : NativeInt;
- ob_type : PPyTypeObject;
- // End of the Head of an object
- wr_object : PPyObject;
- wr_callback : PPyObject;
- hash : NativeInt;
- wr_prev : PPyWeakReference;
- wr_next : PPyWeakReference;
+ cf_feature_version : integer; //added in Python 3.8
end;
// from datetime.h
@@ -1354,8 +997,8 @@ EPyRuntimeError = class (EPyStandardError);
EPyNotImplementedError = class (EPyRuntimeError);
EPySyntaxError = class (EPyStandardError)
public
- EFileName: string;
- ELineStr: string;
+ EFileName: UnicodeString;
+ ELineStr: UnicodeString;
ELineNumber: Integer;
EOffset: Integer;
end;
@@ -1536,21 +1179,9 @@ TDynamicDll = class(TComponent)
type
TPythonInterface=class(TDynamicDll)
- private
- DLL_Py_GetBuildInfo:
- function : PAnsiChar; cdecl;
- DLL_PyCode_Addr2Line:
- function ( co: PPyCodeObject; addrq : Integer ) : Integer; cdecl;
- DLL_PyImport_ExecCodeModule:
- function ( const name : AnsiString; codeobject : PPyObject) : PPyObject; cdecl;
-
- DLL_PyString_FromString: function( str: PAnsiChar): PPyObject; cdecl;
- DLL_Py_FlushLine:procedure; cdecl;
-
protected
FInitialized: Boolean;
FFinalizing: Boolean;
- FIsPython3000: Boolean;
FMajorVersion: integer;
FMinorVersion: integer;
FBuiltInModuleName: string;
@@ -1567,10 +1198,7 @@ TPythonInterface=class(TDynamicDll)
Py_InteractiveFlag: PInteger;
Py_OptimizeFlag: PInteger;
Py_NoSiteFlag: PInteger;
- Py_UseClassExceptionsFlag: PInteger;
Py_FrozenFlag: PInteger;
- Py_TabcheckFlag: PInteger;
- Py_UnicodeFlag: PInteger;
Py_IgnoreEnvironmentFlag: PInteger;
Py_DivisionWarningFlag: PInteger;
//_PySys_TraceFunc: PPPyObject;
@@ -1605,11 +1233,9 @@ TPythonInterface=class(TDynamicDll)
PyExc_Exception: PPPyObject;
PyExc_FloatingPointError: PPPyObject;
PyExc_LookupError: PPPyObject;
- PyExc_StandardError: PPPyObject;
PyExc_AssertionError: PPPyObject;
PyExc_EnvironmentError: PPPyObject;
PyExc_IndentationError: PPPyObject;
- PyExc_MemoryErrorInst: PPPyObject;
PyExc_NotImplementedError: PPPyObject;
PyExc_OSError: PPPyObject;
PyExc_TabError: PPPyObject;
@@ -1631,19 +1257,14 @@ TPythonInterface=class(TDynamicDll)
PyExc_UnicodeEncodeError: PPPyObject;
PyExc_UnicodeTranslateError: PPPyObject;
+ PyCode_Type: PPyTypeObject;
PyType_Type: PPyTypeObject;
PyCFunction_Type: PPyTypeObject;
- PyCObject_Type: PPyTypeObject;
- PyClass_Type: PPyTypeObject;
- PyCode_Type: PPyTypeObject;
PyComplex_Type: PPyTypeObject;
PyDict_Type: PPyTypeObject;
- PyFile_Type: PPyTypeObject;
PyFloat_Type: PPyTypeObject;
PyFrame_Type: PPyTypeObject;
PyFunction_Type: PPyTypeObject;
- PyInstance_Type: PPyTypeObject;
- PyInt_Type: PPyTypeObject;
PyList_Type: PPyTypeObject;
PyLong_Type: PPyTypeObject;
PyMethod_Type: PPyTypeObject;
@@ -1651,10 +1272,9 @@ TPythonInterface=class(TDynamicDll)
PyObject_Type: PPyTypeObject;
PyRange_Type: PPyTypeObject;
PySlice_Type: PPyTypeObject;
- PyString_Type: PPyTypeObject;
+ PyBytes_Type: PPyTypeObject;
PyTuple_Type: PPyTypeObject;
PyBaseObject_Type: PPyTypeObject;
- PyBuffer_Type: PPyTypeObject;
PyCallIter_Type: PPyTypeObject;
PyCell_Type: PPyTypeObject;
PyClassMethod_Type: PPyTypeObject;
@@ -1668,10 +1288,11 @@ TPythonInterface=class(TDynamicDll)
_PyWeakref_RefType: PPyTypeObject;
_PyWeakref_ProxyType: PPyTypeObject;
_PyWeakref_CallableProxyType: PPyTypeObject;
- PyBaseString_Type: PPyTypeObject;
PyBool_Type: PPyTypeObject;
PyEnum_Type: PPyTypeObject;
+ Py_GetBuildInfo: function : PAnsiChar; cdecl;
+ PyImport_ExecCodeModule: function ( const name : AnsiString; codeobject : PPyObject) : PPyObject; cdecl;
PyComplex_FromCComplex: function(c: Py_complex):PPyObject; cdecl;
PyComplex_FromDoubles: function(realv,imag : double):PPyObject; cdecl;
PyComplex_RealAsDouble: function(op : PPyObject ): double; cdecl;
@@ -1680,13 +1301,7 @@ TPythonInterface=class(TDynamicDll)
PyCFunction_GetFunction: function(ob : PPyObject): Pointer; cdecl;
PyCFunction_GetSelf: function(ob : PPyObject): PPyObject; cdecl;
PyCallable_Check: function(ob : PPyObject): integer; cdecl;
- PyCObject_FromVoidPtr: function(cobj, destruct : Pointer): PPyObject; cdecl;
- PyCObject_AsVoidPtr: function(ob : PPyObject): Pointer; cdecl;
- PyClass_New: function (ob1,ob2,ob3 : PPyObject): PPyObject; cdecl;
- PyClass_IsSubclass: function (ob1, ob2 : PPyObject): integer cdecl;
- Py_InitModule4: function( name: PAnsiChar; methods: PPyMethodDef; doc: PAnsiChar;
- passthrough: PPyObject; Api_Version: Integer):PPyObject; cdecl;
PyModule_Create2: function(moduledef: PPyModuleDef; Api_Version: Integer):PPyObject; cdecl;
PyErr_BadArgument: function: integer; cdecl;
PyErr_BadInternalCall: procedure; cdecl;
@@ -1704,7 +1319,6 @@ TPythonInterface=class(TDynamicDll)
PyErr_WarnEx: function (ob: PPyObject; text: PAnsiChar; stack_level: NativeInt): integer; cdecl;
PyErr_WarnExplicit: function (ob: PPyObject; text: PAnsiChar; filename: PAnsiChar; lineno: integer; module: PAnsiChar; registry: PPyObject): integer; cdecl;
PyImport_GetModuleDict: function: PPyObject; cdecl;
- PyInt_FromLong: function( x: LongInt):PPyObject; cdecl;
PyArg_Parse: function( args: PPyObject; format: PAnsiChar {;....}) : Integer; cdecl varargs;
PyArg_ParseTuple: function( args: PPyObject; format: PAnsiChar {;...}): Integer; cdecl varargs;
PyArg_ParseTupleAndKeywords: function( args: PPyObject; kw: PPyObject; format: PAnsiChar; kwargs: PPAnsiChar {;...}): Integer; cdecl varargs;
@@ -1733,12 +1347,10 @@ TPythonInterface=class(TDynamicDll)
PyRun_String: function( str: PAnsiChar; start: Integer; globals: PPyObject;
locals: PPyObject): PPyObject; cdecl;
PyRun_SimpleString: function( str: PAnsiChar): Integer; cdecl;
- PyString_AsString: function( ob: PPyObject): PAnsiChar; cdecl;
- PyString_AsStringAndSize: function( ob: PPyObject; var buffer: PAnsiChar; var size: NativeInt): integer; cdecl;
- PySys_SetArgv: procedure( argc: Integer; argv: PPAnsiChar); cdecl;
- PySys_SetArgv3000: procedure( argc: Integer; argv: PPWideChar); cdecl;
+ PyBytes_AsString: function( ob: PPyObject): PAnsiChar; cdecl;
+ PyBytes_AsStringAndSize: function( ob: PPyObject; var buffer: PAnsiChar; var size: NativeInt): integer; cdecl;
+ PySys_SetArgv: procedure( argc: Integer; argv: PPWideChar); cdecl;
- PyCFunction_New: function(md:PPyMethodDef;ob:PPyObject):PPyObject; cdecl;
PyCFunction_NewEx: function(md:PPyMethodDef;self, ob:PPyObject):PPyObject; cdecl;
// Removed. Use PyEval_CallObjectWithKeywords with third argument nil
// PyEval_CallObject: function(callable_obj, args:PPyObject):PPyObject; cdecl;
@@ -1746,18 +1358,12 @@ TPythonInterface=class(TDynamicDll)
PyEval_GetFrame:function :PPyObject; cdecl;
PyEval_GetGlobals:function :PPyObject; cdecl;
PyEval_GetLocals:function :PPyObject; cdecl;
- //PyEval_GetOwner:function :PPyObject; cdecl;
- PyEval_GetRestricted:function :integer; cdecl;
PyEval_InitThreads:procedure; cdecl;
PyEval_RestoreThread:procedure( tstate: PPyThreadState); cdecl;
PyEval_SaveThread:function :PPyThreadState; cdecl;
- PyFile_FromString:function (pc1,pc2:PAnsiChar):PPyObject; cdecl;
PyFile_GetLine:function (ob:PPyObject;i:integer):PPyObject; cdecl;
- PyFile_Name:function (ob:PPyObject):PPyObject; cdecl;
- PyFile_SetBufSize:procedure(ob:PPyObject;i:integer); cdecl;
- PyFile_SoftSpace:function (ob:PPyObject;i:integer):integer; cdecl;
PyFile_WriteObject:function (ob1,ob2:PPyObject;i:integer):integer; cdecl;
PyFile_WriteString:procedure(s:PAnsiChar;ob:PPyObject); cdecl;
PyFloat_AsDouble:function (ob:PPyObject):DOUBLE; cdecl;
@@ -1770,10 +1376,7 @@ TPythonInterface=class(TDynamicDll)
PyImport_ImportFrozenModule:function (key:PAnsiChar):integer; cdecl;
PyImport_ImportModule:function (name:PAnsiChar):PPyObject; cdecl;
PyImport_Import:function (name:PPyObject):PPyObject; cdecl;
- //PyImport_Init:procedure; cdecl;
PyImport_ReloadModule:function (ob:PPyObject):PPyObject; cdecl;
- PyInstance_New:function (obClass, obArg, obKW:PPyObject):PPyObject; cdecl;
- PyInt_AsLong:function (ob:PPyObject):LongInt; cdecl;
PyList_Append:function (ob1,ob2:PPyObject):integer; cdecl;
PyList_AsTuple:function (ob:PPyObject):PPyObject; cdecl;
PyList_GetItem:function (ob:PPyObject;i:NativeInt):PPyObject; cdecl;
@@ -1802,7 +1405,6 @@ TPythonInterface=class(TDynamicDll)
PyMapping_HasKeyString:function (ob:PPyObject;key:PAnsiChar):integer; cdecl;
PyMapping_Length:function (ob:PPyObject):NativeInt; cdecl;
PyMapping_SetItemString:function (ob:PPyObject; key:PAnsiChar; value:PPyObject):integer; cdecl;
- PyMethod_Class:function (ob:PPyObject):PPyObject; cdecl;
PyMethod_Function:function (ob:PPyObject):PPyObject; cdecl;
PyMethod_New:function (ob1,ob2,ob3:PPyObject):PPyObject; cdecl;
PyMethod_Self:function (ob:PPyObject):PPyObject; cdecl;
@@ -1812,13 +1414,10 @@ TPythonInterface=class(TDynamicDll)
PyNumber_Add:function (ob1,ob2:PPyObject):PPyObject; cdecl;
PyNumber_And:function (ob1,ob2:PPyObject):PPyObject; cdecl;
PyNumber_Check:function (ob:PPyObject):integer; cdecl;
- PyNumber_Coerce:function (var ob1,ob2:PPyObject):integer; cdecl;
- PyNumber_Divide:function (ob1,ob2:PPyObject):PPyObject; cdecl;
PyNumber_FloorDivide:function (ob1,ob2:PPyObject):PPyObject; cdecl;
PyNumber_TrueDivide:function (ob1,ob2:PPyObject):PPyObject; cdecl;
PyNumber_Divmod:function (ob1,ob2:PPyObject):PPyObject; cdecl;
PyNumber_Float:function (ob:PPyObject):PPyObject; cdecl;
- PyNumber_Int:function (ob:PPyObject):PPyObject; cdecl;
PyNumber_Invert:function (ob:PPyObject):PPyObject; cdecl;
PyNumber_Long:function (ob:PPyObject):PPyObject; cdecl;
PyNumber_Lshift:function (ob1,ob2:PPyObject):PPyObject; cdecl;
@@ -1835,7 +1434,6 @@ TPythonInterface=class(TDynamicDll)
PyOS_InterruptOccurred:function :integer; cdecl;
PyObject_CallObject:function (ob,args:PPyObject):PPyObject; cdecl;
PyObject_CallMethod : function ( obj : PPyObject; method, format : PAnsiChar {...}) : PPyObject; cdecl varargs;
- PyObject_Compare: function (ob1,ob2:PPyObject):integer; cdecl;
PyObject_RichCompare:function (ob1,ob2:PPyObject;opid:integer):PPyObject; cdecl;
PyObject_RichCompareBool:function (ob1,ob2:PPyObject;opid:integer):Integer; cdecl;
PyObject_GetAttr:function (ob1,ob2:PPyObject):PPyObject; cdecl;
@@ -1856,6 +1454,7 @@ TPythonInterface=class(TDynamicDll)
PyObject_NewVar:function (t:PPyTypeObject; size:NativeInt):PPyObject; cdecl;
PyObject_Free:procedure (ob:PPyObject); cdecl;
PyObject_GetIter: function (obj: PPyObject) : PPyObject; cdecl;
+ PyIter_Check: function ( obj : PPyObject ) : Boolean;
PyIter_Next: function (obj: PPyObject) : PPyObject; cdecl;
PyObject_IsInstance:function (inst, cls:PPyObject):integer; cdecl;
PyObject_IsSubclass:function (derived, cls:PPyObject):integer; cdecl;
@@ -1887,21 +1486,18 @@ TPythonInterface=class(TDynamicDll)
PySlice_GetIndices:function (ob:PPySliceObject;length:NativeInt;var start,stop,step:NativeInt):integer; cdecl;
PySlice_GetIndicesEx:function (ob:PPySliceObject;length:NativeInt;var start,stop,step,slicelength:NativeInt):integer; cdecl;
PySlice_New:function (start,stop,step:PPyObject):PPyObject; cdecl;
- PyString_Concat:procedure(var ob1:PPyObject;ob2:PPyObject); cdecl;
- PyString_ConcatAndDel:procedure(var ob1:PPyObject;ob2:PPyObject); cdecl;
- PyString_Format:function (ob1,ob2:PPyObject):PPyObject; cdecl;
- PyString_FromStringAndSize:function (s:PAnsiChar;i:NativeInt):PPyObject; cdecl;
- PyString_Size:function (ob:PPyObject):NativeInt; cdecl;
- PyString_DecodeEscape:function(s:PAnsiChar; len:NativeInt; errors:PAnsiChar; unicode:NativeInt; recode_encoding:PAnsiChar):PPyObject; cdecl;
- PyString_Repr:function(ob:PPyObject; smartquotes:integer):PPyObject; cdecl;
+ PyBytes_Concat:procedure(var ob1:PPyObject;ob2:PPyObject); cdecl;
+ PyBytes_ConcatAndDel:procedure(var ob1:PPyObject;ob2:PPyObject); cdecl;
+ PyBytes_FromString:function (s:PAnsiChar):PPyObject; cdecl;
+ PyBytes_FromStringAndSize:function (s:PAnsiChar;i:NativeInt):PPyObject; cdecl;
+ PyBytes_Size:function (ob:PPyObject):NativeInt; cdecl;
+ PyBytes_DecodeEscape:function(s:PAnsiChar; len:NativeInt; errors:PAnsiChar; unicode:NativeInt; recode_encoding:PAnsiChar):PPyObject; cdecl;
+ PyBytes_Repr:function(ob:PPyObject; smartquotes:integer):PPyObject; cdecl;
PySys_GetObject:function (s:PAnsiChar):PPyObject; cdecl;
- //PySys_Init:procedure; cdecl;
PySys_SetObject:function (s:PAnsiChar;ob:PPyObject):integer; cdecl;
PySys_SetPath:procedure(path:PAnsiChar); cdecl;
- //PyTraceBack_Fetch:function :PPyObject; cdecl;
PyTraceBack_Here:function (p:pointer):integer; cdecl;
PyTraceBack_Print:function (ob1,ob2:PPyObject):integer; cdecl;
- //PyTraceBack_Store:function (ob:PPyObject):integer; cdecl;
PyTuple_GetItem:function (ob:PPyObject;i:NativeInt):PPyObject; cdecl;
PyTuple_GetSlice:function (ob:PPyObject;i1,i2:NativeInt):PPyObject; cdecl;
PyTuple_New:function (size:NativeInt):PPyObject; cdecl;
@@ -1926,26 +1522,20 @@ TPythonInterface=class(TDynamicDll)
PyBool_FromLong: function ( ok : Integer) : PPyObject; cdecl;
PyThreadState_SetAsyncExc: function(t_id :LongInt; exc :PPyObject) : Integer; cdecl;
Py_AtExit:function (proc: AtExitProc):integer; cdecl;
- //Py_Cleanup:procedure; cdecl;
- Py_CompileStringFlags:function (s1,s2:PAnsiChar;i:integer;flags:PPyCompilerFlags):PPyObject; cdecl;
Py_CompileStringExFlags:function (s1,s2:PAnsiChar;i:integer;flags:PPyCompilerFlags;optimize:integer):PPyObject; cdecl;
Py_FatalError:procedure(s:PAnsiChar); cdecl;
- Py_FindMethod:function (md:PPyMethodDef;ob:PPyObject;key:PAnsiChar):PPyObject; cdecl;
- Py_FindMethodInChain:function (mc:PPyMethodChain;ob:PPyObject;key:PAnsiChar):PPyObject; cdecl;
_PyObject_New:function (obt:PPyTypeObject;ob:PPyObject):PPyObject; cdecl;
- _PyString_Resize:function (var ob:PPyObject;i:NativeInt):integer; cdecl;
+ _PyBytes_Resize:function (var ob:PPyObject;i:NativeInt):integer; cdecl;
Py_Finalize : procedure; cdecl;
PyErr_ExceptionMatches : function ( exc : PPyObject) : Integer; cdecl;
PyErr_GivenExceptionMatches : function ( raised_exc, exc : PPyObject) : Integer; cdecl;
- PyEval_EvalCode : function ( co : PPyCodeObject; globals, locals : PPyObject) : PPyObject; cdecl;
+ PyEval_EvalCode : function ( co : PPyObject; globals, locals : PPyObject) : PPyObject; cdecl;
Py_GetVersion : function : PAnsiChar; cdecl;
Py_GetCopyright : function : PAnsiChar; cdecl;
Py_GetExecPrefix : function : PAnsiChar; cdecl;
Py_GetPath : function : PAnsiChar; cdecl;
- Py_SetPythonHome : procedure (home : PAnsiChar); cdecl;
- Py_GetPythonHome : function : PAnsiChar; cdecl;
- Py_SetPythonHome3000 : procedure (home : PWideChar); cdecl;
- Py_GetPythonHome3000 : function : PWideChar; cdecl;
+ Py_SetPythonHome : procedure (home : PWideChar); cdecl;
+ Py_GetPythonHome : function : PWideChar; cdecl;
Py_GetPrefix : function : PAnsiChar; cdecl;
Py_GetProgramName : function : PAnsiChar; cdecl;
@@ -1955,8 +1545,7 @@ TPythonInterface=class(TDynamicDll)
PyMem_Malloc : function ( size : NativeInt ) : Pointer;
{New exported Objects in Python 1.5}
- Py_SetProgramName : procedure( name: PAnsiChar); cdecl;
- Py_SetProgramName3000 : procedure( name: PWideChar); cdecl;
+ Py_SetProgramName : procedure( name: PWideChar); cdecl;
Py_IsInitialized : function : integer; cdecl;
Py_GetProgramFullPath : function : PAnsiChar; cdecl;
Py_NewInterpreter : function : PPyThreadState; cdecl;
@@ -1976,70 +1565,11 @@ TPythonInterface=class(TDynamicDll)
PyErr_SetInterrupt : procedure; cdecl;
PyGILState_Ensure : function() : PyGILstate_STATE; cdecl;
PyGILState_Release : procedure(gilstate : PyGILState_STATE); cdecl;
-{Further exported Objects, may be implemented later}
-{
- PyCode_New: Pointer;
- PyFile_AsFile: Pointer;
- PyFile_FromFile: Pointer;
- PyFloat_AsString: Pointer;
- PyFrame_BlockPop: Pointer;
- PyFrame_BlockSetup: Pointer;
- PyFrame_ExtendStack: Pointer;
- PyFrame_FastToLocals: Pointer;
- PyFrame_LocalsToFast: Pointer;
- PyFrame_New: Pointer;
- PyGrammar_AddAccelerators: Pointer;
- PyGrammar_FindDFA: Pointer;
- PyGrammar_LabelRepr: Pointer;
- PyInstance_DoBinOp: Pointer;
- PyInt_GetMax: Pointer;
- PyMarshal_Init: Pointer;
- PyMarshal_ReadLongFromFile: Pointer;
- PyMarshal_ReadObjectFromFile: Pointer;
- PyMarshal_ReadObjectFromString: Pointer;
- PyMarshal_WriteLongToFile: Pointer;
- PyMarshal_WriteObjectToFile: Pointer;
- PyMember_Get: Pointer;
- PyMember_Set: Pointer;
- PyNode_AddChild: Pointer;
- PyNode_Compile: Pointer;
- PyNode_New: Pointer;
- PyOS_GetLastModificationTime: Pointer;
- PyOS_Readline: Pointer;
- PyOS_strtol: Pointer;
- PyOS_strtoul: Pointer;
- PyObject_CallFunction: Pointer;
- PyObject_Print: Pointer;
- PyParser_AddToken: Pointer;
- PyParser_Delete: Pointer;
- PyParser_New: Pointer;
- PyParser_ParseFile: Pointer;
- PyParser_ParseString: Pointer;
- PyParser_SimpleParseFile: Pointer;
- PyRun_AnyFile: Pointer;
- PyRun_File: Pointer;
- PyRun_InteractiveLoop: Pointer;
- PyRun_InteractiveOne: Pointer;
- PyRun_SimpleFile: Pointer;
- PySys_GetFile: Pointer;
- PyToken_OneChar: Pointer;
- PyToken_TwoChars: Pointer;
- PyTokenizer_Free: Pointer;
- PyTokenizer_FromFile: Pointer;
- PyTokenizer_FromString: Pointer;
- PyTokenizer_Get: Pointer;
- Py_Main: Pointer;
- _PyParser_Grammar: Pointer;
- _PyParser_TokenNames: Pointer;
- _PyThread_Started: Pointer;
- _Py_c_diff: Pointer;
- _Py_c_neg: Pointer;
- _Py_c_pow: Pointer;
- _Py_c_prod: Pointer;
- _Py_c_quot: Pointer;
- _Py_c_sum: Pointer;
-}
- // Not exported in Python 3.8 and implemented as functions
+
+ // Not exported in Python 3.8 and implemented as functions - this has been fixed
+ // TODO - deal with the following:
+ // the PyParser_* functions are deprecated in python 3.9 and will be removed in
+ // Python 3.10
function PyParser_SimpleParseString( str : PAnsiChar; start : Integer) : PNode; cdecl;
function Py_CompileString( s1,s2:PAnsiChar;i:integer) : PPyObject; cdecl;
@@ -2049,20 +1579,14 @@ TPythonInterface=class(TDynamicDll)
procedure Py_XINCREF ( op: PPyObject);
procedure Py_XDECREF ( op: PPyObject);
- function PyCode_Addr2Line( co: PPyCodeObject; addrq : Integer ) : Integer; cdecl;
- function Py_GetBuildInfo: PAnsiChar; cdecl;
- function PyImport_ExecCodeModule( const AName : AnsiString; codeobject : PPyObject) : PPyObject;
- function PyString_Check( obj : PPyObject ) : Boolean;
- function PyString_CheckExact( obj : PPyObject ) : Boolean;
+ function PyBytes_Check( obj : PPyObject ) : Boolean;
+ function PyBytes_CheckExact( obj : PPyObject ) : Boolean;
function PyFloat_Check( obj : PPyObject ) : Boolean;
function PyFloat_CheckExact( obj : PPyObject ) : Boolean;
- function PyInt_Check( obj : PPyObject ) : Boolean;
- function PyInt_CheckExact( obj : PPyObject ) : Boolean;
function PyLong_Check( obj : PPyObject ) : Boolean;
function PyLong_CheckExact( obj : PPyObject ) : Boolean;
function PyTuple_Check( obj : PPyObject ) : Boolean;
function PyTuple_CheckExact( obj : PPyObject ) : Boolean;
- function PyInstance_Check( obj : PPyObject ) : Boolean;
function PyClass_Check( obj : PPyObject ) : Boolean;
function PyType_CheckExact( obj : PPyObject ) : Boolean;
function PyMethod_Check( obj : PPyObject ) : Boolean;
@@ -2074,7 +1598,6 @@ TPythonInterface=class(TDynamicDll)
function PyModule_CheckExact( obj : PPyObject ) : Boolean;
function PySlice_Check( obj : PPyObject ) : Boolean;
function PyFunction_Check( obj : PPyObject ) : Boolean;
- function PyIter_Check( obj : PPyObject ) : Boolean;
function PyUnicode_Check( obj : PPyObject ) : Boolean;
function PyUnicode_CheckExact( obj : PPyObject ) : Boolean;
function PyType_IS_GC(t : PPyTypeObject ) : Boolean;
@@ -2083,13 +1606,9 @@ TPythonInterface=class(TDynamicDll)
function PyWeakref_CheckRef( obj : PPyObject ) : Boolean;
function PyWeakref_CheckProxy( obj : PPyObject ) : Boolean;
function PyBool_Check( obj : PPyObject ) : Boolean;
- function PyBaseString_Check( obj : PPyObject ) : Boolean;
function PyEnum_Check( obj : PPyObject ) : Boolean;
function PyObject_TypeCheck(obj:PPyObject; t:PPyTypeObject) : Boolean;
- function Py_InitModule( const AName : PAnsiChar; md : PPyMethodDef) : PPyObject;
- function Py_InitModule3000( const md : PyModuleDef) : PPyObject;
- function PyString_FromString( str: PAnsiChar): PPyObject; virtual; abstract;
- procedure Py_FlushLine; cdecl;
+ function Py_InitModule( const md : PyModuleDef) : PPyObject;
// Constructors & Destructors
constructor Create(AOwner: TComponent); override;
@@ -2100,7 +1619,6 @@ TPythonInterface=class(TDynamicDll)
// Public properties
property Initialized : Boolean read FInitialized;
property Finalizing : Boolean read FFinalizing;
- property IsPython3000 : Boolean read FIsPython3000;
property MajorVersion : integer read FMajorVersion;
property MinorVersion : integer read FMinorVersion;
property BuiltInModuleName: string read FBuiltInModuleName write FBuiltInModuleName;
@@ -2120,8 +1638,8 @@ TPythonInterface=class(TDynamicDll)
TEngineClient = class;
TPathInitializationEvent = procedure ( Sender : TObject; var Path : string ) of Object;
TSysPathInitEvent = procedure ( Sender : TObject; PathList : PPyObject ) of Object;
- TPythonFlag = (pfDebug, pfInteractive, pfNoSite, pfOptimize, pfTabcheck, pfUnicode, pfVerbose,
- pfUseClassExceptionsFlag, pfFrozenFlag, pfIgnoreEnvironmentFlag, pfDivisionWarningFlag);
+ TPythonFlag = (pfDebug, pfInteractive, pfNoSite, pfOptimize, pfVerbose,
+ pfFrozenFlag, pfIgnoreEnvironmentFlag, pfDivisionWarningFlag);
TPythonFlags = set of TPythonFlag;
@@ -2165,10 +1683,8 @@ TPythonEngine = class(TPythonInterface)
FLock: TCriticalSection;
FExecModule: AnsiString;
FAutoFinalize: Boolean;
- FProgramName: AnsiString;
- FProgramNameW: UnicodeString;
- FPythonHome: AnsiString;
- FPythonHomeW: UnicodeString;
+ FProgramName: UnicodeString;
+ FPythonHome: UnicodeString;
FInitThreads: Boolean;
FOnPathInitialization: TPathInitializationEvent;
FOnSysPathInit: TSysPathInitEvent;
@@ -2195,7 +1711,6 @@ TPythonEngine = class(TPythonInterface)
procedure DoOpenDll(const aDllName : string); override;
procedure SetInitScript(Value: TStrings);
function GetThreadState: PPyThreadState;
- function GetInterpreterState: PPyInterpreterState;
procedure SetInitThreads(Value: Boolean);
function GetClientCount : Integer;
function GetClients( idx : Integer ) : TEngineClient;
@@ -2223,7 +1738,6 @@ TPythonEngine = class(TPythonInterface)
procedure SetPythonHome(const PythonHome: UnicodeString);
procedure SetProgramName(const ProgramName: UnicodeString);
function IsType(ob: PPyObject; obt: PPyTypeObject): Boolean;
- function GetAttrString(obj: PPyObject; AName: PAnsiChar):PAnsiChar;
function Run_CommandAsString(const command : AnsiString; mode : Integer) : string;
function Run_CommandAsObject(const command : AnsiString; mode : Integer) : PPyObject;
function Run_CommandAsObjectWithDict(const command : AnsiString; mode : Integer; locals, globals : PPyObject) : PPyObject;
@@ -2271,7 +1785,7 @@ TPythonEngine = class(TPythonInterface)
procedure PyListToStrings( list : PPyObject; strings : TStrings );
procedure PyTupleToStrings( tuple: PPyObject; strings : TStrings );
function PyUnicode_AsWideString( obj : PPyObject ) : UnicodeString;
- function PyUnicode_FromWideString( const AString : UnicodeString) : PPyObject;
+ function PyUnicode_FromWideString(const AString : UnicodeString) : PPyObject;
function ReturnNone : PPyObject;
function FindModule( const ModuleName : AnsiString ) : PPyObject;
function FindFunction(ModuleName,FuncName: AnsiString): PPyObject;
@@ -2292,22 +1806,20 @@ TPythonEngine = class(TPythonInterface)
function PyTZInfo_Check( obj : PPyObject ) : Boolean;
function PyTZInfo_CheckExact( obj : PPyObject ) : Boolean;
{ end date/time functions }
- function PyString_FromString( str: PAnsiChar): PPyObject; override;
- function PyString_FromDelphiString(str : string): PPyObject;
- function PyString_AsDelphiString( ob: PPyObject): string;
- function PyString_AsAnsiString( ob: PPyObject): AnsiString;
- function PyString_AsWideString( ob: PPyObject): UnicodeString;
+ function PyUnicode_FromAnsiString(const Str: AnsiString): PPyObject;
+ function PyUnicode_FromString(const Str : string): PPyObject;
// Public Properties
property ClientCount : Integer read GetClientCount;
property Clients[ idx : Integer ] : TEngineClient read GetClients;
property ExecModule : AnsiString read FExecModule write FExecModule;
property ThreadState: PPyThreadState read GetThreadState;
- property InterpreterState: PPyInterpreterState read GetInterpreterState;
property Traceback : TPythonTraceback read FTraceback;
property LocalVars : PPyObject read FLocalVars Write SetLocalVars;
property GlobalVars : PPyObject read FGlobalVars Write SetGlobalVars;
property IOPythonModule: TObject read FIOPythonModule; {TPythonModule}
+ property PythonHome: UnicodeString read FPythonHome write SetPythonHome;
+ property ProgramName: UnicodeString read FProgramName write SetProgramName;
published
property AutoFinalize: Boolean read FAutoFinalize write FAutoFinalize default True;
property VenvPythonExe: string read FVenvPythonExe write FVenvPythonExe;
@@ -2427,7 +1939,7 @@ TMethodsContainer = class(TEngineClient)
FMethodCount : Integer;
FAllocatedMethodCount : Integer;
FMethods : PPyMethodDef;
- FModuleDef : PyModuleDef; // for Python 3000
+ FModuleDef : PyModuleDef;
FEventDefs: TEventDefs;
procedure AllocMethods;
@@ -2807,9 +2319,7 @@ TPyObject = class
function SqConcat( obj : PPyObject) : PPyObject; virtual;
function SqRepeat( val : NativeInt ) : PPyObject; virtual;
function SqItem( idx : NativeInt ) : PPyObject; virtual;
- function SqSlice( idx1, idx2 : NativeInt ) : PPyObject; virtual;
function SqAssItem( idx : NativeInt; obj : PPyObject) : Integer; virtual;
- function SqAssSlice( idx1, idx2 : NativeInt; obj : PPyObject): integer; virtual;
function SqContains( obj: PPyObject): integer; virtual;
function SqInplaceConcat( obj : PPyObject): PPyObject; virtual;
function SqInplaceRepeat( i: NativeInt): PPyObject; virtual;
@@ -2837,35 +2347,29 @@ TPyObjectClass = class of TPyObject;
// since version 2.2
bsIter, bsIterNext);
TNumberServices = set of (nsAdd, nsSubtract, nsMultiply,
- nsDivide, nsRemainder, nsDivmod,
+ nsRemainder, nsDivmod,
nsPower, nsNegative, nsPositive,
- nsAbsolute, nsNonZero, nsInvert,
+ nsAbsolute, nsInvert,
nsLShift, nsRShift, nsAnd,
- nsXor, nsOr, nsCoerce,
- nsInt, nsLong, nsFloat,
- nsOct, nsHex,
- // since version 2.2
+ nsXor, nsOr,
+ nsInt, nsFloat,
nsFloorDivide, nsTrueDivide,
// since version 3.0
nsMatrixMultiply, nsBool);
// TInplaceNumberServices exists since version 2.0
TInplaceNumberServices = set of (nsInplaceAdd, nsInplaceSubtract,
- nsInplaceMultiply, nsInplaceDivide,
+ nsInplaceMultiply,
nsInplaceRemainder, nsInplacePower,
nsInplaceLShift, nsInplaceRShift,
nsInplaceAnd, nsInplaceXor, nsInplaceOr,
- // since version 2.2
nsInplaceFloorDivide, nsInplaceTrueDivide,
// since version 3.0
nsInplaceMatrixMultiply);
TSequenceServices = set of (ssLength, ssConcat, ssRepeat,
- ssItem, ssSlice, ssAssItem,
- ssAssSlice,
- // since version 2.0
- ssContains,
- ssInplaceConcat,
+ ssItem, ssAssItem,
+ ssContains, ssInplaceConcat,
ssInplaceRepeat
);
@@ -2905,7 +2409,7 @@ TPythonType = class(TGetSetContainer)
FPrefix : AnsiString;
FCreateFuncName : AnsiString;
FServices : TTypeServices;
- FNumber: Pointer; // points either to PyNumberMethods200 or PyNumberMethods300;
+ FNumber: PyNumberMethods;
FSequence: PySequenceMethods;
FMapping: PyMappingMethods;
FCurrentDocString: AnsiString;
@@ -3560,15 +3064,10 @@ constructor TPythonInterface.Create(AOwner: TComponent);
procedure TPythonInterface.AfterLoad;
begin
inherited;
- FIsPython3000 := Pos('PYTHON3', UpperCase(DLLName)) > 0;
FMajorVersion := StrToInt(DLLName[7 {$IFNDEF MSWINDOWS}+3{$ENDIF}]);
FMinorVersion := StrToInt(DLLName[8{$IFNDEF MSWINDOWS}+4{$ENDIF}]);
-
- if FIsPython3000 then
- FBuiltInModuleName := 'builtins'
- else
- FBuiltInModuleName := '__builtin__';
+ FBuiltInModuleName := 'builtins';
try
MapDll;
@@ -3624,11 +3123,6 @@ procedure TPythonInterface.MapDll;
Py_OptimizeFlag := Import('Py_OptimizeFlag');
Py_NoSiteFlag := Import('Py_NoSiteFlag');
Py_FrozenFlag := Import('Py_FrozenFlag');
- if not IsPython3000 then begin
- Py_UseClassExceptionsFlag := Import('Py_UseClassExceptionsFlag');
- Py_TabcheckFlag := Import('Py_TabcheckFlag');
- Py_UnicodeFlag := Import('Py_UnicodeFlag');
- end;
if (fMajorVersion < 3) or ((fMajorVersion = 3) and (fMinorVersion <3)) then
Py_DivisionWarningFlag := Import('Py_DivisionWarningFlag');
@@ -3639,10 +3133,7 @@ procedure TPythonInterface.MapDll;
Py_None := Import('_Py_NoneStruct');
Py_Ellipsis := Import('_Py_EllipsisObject');
- if IsPython3000 then
- Py_False := Import('_Py_FalseStruct')
- else
- Py_False := Import('_Py_ZeroStruct');
+ Py_False := Import('_Py_FalseStruct');
Py_True := Import('_Py_TrueStruct');
Py_NotImplemented := Import('_Py_NotImplementedStruct');
@@ -3669,10 +3160,6 @@ procedure TPythonInterface.MapDll;
PyExc_Exception := Import('PyExc_Exception');
PyExc_FloatingPointError := Import('PyExc_FloatingPointError');
PyExc_LookupError := Import('PyExc_LookupError');
- if not IsPython3000 then begin
- PyExc_StandardError := Import('PyExc_StandardError');
- PyExc_MemoryErrorInst := Import('PyExc_MemoryErrorInst');
- end;
PyExc_AssertionError := Import('PyExc_AssertionError');
PyExc_EnvironmentError := Import('PyExc_EnvironmentError');
PyExc_IndentationError := Import('PyExc_IndentationError');
@@ -3698,22 +3185,12 @@ procedure TPythonInterface.MapDll;
PyExc_UnicodeTranslateError:= Import('PyExc_UnicodeTranslateError');
PyType_Type := Import('PyType_Type');
PyCFunction_Type := Import('PyCFunction_Type');
- if not IsPython3000 then begin
- PyCObject_Type := Import('PyCObject_Type'); // Removed in Python 3.2
- PyClass_Type := Import('PyClass_Type');
- end;
PyCode_Type := Import('PyCode_Type');
PyComplex_Type := Import('PyComplex_Type');
PyDict_Type := Import('PyDict_Type');
- if not IsPython3000 then
- PyFile_Type := Import('PyFile_Type');
PyFloat_Type := Import('PyFloat_Type');
PyFrame_Type := Import('PyFrame_Type');
PyFunction_Type := Import('PyFunction_Type');
- if not IsPython3000 then
- PyInstance_Type := Import('PyInstance_Type');
- if not IsPython3000 then
- PyInt_Type := Import('PyInt_Type');
PyList_Type := Import('PyList_Type');
PyLong_Type := Import('PyLong_Type');
PyMethod_Type := Import('PyMethod_Type');
@@ -3721,15 +3198,10 @@ procedure TPythonInterface.MapDll;
PyObject_Type := Import('PyObject_Type');
PyRange_Type := Import('PyRange_Type');
PySlice_Type := Import('PySlice_Type');
- if not IsPython3000 then
- PyString_Type := Import('PyString_Type')
- else
- PyString_Type := Import('PyBytes_Type');
+ PyBytes_Type := Import('PyBytes_Type');
PyTuple_Type := Import('PyTuple_Type');
PyUnicode_Type := Import('PyUnicode_Type');
PyBaseObject_Type := Import('PyBaseObject_Type');
- if not IsPython3000 then
- PyBuffer_Type := Import('PyBuffer_Type');
PyCallIter_Type := Import('PyCallIter_Type');
PyCell_Type := Import('PyCell_Type');
PyClassMethod_Type := Import('PyClassMethod_Type');
@@ -3742,8 +3214,6 @@ procedure TPythonInterface.MapDll;
_PyWeakref_RefType := Import('_PyWeakref_RefType');
_PyWeakref_ProxyType := Import('_PyWeakref_ProxyType');
_PyWeakref_CallableProxyType:=Import('_PyWeakref_CallableProxyType');
- if not IsPython3000 then
- PyBaseString_Type := Import('PyBaseString_Type');
PyBool_Type := Import('PyBool_Type');
PyEnum_Type := Import('PyEnum_Type');
@@ -3755,12 +3225,6 @@ procedure TPythonInterface.MapDll;
PyCFunction_GetFunction := Import('PyCFunction_GetFunction');
PyCFunction_GetSelf := Import('PyCFunction_GetSelf');
PyCallable_Check := Import('PyCallable_Check');
- if not IsPython3000 then begin
- PyClass_New := Import('PyClass_New');
- PyClass_IsSubclass := Import('PyClass_IsSubclass');
- PyCObject_FromVoidPtr := Import('PyCObject_FromVoidPtr'); // Removed in Python 3.2
- PyCObject_AsVoidPtr := Import('PyCObject_AsVoidPtr');
- end;
PyDict_GetItem := Import('PyDict_GetItem');
PyDict_SetItem := Import('PyDict_SetItem');
PyDict_DelItem := Import('PyDict_DelItem');
@@ -3773,10 +3237,7 @@ procedure TPythonInterface.MapDll;
PyDict_DelItemString := Import('PyDict_DelItemString');
PyDict_Copy := Import('PyDict_Copy');
PyDictProxy_New := Import('PyDictProxy_New');
- if not IsPython3000 then
- Py_InitModule4 := {$IFDEF CPUX64}Import('Py_InitModule4_64'){$ELSE}Import('Py_InitModule4'){$ENDIF}
- else
- PyModule_Create2 := Import('PyModule_Create2');
+ PyModule_Create2 := Import('PyModule_Create2');
PyErr_Print := Import('PyErr_Print');
PyErr_SetNone := Import('PyErr_SetNone');
PyErr_SetObject := Import('PyErr_SetObject');
@@ -3794,10 +3255,6 @@ procedure TPythonInterface.MapDll;
PyErr_WarnExplicit := Import('PyErr_WarnExplicit');
PyEval_GetBuiltins := Import('PyEval_GetBuiltins');
PyImport_GetModuleDict := Import('PyImport_GetModuleDict');
- if IsPython3000 then
- PyInt_FromLong := Import('PyLong_FromLong')
- else
- PyInt_FromLong := Import('PyInt_FromLong');
PyArg_Parse := Import('PyArg_Parse');
PyArg_ParseTuple := Import('PyArg_ParseTuple');
PyArg_ParseTupleAndKeywords := Import('PyArg_ParseTupleAndKeywords');
@@ -3810,46 +3267,19 @@ procedure TPythonInterface.MapDll;
PyRun_String := Import('PyRun_String');
PyRun_SimpleString := Import('PyRun_SimpleString');
PyDict_GetItemString := Import('PyDict_GetItemString');
- if not IsPython3000 then begin
- PyString_AsString := Import('PyString_AsString');
- PyString_AsStringAndSize := Import('PyString_AsStringAndSize')
- end else begin
- PyString_AsString := Import('PyBytes_AsString');
- PyString_AsStringAndSize := Import('PyBytes_AsStringAndSize');
- end;
- if not IsPython3000 then
- DLL_PyString_FromString := Import('PyString_FromString');
- if not IsPython3000 then
- PySys_SetArgv := Import('PySys_SetArgv')
- else
- PySys_SetArgv3000 := Import('PySys_SetArgv');
+ PySys_SetArgv := Import('PySys_SetArgv');
Py_Exit := Import('Py_Exit');
- if IsPython3000 then
- PyCFunction_NewEx :=Import('PyCFunction_NewEx')
- else
- PyCFunction_New :=Import('PyCFunction_New');
-
+ PyCFunction_NewEx :=Import('PyCFunction_NewEx');
PyEval_CallObjectWithKeywords:=Import('PyEval_CallObjectWithKeywords');
PyEval_GetFrame :=Import('PyEval_GetFrame');
PyEval_GetGlobals :=Import('PyEval_GetGlobals');
PyEval_GetLocals :=Import('PyEval_GetLocals');
- //@PyEval_GetOwner :=Import('PyEval_GetOwner');
- if not IsPython3000 then
- PyEval_GetRestricted :=Import('PyEval_GetRestricted');
PyEval_InitThreads :=Import('PyEval_InitThreads');
PyEval_RestoreThread :=Import('PyEval_RestoreThread');
PyEval_SaveThread :=Import('PyEval_SaveThread');
- if not IsPython3000 then
- PyFile_FromString :=Import('PyFile_FromString');
PyFile_GetLine :=Import('PyFile_GetLine');
- if not IsPython3000 then
- PyFile_Name :=Import('PyFile_Name');
- if not IsPython3000 then
- PyFile_SetBufSize :=Import('PyFile_SetBufSize');
- if not IsPython3000 then
- PyFile_SoftSpace :=Import('PyFile_SoftSpace');
PyFile_WriteObject :=Import('PyFile_WriteObject');
PyFile_WriteString :=Import('PyFile_WriteString');
PyFloat_AsDouble :=Import('PyFloat_AsDouble');
@@ -3862,14 +3292,8 @@ procedure TPythonInterface.MapDll;
PyImport_ImportFrozenModule:=Import('PyImport_ImportFrozenModule');
PyImport_ImportModule :=Import('PyImport_ImportModule');
PyImport_Import :=Import('PyImport_Import');
- //PyImport_Init :=Import('PyImport_Init');
PyImport_ReloadModule :=Import('PyImport_ReloadModule');
- if not IsPython3000 then
- PyInstance_New :=Import('PyInstance_New');
- if IsPython3000 then
- PyInt_AsLong :=Import('PyLong_AsLong')
- else
- PyInt_AsLong :=Import('PyInt_AsLong');
+ PyLong_AsLong :=Import('PyLong_AsLong');
PyList_Append :=Import('PyList_Append');
PyList_AsTuple :=Import('PyList_AsTuple');
PyList_GetItem :=Import('PyList_GetItem');
@@ -3899,8 +3323,6 @@ procedure TPythonInterface.MapDll;
PyMapping_HasKeyString :=Import('PyMapping_HasKeyString');
PyMapping_Length :=Import('PyMapping_Length');
PyMapping_SetItemString :=Import('PyMapping_SetItemString');
- if not IsPython3000 then
- PyMethod_Class :=Import('PyMethod_Class');
PyMethod_Function :=Import('PyMethod_Function');
PyMethod_New :=Import('PyMethod_New');
PyMethod_Self :=Import('PyMethod_Self');
@@ -3910,18 +3332,10 @@ procedure TPythonInterface.MapDll;
PyNumber_Add :=Import('PyNumber_Add');
PyNumber_And :=Import('PyNumber_And');
PyNumber_Check :=Import('PyNumber_Check');
- if not IsPython3000 then
- PyNumber_Coerce :=Import('PyNumber_Coerce');
- if IsPython3000 then
- PyNumber_Divide :=Import('PyNumber_TrueDivide')
- else
- PyNumber_Divide :=Import('PyNumber_Divide');
PyNumber_FloorDivide :=Import('PyNumber_FloorDivide');
PyNumber_TrueDivide :=Import('PyNumber_TrueDivide');
PyNumber_Divmod :=Import('PyNumber_Divmod');
PyNumber_Float :=Import('PyNumber_Float');
- if not IsPython3000 then
- PyNumber_Int :=Import('PyNumber_Int');
PyNumber_Invert :=Import('PyNumber_Invert');
PyNumber_Long :=Import('PyNumber_Long');
PyNumber_Lshift :=Import('PyNumber_Lshift');
@@ -3938,8 +3352,6 @@ procedure TPythonInterface.MapDll;
PyOS_InterruptOccurred :=Import('PyOS_InterruptOccurred');
PyObject_CallObject :=Import('PyObject_CallObject');
PyObject_CallMethod :=Import('PyObject_CallMethod');
- if not IsPython3000 then
- PyObject_Compare :=Import('PyObject_Compare');
PyObject_RichCompare :=Import('PyObject_RichCompare');
PyObject_RichCompareBool :=Import('PyObject_RichCompareBool');
PyObject_GetAttr :=Import('PyObject_GetAttr');
@@ -3960,6 +3372,7 @@ procedure TPythonInterface.MapDll;
PyObject_NewVar :=Import('_PyObject_NewVar');
PyObject_Free :=Import('PyObject_Free');
PyObject_GetIter :=Import('PyObject_GetIter');
+ PyIter_Check :=Import('PyIter_Check');
PyIter_Next :=Import('PyIter_Next');
PyObject_IsInstance :=Import('PyObject_IsInstance');
PyObject_IsSubclass :=Import('PyObject_IsSubclass');
@@ -3991,30 +3404,21 @@ procedure TPythonInterface.MapDll;
PySeqIter_New :=Import('PySeqIter_New');
PySlice_GetIndicesEx :=Import('PySlice_GetIndicesEx');
PySlice_New :=Import('PySlice_New');
- if not IsPython3000 then begin
- PyString_Concat :=Import('PyString_Concat');
- PyString_ConcatAndDel :=Import('PyString_ConcatAndDel');
- PyString_Format :=Import('PyString_Format');
- PyString_FromStringAndSize:=Import('PyString_FromStringAndSize');
- PyString_Size :=Import('PyString_Size');
- PyString_DecodeEscape :=Import('PyString_DecodeEscape');
- PyString_Repr :=Import('PyString_Repr');
- end else begin
- PyString_Concat :=Import('PyBytes_Concat');
- PyString_ConcatAndDel :=Import('PyBytes_ConcatAndDel');
- PyString_FromStringAndSize:=Import('PyBytes_FromStringAndSize');
- PyString_Size :=Import('PyBytes_Size');
- PyString_DecodeEscape :=Import('PyBytes_DecodeEscape');
- PyString_Repr :=Import('PyBytes_Repr');
- end;
+ PyBytes_AsString := Import('PyBytes_AsString');
+ PyBytes_AsStringAndSize := Import('PyBytes_AsStringAndSize');
+ PyBytes_Concat :=Import('PyBytes_Concat');
+ PyBytes_ConcatAndDel :=Import('PyBytes_ConcatAndDel');
+ PyBytes_FromString :=Import('PyBytes_FromString');
+ PyBytes_FromStringAndSize :=Import('PyBytes_FromStringAndSize');
+ PyBytes_Size :=Import('PyBytes_Size');
+ PyBytes_DecodeEscape :=Import('PyBytes_DecodeEscape');
+ PyBytes_Repr :=Import('PyBytes_Repr');
+ _PyBytes_Resize :=Import('_PyBytes_Resize');
PySys_GetObject :=Import('PySys_GetObject');
- //PySys_Init :=Import('PySys_Init');
PySys_SetObject :=Import('PySys_SetObject');
PySys_SetPath :=Import('PySys_SetPath');
- //PyTraceBack_Fetch :=Import('PyTraceBack_Fetch');
PyTraceBack_Here :=Import('PyTraceBack_Here');
PyTraceBack_Print :=Import('PyTraceBack_Print');
- //@PyTraceBack_Store :=Import('PyTraceBack_Store');
PyTuple_GetItem :=Import('PyTuple_GetItem');
PyTuple_GetSlice :=Import('PyTuple_GetSlice');
PyTuple_New :=Import('PyTuple_New');
@@ -4039,57 +3443,33 @@ procedure TPythonInterface.MapDll;
PyBool_FromLong :=Import('PyBool_FromLong');
PyThreadState_SetAsyncExc :=Import('PyThreadState_SetAsyncExc');
Py_AtExit :=Import('Py_AtExit');
- //Py_Cleanup :=Import('Py_Cleanup');
Py_FatalError :=Import('Py_FatalError');
- if not IsPython3000 then begin
- Py_FindMethod :=Import('Py_FindMethod');
- Py_FindMethodInChain :=Import('Py_FindMethodInChain');
- DLL_Py_FlushLine :=Import('Py_FlushLine');
- _PyString_Resize :=Import('_PyString_Resize');
- Py_CompileStringFlags :=Import('Py_CompileStringFlags');
- end else begin
- _PyString_Resize :=Import('_PyBytes_Resize');
- Py_CompileStringExFlags :=Import('Py_CompileStringExFlags');
- end;
+ Py_CompileStringExFlags :=Import('Py_CompileStringExFlags');
_PyObject_New :=Import('_PyObject_New');
- Py_Finalize :=Import('Py_Finalize');
- if getProcAddress( FDLLHandle, 'PyCode_Addr2Line' ) <> nil then
- DLL_PyCode_Addr2Line := Import('PyCode_Addr2Line');
- if getProcAddress( FDLLHandle, 'PyImport_ExecCodeModule' ) <> nil then
- DLL_PyImport_ExecCodeModule := Import('PyImport_ExecCodeModule');
- //@PyClass_IsSubclass :=Import('PyClass_IsSubclass');
- PyErr_ExceptionMatches :=Import('PyErr_ExceptionMatches');
- PyErr_GivenExceptionMatches:=Import('PyErr_GivenExceptionMatches');
- PyEval_EvalCode :=Import('PyEval_EvalCode');
- Py_GetVersion :=Import('Py_GetVersion');
- Py_GetCopyright :=Import('Py_GetCopyright');
- Py_GetExecPrefix :=Import('Py_GetExecPrefix');
- Py_GetPath :=Import('Py_GetPath');
- if IsPython3000 then
- Py_SetPythonHome3000 :=Import('Py_SetPythonHome')
- else
- Py_SetPythonHome :=Import('Py_SetPythonHome');
- if IsPython3000 then
- Py_GetPythonHome3000 :=Import('Py_GetPythonHome')
- else
- Py_GetPythonHome :=Import('Py_GetPythonHome');
- Py_GetPrefix :=Import('Py_GetPrefix');
- Py_GetProgramName :=Import('Py_GetProgramName');
+ Py_Finalize :=Import('Py_Finalize');
+ PyImport_ExecCodeModule := Import('PyImport_ExecCodeModule');
+ PyErr_ExceptionMatches :=Import('PyErr_ExceptionMatches');
+ PyErr_GivenExceptionMatches :=Import('PyErr_GivenExceptionMatches');
+ PyEval_EvalCode :=Import('PyEval_EvalCode');
+ Py_GetVersion :=Import('Py_GetVersion');
+ Py_GetCopyright :=Import('Py_GetCopyright');
+ Py_GetExecPrefix :=Import('Py_GetExecPrefix');
+ Py_GetPath :=Import('Py_GetPath');
+ Py_SetPythonHome :=Import('Py_SetPythonHome');
+ Py_GetPythonHome :=Import('Py_GetPythonHome');
+ Py_GetPrefix :=Import('Py_GetPrefix');
+ Py_GetProgramName :=Import('Py_GetProgramName');
PyParser_SimpleParseStringFlags := Import('PyParser_SimpleParseStringFlags');
- PyNode_Free :=Import('PyNode_Free');
- PyErr_NewException :=Import('PyErr_NewException');
+ PyNode_Free :=Import('PyNode_Free');
+ PyErr_NewException :=Import('PyErr_NewException');
try
PyMem_Malloc := Import ('PyMem_Malloc');
except
end;
- if not IsPython3000 then
- Py_SetProgramName := Import('Py_SetProgramName')
- else
- Py_SetProgramName3000 := Import('Py_SetProgramName');
+ Py_SetProgramName := Import('Py_SetProgramName');
Py_IsInitialized := Import('Py_IsInitialized');
Py_GetProgramFullPath := Import('Py_GetProgramFullPath');
- if getProcAddress( FDLLHandle, 'Py_GetBuildInfo' ) <> nil then
- DLL_Py_GetBuildInfo := Import('Py_GetBuildInfo');
+ Py_GetBuildInfo := Import('Py_GetBuildInfo');
Py_NewInterpreter := Import('Py_NewInterpreter');
Py_EndInterpreter := Import('Py_EndInterpreter');
PyEval_AcquireLock := Import('PyEval_AcquireLock');
@@ -4109,12 +3489,9 @@ procedure TPythonInterface.MapDll;
PyGILState_Release := Import('PyGILState_Release');
end;
-function TPythonInterface.Py_CompileString( s1,s2:PAnsiChar;i:integer):PPyObject; cdecl;
+function TPythonInterface.Py_CompileString(s1,s2:PAnsiChar;i:integer):PPyObject;
begin
- if IsPython3000 then
- Result := Py_CompileStringExFlags(s1, s2, i, nil, -1)
- else
- Result := Py_CompileStringFlags(s1, s2, i, nil);
+ Result := Py_CompileStringExFlags(s1, s2, i, nil, -1);
end;
function TPythonInterface.PyParser_SimpleParseString( str : PAnsiChar; start : integer) : PNode; cdecl;
@@ -4147,106 +3524,14 @@ procedure TPythonInterface.Py_XDECREF(op: PPyObject);
if op <> nil then Py_DECREF(op);
end;
-// This function is copied from compile.c because it was not
-// exported in the Dll
-function TPythonInterface.PyCode_Addr2Line( co: PPyCodeObject; addrq : Integer ) : Integer; cdecl;
-var
- size : Integer;
- p : PAnsiChar;
- line : Integer;
- addr : Integer;
- cpt : Integer;
-begin
- if Assigned(DLL_PyCode_Addr2Line) then
- begin
- Result := DLL_PyCode_Addr2Line( co, addrq );
- Exit;
- end;
- size := PyString_Size(co^.co_lnotab) div 2;
- p := PyString_AsString(co^.co_lnotab);
- line := co^.co_firstlineno;
- addr := 0;
- cpt := 0;
- while (size-1) >= 0 do
- begin
- Dec(size);
- Inc( addr, Ord(p[cpt]) );
- Inc(cpt);
- if addr > addrq then
- Break;
- Inc( line, Ord(p[cpt]) );
- Inc(cpt);
- end;
- Result := line;
-end;
-
-function TPythonInterface.Py_GetBuildInfo : PAnsiChar; cdecl;
-begin
- if Assigned(DLL_Py_GetBuildInfo) then
- begin
- Result := DLL_Py_GetBuildInfo;
- Exit;
- end;
- Result := 'No build info';
-end;
-
-function TPythonInterface.PyImport_ExecCodeModule( const AName : AnsiString; codeobject : PPyObject) : PPyObject;
-var
- m, d, v, modules : PPyObject;
+function TPythonInterface.PyBytes_Check( obj : PPyObject ) : Boolean;
begin
- if Assigned(DLL_PyImport_ExecCodeModule) then
- begin
- Result := DLL_PyImport_ExecCodeModule(PAnsiChar(AName), codeobject);
- Exit;
- end;
- CheckPython;
- m := PyImport_AddModule(PAnsiChar(AName));
- if not Assigned(m) then
- begin
- Result := nil;
- Exit;
- end;
- d := PyModule_GetDict(m);
- if PyDict_GetItemString(d, '__builtins__') = nil then
- begin
- if PyDict_SetItemString(d, '__builtins__', PyEval_GetBuiltins) <> 0 then
- begin
- Result := nil;
- Exit;
- end;
- end;
- // Remember the fielname as the __file__ attribute
- if PyDict_SetItemString(d, '__file__', PPyCodeObject(codeobject)^.co_filename) <> 0 then
- PyErr_Clear; // Not important enough to report
- v := PyEval_EvalCode(PPyCodeObject(codeobject), d, d); // XXX owner ?
- if not Assigned(v) then
- begin
- Result := nil;
- Exit;
- end;
- Py_XDECREF(v);
- modules := PyImport_GetModuleDict;
- if PyDict_GetItemString(modules, PAnsiChar(AName)) = nil then
- begin
- PyErr_SetString(PyExc_ImportError^,
- PAnsiChar(AnsiString(Format('Loaded module %.200s not found in sys.modules', [AName]))));
- Result := nil;
- Exit;
- end;
- Py_XINCREF(m);
- Result := m;
+ Result := PyObject_TypeCheck(obj, PyBytes_Type);
end;
-function TPythonInterface.PyString_Check( obj : PPyObject ) : Boolean;
+function TPythonInterface.PyBytes_CheckExact(obj: PPyObject): Boolean;
begin
- Result := PyObject_TypeCheck(obj, PyString_Type);
- if not Result then
- Result := PyObject_TypeCheck(obj, PyUnicode_Type);
-end;
-
-function TPythonInterface.PyString_CheckExact(obj: PPyObject): Boolean;
-begin
- Result := Assigned( obj ) and (obj^.ob_type = PPyTypeObject(PyString_Type));
+ Result := Assigned( obj ) and (obj^.ob_type = PPyTypeObject(PyBytes_Type));
end;
function TPythonInterface.PyFloat_Check( obj : PPyObject ) : Boolean;
@@ -4259,22 +3544,6 @@ function TPythonInterface.PyFloat_CheckExact(obj: PPyObject): Boolean;
Result := Assigned( obj ) and (obj^.ob_type = PPyTypeObject(PyFloat_Type));
end;
-function TPythonInterface.PyInt_Check( obj : PPyObject ) : Boolean;
-begin
- if IsPython3000 then
- Result := PyObject_TypeCheck(obj, PyLong_Type)
- else
- Result := PyObject_TypeCheck(obj, PyInt_Type);
-end;
-
-function TPythonInterface.PyInt_CheckExact(obj: PPyObject): Boolean;
-begin
- if IsPython3000 then
- Result := Assigned( obj ) and (obj^.ob_type = PPyTypeObject(PyLong_Type))
- else
- Result := Assigned( obj ) and (obj^.ob_type = PPyTypeObject(PyInt_Type));
-end;
-
function TPythonInterface.PyLong_Check( obj : PPyObject ) : Boolean;
begin
Result := PyObject_TypeCheck(obj, PyLong_Type);
@@ -4295,14 +3564,9 @@ function TPythonInterface.PyTuple_CheckExact(obj: PPyObject): Boolean;
Result := Assigned( obj ) and (obj^.ob_type = PPyTypeObject(PyTuple_Type));
end;
-function TPythonInterface.PyInstance_Check( obj : PPyObject ) : Boolean;
-begin
- Result := Assigned( obj ) and (not IsPython3000) and (obj^.ob_type = PPyTypeObject(PyInstance_Type));
-end;
-
function TPythonInterface.PyClass_Check( obj : PPyObject ) : Boolean;
begin
- Result := Assigned( obj ) and not IsPython3000 and (obj^.ob_type = PPyTypeObject(PyClass_Type));
+ Result := Assigned( obj ) and (PyObject_IsInstance(obj, PPyObject(PyType_Type)) <> 0);
end;
function TPythonInterface.PyType_CheckExact( obj : PPyObject ) : Boolean;
@@ -4357,13 +3621,6 @@ function TPythonInterface.PyFunction_Check( obj : PPyObject ) : Boolean;
(obj^.ob_type = PPyTypeObject(PyFunction_Type)));
end;
-function TPythonInterface.PyIter_Check( obj : PPyObject ) : Boolean;
-begin
- Result := Assigned( obj ) and
- (IsPython3000 or (PyType_HasFeature(obj^.ob_type, Py_TPFLAGS_HAVE_ITER))
- and Assigned(obj^.ob_type^.tp_iternext));
-end;
-
function TPythonInterface.PyUnicode_Check( obj : PPyObject ) : Boolean;
begin
Result := PyObject_TypeCheck(obj, PyUnicode_Type);
@@ -4407,14 +3664,6 @@ function TPythonInterface.PyBool_Check( obj : PPyObject ) : Boolean;
Result := PyObject_TypeCheck(obj, PyBool_Type);
end;
-function TPythonInterface.PyBaseString_Check( obj : PPyObject ) : Boolean;
-begin
- if IsPython3000 then
- Result:= PyObject_TypeCheck(obj, PyUnicode_Type)
- else
- Result := PyObject_TypeCheck(obj, PyBaseString_Type);
-end;
-
function TPythonInterface.PyEnum_Check( obj : PPyObject ) : Boolean;
begin
Result := Assigned( obj ) and (obj^.ob_type = PPyTypeObject(PyEnum_Type));
@@ -4427,13 +3676,7 @@ function TPythonInterface.PyObject_TypeCheck(obj : PPyObject; t : PPyTypeObject)
Result := PyType_IsSubtype(obj^.ob_type, t) = 1;
end;
-function TPythonInterface.Py_InitModule( const AName : PAnsiChar; md : PPyMethodDef) : PPyObject;
-begin
- CheckPython;
- Result := Py_InitModule4( AName, md, nil, nil, APIVersion );
-end;
-
-function TPythonInterface.Py_InitModule3000(const md: PyModuleDef): PPyObject;
+function TPythonInterface.Py_InitModule(const md: PyModuleDef): PPyObject;
Var
modules : PPyObject;
begin
@@ -4447,11 +3690,6 @@ function TPythonInterface.Py_InitModule3000(const md: PyModuleDef): PPyObject;
GetPythonEngine.CheckError;
end;
-procedure TPythonInterface.Py_FlushLine; cdecl;
-begin
- if Assigned(DLL_Py_FlushLine) then
- DLL_Py_FlushLine;
-end;
(*******************************************************)
(** **)
@@ -4505,7 +3743,6 @@ procedure TPythonTraceback.Clear;
}
procedure TPythonTraceback.Refresh;
var
-// tb, tb1 : PPyTraceBackObject;
tb, tb1 : PPyObject;
obj : PPyObject;
frame : PPyObject;
@@ -4521,8 +3758,8 @@ procedure TPythonTraceback.Refresh;
// get the limit of the traceback
alimit := FLimit;
limitv := PySys_GetObject('tracebacklimit');
- if Assigned(limitv) and PyInt_Check(limitv) then
- alimit := PyInt_AsLong(limitv);
+ if Assigned(limitv) and PyLong_Check(limitv) then
+ alimit := PyLong_AsLong(limitv);
tb := PySys_GetObject('last_traceback');
tb1 := tb;
Py_XIncRef(tb1);
@@ -4684,7 +3921,7 @@ procedure TPythonEngine.Finalize;
FFinalizing := False;
FInitialized := False;
end;
- except
+ except
end;
end;
// Detach our clients, when engine is beeing destroyed or one of its clients.
@@ -4776,11 +4013,6 @@ procedure TPythonEngine.AssignPyFlags;
SetFlag(Py_OptimizeFlag, pfOptimize in FPyFlags);
SetFlag(Py_NoSiteFlag, pfNoSite in FPyFlags);
SetFlag(Py_FrozenFlag, pfFrozenFlag in FPyFlags);
- if not IsPython3000 then begin
- SetFlag(Py_UseClassExceptionsFlag, pfUseClassExceptionsFlag in FPyFlags);
- SetFlag(Py_UnicodeFlag, pfUnicode in FPyFlags);
- SetFlag(Py_TabcheckFlag, pfTabcheck in FPyFlags);
- end;
SetFlag(Py_IgnoreEnvironmentFlag, pfIgnoreEnvironmentFlag in FPyFlags);
if Assigned(Py_DivisionWarningFlag) then
SetFlag(Py_DivisionWarningFlag, pfDivisionWarningFlag in FPyFlags);
@@ -4864,28 +4096,15 @@ procedure TPythonEngine.Initialize;
gPythonEngine := Self;
CheckRegistry;
- if IsPython3000 then begin
- if Assigned(Py_SetProgramName3000) then
- begin
- if FProgramNameW = '' then
- FProgramNameW := UnicodeString(ParamStr(0));
- Py_SetProgramName3000(PWideChar(FProgramNameW));
- end
- end else begin
- if Assigned(Py_SetProgramName) then
- begin
- if FProgramName = '' then
- FProgramName := AnsiString(ParamStr(0));
- Py_SetProgramName(PAnsiChar(FProgramName));
- end
+ if Assigned(Py_SetProgramName) then
+ begin
+ if FProgramName = '' then
+ FProgramName := UnicodeString(ParamStr(0));
+ Py_SetProgramName(PWideChar(FProgramName));
end;
AssignPyFlags;
- if FPythonHomeW <> '' then begin
- if IsPython3000 then
- Py_SetPythonHome3000(PWideChar(FPythonHomeW))
- else
- Py_SetPythonHome(PAnsiChar(FPythonHome));
- end;
+ if FPythonHome <> '' then
+ Py_SetPythonHome(PWideChar(FPythonHome));
Py_Initialize;
if Assigned(Py_IsInitialized) then
FInitialized := Py_IsInitialized() <> 0
@@ -4915,20 +4134,6 @@ procedure TPythonEngine.SetInitScript(Value: TStrings);
FInitScript.Assign(Value);
end;
-function TPythonEngine.GetInterpreterState: PPyInterpreterState;
-var
- res: PPyThreadState;
-begin
- if Assigned(PyThreadState_Get) then begin
- res:= PyThreadState_Get();
- if (MajorVersion > 3) or ((MajorVersion = 3) and (MinorVersion >= 4)) then
- Result := res^.interp34
- else
- Result := res^.interp;
- end else
- Result := nil;
-end;
-
function TPythonEngine.GetThreadState: PPyThreadState;
begin
if Assigned(PyThreadState_Get) then
@@ -5039,8 +4244,6 @@ procedure TPythonEngine.CheckRegistry;
procedure TPythonEngine.SetProgramArgs;
var
i, argc : Integer;
- argv : array of PAnsiChar;
- L : array of AnsiString;
wargv : array of PWideChar;
{$IFDEF POSIX}
UCS4L : array of UCS4String;
@@ -5051,37 +4254,24 @@ procedure TPythonEngine.SetProgramArgs;
// we build a string list of the arguments, because ParamStr returns a volatile string
// and we want to build an array of PAnsiChar, pointing to valid strings.
argc := ParamCount;
- if not IsPython3000 then begin
- SetLength(L, argc+1);
- SetLength(argv, argc + 1);
- // get the strings
- // build the PAnsiChar array
- for i := 0 to argc do begin
- L[i] := AnsiString(ParamStr(i));
- argv[i] := PAnsiChar(L[i]);
- end;
- // set the argv list of the sys module with the application arguments
- PySys_SetArgv( argc+1, PPAnsiChar(argv) );
- end else begin
- SetLength(wargv, argc + 1);
- // build the PWideChar array
- {$IFDEF POSIX}
- // Note that Linux uses UCS4 strings, whereas it declares using UCS2 strings!!!
- SetLength(UCS4L, argc+1);
- for i := 0 to argc do begin
- UCS4L[i] := WideStringToUCS4String(ParamStr(i));
- wargv[i] := @UCS4L[i][0];
- end;
- {$ELSE}
- SetLength(WL, argc+1);
- for i := 0 to argc do begin
- WL[i] := UnicodeString(ParamStr(i));
- wargv[i] := PWideChar(WL[i]);
- end;
- {$ENDIF}
- // set the argv list of the sys module with the application arguments
- PySys_SetArgv3000( argc + 1, PPWideChar(wargv) );
+ SetLength(wargv, argc + 1);
+ // build the PWideChar array
+ {$IFDEF POSIX}
+ // Note that Linux uses UCS4 strings, whereas it declares using UCS2 strings!!!
+ SetLength(UCS4L, argc+1);
+ for i := 0 to argc do begin
+ UCS4L[i] := WideStringToUCS4String(ParamStr(i));
+ wargv[i] := @UCS4L[i][0];
+ end;
+ {$ELSE}
+ SetLength(WL, argc+1);
+ for i := 0 to argc do begin
+ WL[i] := UnicodeString(ParamStr(i));
+ wargv[i] := PWideChar(WL[i]);
end;
+ {$ENDIF}
+ // set the argv list of the sys module with the application arguments
+ PySys_SetArgv( argc + 1, PPWideChar(wargv) );
end;
procedure TPythonEngine.InitWinConsole;
@@ -5148,14 +4338,12 @@ procedure TPythonEngine.SetPyFlags(const Value: TPythonFlags);
procedure TPythonEngine.SetPythonHome(const PythonHome: UnicodeString);
begin
- FPythonHomeW := PythonHome;
- FPythonHome := EncodeString(PythonHome);
+ FPythonHome := PythonHome;
end;
procedure TPythonEngine.SetProgramName(const ProgramName: UnicodeString);
begin
- FProgramNameW := ProgramName;
- FProgramName := EncodeString(ProgramName);
+ FProgramName := ProgramName;
end;
function TPythonEngine.IsType(ob: PPyObject; obt: PPyTypeObject): Boolean;
@@ -5163,20 +4351,6 @@ function TPythonEngine.IsType(ob: PPyObject; obt: PPyTypeObject): Boolean;
result := ob^.ob_type = obt;
end;
-function TPythonEngine.GetAttrString(obj: PPyObject; AName: PAnsiChar):PAnsiChar;
-var
- attr: PPyObject;
-begin
- CheckPython;
- result := nil;
- attr := PyObject_GetAttrString(obj, AName);
- if attr <> nil then begin
- result := PyString_AsString(attr);
- Py_XDECREF(attr);
- end;
- PyErr_Clear;
-end;
-
function TPythonEngine.EvalPyFunction(pyfunc, pyargs:PPyObject): Variant;
var presult :PPyObject;
begin
@@ -5202,9 +4376,7 @@ function TPythonEngine.EvalPyFunction(pyfunc, pyargs:PPyObject): Variant;
Py_DECREF(presult);
end;
end;
- Py_FlushLine;
except
- Py_FlushLine;
if PyErr_Occurred <> nil then
CheckError(False)
else
@@ -5298,9 +4470,7 @@ function TPythonEngine.Run_CommandAsObjectWithDict(const command : AnsiString; m
Result := PyRun_String(PAnsiChar(CleanString(command)), mode, _globals, _locals);
if Result = nil then
CheckError(False);
- Py_FlushLine;
except
- Py_FlushLine;
if PyErr_Occurred <> nil then
CheckError(False)
else
@@ -5376,11 +4546,11 @@ procedure TPythonEngine.RaiseError;
Result := E;
end;
- function DefineSyntaxError( E : EPySyntaxError; const sType, sValue : string; err_type, err_value : PPyObject ) : EPySyntaxError;
+ function DefineSyntaxError( E : EPySyntaxError; const sType, sValue : UnicodeString; err_type, err_value : PPyObject ) : EPySyntaxError;
var
- s_value : string;
- s_line : string;
- s_filename : string;
+ s_value : UnicodeString;
+ s_line : UnicodeString;
+ s_filename : UnicodeString;
i_line_number : Integer;
i_offset : Integer;
tmp : PPyObject;
@@ -5396,49 +4566,50 @@ procedure TPythonEngine.RaiseError;
// Sometimes there's a tuple instead of instance...
if PyTuple_Check( err_value ) and (PyTuple_Size( err_value) >= 2) then
begin
- s_value := PyString_AsDelphiString(PyTuple_GetItem( err_value, 0));
+ s_value := PyObjectAsString(PyTuple_GetItem( err_value, 0));
err_value := PyTuple_GetItem( err_value, 1);
if PyTuple_Check( err_value ) and (PyTuple_Size( err_value) >= 4) then
begin
- i_line_number := PyInt_AsLong(PyTuple_GetItem( err_value, 1));
- i_offset := PyInt_AsLong(PyTuple_GetItem( err_value, 2));
- s_line := Trim(PyString_AsDelphiString(PyTuple_GetItem( err_value, 3)));
+ i_line_number := PyLong_AsLong(PyTuple_GetItem( err_value, 1));
+ i_offset := PyLong_AsLong(PyTuple_GetItem( err_value, 2));
+ s_line := Trim(PyObjectAsString(PyTuple_GetItem( err_value, 3)));
end;
end else
// Is it an instance of the SyntaxError class ?
- if (PyInstance_Check( err_value ) and (PyClass_IsSubclass( PPyObject(PPyInstanceObject(err_value)^.in_class), err_type ) <> 0)) or
- ((PyType_IsSubtype(PPyTypeObject(err_type), PPyTypeObject(PyExc_SyntaxError^)) = 1) and IsType(err_value, PPyTypeObject(err_type))) then
- begin
- // Get the filename
- tmp := PyObject_GetAttrString(err_value, 'filename');
- if tmp <> nil then begin
- if PyString_Check(tmp) then
- s_filename := PyString_AsDelphiString(tmp)
- else if tmp = Py_None then
- s_filename := '???';
- Py_XDECREF(tmp);
- end;
- // Get the text containing the error, cut of carriage return
- tmp := PyObject_GetAttrString(err_value, 'text');
- if Assigned(tmp) and PyString_Check(tmp) then
- s_line := Trim(PyString_AsDelphiString(tmp));
- Py_XDECREF(tmp);
- // Get the offset where the error should appear
- tmp := PyObject_GetAttrString(err_value, 'offset' );
- if Assigned(tmp) and PyInt_Check(tmp) then
- i_offset := PyInt_AsLong(tmp);
- Py_XDECREF(tmp);
- // Get the line number of the error
- tmp := PyObject_GetAttrString(err_value, 'lineno' );
- if Assigned(tmp) and PyInt_Check(tmp) then
- i_line_number := PyInt_AsLong(tmp);
- Py_XDECREF(tmp);
- // Get the message of the error
- tmp := PyObject_GetAttrString(err_value, 'msg' );
- if Assigned(tmp) and PyString_Check(tmp) then
- s_value := PyString_AsDelphiString(tmp);
+ if (PyType_IsSubtype(PPyTypeObject(err_type), PPyTypeObject(PyExc_SyntaxError^)) = 1)
+ and IsType(err_value, PPyTypeObject(err_type))
+ then
+ begin
+ // Get the filename
+ tmp := PyObject_GetAttrString(err_value, 'filename');
+ if tmp <> nil then begin
+ if PyUnicode_Check(tmp) then
+ s_filename := PyUnicode_AsWideString(tmp)
+ else if tmp = Py_None then
+ s_filename := '???';
Py_XDECREF(tmp);
end;
+ // Get the text containing the error, cut of carriage return
+ tmp := PyObject_GetAttrString(err_value, 'text');
+ if Assigned(tmp) and PyUnicode_Check(tmp) then
+ s_line := Trim(PyUnicode_AsWideString(tmp));
+ Py_XDECREF(tmp);
+ // Get the offset where the error should appear
+ tmp := PyObject_GetAttrString(err_value, 'offset' );
+ if Assigned(tmp) and PyLong_Check(tmp) then
+ i_offset := PyLong_AsLong(tmp);
+ Py_XDECREF(tmp);
+ // Get the line number of the error
+ tmp := PyObject_GetAttrString(err_value, 'lineno' );
+ if Assigned(tmp) and PyLong_Check(tmp) then
+ i_line_number := PyLong_AsLong(tmp);
+ Py_XDECREF(tmp);
+ // Get the message of the error
+ tmp := PyObject_GetAttrString(err_value, 'msg' );
+ if Assigned(tmp) and PyUnicode_Check(tmp) then
+ s_value := PyUnicode_AsWideString(tmp);
+ Py_XDECREF(tmp);
+ end;
// If all is ok
if s_value <> '' then
begin
@@ -5459,11 +4630,8 @@ procedure TPythonEngine.RaiseError;
function GetTypeAsString( obj : PPyObject ) : string;
begin
- if PyClass_Check( obj ) then
- with PPyClassObject(obj)^ do
- Result := PyString_AsDelphiString(cl_name)
- else if PyType_CheckExact( obj ) then
- Result := string(PPyTypeObject(obj).tp_name)
+ if PyType_CheckExact( obj ) then
+ Result := string(PPyTypeObject(obj).tp_name)
else
Result := PyObjectAsString(obj);
end;
@@ -5554,8 +4722,6 @@ procedure TPythonEngine.RaiseError;
raise Define( EPySystemError.Create(''), s_type, s_value )
else if (PyErr_GivenExceptionMatches(err_type, PyExc_MemoryError^) <> 0) then
raise Define( EPyMemoryError.Create(''), s_type, s_value )
- else if (not IsPython3000) and (PyErr_GivenExceptionMatches(err_type, PyExc_StandardError^) <> 0) then
- raise Define( EPyStandardError.Create(''), s_type, s_value )
else if (PyErr_GivenExceptionMatches(err_type, PyExc_UserWarning^) <> 0) then
raise Define( EPyUserWarning.Create(''), s_type, s_value )
else if (PyErr_GivenExceptionMatches(err_type, PyExc_DeprecationWarning^) <> 0) then
@@ -5582,24 +4748,23 @@ procedure TPythonEngine.RaiseError;
function TPythonEngine.PyObjectAsString( obj : PPyObject ) : string;
var
- s : PPyObject;
- w : UnicodeString;
+ S : PPyObject;
+ W : UnicodeString;
begin
- CheckPython;
Result := '';
if not Assigned( obj ) then
Exit;
if PyUnicode_Check(obj) then
begin
- w := PyUnicode_AsWideString(obj);
- Result := string(w);
+ W := PyUnicode_AsWideString(obj);
+ Result := string(W);
Exit;
end;
- s := PyObject_Str( obj );
- if Assigned(s) and PyString_Check(s) then
- Result := PyString_AsDelphiString(s);
- Py_XDECREF(s);
+ S := PyObject_Str( obj );
+ if Assigned(S) and PyUnicode_Check(S) then
+ Result := PyUnicode_AsWideString(S);
+ Py_XDECREF(S);
end;
procedure TPythonEngine.DoRedirectIO;
@@ -5681,10 +4846,7 @@ function TPythonEngine.FindClient( const aName : string ) : TEngineClient;
function TPythonEngine.EncodeString(const str: UnicodeString): AnsiString; {$IFDEF FPC}overload;{$ENDIF}
begin
- if IsPython3000 then
- Result := UTF8Encode(str)
- else
- Result := AnsiString(str);
+ Result := UTF8Encode(str)
end;
{$IFDEF FPC}
@@ -5840,7 +5002,7 @@ function TPythonEngine.VariantAsPyObject( const V : Variant ) : PPyObject;
varShortInt,
varWord,
varLongWord,
- varInteger: Result := PyInt_FromLong( DeRefV );
+ varInteger: Result := PyLong_FromLong( DeRefV );
varInt64: Result := PyLong_FromLongLong( DeRefV );
varSingle,
varDouble,
@@ -5883,7 +5045,7 @@ function TPythonEngine.VariantAsPyObject( const V : Variant ) : PPyObject;
varString:
begin
s := AnsiString(DeRefV);
- Result := PyString_FromStringAndSize(PAnsiChar(s), Length(s));
+ Result := PyBytes_FromStringAndSize(PAnsiChar(s), Length(s));
end;
varUString:
begin
@@ -5921,8 +5083,8 @@ function TPythonEngine.PyObjectAsVariant( obj : PPyObject ) : Variant;
begin
member := PyObject_GetAttrString( obj, PAnsiChar(AMember) );
CheckError(False);
- if PyInt_Check(member) then
- Result := PyInt_AsLong(member)
+ if PyLong_Check(member) then
+ Result := PyLong_AsLong(member)
else
raise EPythonError.CreateFmt('Unexpected type found in member %s of a time_struct object', [AMember]);
Py_XDecRef(member);
@@ -5992,17 +5154,17 @@ function TPythonEngine.PyObjectAsVariant( obj : PPyObject ) : Variant;
else if PyTuple_Check( obj ) and (PyTuple_Size(obj) = 9) then
begin
for i := 0 to 8 do
- if not PyInt_Check(PyTuple_GetItem(obj, i)) then
+ if not PyLong_Check(PyTuple_GetItem(obj, i)) then
Exit;
- y := PyInt_AsLong( PyTuple_GetItem(obj, 0) );
- m := PyInt_AsLong( PyTuple_GetItem(obj, 1) );
- d := PyInt_AsLong( PyTuple_GetItem(obj, 2) );
- h := PyInt_AsLong( PyTuple_GetItem(obj, 3) );
- mi := PyInt_AsLong( PyTuple_GetItem(obj, 4) );
- sec := PyInt_AsLong( PyTuple_GetItem(obj, 5) );
- wd := PyInt_AsLong( PyTuple_GetItem(obj, 6) );
- jd := PyInt_AsLong( PyTuple_GetItem(obj, 7) );
- dl := PyInt_AsLong( PyTuple_GetItem(obj, 8) );
+ y := PyLong_AsLong( PyTuple_GetItem(obj, 0) );
+ m := PyLong_AsLong( PyTuple_GetItem(obj, 1) );
+ d := PyLong_AsLong( PyTuple_GetItem(obj, 2) );
+ h := PyLong_AsLong( PyTuple_GetItem(obj, 3) );
+ mi := PyLong_AsLong( PyTuple_GetItem(obj, 4) );
+ sec := PyLong_AsLong( PyTuple_GetItem(obj, 5) );
+ wd := PyLong_AsLong( PyTuple_GetItem(obj, 6) );
+ jd := PyLong_AsLong( PyTuple_GetItem(obj, 7) );
+ dl := PyLong_AsLong( PyTuple_GetItem(obj, 8) );
if not (m in [1..12]) or
not (d in [1..31]) or
not (h in [0..23]) or
@@ -6043,13 +5205,10 @@ function TPythonEngine.PyObjectAsVariant( obj : PPyObject ) : Variant;
Result := PyObject_IsTrue(obj) = 1
else if PyLong_Check(obj) then
Result := PyLong_AsLongLong(obj)
- // changed the order of Long and int check (KV)
- else if PyInt_Check(obj) then
- Result := PyInt_AsLong(obj)
else if PyUnicode_Check(obj) then
Result := PyUnicode_AsWideString(obj)
- else if PyString_Check(obj) then
- Result := PyObjectAsString(obj)
+ else if PyBytes_Check(obj) then
+ Result := AnsiString(PyBytes_AsString(obj))
else if ExtractDate( Result ) then
begin
// Nothing to do
@@ -6083,24 +5242,24 @@ function TPythonEngine.PyObjectAsVariant( obj : PPyObject ) : Variant;
function TPythonEngine.VarRecAsPyObject( v : TVarRec ) : PPyObject;
begin
case v.VType of
- vtInteger: Result := PyInt_FromLong( v.VInteger );
- vtBoolean: Result := PyInt_FromLong( Integer(v.VBoolean) );
- vtChar: Result := PyString_FromString( PAnsiChar(AnsiString(v.VChar)) );
+ vtInteger: Result := PyLong_FromLong( v.VInteger );
+ vtBoolean: Result := PyLong_FromLong( Integer(v.VBoolean) );
+ vtChar: Result := PyUnicode_FromAnsiString(AnsiString(v.VChar));
vtExtended: Result := PyFloat_FromDouble( v.VExtended^ );
vtString:
begin
if Assigned(v.VString) then
- Result := PyString_FromString(PAnsiChar(AnsiString(v.VString^)))
+ Result := PyUnicode_FromAnsiString(AnsiString(v.VString^))
else
- Result := PyString_FromString( '' );
+ Result := PyUnicode_FromAnsiString('');
end;
- vtPChar: Result := PyString_FromString( v.VPChar );
+ vtPChar: Result := PyUnicode_FromAnsiString(AnsiString(v.VPChar));
vtAnsiString:
begin
if Assigned(v.VAnsiString) then
- Result := PyString_FromString( v.VAnsiString )
+ Result := PyUnicode_FromAnsiString(PAnsiChar(v.VAnsiString))
else
- Result := PyString_FromString('');
+ Result := PyUnicode_FromAnsiString('');
end;
vtCurrency: Result := PyFloat_FromDouble( v.VCurrency^ );
vtVariant: Result := VariantAsPyObject( v.VVariant^ );
@@ -6281,7 +5440,7 @@ function TPythonEngine.StringsToPyList( strings : TStrings ) : PPyObject;
raise EPythonError.Create('Could not create a new list object');
for i := 0 to strings.Count - 1 do
PyList_SetItem( Result, i,
- PyString_FromDelphiString( strings.Strings[i]) );
+ PyUnicode_FromString( strings.Strings[i]) );
end;
function TPythonEngine.StringsToPyTuple( strings : TStrings ) : PPyObject;
@@ -6293,7 +5452,7 @@ function TPythonEngine.StringsToPyTuple( strings : TStrings ) : PPyObject;
raise EPythonError.Create('Could not create a new tuple object');
for i := 0 to strings.Count - 1 do
PyTuple_SetItem( Result, i,
- PyString_FromDelphiString( strings.Strings[i]) );
+ PyUnicode_FromString( strings.Strings[i]) );
end;
procedure TPythonEngine.PyListToStrings( list : PPyObject; strings : TStrings );
@@ -6352,7 +5511,7 @@ function TPythonEngine.PyUnicode_AsWideString( obj : PPyObject ) : UnicodeString
raise EPythonError.Create('PyUnicode_AsWideString expects a Unicode Python object');
end;
-function TPythonEngine.PyUnicode_FromWideString( const AString : UnicodeString) : PPyObject;
+function TPythonEngine.PyUnicode_FromWideString(const AString : UnicodeString) : PPyObject;
{$IFDEF POSIX}
var
_ucs4Str : UCS4String;
@@ -6436,7 +5595,7 @@ function TPythonEngine.SetToList( data : Pointer; size : Integer ) : PPyObject;
for i := 0 to size*8-1 do
if GetBit(i) then
begin
- PyList_SetItem( Result, cpt, PyInt_FromLong(i) );
+ PyList_SetItem( Result, cpt, PyLong_FromLong(i) );
Inc(cpt);
end;
end;
@@ -6540,55 +5699,20 @@ function TPythonEngine.PyTZInfo_CheckExact( obj : PPyObject ) : Boolean;
Result := Assigned(FPyDateTime_DateType) and (Pointer(obj^.ob_type) = FPyDateTime_TZInfoType);
end;
-function TPythonEngine.PyString_AsDelphiString(ob: PPyObject): string;
-begin
- if PyUnicode_Check(ob) then
- Result := string(PyUnicode_AsWideString(ob))
- else
- Result := string(PyString_AsString(ob));
-end;
-
-function TPythonEngine.PyString_AsAnsiString( ob: PPyObject): AnsiString;
+function TPythonEngine.PyUnicode_FromString(const Str: string): PPyObject;
begin
- if PyUnicode_Check(ob) then
- Result := AnsiString(PyUnicode_AsWideString(ob))
- else
- Result := AnsiString(PyString_AsString(ob));
+ Result := PyUnicode_FromWideString(UnicodeString(str));
end;
-function TPythonEngine.PyString_AsWideString( ob: PPyObject): UnicodeString;
-begin
- if PyUnicode_Check(ob) then
- Result := PyUnicode_AsWideString(ob)
- else
- Result := UnicodeString(PyString_AsString(ob));
-end;
-
-function TPythonEngine.PyString_FromDelphiString(str: string): PPyObject;
-begin
- if IsPython3000 then
- begin
- Result := PyUnicode_FromWideString(UnicodeString(str));
- end
- else
- Result := DLL_PyString_FromString(PAnsiChar(AnsiString(str)));
-end;
-
-function TPythonEngine.PyString_FromString( str: PAnsiChar): PPyObject;
+function TPythonEngine.PyUnicode_FromAnsiString(const Str: AnsiString): PPyObject;
var
_text : UnicodeString;
begin
- if IsPython3000 then
- begin
- _text := UnicodeString(str);
- Result := PyUnicode_FromWideString(_text);
- end
- else
- Result := DLL_PyString_FromString(str);
+ _text := UnicodeString(str);
+ Result := PyUnicode_FromWideString(_text);
end;
-
(*******************************************************)
(** **)
(** class TEngineClient **)
@@ -7269,7 +6393,7 @@ procedure TError.BuildError( const ModuleName : AnsiString );
with Owner.Owner.Engine do
begin
if ErrorType = etString then
- Error := PyString_FromString( PAnsiChar(Text) )
+ Error := PyUnicode_FromAnsiString(Text)
else if ErrorType = etClass then
begin
if FParentClass.Name <> '' then
@@ -7295,7 +6419,6 @@ procedure TError.RaiseError( const msg : AnsiString );
procedure TError.RaiseErrorObj( const msg : AnsiString; obj : PPyObject );
var
args, res, str : PPyObject;
- inst : PPyInstanceObject;
i : Integer;
keys : PPyObject;
key : PPyObject;
@@ -7314,21 +6437,12 @@ procedure TError.RaiseErrorObj( const msg : AnsiString; obj : PPyObject );
Py_DECREF(args);
if not Assigned(res) then
raise Exception.CreateFmt('TError.RaiseErrorObj: Could not create an instance of "%s"', [Self.Name]);
- if PyInstance_Check( res ) then
- begin
- inst := PPyInstanceObject(res);
- Py_XDECREF( inst^.in_dict );
- inst^.in_dict := obj;
- str := PyString_FromString( PAnsiChar(msg) );
- PyDict_SetItemString( obj, 'args', str );
- Py_XDecRef(str);
- end
- else if PyObject_TypeCheck(res, PPyTypeObject(PyExc_Exception^)) then
+ if PyObject_TypeCheck(res, PPyTypeObject(PyExc_Exception^)) then
begin
args := PyTuple_New(1);
if not Assigned(args) then
raise Exception.Create('TError.RaiseErrorObj: Could not create an empty tuple');
- str := PyString_FromString( PAnsiChar(msg) );
+ str := PyUnicode_FromAnsiString(msg);
PyTuple_SetItem(args, 0, str);
res := PyEval_CallObjectWithKeywords(Error, args, nil);
Py_DECREF(args);
@@ -7477,7 +6591,7 @@ procedure TPythonModule.DefineDocString;
if DocString.Text <> '' then
begin
doc :=
- PyString_FromDelphiString(CleanString(FDocString.Text, False));
+ PyUnicode_FromString(CleanString(FDocString.Text, False));
PyObject_SetAttrString( FModule, '__doc__', doc );
Py_XDecRef(doc);
CheckError(False);
@@ -7492,15 +6606,12 @@ procedure TPythonModule.MakeModule;
Exit;
with Engine do
begin
- if IsPython3000 then begin
- FillChar(FModuleDef, SizeOf(FModuleDef), 0);
- FModuleDef.m_base.ob_refcnt := 1;
- FModuleDef.m_name := PAnsiChar(ModuleName);
- FModuleDef.m_methods := MethodsData;
- FModuleDef.m_size := -1;
- FModule := Py_InitModule3000( ModuleDef );
- end else
- FModule := Py_InitModule( PAnsiChar(ModuleName), MethodsData );
+ FillChar(FModuleDef, SizeOf(FModuleDef), 0);
+ FModuleDef.m_base.ob_refcnt := 1;
+ FModuleDef.m_name := PAnsiChar(ModuleName);
+ FModuleDef.m_methods := MethodsData;
+ FModuleDef.m_size := -1;
+ FModule := Py_InitModule( ModuleDef );
DefineDocString;
end;
end;
@@ -7794,7 +6905,7 @@ function TPyObject.GetAttr(key : PAnsiChar) : PPyObject;
begin
with GetPythonEngine do
begin
- PyKey := PyString_FromString(key);
+ PyKey := PyUnicode_FromAnsiString(key);
try
Result := PyObject_GenericGetAttr(GetSelf, PyKey)
finally
@@ -7816,7 +6927,7 @@ function TPyObject.SetAttr(key : PAnsiChar; value : PPyObject) : Integer;
function TPyObject.Repr : PPyObject;
begin
Result :=
- GetPythonEngine.PyString_FromDelphiString( Format('<%s at %x>',
+ GetPythonEngine.PyUnicode_FromString( Format('<%s at %x>',
[PythonType.TypeName, NativeInt(self)]) );
end;
@@ -8123,21 +7234,11 @@ function TPyObject.SqItem( idx : NativeInt ) : PPyObject;
Result := GetPythonEngine.ReturnNone;
end;
-function TPyObject.SqSlice( idx1, idx2 : NativeInt ) : PPyObject;
-begin
- Result := GetPythonEngine.ReturnNone;
-end;
-
function TPyObject.SqAssItem( idx : NativeInt; obj : PPyObject) : Integer;
begin
Result := -1;
end;
-function TPyObject.SqAssSlice( idx1, idx2 : NativeInt; obj : PPyObject): integer;
-begin
- Result := -1;
-end;
-
function TPyObject.SqContains(obj: PPyObject): integer;
begin
Result := -1;
@@ -8334,24 +7435,6 @@ procedure TPythonType.SetDocString( value : TStringList );
function TPythonType.TypeFlagsAsInt : LongInt;
begin
Result := 0;
- if tpfHaveGetCharBuffer in TypeFlags then
- Result := Result or Py_TPFLAGS_HAVE_GETCHARBUFFER;
- if tpfHaveSequenceIn in TypeFlags then
- Result := Result or Py_TPFLAGS_HAVE_SEQUENCE_IN;
- if tpfGC in TypeFlags then
- Result := Result or Py_TPFLAGS_GC;
- if tpfHaveInplaceOps in TypeFlags then
- Result := Result or Py_TPFLAGS_HAVE_INPLACEOPS;
- if tpfCheckTypes in TypeFlags then
- Result := Result or Py_TPFLAGS_CHECKTYPES;
- if tpfHaveRichCompare in TypeFlags then
- Result := Result or Py_TPFLAGS_HAVE_RICHCOMPARE;
- if tpfHaveWeakRefs in TypeFlags then
- Result := Result or Py_TPFLAGS_HAVE_WEAKREFS;
- if tpfHaveIter in TypeFlags then
- Result := Result or Py_TPFLAGS_HAVE_ITER;
- if tpfHaveClass in TypeFlags then
- Result := Result or Py_TPFLAGS_HAVE_CLASS;
if tpfHeapType in TypeFlags then
Result := Result or Py_TPFLAGS_HEAPTYPE;
if tpfBaseType in TypeFlags then
@@ -8362,6 +7445,28 @@ function TPythonType.TypeFlagsAsInt : LongInt;
Result := Result or Py_TPFLAGS_READYING;
if tpfHaveGC in TypeFlags then
Result := Result or Py_TPFLAGS_HAVE_GC;
+ if tpVectorCall in TypeFlags then
+ Result := Result or _Py_TPFLAGS_HAVE_VECTORCALL;
+ if tpMethodDescriptor in TypeFlags then
+ Result := Result or Py_TPFLAGS_METHOD_DESCRIPTOR;
+ if tpHaveVersionTag in TypeFlags then
+ Result := Result or Py_TPFLAGS_HAVE_VERSION_TAG;
+ if tpValidVersionTag in TypeFlags then
+ Result := Result or Py_TPFLAGS_VALID_VERSION_TAG;
+ if tpIsAbstract in TypeFlags then
+ Result := Result or Py_TPFLAGS_IS_ABSTRACT;
+ if tpLongSubclass in TypeFlags then
+ Result := Result or Py_TPFLAGS_LONG_SUBCLASS;
+ if tpListSubClass in TypeFlags then
+ Result := Result or Py_TPFLAGS_LIST_SUBCLASS;
+ if tpTupleSubclass in TypeFlags then
+ Result := Result or Py_TPFLAGS_TUPLE_SUBCLASS;
+ if tpBytesSubclass in TypeFlags then
+ Result := Result or Py_TPFLAGS_BYTES_SUBCLASS;
+ if tpBaseExcSubclass in TypeFlags then
+ Result := Result or Py_TPFLAGS_BASE_EXC_SUBCLASS;
+ if tpTypeSubclass in TypeFlags then
+ Result := Result or Py_TPFLAGS_TYPE_SUBCLASS;
end;
// Type services
@@ -8715,22 +7820,11 @@ function TPythonType_SqItem( pSelf : PPyObject; idx : NativeInt ) : PPyObject;
Result := PythonToDelphi(pSelf).SqItem( idx );
end;
-function TPythonType_SqSlice( pSelf : PPyObject; idx1, idx2 : NativeInt ) : PPyObject; cdecl;
-begin
- Result := PythonToDelphi(pSelf).SqSlice( idx1, idx2 );
-end;
-
function TPythonType_SqAssItem( pSelf : PPyObject; idx : NativeInt; obj : PPyObject) : Integer; cdecl;
begin
Result := PythonToDelphi(pSelf).SqAssItem( idx, obj );
end;
-function TPythonType_SqAssSlice( pSelf : PPyObject; idx1, idx2 : NativeInt; obj : PPyObject): integer; cdecl;
-begin
- Result := PythonToDelphi(pSelf).SqAssSlice( idx1, idx2, obj );
-end;
-
-
// Mapping services
function TPythonType_MpLength( pSelf : PPyObject ) : NativeInt; cdecl;
@@ -8784,8 +7878,6 @@ procedure TPythonType.InitServices;
tp_repr := TPythonType_Repr;
if bsStr in Services.Basic then
tp_str := TPythonType_Str;
- if (bsCompare in Services.Basic) and not FEngine.IsPython3000 then
- tp_compare := TPythonType_Compare;
if bsHash in Services.Basic then
tp_hash := TPythonType_Hash;
if bsGetAttrO in Services.Basic then
@@ -8818,117 +7910,60 @@ procedure TPythonType.InitServices;
// Number services
if Services.Number <> [] then
begin
- if FEngine.IsPython3000 then
- begin
- FNumber := AllocMem(SizeOf(PyNumberMethods300)); // zeroes memory
- with PPyNumberMethods300(FNumber)^ do
- begin
- if nsAdd in Services.Number then nb_add := TPythonType_NbAdd; // #3.1
- if nsSubtract in Services.Number then nb_subtract := TPythonType_NbSubtract; // #3.2
- if nsMultiply in Services.Number then nb_multiply := TPythonType_NbMultiply; // #3.3
- if nsDivide in Services.Number then; // gone in Python 3.x
- if nsFloorDivide in Services.Number then nb_floor_divide := TPythonType_NbFloorDivide; // #3.30
- if nsTrueDivide in Services.Number then nb_true_divide := TPythonType_NbTrueDivide; // #3.31
- if (nsMatrixMultiply in Services.Number) and ((FEngine.MajorVersion > 3)
- or ((FEngine.MajorVersion = 3) and (FEngine.MinorVersion >= 5)))
- then
- nb_matrix_multiply := TPythonType_NbMatrixMultiply; // #3.35
- if nsRemainder in Services.Number then nb_remainder := TPythonType_NbRemainder; // #3.4
- if nsDivmod in Services.Number then nb_divmod := TPythonType_NbDivmod; // #3.5
- if nsPower in Services.Number then nb_power := TPythonType_NbPower; // #3.6
- if nsNegative in Services.Number then nb_negative := TPythonType_NbNegative; // #3.7
- if nsPositive in Services.Number then nb_positive := TPythonType_NbPositive; // #3.8
- if nsAbsolute in Services.Number then nb_absolute := TPythonType_NbAbsolute; // #3.9
- if nsNonZero in Services.Number then ; // gone in Python 3.x
- if nsBool in Services.Number then nb_bool := TPythonType_NbBool; // #3.10
- if nsInvert in Services.Number then nb_invert := TPythonType_NbInvert; // #3.11
- if nsLShift in Services.Number then nb_lshift := TPythonType_NbLShift; // #3.12
- if nsRShift in Services.Number then nb_rshift := TPythonType_NbRShift; // #3.13
- if nsAnd in Services.Number then nb_and := TPythonType_NbAnd; // #3.14
- if nsXor in Services.Number then nb_xor := TPythonType_NbXor; // #3.15
- if nsOr in Services.Number then nb_or := TPythonType_NbOr; // #3.16
- if nsCoerce in Services.Number then ;// gone in Python 3.x
- if nsInt in Services.Number then nb_int := TPythonType_NbInt; // #3.17
- if nsLong in Services.Number then ;// gone in Python 3.x, now nb_reserved
- if nsFloat in Services.Number then nb_float := TPythonType_NbFloat; // #3.19
- if nsOct in Services.Number then ;// gone in Python 3.x
- if nsHex in Services.Number then ;// gone in Python 3.x
- if nsInplaceAdd in Services.InplaceNumber then nb_inplace_add := TPythonType_NbInplaceAdd; // #3.20
- if nsInplaceSubtract in Services.InplaceNumber then nb_inplace_subtract := TPythonType_NbInplaceSubtract; // #3.21
- if nsInplaceMultiply in Services.InplaceNumber then nb_inplace_multiply := TPythonType_NbInplaceMultiply; // #3.22
- if nsInplaceDivide in Services.InplaceNumber then ;// gone in Python 3.x
- if nsInplaceFloorDivide in Services.InplaceNumber then nb_inplace_floor_divide := TPythonType_NbInplaceFloorDivide; // #3.32
- if nsInplaceTrueDivide in Services.InplaceNumber then nb_inplace_true_divide := TPythonType_NbInplaceTrueDivide; // #3.33
- if nsInplaceRemainder in Services.InplaceNumber then nb_inplace_remainder := TPythonType_NbInplaceRemainder; // #3.23
- if nsInplacePower in Services.InplaceNumber then nb_inplace_power := TPythonType_NbInplacePower; // #3.24
- if nsInplaceLShift in Services.InplaceNumber then nb_inplace_lshift := TPythonType_NbInplaceLShift; // #3.25
- if nsInplaceRShift in Services.InplaceNumber then nb_inplace_rshift := TPythonType_NbInplaceRShift; // #3.26
- if nsInplaceAnd in Services.InplaceNumber then nb_inplace_and := TPythonType_NbInplaceAnd; // #3.27
- if nsInplaceXor in Services.InplaceNumber then nb_inplace_xor := TPythonType_NbInplaceXor; // #3.28
- if nsInplaceOr in Services.InplaceNumber then nb_inplace_or := TPythonType_NbInplaceOr; // #3.29
- if (nsInplaceMatrixMultiply in Services.InplaceNumber) and
- ((FEngine.MajorVersion > 3) or ((FEngine.MajorVersion = 3)
- and (FEngine.MinorVersion >= 5)))
- then
- nb_inplace_matrix_multiply := TPythonType_NbInplaceMatrixMultiply; // #3.36
- end;
- end
- else
+ tp_as_number := @FNumber;
+
+ with FNumber do
begin
- FNumber := AllocMem(SizeOf(PyNumberMethods200));
- with PPyNumberMethods200(FNumber)^ do
- begin
- if nsAdd in Services.Number then nb_add := TPythonType_NbAdd; // #2.1
- if nsSubtract in Services.Number then nb_subtract := TPythonType_NbSubtract; // #2.2
- if nsMultiply in Services.Number then nb_multiply := TPythonType_NbMultiply; // #2.3
- if nsDivide in Services.Number then nb_divide := TPythonType_NbDivide; // #2.4
- if nsFloorDivide in Services.Number then nb_floor_divide := TPythonType_NbFloorDivide; // #2.35
- if nsTrueDivide in Services.Number then nb_true_divide := TPythonType_NbTrueDivide; // #2.36
- if nsMatrixMultiply in Services.Number then ;// new in Python 3.x
- if nsRemainder in Services.Number then nb_remainder := TPythonType_NbRemainder; // #2.5
- if nsDivmod in Services.Number then nb_divmod := TPythonType_NbDivmod; // #2.6
- if nsPower in Services.Number then nb_power := TPythonType_NbPower; // #2.7
- if nsNegative in Services.Number then nb_negative := TPythonType_NbNegative; // #2.8
- if nsPositive in Services.Number then nb_positive := TPythonType_NbPositive; // #2.9
- if nsAbsolute in Services.Number then nb_absolute := TPythonType_NbAbsolute; // #2.10
- if nsNonZero in Services.Number then nb_nonzero := TPythonType_NbNonZero; // #2.11
- if nsBool in Services.Number then // new in Python 3.x
- if nsInvert in Services.Number then nb_invert := TPythonType_NbInvert; // #2.12
- if nsLShift in Services.Number then nb_lshift := TPythonType_NbLShift; // #2.13
- if nsRShift in Services.Number then nb_rshift := TPythonType_NbRShift; // #2.14
- if nsAnd in Services.Number then nb_and := TPythonType_NbAnd; // #2.15
- if nsXor in Services.Number then nb_xor := TPythonType_NbXor; // #2.16
- if nsOr in Services.Number then nb_or := TPythonType_NbOr; // #2.17
- if nsCoerce in Services.Number then nb_coerce := TPythonType_NbCoerce; // #2.18
- if nsInt in Services.Number then nb_int := TPythonType_NbInt; // #2.19
- if nsLong in Services.Number then nb_long := TPythonType_NbLong; // #2.20
- if nsFloat in Services.Number then nb_float := TPythonType_NbFloat; // #2.21
- if nsOct in Services.Number then nb_oct := TPythonType_NbOct; // #2.22
- if nsHex in Services.Number then nb_hex := TPythonType_NbHex; // #2.23
- if nsInplaceAdd in Services.InplaceNumber then nb_inplace_add := TPythonType_NbInplaceAdd; // #2.24
- if nsInplaceSubtract in Services.InplaceNumber then nb_inplace_subtract := TPythonType_NbInplaceSubtract; // #2.25
- if nsInplaceMultiply in Services.InplaceNumber then nb_inplace_multiply := TPythonType_NbInplaceMultiply; // #2.26
- if nsInplaceDivide in Services.InplaceNumber then nb_inplace_divide := TPythonType_NbInplaceDivide; // #2.27
- if nsInplaceFloorDivide in Services.InplaceNumber then nb_inplace_floor_divide := TPythonType_NbInplaceFloorDivide; // #2.37
- if nsInplaceTrueDivide in Services.InplaceNumber then nb_inplace_true_divide := TPythonType_NbInplaceTrueDivide; // #2.38
- if nsInplaceRemainder in Services.InplaceNumber then nb_inplace_remainder := TPythonType_NbInplaceRemainder; // #2.28
- if nsInplacePower in Services.InplaceNumber then nb_inplace_power := TPythonType_NbInplacePower; // #2.29
- if nsInplaceLShift in Services.InplaceNumber then nb_inplace_lshift := TPythonType_NbInplaceLShift; // #2.30
- if nsInplaceRShift in Services.InplaceNumber then nb_inplace_rshift := TPythonType_NbInplaceRShift; // #2.31
- if nsInplaceAnd in Services.InplaceNumber then nb_inplace_and := TPythonType_NbInplaceAnd; // #2.32
- if nsInplaceXor in Services.InplaceNumber then nb_inplace_xor := TPythonType_NbInplaceXor; // #2.33
- if nsInplaceOr in Services.InplaceNumber then nb_inplace_or := TPythonType_NbInplaceOr; // #2.34
- if nsInplaceMatrixMultiply in Services.InplaceNumber then ; // new in Python 3.5
- end;
+ if nsAdd in Services.Number then nb_add := TPythonType_NbAdd; // #3.1
+ if nsSubtract in Services.Number then nb_subtract := TPythonType_NbSubtract; // #3.2
+ if nsMultiply in Services.Number then nb_multiply := TPythonType_NbMultiply; // #3.3
+ if nsFloorDivide in Services.Number then nb_floor_divide := TPythonType_NbFloorDivide; // #3.30
+ if nsTrueDivide in Services.Number then nb_true_divide := TPythonType_NbTrueDivide; // #3.31
+ if (nsMatrixMultiply in Services.Number) and ((FEngine.MajorVersion > 3)
+ or ((FEngine.MajorVersion = 3) and (FEngine.MinorVersion >= 5)))
+ then
+ nb_matrix_multiply := TPythonType_NbMatrixMultiply; // #3.35
+ if nsRemainder in Services.Number then nb_remainder := TPythonType_NbRemainder; // #3.4
+ if nsDivmod in Services.Number then nb_divmod := TPythonType_NbDivmod; // #3.5
+ if nsPower in Services.Number then nb_power := TPythonType_NbPower; // #3.6
+ if nsNegative in Services.Number then nb_negative := TPythonType_NbNegative; // #3.7
+ if nsPositive in Services.Number then nb_positive := TPythonType_NbPositive; // #3.8
+ if nsAbsolute in Services.Number then nb_absolute := TPythonType_NbAbsolute; // #3.9
+ if nsBool in Services.Number then nb_bool := TPythonType_NbBool; // #3.10
+ if nsInvert in Services.Number then nb_invert := TPythonType_NbInvert; // #3.11
+ if nsLShift in Services.Number then nb_lshift := TPythonType_NbLShift; // #3.12
+ if nsRShift in Services.Number then nb_rshift := TPythonType_NbRShift; // #3.13
+ if nsAnd in Services.Number then nb_and := TPythonType_NbAnd; // #3.14
+ if nsXor in Services.Number then nb_xor := TPythonType_NbXor; // #3.15
+ if nsOr in Services.Number then nb_or := TPythonType_NbOr; // #3.16
+ if nsInt in Services.Number then nb_int := TPythonType_NbInt; // #3.17
+ if nsFloat in Services.Number then nb_float := TPythonType_NbFloat; // #3.19
+ if nsInplaceAdd in Services.InplaceNumber then nb_inplace_add := TPythonType_NbInplaceAdd; // #3.20
+ if nsInplaceSubtract in Services.InplaceNumber then nb_inplace_subtract := TPythonType_NbInplaceSubtract; // #3.21
+ if nsInplaceMultiply in Services.InplaceNumber then nb_inplace_multiply := TPythonType_NbInplaceMultiply; // #3.22
+ if nsInplaceFloorDivide in Services.InplaceNumber then nb_inplace_floor_divide := TPythonType_NbInplaceFloorDivide; // #3.32
+ if nsInplaceTrueDivide in Services.InplaceNumber then nb_inplace_true_divide := TPythonType_NbInplaceTrueDivide; // #3.33
+ if nsInplaceRemainder in Services.InplaceNumber then nb_inplace_remainder := TPythonType_NbInplaceRemainder; // #3.23
+ if nsInplacePower in Services.InplaceNumber then nb_inplace_power := TPythonType_NbInplacePower; // #3.24
+ if nsInplaceLShift in Services.InplaceNumber then nb_inplace_lshift := TPythonType_NbInplaceLShift; // #3.25
+ if nsInplaceRShift in Services.InplaceNumber then nb_inplace_rshift := TPythonType_NbInplaceRShift; // #3.26
+ if nsInplaceAnd in Services.InplaceNumber then nb_inplace_and := TPythonType_NbInplaceAnd; // #3.27
+ if nsInplaceXor in Services.InplaceNumber then nb_inplace_xor := TPythonType_NbInplaceXor; // #3.28
+ if nsInplaceOr in Services.InplaceNumber then nb_inplace_or := TPythonType_NbInplaceOr; // #3.29
+ if (nsInplaceMatrixMultiply in Services.InplaceNumber) and
+ ((FEngine.MajorVersion > 3) or ((FEngine.MajorVersion = 3)
+ and (FEngine.MinorVersion >= 5)))
+ then
+ nb_inplace_matrix_multiply := TPythonType_NbInplaceMatrixMultiply; // #3.36
end;
- tp_as_number := FNumber;
end;
// Sequence services
if Services.Sequence <> [] then
+ begin
tp_as_sequence := @FSequence;
- with FSequence do
+ with FSequence do
begin
if ssLength in Services.Sequence then
sq_length := TPythonType_SqLength;
@@ -8938,12 +7973,8 @@ procedure TPythonType.InitServices;
sq_repeat := TPythonType_SqRepeat;
if ssItem in Services.Sequence then
sq_item := TPythonType_SqItem;
- if (ssSlice in Services.Sequence) and not FEngine.IsPython3000 then
- sq_slice := TPythonType_SqSlice;
if ssAssItem in Services.Sequence then
sq_ass_item := TPythonType_SqAssItem;
- if (ssAssSlice in Services.Sequence) and not FEngine.IsPython3000 then
- sq_ass_slice := TPythonType_SqAssSlice;
if ssContains in Services.Sequence then
sq_contains := TPythonType_SqContains;
if ssInplaceConcat in Services.Sequence then
@@ -8951,12 +7982,14 @@ procedure TPythonType.InitServices;
if ssInplaceRepeat in Services.Sequence then
sq_inplace_repeat := TPythonType_SqInplaceRepeat;
end;
+ end;
// Mapping services
if Services.Mapping <> [] then
+ begin
tp_as_mapping := @FMapping;
- with FMapping do
+ with FMapping do
begin
if msLength in Services.Mapping then
mp_length := TPythonType_MpLength;
@@ -8965,6 +7998,7 @@ procedure TPythonType.InitServices;
if msAssSubscript in Services.Mapping then
mp_ass_subscript := TPythonType_MpAssSubscript;
end;
+ end;
end;
end;
@@ -8986,7 +8020,6 @@ destructor TPythonType.Destroy;
gVarType := nil;
FDocString.Free;
FServices.Free;
- FreeMem(FNumber);
inherited;
end;
@@ -9080,10 +8113,7 @@ procedure TPythonType.AddTypeVar;
FCreateFuncDef.ml_meth := GetOfObjectCallBack( TCallBack(meth), 2, ctCDECL);
FCreateFuncDef.ml_flags := METH_VARARGS;
FCreateFuncDef.ml_doc := PAnsiChar(FCreateFuncDoc);
- if GetPythonEngine.IsPython3000 then
- FCreateFunc := Engine.PyCFunction_NewEx(@FCreateFuncDef, nil, nil)
- else
- FCreateFunc := Engine.PyCFunction_New(@FCreateFuncDef, nil);
+ FCreateFunc := Engine.PyCFunction_NewEx(@FCreateFuncDef, nil, nil)
end;
Assert(Assigned(FCreateFunc));
end;
@@ -9376,7 +8406,7 @@ function TPyVar.Repr : PPyObject;
obj := GetValue;
try
Result :=
- PyString_FromDelphiString( Format('<%s: %s>',
+ PyUnicode_FromString( Format('<%s: %s>',
[PythonType.TypeName, PyObjectAsString(obj)]) );
finally
Py_XDecRef(obj);
@@ -9547,7 +8577,6 @@ procedure TPythonThread.Py_Begin_Unblock_Threads;
Py_Begin_Allow_Threads;
end;
-
(*******************************************************)
(** **)
(** Methods for new Python objects or modules **)
@@ -9584,8 +8613,7 @@ function pyio_write(self, args : PPyObject) : PPyObject;
if PyUnicode_Check(a1) then
IO.Write(PyUnicode_AsWideString(a1))
else
- if PyString_Check(a1) then
- IO.Write(IOString(PyObjectAsString(a1)));
+ IO.Write(IOString(PyObjectAsString(a1)));
end;
Result := ReturnNone;
end
@@ -9619,10 +8647,10 @@ function pyio_read(self, args : PPyObject) : PPyObject;
if PyErr_Occurred <> nil then
Result := nil
else
- Result := PyString_FromString(PAnsiChar(txt));
+ Result := PyUnicode_FromAnsiString(txt);
end
else
- Result := PyString_FromString(PAnsiChar(txt));
+ Result := PyUnicode_FromAnsiString(txt);
end
else
Result := ReturnNone;
@@ -9676,10 +8704,10 @@ function pyio_GetTypesStats(self, args : PPyObject) : PPyObject;
with GetPythonEngine do
begin
Result := PyTuple_New(4);
- PyTuple_SetItem( Result, 0, PyString_FromString(PAnsiChar(T.TypeName)) );
- PyTuple_SetItem( Result, 1, PyInt_FromLong(T.InstanceCount) );
- PyTuple_SetItem( Result, 2, PyInt_FromLong(T.CreateHits) );
- PyTuple_SetItem( Result, 3, PyInt_FromLong(T.DeleteHits) );
+ PyTuple_SetItem( Result, 0, PyUnicode_FromAnsiString(T.TypeName));
+ PyTuple_SetItem( Result, 1, PyLong_FromLong(T.InstanceCount) );
+ PyTuple_SetItem( Result, 2, PyLong_FromLong(T.CreateHits) );
+ PyTuple_SetItem( Result, 3, PyLong_FromLong(T.DeleteHits) );
end;
end;
@@ -9732,9 +8760,6 @@ function pyio_GetTypesStats(self, args : PPyObject) : PPyObject;
end;
-
-
-
(*******************************************************)
(** **)
(** Global procedures **)
diff --git a/Source/PythonGUIInputOutput.pas b/Source/PythonGUIInputOutput.pas
index 2f256431..e0db8ec8 100644
--- a/Source/PythonGUIInputOutput.pas
+++ b/Source/PythonGUIInputOutput.pas
@@ -182,9 +182,18 @@ procedure TPythonGUIInputOutput.WriteOutput;
begin
if FQueue.Count = 0 then
Exit;
- S := FQueue.Strings[ 0 ];
- FQueue.Delete(0);
- DisplayString( S )
+
+ Lock;
+ try
+ while FQueue.Count > 0 do
+ begin
+ S := FQueue.Strings[ 0 ];
+ FQueue.Delete(0);
+ DisplayString( S );
+ end;
+ finally
+ Unlock;
+ end;
end;
{PUBLIC METHODS}
diff --git a/Source/VarPyth.pas b/Source/VarPyth.pas
index 270c3725..1f97f342 100644
--- a/Source/VarPyth.pas
+++ b/Source/VarPyth.pas
@@ -68,7 +68,6 @@ function VarIsPythonTuple(const AValue: Variant): Boolean;
function VarIsPythonList(const AValue: Variant): Boolean;
function VarIsPythonDict(const AValue: Variant): Boolean;
function VarIsPythonClass(const AValue: Variant): Boolean;
-function VarIsPythonInstance(const AValue: Variant): Boolean;
function VarIsPythonMethod(const AValue: Variant): Boolean;
function VarIsPythonFunction(const AValue: Variant): Boolean;
function VarIsPythonModule(const AValue: Variant): Boolean;
@@ -239,7 +238,6 @@ TPythonData = class(TObject)
// non-destructive operations
function Equal(const Right: TPythonData): Boolean;
- function Compare(const Right: TPythonData): Integer;
function LessThan(const Right: TPythonData): Boolean;
function LessOrEqualThan(const Right: TPythonData): Boolean;
function GreaterThan(const Right: TPythonData): Boolean;
@@ -435,13 +433,13 @@ function VarIsPythonNumber(const AValue: Variant): Boolean;
function VarIsPythonString(const AValue: Variant): Boolean;
begin
Result := VarIsPython(AValue) and
- GetPythonEngine.PyString_Check(ExtractPythonObjectFrom(AValue));
+ GetPythonEngine.PyUnicode_Check(ExtractPythonObjectFrom(AValue));
end;
function VarIsPythonInteger(const AValue: Variant): Boolean;
begin
Result := VarIsPython(AValue) and
- GetPythonEngine.PyInt_Check(ExtractPythonObjectFrom(AValue));
+ GetPythonEngine.PyLong_Check(ExtractPythonObjectFrom(AValue));
end;
function VarIsPythonFloat(const AValue: Variant): Boolean;
@@ -475,12 +473,6 @@ function VarIsPythonClass(const AValue: Variant): Boolean;
or (GetPythonEngine.PyObject_HasAttrString(ExtractPythonObjectFrom(AValue), '__bases__') <> 0));
end;
-function VarIsPythonInstance(const AValue: Variant): Boolean;
-begin
- Result := VarIsPython(AValue) and
- GetPythonEngine.PyInstance_Check(ExtractPythonObjectFrom(AValue));
-end;
-
function VarIsPythonMethod(const AValue: Variant): Boolean;
begin
Result := VarIsPython(AValue) and
@@ -719,7 +711,7 @@ function Import( const AModule : AnsiString ) : Variant;
begin
with GetPythonEngine do
begin
- _module_name := PyString_FromString(PAnsiChar(AModule));
+ _module_name := PyUnicode_FromAnsiString(AModule);
try
_module := PyImport_Import(_module_name);
CheckError;
@@ -1692,7 +1684,7 @@ function TPythonVariantType.EvalPython(const V: TVarData;
Py_XDecRef(_value);
end; // of try
CheckError;
- Result := PyInt_FromLong(_result);
+ Result := PyLong_FromLong(_result);
finally
Py_XDecRef(_key);
end; // of try
@@ -1764,7 +1756,7 @@ function TPythonVariantType.EvalPython(const V: TVarData;
try
_result := PySequence_SetSlice( AObject, _start, _end, _value);
CheckError;
- Result := PyInt_FromLong(_result);
+ Result := PyLong_FromLong(_result);
finally
Py_XDecRef(_value);
end; // of try
@@ -1781,7 +1773,7 @@ function TPythonVariantType.EvalPython(const V: TVarData;
ExtractSliceIndexes(AObject, AStart, AEnd, _start, _end);
_result := PySequence_DelSlice( AObject, _start, _end);
CheckError;
- Result := PyInt_FromLong(_result);
+ Result := PyLong_FromLong(_result);
end; // of with
end; // of function
@@ -1799,7 +1791,7 @@ function TPythonVariantType.EvalPython(const V: TVarData;
try
_result := PySequence_Contains( AObject, _value );
CheckError;
- Result := PyInt_FromLong(_result);
+ Result := PyLong_FromLong(_result);
finally
Py_XDecRef(_value);
end; // of try
@@ -1856,7 +1848,7 @@ function TPythonVariantType.EvalPython(const V: TVarData;
else if (Length(Arguments) = 1) and SameText(string(AName), 'Contains') then
Result := SequenceContains(_container, Arguments[0])
else if SameText(string(AName), 'Length') then
- Result := PyInt_FromLong( GetObjectLength(_container) );
+ Result := PyLong_FromLong( GetObjectLength(_container) );
end; // of if
finally
// if the key did not exist, Python generated an exception that we must propagate through CheckError
@@ -1970,7 +1962,7 @@ function TPythonVariantType.GetProperty(var Dest: TVarData;
_len := PyObject_Length(TPythonVarData(V).VPython.PyObject);
CheckError;
// convert the length into a Python integer
- _prop := PyInt_FromLong( _len );
+ _prop := PyLong_FromLong( _len );
end; // of if
end;
end; // of if
@@ -2098,26 +2090,6 @@ function TPythonVariantType.VarDataToPythonObject(AVarData: TVarData): PPyObject
//------------------------------------------------------------------------------
{ TPythonData }
-function TPythonData.Compare(const Right: TPythonData): Integer;
-begin
- with GetPythonEngine do
- begin
- if IsPython3000 then begin
- // not used but anyway
- if Self.LessThan(Right) then
- Result := -1
- else if Self.Equal(Right) then
- Result := 0
- else
- Result := 1;
- PyErr_Clear;
- end else begin
- Result := PyObject_Compare(PyObject, Right.PyObject);
- CheckError;
- end;
- end; // of with
-end;
-
constructor TPythonData.Create(AObject: PPyObject);
begin
PyObject := AObject;
@@ -2345,20 +2317,14 @@ function TPythonData.Equal(const Right: TPythonData): Boolean;
begin
with GetPythonEngine do
begin
- if IsPython3000 then
- Result := PyObject_RichCompareBool(PyObject, Right.PyObject, Py_EQ) = 1
- else
- Result := PyObject_Compare(PyObject, Right.PyObject) = 0;
+ Result := PyObject_RichCompareBool(PyObject, Right.PyObject, Py_EQ) = 1;
CheckError;
end; // of with
end;
function TPythonData.GetAsAnsiString: AnsiString;
begin
- if Assigned(PyObject) and GetPythonEngine.PyString_CheckExact(PyObject) then
- Result := GetPythonEngine.PyString_AsString(PyObject)
- else
- Result := AnsiString(GetAsString);
+ Result := AnsiString(GetAsString);
end;
function TPythonData.GetAsString: string;
@@ -2388,23 +2354,13 @@ function TPythonData.GetAsWideString: UnicodeString;
function TPythonData.GreaterOrEqualThan(const Right: TPythonData): Boolean;
begin
with GetPythonEngine do
- begin
- if IsPython3000 then
- Result := PyObject_RichCompareBool(PyObject, Right.PyObject, Py_GE) = 1
- else
- Result := Self.Compare(Right) >= 0;
- end;
+ Result := PyObject_RichCompareBool(PyObject, Right.PyObject, Py_GE) = 1
end;
function TPythonData.GreaterThan(const Right: TPythonData): Boolean;
begin
with GetPythonEngine do
- begin
- if IsPython3000 then
- Result := PyObject_RichCompareBool(PyObject, Right.PyObject, Py_GT) = 1
- else
- Result := Self.Compare(Right) > 0;
- end;
+ Result := PyObject_RichCompareBool(PyObject, Right.PyObject, Py_GT) = 1
end;
function TPythonData.IsNone: Boolean;
@@ -2415,23 +2371,13 @@ function TPythonData.IsNone: Boolean;
function TPythonData.LessOrEqualThan(const Right: TPythonData): Boolean;
begin
with GetPythonEngine do
- begin
- if IsPython3000 then
- Result := PyObject_RichCompareBool(PyObject, Right.PyObject, Py_LE) = 1
- else
- Result := Self.Compare(Right) <= 0;
- end;
+ Result := PyObject_RichCompareBool(PyObject, Right.PyObject, Py_LE) = 1
end;
function TPythonData.LessThan(const Right: TPythonData): Boolean;
begin
with GetPythonEngine do
- begin
- if IsPython3000 then
- Result := PyObject_RichCompareBool(PyObject, Right.PyObject, Py_LT) = 1
- else
- Result := Self.Compare(Right) < 0;
- end;
+ Result := PyObject_RichCompareBool(PyObject, Right.PyObject, Py_LT) = 1
end;
procedure TPythonData.SetPyObject(const Value: PPyObject);
diff --git a/Source/WrapDelphi.pas b/Source/WrapDelphi.pas
index 01fb4104..6a1366ce 100644
--- a/Source/WrapDelphi.pas
+++ b/Source/WrapDelphi.pas
@@ -49,10 +49,10 @@
component events if you respect a specific pattern for naming your methods:
handle_ComponentName_EventName --> handle_Button1_OnClick
This function is especially useful when you subclass an existing Delphi form,
- as the form will already have all the necessary components setup, but you'll
+ as the form will already have all the necessary components setup, but you'll
be missing the events to your Python code.
If you subclass Form in Python and name your class with the same name as
- an existing Delphi form (that must be registered with RegisterClass),
+ an existing Delphi form (that must be registered with RegisterClass),
then this class will be used to instanciate the form instead of the regular empty TForm.
class TTestForm(Form):
@@ -62,20 +62,20 @@
def handle_btnAdd_OnClick(self, Sender):
self.ListBox1.Items.Add(self.Edit1.Text)
-
+
There is also a helper method named SetProps at the TPyDelphiObject level,
allowing any wrapped object to do:
button.SetProps(Left=10, Top=20, Caption='Clickme!)
You can inspect the published properties of any wrapped object by inspecting the
__published__ property.
-
+
Note that events requiring var parameters like OnCloseQuery will provide a specific object
containing a single Value property that will hold the actual value of the parameter,
because Python does not allow modifying the parameters:
def handle_close_query(self, sender, accept):
accept.Value = False # accept = False would have not effect!
-
+
Usage:
Drop a PyDelphiWrapper component on a form, set its engine and module
properties to a PythonEngine and PythonModule.
@@ -461,7 +461,6 @@ TPyDelphiContainer = class(TPyObject)
function SqLength : NativeInt; override;
function SqItem( idx : NativeInt ) : PPyObject; override;
function SqAssItem( idx : NativeInt; obj : PPyObject) : Integer; override;
- function SqSlice( idx1, idx2 : NativeInt ) : PPyObject; override;
function SqContains( obj: PPyObject): integer; override;
// Properties
@@ -500,7 +499,7 @@ TPyInterfacedObject = class(TPyObject, IInterface)
{$IFDEF FPC_HAS_CONSTREF}
function QueryInterface(constref IID: TGUID; out Obj): HResult; {$IFDEF MSWINDOWS}stdcall{$ELSE}cdecl{$ENDIF};
function _AddRef: Integer; {$IFDEF MSWINDOWS}stdcall{$ELSE}cdecl{$ENDIF};
- function _Release: Integer; {$IFDEF MSWINDOWS}stdcall{$ELSE}cdecl{$ENDIF};
+ function _Release: Integer; {$IFDEF MSWINDOWS}stdcall{$ELSE}cdecl{$ENDIF};
{$ELSE}
function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
function _AddRef: Integer; stdcall;
@@ -559,7 +558,6 @@ TPyDelphiObject = class (TPyInterfacedObject, IFreeNotificationSubscriber)
// Sequence services
function SqLength : NativeInt; override;
function SqItem( idx : NativeInt ) : PPyObject; override;
- function SqSlice( idx1, idx2 : NativeInt ) : PPyObject; override;
function SqContains( obj: PPyObject): integer; override;
function SqAssItem( idx : NativeInt; obj : PPyObject) : Integer; override;
@@ -881,7 +879,6 @@ TPyDelphiWrapper = class(TEngineClient, IFreeNotificationSubscriber)
out AValue : TObject) : Boolean;
function CheckCallableAttribute(AAttribute : PPyObject; const AAttributeName : string) : Boolean;
function CheckEnum(const AEnumName : string; AValue, AMinValue, AMaxValue : Integer) : Boolean;
- function CreateSlice(ASequence : TPyObject; AIndex1, AIndex2 : Integer) : PPyObject;
function CreateVarParam(PyDelphiWrapper : TPyDelphiWrapper; const AValue : Variant) : PPyObject;
function SetToPython(ATypeInfo: PTypeInfo; AValue : Integer) : PPyObject; overload;
function SetToPython(APropInfo: PPropInfo; AValue : Integer) : PPyObject; overload;
@@ -983,7 +980,7 @@ function SimpleValueToPython(const Value: TValue; out ErrMsg: string): PPyObject
Py_XIncRef(Result);
end
else
- Result := GetPythonEngine.PyString_FromDelphiString(GetEnumName(Value.TypeInfo,
+ Result := GetPythonEngine.PyUnicode_FromString(GetEnumName(Value.TypeInfo,
PInteger(Value.GetReferenceToRawData)^));
end;
tkSet:
@@ -1044,7 +1041,7 @@ function SimplePythonToValue(PyValue: PPyObject; TypeInfo: PTypeInfo;
end;
tkEnumeration:
begin
- S := GetPythonEngine.PyString_AsDelphiString(PyValue);
+ S := GetPythonEngine.PyObjectAsString(PyValue);
I := GetEnumValue(TypeInfo, S);
Value := TValue.FromOrdinal(TypeInfo, I);
Result := True;
@@ -1160,7 +1157,7 @@ function CheckIndex(AIndex, ACount : Integer; const AIndexName : string = 'Index
with GetPythonEngine do
begin
Result := False;
- PyErr_SetObject (PyExc_IndexError^, PyString_FromDelphiString(
+ PyErr_SetObject (PyExc_IndexError^, PyUnicode_FromString(
Format(rs_ErrCheckIndex,[AIndexName, AIndex])));
end
else
@@ -1169,9 +1166,9 @@ function CheckIndex(AIndex, ACount : Integer; const AIndexName : string = 'Index
function CheckIntAttribute(AAttribute : PPyObject; const AAttributeName : string; out AValue : Integer) : Boolean;
begin
- if GetPythonEngine.PyInt_Check(AAttribute) then
+ if GetPythonEngine.PyLong_Check(AAttribute) then
begin
- AValue := GetPythonEngine.PyInt_AsLong(AAttribute);
+ AValue := GetPythonEngine.PyLong_AsLong(AAttribute);
Result := True;
end
else
@@ -1179,7 +1176,7 @@ function CheckIntAttribute(AAttribute : PPyObject; const AAttributeName : string
Result := False;
with GetPythonEngine do
PyErr_SetObject (PyExc_AttributeError^,
- PyString_FromDelphiString(Format(rs_ErrCheckInt, [AAttributeName])));
+ PyUnicode_FromString(Format(rs_ErrCheckInt, [AAttributeName])));
end;
end;
@@ -1191,9 +1188,9 @@ function CheckBoolAttribute(AAttribute : PPyObject; const AAttributeName : strin
function CheckStrAttribute(AAttribute : PPyObject; const AAttributeName : string; out AValue : string) : Boolean;
begin
- if GetPythonEngine.PyString_Check(AAttribute) then
+ if GetPythonEngine.PyUnicode_Check(AAttribute) then
begin
- AValue := GetPythonEngine.PyString_AsDelphiString(AAttribute);
+ AValue := GetPythonEngine.PyUnicode_AsWideString(AAttribute);
Result := True;
end
else
@@ -1201,7 +1198,7 @@ function CheckStrAttribute(AAttribute : PPyObject; const AAttributeName : string
Result := False;
with GetPythonEngine do
PyErr_SetObject (PyExc_AttributeError^,
- PyString_FromDelphiString(Format(rs_ErrCheckStr, [AAttributeName])));
+ PyUnicode_FromString(Format(rs_ErrCheckStr, [AAttributeName])));
end;
end;
@@ -1214,7 +1211,7 @@ function CheckCallableAttribute(AAttribute : PPyObject; const AAttributeName : s
Result := False;
with GetPythonEngine do
PyErr_SetObject (PyExc_AttributeError^,
- PyString_FromDelphiString(Format(rs_ErrCheckCallable, [AAttributeName])));
+ PyUnicode_FromString(Format(rs_ErrCheckCallable, [AAttributeName])));
end;
end;
@@ -1227,7 +1224,7 @@ function CheckEnum(const AEnumName : string; AValue, AMinValue, AMaxValue : Int
Result := False;
with GetPythonEngine do
PyErr_SetObject (PyExc_AttributeError^,
- PyString_FromDelphiString(Format(rs_ErrCheckEnum,
+ PyUnicode_FromString(Format(rs_ErrCheckEnum,
[AEnumName, AMinValue, AMaxValue, AValue])));
end;
end;
@@ -1252,7 +1249,7 @@ function CheckObjAttribute(AAttribute : PPyObject; const AAttributeName : string
Result := False;
with GetPythonEngine do
PyErr_SetObject (PyExc_AttributeError^,
- PyString_FromDelphiString(Format(rs_ErrCheckObjOfType, [AAttributeName, AExpectedClass.ClassName])));
+ PyUnicode_FromString(Format(rs_ErrCheckObjOfType, [AAttributeName, AExpectedClass.ClassName])));
end
else
begin
@@ -1265,31 +1262,7 @@ function CheckObjAttribute(AAttribute : PPyObject; const AAttributeName : string
Result := False;
with GetPythonEngine do
PyErr_SetObject (PyExc_AttributeError^,
- PyString_FromDelphiString(Format(rs_ErrCheckObj, [AAttributeName])));
- end;
-end;
-
-function CreateSlice(ASequence : TPyObject; AIndex1, AIndex2 : Integer) : PPyObject;
-var
- i : Integer;
- tmp : Integer;
-begin
- if not CheckIndex(AIndex1, ASequence.SqLength, 'Index1') then
- Result := nil
- else if not CheckIndex(AIndex2, ASequence.SqLength, 'Index2') then
- Result := nil
- else with GetPythonEngine do
- begin
- if AIndex1 > AIndex2 then
- begin
- tmp := AIndex2;
- AIndex2 := AIndex1;
- AIndex1 := tmp;
- end;
-
- Result := PyTuple_New(AIndex2-AIndex1+1);
- for i := 0 to PyTuple_Size(Result)-1 do
- PyTuple_SetItem(Result, i, ASequence.SqItem(AIndex1));
+ PyUnicode_FromString(Format(rs_ErrCheckObj, [AAttributeName])));
end;
end;
@@ -1343,7 +1316,7 @@ function SetToPython(ATypeInfo: PTypeInfo; AValue : Integer) : PPyObject; overlo
for I := 0 to SizeOf(Integer) * 8 - 1 do
if I in S then
begin
- _name := GetPythonEngine.PyString_FromDelphiString(GetEnumName(ATypeInfo, I));
+ _name := GetPythonEngine.PyUnicode_FromString(GetEnumName(ATypeInfo, I));
GetPythonEngine.PyList_Append(Result, _name);
GetPythonEngine.Py_XDecRef(_name);
end;
@@ -1568,7 +1541,7 @@ function TPyDelphiContainer.Iter: PPyObject;
function TPyDelphiContainer.Repr: PPyObject;
begin
with GetPythonEngine do
- Result := PyString_FromDelphiString( Format('',
+ Result := PyUnicode_FromString( Format('',
[ContainerAccess.Name, NativeInt(Self)]) );
end;
@@ -1589,7 +1562,7 @@ class procedure TPyDelphiContainer.SetupType(PythonType: TPythonType);
PythonType.GenerateCreateFunction := False;
PythonType.DocString.Text := 'Abstract Container type for Delphi';
PythonType.Services.Basic := PythonType.Services.Basic + [bsRepr, bsIter];
- PythonType.Services.Sequence := PythonType.Services.Sequence + [ssLength, ssItem, ssAssItem, ssContains, ssSlice];
+ PythonType.Services.Sequence := PythonType.Services.Sequence + [ssLength, ssItem, ssAssItem, ssContains];
end;
function TPyDelphiContainer.SqAssItem(idx: NativeInt;
@@ -1610,7 +1583,7 @@ function TPyDelphiContainer.SqAssItem(idx: NativeInt;
Result := -1;
with GetPythonEngine do
PyErr_SetObject( PyExc_SystemError^,
- PyString_FromDelphiString(Format(rs_ErrSqAss, [fContainerAccess.Name])) );
+ PyUnicode_FromString(Format(rs_ErrSqAss, [fContainerAccess.Name])) );
end;
end;
@@ -1628,7 +1601,7 @@ function TPyDelphiContainer.SqContains(obj: PPyObject): integer;
Result := -1;
with GetPythonEngine do
PyErr_SetObject( PyExc_SystemError^,
- PyString_FromDelphiString(Format(rs_ErrSqContains, [fContainerAccess.Name])) );
+ PyUnicode_FromString(Format(rs_ErrSqContains, [fContainerAccess.Name])) );
end;
end;
@@ -1645,11 +1618,6 @@ function TPyDelphiContainer.SqLength: NativeInt;
Result := ContainerAccess.GetSize;
end;
-function TPyDelphiContainer.SqSlice(idx1, idx2: NativeInt): PPyObject;
-begin
- Result := CreateSlice(Self, idx1, idx2);
-end;
-
{ TPyDelphiIterator }
destructor TPyDelphiIterator.Destroy;
@@ -1678,7 +1646,7 @@ function TPyDelphiIterator.IterNext: PPyObject;
function TPyDelphiIterator.Repr: PPyObject;
begin
with GetPythonEngine do
- Result := PyString_FromDelphiString( Format('',
+ Result := PyUnicode_FromString( Format('',
[ContainerAccess.Name, NativeInt(Self)]) );
end;
@@ -1728,7 +1696,7 @@ function TPyDelphiObject.CheckBound: Boolean;
if not Result then
with GetPythonEngine do
PyErr_SetObject(PyExc_AttributeError^,
- PyString_FromDelphiString(Format(rs_ErrCheckBound, [ClassName])));
+ PyUnicode_FromString(Format(rs_ErrCheckBound, [ClassName])));
end;
function TPyDelphiObject.Compare(obj: PPyObject): Integer;
@@ -1789,7 +1757,7 @@ function TPyDelphiObject.Free_Wrapper(args: PPyObject): PPyObject;
Result := ReturnNone;
end else begin
PyErr_SetObject (PyExc_AttributeError^,
- PyString_FromDelphiString(rs_ErrFree));
+ PyUnicode_FromString(rs_ErrFree));
Result := nil;
end;
end
@@ -2035,8 +2003,8 @@ function TPyRttiObject.GetAttrO(key: PPyObject): PPyObject;
ErrMsg : string;
begin
Result := nil;
- if (fAddr <> nil) and GetPythonEngine.PyString_Check(Key) then
- KeyName := GetPythonEngine.PyString_AsDelphiString(Key)
+ if (fAddr <> nil) and GetPythonEngine.PyUnicode_Check(Key) then
+ KeyName := GetPythonEngine.PyUnicode_AsWideString(Key)
else
Exit;
@@ -2045,7 +2013,7 @@ function TPyRttiObject.GetAttrO(key: PPyObject): PPyObject;
if not Assigned(Result) then
with GetPythonEngine do
PyErr_SetObject (PyExc_AttributeError^,
- PyString_FromDelphiString(Format(rs_ErrAttrGet,[KeyName, ErrMsg])));
+ PyUnicode_FromString(Format(rs_ErrAttrGet,[KeyName, ErrMsg])));
end;
class procedure TPyRttiObject.RegisterMethods(PythonType: TPythonType);
@@ -2060,7 +2028,7 @@ class procedure TPyRttiObject.RegisterMethods(PythonType: TPythonType);
function TPyRttiObject.Repr: PPyObject;
begin
- Result := GetPythonEngine.PyString_FromDelphiString(
+ Result := GetPythonEngine.PyUnicode_FromString(
Format('',
[RttiType.Name, NativeInt(Self)]) )
end;
@@ -2071,8 +2039,8 @@ function TPyRttiObject.SetAttrO(key, value: PPyObject): Integer;
ErrMsg: string;
begin
Result := -1;
- if (fAddr <> nil) and GetPythonEngine.PyString_Check(Key) then
- KeyName := GetPythonEngine.PyString_AsDelphiString(Key)
+ if (fAddr <> nil) and GetPythonEngine.PyUnicode_Check(Key) then
+ KeyName := GetPythonEngine.PyUnicode_AsWideString(Key)
else begin
Exit;
end;
@@ -2082,7 +2050,7 @@ function TPyRttiObject.SetAttrO(key, value: PPyObject): Integer;
if Result <> 0 then
with GetPythonEngine do
- PyErr_SetObject(PyExc_AttributeError^, PyString_FromDelphiString(
+ PyErr_SetObject(PyExc_AttributeError^, PyUnicode_FromString(
Format(rs_ErrAttrSetr, [KeyName, ErrMsg])));
end;
@@ -2097,7 +2065,6 @@ class procedure TPyRttiObject.SetupType(PythonType: TPythonType);
inherited;
PythonType.TypeName := 'RttiObject';
PythonType.Name := string(PythonType.TypeName) + 'Type';
- PythonType.TypeFlags := [tpfHaveClass];
PythonType.GenerateCreateFunction := False;
PythonType.DocString.Text := 'Wrapper of a Pascal record';
PythonType.Services.Basic := [bsGetAttrO, bsSetAttrO, bsRepr, bsStr];
@@ -2168,8 +2135,8 @@ function TPyDelphiObject.GetAttrO(key: PPyObject): PPyObject;
Result := inherited GetAttrO(key);
if GetPythonEngine.PyErr_Occurred = nil then Exit; // We found what we wanted
- if Assigned(DelphiObject) and GetPythonEngine.PyString_Check(Key) then
- KeyName := GetPythonEngine.PyString_AsDelphiString(Key)
+ if Assigned(DelphiObject) and GetPythonEngine.PyUnicode_Check(Key) then
+ KeyName := GetPythonEngine.PyUnicode_AsWideString(Key)
else
Exit;
@@ -2233,9 +2200,9 @@ function TPyDelphiObject.GetAttrO(key: PPyObject): PPyObject;
Result := GetPythonEngine.VariantAsPyObject(Boolean(GetOrdProp(Self.DelphiObject, PropInfo)))
else
{$IFDEF FPC}
- Result := GetPythonEngine.PyString_FromDelphiString(GetEnumName(PropInfo^.PropType,
+ Result := GetPythonEngine.PyUnicode_FromString(GetEnumName(PropInfo^.PropType,
{$ELSE FPC}
- Result := GetPythonEngine.PyString_FromDelphiString(GetEnumName(PropInfo^.PropType^,
+ Result := GetPythonEngine.PyUnicode_FromString(GetEnumName(PropInfo^.PropType^,
{$ENDIF FPC}
GetOrdProp(Self.DelphiObject, PropInfo)));
end
@@ -2252,7 +2219,7 @@ function TPyDelphiObject.GetAttrO(key: PPyObject): PPyObject;
if not Assigned(Result) then
with GetPythonEngine do
PyErr_SetObject (PyExc_AttributeError^,
- PyString_FromDelphiString(Format(rs_ErrAttrGet,[KeyName, ErrMsg])));
+ PyUnicode_FromString(Format(rs_ErrAttrGet,[KeyName, ErrMsg])));
end;
function TPyDelphiObject.GetContainerAccess: TContainerAccess;
@@ -2277,7 +2244,7 @@ function TPyDelphiObject.Get_ClassName(Acontext: Pointer): PPyObject;
begin
Adjust(@Self);
if CheckBound then
- Result := GetPythonEngine.PyString_FromDelphiString(DelphiObject.ClassName)
+ Result := GetPythonEngine.PyUnicode_FromString(DelphiObject.ClassName)
else
Result := nil;
end;
@@ -2392,7 +2359,7 @@ function TPyDelphiObject.Iter: PPyObject;
Result := nil;
with GetPythonEngine do
PyErr_SetObject( PyExc_SystemError^,
- PyString_FromDelphiString(Format(rs_ErrIterSupport,
+ PyUnicode_FromString(Format(rs_ErrIterSupport,
[Self.ClassName])) );
end;
end;
@@ -2445,10 +2412,10 @@ function TPyDelphiObject.Repr: PPyObject;
begin
with GetPythonEngine do
if Assigned(DelphiObject) then
- Result := PyString_FromDelphiString( Format('',
+ Result := PyUnicode_FromString( Format('',
[DelphiObject.ClassName, NativeInt(Self)]) )
else
- Result := PyString_FromDelphiString( Format('',
+ Result := PyUnicode_FromString( Format('',
[DelphiObjectClass.ClassName, NativeInt(Self)]) );
end;
@@ -2526,8 +2493,8 @@ function TPyDelphiObject.SetAttrO(key, value: PPyObject): Integer;
ErrMsg: string;
begin
Result := -1;
- if Assigned(DelphiObject) and GetPythonEngine.PyString_Check(Key) then
- KeyName := GetPythonEngine.PyString_AsDelphiString(Key)
+ if Assigned(DelphiObject) and GetPythonEngine.PyUnicode_Check(Key) then
+ KeyName := GetPythonEngine.PyUnicode_AsWideString(Key)
else begin
Exit;
end;
@@ -2566,7 +2533,7 @@ function TPyDelphiObject.SetAttrO(key, value: PPyObject): Integer;
Result := inherited SetAttrO(key, value);
if Result <> 0 then
with GetPythonEngine do
- PyErr_SetObject(PyExc_AttributeError^, PyString_FromDelphiString(
+ PyErr_SetObject(PyExc_AttributeError^, PyUnicode_FromString(
Format(rs_ErrAttrSetr, [KeyName, ErrMsg])));
end;
@@ -2633,7 +2600,6 @@ class procedure TPyDelphiObject.SetupType(PythonType: TPythonType);
inherited;
PythonType.TypeName := AnsiString(GetTypeName);
PythonType.Name := string(PythonType.TypeName) + 'Type';
- PythonType.TypeFlags := PythonType.TypeFlags + [tpfBaseType, tpfHaveRichCompare];
PythonType.GenerateCreateFunction := False;
PythonType.DocString.Text := 'Wrapper for Delphi ' + DelphiObjectClass.ClassName;
PythonType.Services.Basic := [bsGetAttrO, bsSetAttrO, bsRepr, bsStr, bsRichCompare];
@@ -2641,7 +2607,7 @@ class procedure TPyDelphiObject.SetupType(PythonType: TPythonType);
if Assigned(_ContainerAccessClass) then
begin
PythonType.Services.Basic := PythonType.Services.Basic + [bsIter];
- PythonType.Services.Sequence := PythonType.Services.Sequence + [ssLength, ssItem, ssSlice];
+ PythonType.Services.Sequence := PythonType.Services.Sequence + [ssLength, ssItem];
if _ContainerAccessClass.SupportsWrite then
PythonType.Services.Sequence := PythonType.Services.Sequence + [ssAssItem];
if _ContainerAccessClass.SupportsIndexOf then
@@ -2666,7 +2632,7 @@ function TPyDelphiObject.SqAssItem(idx: NativeInt; obj: PPyObject): integer;
Result := -1;
with GetPythonEngine do
PyErr_SetObject( PyExc_SystemError^,
- PyString_FromDelphiString(Format(rs_ErrSqAss, [Self.ClassName])) );
+ PyUnicode_FromString(Format(rs_ErrSqAss, [Self.ClassName])) );
end;
end;
@@ -2697,7 +2663,7 @@ function TPyDelphiObject.SqItem(idx: NativeInt): PPyObject;
Result := nil;
with GetPythonEngine do
PyErr_SetObject( PyExc_SystemError^,
- PyString_FromDelphiString(Format(rs_ErrSequence, [Self.ClassName])) );
+ PyUnicode_FromString(Format(rs_ErrSequence, [Self.ClassName])) );
end;
end;
@@ -2709,11 +2675,6 @@ function TPyDelphiObject.SqLength: NativeInt;
Result := 0;
end;
-function TPyDelphiObject.SqSlice(idx1, idx2: NativeInt): PPyObject;
-begin
- Result := CreateSlice(Self, idx1, idx2);
-end;
-
procedure TPyDelphiObject.SubscribeToFreeNotification;
var
_FreeNotification : IFreeNotification;
@@ -2734,7 +2695,7 @@ function TPyDelphiObject.ToList_Wrapper(args: PPyObject): PPyObject;
Result := nil;
with GetPythonEngine do
PyErr_SetObject( PyExc_SystemError^,
- PyString_FromDelphiString(Format(rs_ErrSequence, [Self.ClassName])) );
+ PyUnicode_FromString(Format(rs_ErrSequence, [Self.ClassName])) );
end
else if GetPythonEngine.PyArg_ParseTuple( args, ':ToList' ) <> 0 then
with GetPythonEngine do
@@ -2758,7 +2719,7 @@ function TPyDelphiObject.ToTuple_Wrapper(args: PPyObject): PPyObject;
Result := nil;
with GetPythonEngine do
PyErr_SetObject( PyExc_SystemError^,
- PyString_FromDelphiString(Format(rs_ErrSequence, [Self.ClassName])) );
+ PyUnicode_FromString(Format(rs_ErrSequence, [Self.ClassName])) );
end
else if GetPythonEngine.PyArg_ParseTuple( args, ':ToTuple' ) <> 0 then
with GetPythonEngine do
@@ -2863,7 +2824,7 @@ function TPyDelphiMethodObject.Call(ob1, ob2: PPyObject): PPyObject;
procedure InvalidArguments(const MethName, ErrMsg : string);
begin
with GetPythonEngine do
- PyErr_SetObject(PyExc_TypeError^, PyString_FromDelphiString(
+ PyErr_SetObject(PyExc_TypeError^, PyUnicode_FromString(
Format(rs_ErrInvalidArgs,
[MethName, ErrMsg])));
end;
@@ -2907,7 +2868,7 @@ function TPyDelphiMethodObject.Call(ob1, ob2: PPyObject): PPyObject;
Result := SimpleValueToPython(ret, ErrMsg);
if Result = nil then
with PythonType.Engine do
- PyErr_SetObject(PyExc_TypeError^, PyString_FromDelphiString(
+ PyErr_SetObject(PyExc_TypeError^, PyUnicode_FromString(
Format(rs_ErrInvalidRet, [MethName, ErrMsg])));
end;
except
@@ -2948,7 +2909,7 @@ function TPyDelphiMethodObject.Call(ob1, ob2: PPyObject): PPyObject;
begin
Result := nil;
PyErr_SetObject (PyExc_TypeError^,
- PyString_FromDelphiString(Format(rs_ErrInvalidArgs,
+ PyUnicode_FromString(Format(rs_ErrInvalidArgs,
[MethodInfo.Name, E.Message])));
end;
end;
@@ -2958,7 +2919,7 @@ function TPyDelphiMethodObject.Call(ob1, ob2: PPyObject): PPyObject;
function TPyDelphiMethodObject.Repr: PPyObject;
begin
with GetPythonEngine do
- Result := PyString_FromDelphiString(
+ Result := PyUnicode_FromString(
Format('',
[
{$IFDEF EXTENDED_RTTI}
@@ -3021,7 +2982,7 @@ function TPyDelphiVarParameter.Repr: PPyObject;
_value := GetPythonEngine.PyObject_Repr(Value);
try
Result :=
- GetPythonEngine.PyString_FromDelphiString(Format('',
+ GetPythonEngine.PyUnicode_FromString(Format('',
[GetPythonEngine.PyObjectAsString(_value)]));
finally
GetPythonEngine.Py_DECREF(_value);
@@ -3048,7 +3009,6 @@ class procedure TPyDelphiVarParameter.SetupType(PythonType: TPythonType);
inherited;
PythonType.TypeName := 'VarParameter';
PythonType.Name := string(PythonType.TypeName) + 'Type';
- PythonType.TypeFlags := PythonType.TypeFlags + [tpfBaseType, tpfHaveRichCompare];
PythonType.GenerateCreateFunction := False;
PythonType.DocString.Text := 'Container object allowing modification of Delphi var parameters from Python';
PythonType.Services.Basic := [bsGetAttrO, bsSetAttrO, bsRepr, bsStr, bsRichCompare];
@@ -3394,7 +3354,7 @@ function TPyDelphiWrapper.CreateComponent(pself, args: PPyObject): PPyObject;
Klass := nil;
end;
if (Klass = nil) or not Klass.InheritsFrom(TComponent) then begin
- PyErr_SetObject(PyExc_TypeError^, PyString_FromDelphiString(
+ PyErr_SetObject(PyExc_TypeError^, PyUnicode_FromString(
Format(rs_ErrInvalidArgs,
['CreateComponent', rs_InvalidClass])));
Exit;
@@ -3411,7 +3371,7 @@ function TPyDelphiWrapper.CreateComponent(pself, args: PPyObject): PPyObject;
Ownership := soOwned;
Result := Self.Wrap(Component, Ownership);
end else
- PyErr_SetObject(PyExc_TypeError^, PyString_FromDelphiString(
+ PyErr_SetObject(PyExc_TypeError^, PyUnicode_FromString(
Format(rs_ErrInvalidArgs,
['CreateComponent', ''])));
end;
@@ -3452,10 +3412,7 @@ procedure TPyDelphiWrapper.CreatePyFunc(AModule: TPythonModule; AMethodDef: PPyM
begin
d := PyModule_GetDict(FModule.Module);
Assert(Assigned(d));
- if IsPython3000 then
- PyDict_SetItemString( d, AMethodDef^.ml_name, PyCFunction_NewEx(AMethodDef, nil, nil))
- else
- PyDict_SetItemString( d, AMethodDef^.ml_name, PyCFunction_New(AMethodDef, nil));
+ PyDict_SetItemString( d, AMethodDef^.ml_name, PyCFunction_NewEx(AMethodDef, nil, nil))
end;
end;
diff --git a/Source/WrapDelphiActnList.pas b/Source/WrapDelphiActnList.pas
index 5fff9518..d26b65b9 100644
--- a/Source/WrapDelphiActnList.pas
+++ b/Source/WrapDelphiActnList.pas
@@ -97,7 +97,7 @@ function TPyDelphiCustomActionList.GetDelphiObject: TCustomActionList;
function TPyDelphiCustomActionList.Get_ActionCount(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.ActionCount);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.ActionCount);
end;
function TPyDelphiCustomActionList.Get_Actions(AContext: Pointer): PPyObject;
diff --git a/Source/WrapDelphiClasses.pas b/Source/WrapDelphiClasses.pas
index 0a6e9159..edb4d2c5 100644
--- a/Source/WrapDelphiClasses.pas
+++ b/Source/WrapDelphiClasses.pas
@@ -292,7 +292,7 @@ function ShiftToPython(AShift : TShiftState) : PPyObject;
begin
with GetPythonEngine do
begin
- _item := PyString_FromDelphiString(AString);
+ _item := PyUnicode_FromString(AString);
PyList_Append(AList, _item);
Py_XDecRef(_item);
end;
@@ -363,7 +363,7 @@ function TPyDelphiPersistent.GetNamePath_Wrapper(
Adjust(@Self);
with GetPythonEngine do begin
if PyArg_ParseTuple( args, ':GetNamePath' ) <> 0 then begin
- Result := PyString_FromDelphiString(DelphiObject.GetNamePath)
+ Result := PyUnicode_FromString(DelphiObject.GetNamePath)
end else
Result := nil;
end;
@@ -417,9 +417,9 @@ function TCollectionAccess.IndexOf(AValue: PPyObject): Integer;
Result := -1;
with GetPythonEngine do
begin
- if PyInt_Check(AValue) then
+ if PyLong_Check(AValue) then
begin
- _item := Container.FindItemID(PyInt_AsLong(AValue));
+ _item := Container.FindItemID(PyLong_AsLong(AValue));
if Assigned(_item) then
Result := _item.Index;
end
@@ -534,7 +534,7 @@ function TPyDelphiCollection.GetDelphiObject: TCollection;
function TPyDelphiCollection.Get_Count(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.Count);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.Count);
end;
function TPyDelphiCollection.Get_Items(AContext: Pointer): PPyObject;
@@ -639,9 +639,9 @@ function TComponentsAccess.IndexOf(AValue: PPyObject): Integer;
Result := -1;
with GetPythonEngine do
begin
- if PyString_Check(AValue) then
+ if PyUnicode_Check(AValue) then
begin
- S := PyString_AsDelphiString(AValue);
+ S := PyUnicode_AsWideString(AValue);
for i := 0 to Container.ComponentCount-1 do
if SameText( Container.Components[i].Name, S) then
begin
@@ -730,7 +730,7 @@ function TPyDelphiComponent.BindMethodsToEvents(args: PPyObject): PPyObject;
if PyArg_ParseTuple( args, '|O:BindMethodsToEvents',@s ) <> 0 then
begin
if Assigned(S) then
- _prefix := PyString_AsDelphiString(s);
+ _prefix := PyObjectAsString(s);
_bindings := PyList_New(0);
try
_type := GetSelf.ob_type;
@@ -800,8 +800,8 @@ function TPyDelphiComponent.BindMethodsToEvents(args: PPyObject): PPyObject;
else
begin
_pair := PyTuple_New(3);
- PyTuple_SetItem(_pair, 0, PyString_FromDelphiString(_compName));
- PyTuple_SetItem(_pair, 1, PyString_FromDelphiString(_eventName));
+ PyTuple_SetItem(_pair, 0, PyUnicode_FromString(_compName));
+ PyTuple_SetItem(_pair, 1, PyUnicode_FromString(_eventName));
PyTuple_SetItem(_pair, 2, objMethod);
PyList_Append(_bindings, _pair);
end;
@@ -835,7 +835,7 @@ function TPyDelphiComponent.BindMethodsToEvents(args: PPyObject): PPyObject;
function TPyDelphiComponent.Get_ComponentCount(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.ComponentCount);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.ComponentCount);
end;
function TPyDelphiComponent.Get_Components(AContext: Pointer): PPyObject;
@@ -885,9 +885,9 @@ function TPyDelphiComponent.GetAttrO(key: PPyObject): PPyObject;
Result := nil;
if Assigned(DelphiObject) then
begin
- if GetPythonEngine.PyString_Check(Key) then
+ if GetPythonEngine.PyUnicode_Check(Key) then
begin
- Name := GetPythonEngine.PyString_AsDelphiString(Key);
+ Name := GetPythonEngine.PyUnicode_AsWideString(Key);
// try a sub component
Component := DelphiObject.FindComponent(Name);
if Component <> nil then
@@ -960,16 +960,16 @@ function TPyDelphiComponent.MpLength: NativeInt;
function TPyDelphiComponent.MpSubscript(obj: PPyObject): PPyObject;
var
- _name : string;
+ _name : UnicodeString;
_comp : TComponent;
begin
with GetPythonEngine do
begin
- if PyInt_Check(obj) then
- Result := SqItem(PyInt_AsLong(obj))
- else if PyString_Check(obj) then
+ if PyLong_Check(obj) then
+ Result := SqItem(PyLong_AsLong(obj))
+ else if PyUnicode_Check(obj) then
begin
- _name := string(PyString_AsDelphiString(obj));
+ _name := PyUnicode_AsWideString(obj);
_comp := DelphiObject.FindComponent(_name);
if Assigned(_comp) then
Result := Wrap(_comp)
@@ -1060,7 +1060,7 @@ function TStringsAccess.GetContainer: TStrings;
function TStringsAccess.GetItem(AIndex: Integer): PPyObject;
begin
- Result := GetPythonEngine.PyString_FromDelphiString( Container[AIndex] );
+ Result := GetPythonEngine.PyUnicode_FromString( Container[AIndex] );
end;
function TStringsAccess.GetSize: Integer;
@@ -1077,9 +1077,9 @@ function TStringsAccess.SetItem(AIndex: Integer; AValue: PPyObject): Boolean;
begin
with GetPythonEngine do
begin
- if PyString_Check(AValue) then
+ if PyUnicode_Check(AValue) then
begin
- Container[AIndex] := PyString_AsDelphiString(AValue);
+ Container[AIndex] := PyUnicode_AsWideString(AValue);
Result := True;
end
else
@@ -1168,7 +1168,7 @@ function TPyDelphiStrings.AddObject_Wrapper(args: PPyObject): PPyObject;
if PyArg_ParseTuple( args, 'OO:AddObject',@PStr, @_obj ) <> 0 then
begin
if CheckObjAttribute(_obj, 'The second argument of AddObject', TObject, _value) then
- Result := PyInt_FromLong(DelphiObject.AddObject(PyString_AsDelphiString(PStr), _value))
+ Result := PyLong_FromLong(DelphiObject.AddObject(PyObjectAsString(PStr), _value))
else
Result := nil;
end
@@ -1184,7 +1184,7 @@ function TPyDelphiStrings.Add_Wrapper(args: PPyObject): PPyObject;
Adjust(@Self);
with GetPythonEngine do
if PyArg_ParseTuple( args, 'O:Add',@PStr ) <> 0 then
- Result := PyInt_FromLong(DelphiObject.Add(PyString_AsDelphiString(PStr)))
+ Result := PyLong_FromLong(DelphiObject.Add(PyObjectAsString(PStr)))
else
Result := nil;
end;
@@ -1292,7 +1292,7 @@ function TPyDelphiStrings.GetDelphiObject: TStrings;
function TPyDelphiStrings.Get_Capacity(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.Capacity);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.Capacity);
end;
function TPyDelphiStrings.Get_Objects(AContext: Pointer): PPyObject;
@@ -1307,7 +1307,7 @@ function TPyDelphiStrings.Get_Objects(AContext: Pointer): PPyObject;
function TPyDelphiStrings.Get_Text(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyString_FromDelphiString(
+ Result := GetPythonEngine.PyUnicode_FromString(
CleanString(DelphiObject.Text, False));
end;
@@ -1319,7 +1319,7 @@ function TPyDelphiStrings.IndexOf_Wrapper(args: PPyObject): PPyObject;
Adjust(@Self);
with GetPythonEngine do
if PyArg_ParseTuple( args, 'O:IndexOf',@PStr ) <> 0 then
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.IndexOf(PyString_AsDelphiString(PStr)))
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.IndexOf(PyObjectAsString(PStr)))
else
Result := nil;
end;
@@ -1351,8 +1351,8 @@ function TPyDelphiStrings.MpSubscript(obj: PPyObject): PPyObject;
begin
with GetPythonEngine do
begin
- if PyInt_Check(obj) then
- Result := SqItem(PyInt_AsLong(obj))
+ if PyLong_Check(obj) then
+ Result := SqItem(PyLong_AsLong(obj))
else
begin
S := PyObjectAsString(obj);
@@ -1423,7 +1423,7 @@ class procedure TPyDelphiStrings.RegisterMethods(PythonType: TPythonType);
function TPyDelphiStrings.Repr: PPyObject;
begin
- Result := GetPythonEngine.PyString_FromDelphiString( Format('',
+ Result := GetPythonEngine.PyUnicode_FromString( Format('',
[NativeInt(self)]) );
end;
diff --git a/Source/WrapDelphiComCtrls.pas b/Source/WrapDelphiComCtrls.pas
index 0a0efdfa..b855c348 100644
--- a/Source/WrapDelphiComCtrls.pas
+++ b/Source/WrapDelphiComCtrls.pas
@@ -203,7 +203,7 @@ function TPyDelphiPageControl.GetHitTestInfoAt_Wrapper(
begin
with GetPythonEngine do
begin
- _text := PyString_FromDelphiString(AText);
+ _text := PyUnicode_FromString(AText);
PyList_Append(Result, _text);
Py_DecRef(_text);
end;
@@ -258,7 +258,7 @@ function TPyDelphiPageControl.Get_ActivePageIndex(
AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.ActivePageIndex);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.ActivePageIndex);
end;
{$IFNDEF FPC}
@@ -271,7 +271,7 @@ function TPyDelphiPageControl.Get_Canvas(AContext: Pointer): PPyObject;
function TPyDelphiPageControl.Get_PageCount(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.PageCount);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.PageCount);
end;
function TPyDelphiPageControl.Get_Pages(AContext: Pointer): PPyObject;
@@ -286,7 +286,7 @@ function TPyDelphiPageControl.Get_Pages(AContext: Pointer): PPyObject;
function TPyDelphiPageControl.Get_RowCount(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.RowCount);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.RowCount);
end;
function TPyDelphiPageControl.IndexOfTabAt_Wrapper(
@@ -459,7 +459,7 @@ function TPyDelphiTabSheet.Get_PageControl(AContext: Pointer): PPyObject;
function TPyDelphiTabSheet.Get_TabIndex(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.TabIndex);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.TabIndex);
end;
class procedure TPyDelphiTabSheet.RegisterGetSets(PythonType: TPythonType);
@@ -524,9 +524,9 @@ function TPagesAccess.IndexOf(AValue: PPyObject): Integer;
Result := -1;
with GetPythonEngine do
begin
- if PyString_Check(AValue) then
+ if PyUnicode_Check(AValue) then
begin
- S := PyString_AsDelphiString(AValue);
+ S := PyUnicode_AsWideString(AValue);
for i := 0 to Container.PageCount-1 do
if SameText( Container.Pages[i].Name, S) then
begin
diff --git a/Source/WrapDelphiControls.pas b/Source/WrapDelphiControls.pas
index 0cf690e4..c4f0d161 100644
--- a/Source/WrapDelphiControls.pas
+++ b/Source/WrapDelphiControls.pas
@@ -446,9 +446,9 @@ function TControlsAccess.IndexOf(AValue: PPyObject): Integer;
Result := -1;
with GetPythonEngine do
begin
- if PyString_Check(AValue) then
+ if PyUnicode_Check(AValue) then
begin
- S := PyString_AsDelphiString(AValue);
+ S := PyUnicode_AsWideString(AValue);
for i := 0 to Container.ControlCount-1 do
if SameText( Container.Controls[i].Name, S) then
begin
@@ -514,7 +514,7 @@ function TPyDelphiWinControl.GetDelphiObject: TWinControl;
function TPyDelphiWinControl.Get_ControlCount(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.ControlCount);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.ControlCount);
end;
function TPyDelphiWinControl.Get_Controls(AContext: Pointer): PPyObject;
@@ -534,7 +534,7 @@ function TPyDelphiWinControl.Get_Focused(AContext: Pointer): PPyObject;
function TPyDelphiWinControl.Get_Handle(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.Handle);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.Handle);
end;
function TPyDelphiWinControl.Get_HandleAllocated(
@@ -548,7 +548,7 @@ function TPyDelphiWinControl.Get_ParentWindow(
AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.ParentWindow);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.ParentWindow);
end;
function TPyDelphiWinControl.Get_Showing(AContext: Pointer): PPyObject;
@@ -680,9 +680,9 @@ procedure TKeyPressEventHandler.DoEvent(Sender: TObject;
Py_DECREF(PyResult);
if _varParam.Value = Py_None then
Key := #0
- else if PyString_Check(_varParam.Value) then
+ else if PyUnicode_Check(_varParam.Value) then
begin
- _key := PyString_AsDelphiString(_varParam.Value);
+ _key := PyUnicode_AsWideString(_varParam.Value);
if Length(_key) > 0 then
Key := _key[1];
end;
@@ -733,8 +733,8 @@ procedure TKeyEventHandler.DoEvent(Sender: TObject; var Key: Word;
if Assigned(PyResult) then
begin
Py_DECREF(PyResult);
- if PyInt_Check(_varParam.Value) then
- Key := PyInt_AsLong(_varParam.Value);
+ if PyLong_Check(_varParam.Value) then
+ Key := PyLong_AsLong(_varParam.Value);
end;
finally
Py_DECREF(PyTuple);
diff --git a/Source/WrapDelphiForms.pas b/Source/WrapDelphiForms.pas
index a86310c4..8952905e 100644
--- a/Source/WrapDelphiForms.pas
+++ b/Source/WrapDelphiForms.pas
@@ -509,7 +509,7 @@ function TPyDelphiCustomForm.ShowModal_Wrapper(args: PPyObject): PPyObject;
with GetPythonEngine do begin
if PyArg_ParseTuple( args, ':ShowModal') <> 0 then begin
ModalResult := (DelphiObject as TForm).ShowModal;
- Result := PyInt_FromLong(ModalResult);
+ Result := PyLong_FromLong(ModalResult);
end else
Result := nil;
end;
@@ -560,7 +560,7 @@ class function TPyDelphiCustomForm.DelphiObjectClass: TClass;
function TPyDelphiCustomForm.Get_ModalResult(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.ModalResult);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.ModalResult);
end;
function TPyDelphiCustomForm.Set_ModalResult(AValue: PPyObject;
@@ -698,7 +698,7 @@ function TPyDelphiScreen.Get_ActiveForm(AContext: Pointer): PPyObject;
function TPyDelphiScreen.Get_Cursor(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.Cursor);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.Cursor);
end;
function TPyDelphiScreen.Get_Cursors(AContext: Pointer): PPyObject;
@@ -712,7 +712,7 @@ function TPyDelphiScreen.Get_Cursors(AContext: Pointer): PPyObject;
function TPyDelphiScreen.Get_CustomFormCount(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.CustomFormCount);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.CustomFormCount);
end;
function TPyDelphiScreen.Get_CustomForms(AContext: Pointer): PPyObject;
@@ -726,7 +726,7 @@ function TPyDelphiScreen.Get_CustomForms(AContext: Pointer): PPyObject;
function TPyDelphiScreen.Get_DataModuleCount(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.DataModuleCount);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.DataModuleCount);
end;
function TPyDelphiScreen.Get_DataModules(AContext: Pointer): PPyObject;
@@ -741,27 +741,27 @@ function TPyDelphiScreen.Get_DataModules(AContext: Pointer): PPyObject;
function TPyDelphiScreen.Get_DefaultIme(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyString_FromDelphiString(DelphiObject.DefaultIme);
+ Result := GetPythonEngine.PyUnicode_FromString(DelphiObject.DefaultIme);
end;
function TPyDelphiScreen.Get_DefaultKbLayout(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.DefaultKbLayout);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.DefaultKbLayout);
end;
{$ENDIF FPC}
function TPyDelphiScreen.Get_DesktopHeight(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.DesktopHeight);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.DesktopHeight);
end;
{$IFNDEF FPC}
function TPyDelphiScreen.Get_DesktopLeft(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.DesktopLeft);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.DesktopLeft);
end;
function TPyDelphiScreen.Get_DesktopRect(AContext: Pointer): PPyObject;
@@ -773,14 +773,14 @@ function TPyDelphiScreen.Get_DesktopRect(AContext: Pointer): PPyObject;
function TPyDelphiScreen.Get_DesktopTop(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.DesktopTop);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.DesktopTop);
end;
{$ENDIF FPC}
function TPyDelphiScreen.Get_DesktopWidth(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.DesktopWidth);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.DesktopWidth);
end;
function TPyDelphiScreen.Get_Fonts(AContext: Pointer): PPyObject;
@@ -792,7 +792,7 @@ function TPyDelphiScreen.Get_Fonts(AContext: Pointer): PPyObject;
function TPyDelphiScreen.Get_FormCount(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.FormCount);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.FormCount);
end;
function TPyDelphiScreen.Get_Forms(AContext: Pointer): PPyObject;
@@ -806,7 +806,7 @@ function TPyDelphiScreen.Get_Forms(AContext: Pointer): PPyObject;
function TPyDelphiScreen.Get_Height(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.Height);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.Height);
end;
function TPyDelphiScreen.Get_HintFont(AContext: Pointer): PPyObject;
@@ -838,7 +838,7 @@ function TPyDelphiScreen.Get_MenuFont(AContext: Pointer): PPyObject;
function TPyDelphiScreen.Get_MonitorCount(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.MonitorCount);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.MonitorCount);
end;
function TPyDelphiScreen.Get_Monitors(AContext: Pointer): PPyObject;
@@ -882,26 +882,26 @@ function TPyDelphiScreen.Get_OnActiveFormChange(
function TPyDelphiScreen.Get_PixelsPerInch(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.PixelsPerInch);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.PixelsPerInch);
end;
function TPyDelphiScreen.Get_Width(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.Width);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.Width);
end;
{$IFNDEF FPC}
function TPyDelphiScreen.Get_WorkAreaHeight(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.WorkAreaHeight);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.WorkAreaHeight);
end;
function TPyDelphiScreen.Get_WorkAreaLeft(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.WorkAreaLeft);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.WorkAreaLeft);
end;
function TPyDelphiScreen.Get_WorkAreaRect(AContext: Pointer): PPyObject;
@@ -913,13 +913,13 @@ function TPyDelphiScreen.Get_WorkAreaRect(AContext: Pointer): PPyObject;
function TPyDelphiScreen.Get_WorkAreaTop(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.WorkAreaTop);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.WorkAreaTop);
end;
function TPyDelphiScreen.Get_WorkAreaWidth(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.WorkAreaWidth);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.WorkAreaWidth);
end;
{$ENDIF FPC}
@@ -1273,7 +1273,7 @@ class function TScreenDataModulesAccess.Name: string;
function TScreenCursorsAccess.GetItem(AIndex: Integer): PPyObject;
begin
- Result := GetPythonEngine.PyInt_FromLong( Container.Cursors[AIndex] );
+ Result := GetPythonEngine.PyLong_FromLong( Container.Cursors[AIndex] );
end;
function TScreenCursorsAccess.GetSize: Integer;
@@ -1314,25 +1314,25 @@ function TPyDelphiMonitor.Get_BoundsRect(AContext : Pointer): PPyObject;
function TPyDelphiMonitor.Get_Handle(AContext : Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.Handle);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.Handle);
end;
function TPyDelphiMonitor.Get_Height(AContext : Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.Height);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.Height);
end;
function TPyDelphiMonitor.Get_Left(AContext : Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.Left);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.Left);
end;
function TPyDelphiMonitor.Get_MonitorNum(AContext : Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.MonitorNum);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.MonitorNum);
end;
function TPyDelphiMonitor.Get_Primary(AContext : Pointer): PPyObject;
@@ -1344,13 +1344,13 @@ function TPyDelphiMonitor.Get_Primary(AContext : Pointer): PPyObject;
function TPyDelphiMonitor.Get_Top(AContext : Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.Top);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.Top);
end;
function TPyDelphiMonitor.Get_Width(AContext : Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.Width);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.Width);
end;
function TPyDelphiMonitor.Get_WorkareaRect(AContext : Pointer): PPyObject;
@@ -1626,7 +1626,7 @@ function TPyDelphiApplication.MessageBox_Wrapper(
Adjust(@Self);
with GetPythonEngine do begin
if PyArg_ParseTuple( args, 'ssi:MessageBox',@_text, @_caption, @_flags ) <> 0 then begin
- Result := PyInt_FromLong(
+ Result := PyLong_FromLong(
DelphiObject.MessageBox(PChar(string(_text)), PChar(string(_caption)), _flags) );
end else
Result := nil;
@@ -2055,14 +2055,14 @@ function TPyDelphiApplication.Get_BiDiKeyboard(
AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyString_FromDelphiString(DelphiObject.BiDiKeyboard);
+ Result := GetPythonEngine.PyUnicode_FromString(DelphiObject.BiDiKeyboard);
end;
{$ENDIF FPC}
function TPyDelphiApplication.Get_BiDiMode(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(Ord(DelphiObject.BiDiMode));
+ Result := GetPythonEngine.PyLong_FromLong(Ord(DelphiObject.BiDiMode));
end;
{$IFNDEF FPC}
@@ -2070,60 +2070,60 @@ function TPyDelphiApplication.Get_CurrentHelpFile(
AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyString_FromDelphiString(DelphiObject.CurrentHelpFile);
+ Result := GetPythonEngine.PyUnicode_FromString(DelphiObject.CurrentHelpFile);
end;
function TPyDelphiApplication.Get_DialogHandle(
AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.DialogHandle);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.DialogHandle);
end;
{$ENDIF FPC}
function TPyDelphiApplication.Get_ExeName(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyString_FromDelphiString(DelphiObject.ExeName);
+ Result := GetPythonEngine.PyUnicode_FromString(DelphiObject.ExeName);
end;
{$IFNDEF FPC}
function TPyDelphiApplication.Get_Handle(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.Handle);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.Handle);
end;
{$ENDIF FPC}
function TPyDelphiApplication.Get_HelpFile(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyString_FromDelphiString(DelphiObject.HelpFile);
+ Result := GetPythonEngine.PyUnicode_FromString(DelphiObject.HelpFile);
end;
function TPyDelphiApplication.Get_Hint(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyString_FromDelphiString(DelphiObject.Hint);
+ Result := GetPythonEngine.PyUnicode_FromString(DelphiObject.Hint);
end;
function TPyDelphiApplication.Get_HintColor(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.HintColor);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.HintColor);
end;
function TPyDelphiApplication.Get_HintHidePause(
AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.HintHidePause);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.HintHidePause);
end;
function TPyDelphiApplication.Get_HintPause(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.HintPause);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.HintPause);
end;
function TPyDelphiApplication.Get_HintShortCuts(
@@ -2137,7 +2137,7 @@ function TPyDelphiApplication.Get_HintShortPause(
AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.HintShortPause);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.HintShortPause);
end;
function TPyDelphiApplication.Get_Icon(AContext: Pointer): PPyObject;
@@ -2157,7 +2157,7 @@ function TPyDelphiApplication.Get_NonBiDiKeyboard(
AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyString_FromDelphiString(DelphiObject.NonBiDiKeyboard);
+ Result := GetPythonEngine.PyUnicode_FromString(DelphiObject.NonBiDiKeyboard);
end;
{$ENDIF FPC}
@@ -2183,7 +2183,7 @@ function TPyDelphiApplication.Get_Terminated(AContext: Pointer): PPyObject;
function TPyDelphiApplication.Get_Title(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyString_FromDelphiString(DelphiObject.Title);
+ Result := GetPythonEngine.PyUnicode_FromString(DelphiObject.Title);
end;
{$IFNDEF FPC}
@@ -2595,9 +2595,9 @@ procedure TCloseEventHandler.DoEvent(Sender: TObject;
if Assigned(PyResult) then
begin
Py_DECREF(PyResult);
- if PyInt_Check(_varParam.Value) and
- CheckEnum('TCloseAction', PyInt_AsLong(_varParam.Value), Ord(Low(TCloseAction)), Ord(High(TCloseAction))) then
- Action := TCloseAction(PyInt_AsLong(_varParam.Value));
+ if PyLong_Check(_varParam.Value) and
+ CheckEnum('TCloseAction', PyLong_AsLong(_varParam.Value), Ord(Low(TCloseAction)), Ord(High(TCloseAction))) then
+ Action := TCloseAction(PyLong_AsLong(_varParam.Value));
end;
finally
Py_DECREF(PyTuple);
diff --git a/Source/WrapDelphiGraphics.pas b/Source/WrapDelphiGraphics.pas
index b761144c..500bac0a 100644
--- a/Source/WrapDelphiGraphics.pas
+++ b/Source/WrapDelphiGraphics.pas
@@ -381,7 +381,7 @@ function TPyDelphiGraphic.Get_Empty(AContext: Pointer): PPyObject;
function TPyDelphiGraphic.Get_Height(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.Height);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.Height);
end;
function TPyDelphiGraphic.Get_Modified(AContext: Pointer): PPyObject;
@@ -393,7 +393,7 @@ function TPyDelphiGraphic.Get_Modified(AContext: Pointer): PPyObject;
function TPyDelphiGraphic.Get_Palette(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.Palette);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.Palette);
end;
function TPyDelphiGraphic.Get_PaletteModified(
@@ -412,7 +412,7 @@ function TPyDelphiGraphic.Get_Transparent(AContext: Pointer): PPyObject;
function TPyDelphiGraphic.Get_Width(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.Width);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.Width);
end;
function TPyDelphiGraphic.LoadFromClipboardFormat_Wrapper(
@@ -452,7 +452,7 @@ function TPyDelphiGraphic.LoadFromFile_Wrapper(args: PPyObject): PPyObject;
with GetPythonEngine do begin
if PyArg_ParseTuple( args, 'O:LoadFromFile',@_pFileName ) <> 0 then
begin
- DelphiObject.LoadFromFile(PyString_AsDelphiString(_pFileName));
+ DelphiObject.LoadFromFile(PyObjectAsString(_pFileName));
Result := ReturnNone;
end
else
@@ -550,10 +550,10 @@ function TPyDelphiGraphic.SaveToClipboardFormat_Wrapper(
DelphiObject.SaveToClipboardFormat(_format, _data, _palette);
{$ENDIF FPC}
Result := PyTuple_New(3);
- PyTuple_SetItem(Result, 0, PyInt_FromLong(_format));
+ PyTuple_SetItem(Result, 0, PyLong_FromLong(_format));
{$IFNDEF FPC}
- PyTuple_SetItem(Result, 1, PyInt_FromLong(_data));
- PyTuple_SetItem(Result, 2, PyInt_FromLong(_palette));
+ PyTuple_SetItem(Result, 1, PyLong_FromLong(_data));
+ PyTuple_SetItem(Result, 2, PyLong_FromLong(_palette));
{$ENDIF FPC}
end
else
@@ -570,7 +570,7 @@ function TPyDelphiGraphic.SaveToFile_Wrapper(args: PPyObject): PPyObject;
with GetPythonEngine do begin
if PyArg_ParseTuple( args, 'O:SaveToFile',@_pFileName ) <> 0 then
begin
- DelphiObject.SaveToFile(PyString_AsDelphiString(_pFileName));
+ DelphiObject.SaveToFile(PyObjectAsString(_pFileName));
Result := ReturnNone;
end
else
@@ -748,7 +748,7 @@ function TPyDelphiBitmap.Get_Canvas(AContext: Pointer): PPyObject;
function TPyDelphiBitmap.Get_Handle(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.Handle);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.Handle);
end;
function TPyDelphiBitmap.Get_HandleAllocated(AContext: Pointer): PPyObject;
@@ -762,8 +762,8 @@ function TPyDelphiBitmap.Get_HandleType(AContext: Pointer): PPyObject;
Adjust(@Self);
with GetPythonEngine do begin
case DelphiObject.HandleType of
- bmDIB: Result := PyString_FromDelphiString('bmDIB');
- bmDDB: Result := PyString_FromDelphiString('bmDDB');
+ bmDIB: Result := PyUnicode_FromString('bmDIB');
+ bmDDB: Result := PyUnicode_FromString('bmDDB');
else
Result := ReturnNone;
end;
@@ -781,7 +781,7 @@ function TPyDelphiBitmap.Get_IgnorePalette(AContext: Pointer): PPyObject;
function TPyDelphiBitmap.Get_MaskHandle(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.MaskHandle);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.MaskHandle);
end;
function TPyDelphiBitmap.Get_Monochrome(AContext: Pointer): PPyObject;
@@ -795,15 +795,15 @@ function TPyDelphiBitmap.Get_PixelFormat(AContext: Pointer): PPyObject;
Adjust(@Self);
with GetPythonEngine do begin
case DelphiObject.PixelFormat of
- pfDevice: Result := PyString_FromDelphiString('pfDevice');
- pf1bit: Result := PyString_FromDelphiString('pf1bit');
- pf4bit: Result := PyString_FromDelphiString('pf4bit');
- pf8bit: Result := PyString_FromDelphiString('pf8bit');
- pf15bit: Result := PyString_FromDelphiString('pf15bit');
- pf16bit: Result := PyString_FromDelphiString('pf16bit');
- pf24bit: Result := PyString_FromDelphiString('pf24bit');
- pf32bit: Result := PyString_FromDelphiString('pf32bit');
- pfCustom: Result := PyString_FromDelphiString('pfCustom');
+ pfDevice: Result := PyUnicode_FromString('pfDevice');
+ pf1bit: Result := PyUnicode_FromString('pf1bit');
+ pf4bit: Result := PyUnicode_FromString('pf4bit');
+ pf8bit: Result := PyUnicode_FromString('pf8bit');
+ pf15bit: Result := PyUnicode_FromString('pf15bit');
+ pf16bit: Result := PyUnicode_FromString('pf16bit');
+ pf24bit: Result := PyUnicode_FromString('pf24bit');
+ pf32bit: Result := PyUnicode_FromString('pf32bit');
+ pfCustom: Result := PyUnicode_FromString('pfCustom');
else
Result := ReturnNone;
end;
@@ -814,7 +814,7 @@ function TPyDelphiBitmap.Get_TransparentColor(
AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.TransparentColor);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.TransparentColor);
end;
function TPyDelphiBitmap.Get_TransparentMode(AContext: Pointer): PPyObject;
@@ -822,8 +822,8 @@ function TPyDelphiBitmap.Get_TransparentMode(AContext: Pointer): PPyObject;
Adjust(@Self);
with GetPythonEngine do begin
case DelphiObject.TransparentMode of
- tmAuto: Result := PyString_FromDelphiString('tmAuto');
- tmFixed: Result := PyString_FromDelphiString('tmFixed');
+ tmAuto: Result := PyUnicode_FromString('tmAuto');
+ tmFixed: Result := PyUnicode_FromString('tmFixed');
else
Result := ReturnNone;
end;
@@ -955,7 +955,7 @@ function TPyDelphiBitmap.ReleaseHandle_Wrapper(args: PPyObject): PPyObject;
with GetPythonEngine do begin
if PyArg_ParseTuple( args, ':ReleaseHandle') <> 0 then
begin
- Result := PyInt_FromLong(DelphiObject.ReleaseHandle);
+ Result := PyLong_FromLong(DelphiObject.ReleaseHandle);
end
else
Result := nil;
@@ -970,7 +970,7 @@ function TPyDelphiBitmap.ReleaseMaskHandle_Wrapper(
with GetPythonEngine do begin
if PyArg_ParseTuple( args, ':ReleaseMaskHandle') <> 0 then
begin
- Result := PyInt_FromLong(DelphiObject.ReleaseMaskHandle);
+ Result := PyLong_FromLong(DelphiObject.ReleaseMaskHandle);
end
else
Result := nil;
@@ -985,7 +985,7 @@ function TPyDelphiBitmap.ReleasePalette_Wrapper(
with GetPythonEngine do begin
if PyArg_ParseTuple( args, ':ReleasePalette') <> 0 then
begin
- Result := PyInt_FromLong(DelphiObject.ReleasePalette);
+ Result := PyLong_FromLong(DelphiObject.ReleasePalette);
end
else
Result := nil;
@@ -1359,7 +1359,7 @@ function TPyDelphiCanvas.FloodFill_Wrapper(args: PPyObject): PPyObject;
with GetPythonEngine do begin
if PyArg_ParseTuple( args, 'iiiO:FloodFill',@x, @y, @_color, @_pFillStyle ) <> 0 then
begin
- if SameText(PyString_AsDelphiString(_pFillStyle), 'fsBorder') then
+ if SameText(PyObjectAsString(_pFillStyle), 'fsBorder') then
_FillStyle := fsBorder
else
_FillStyle := fsSurface;
@@ -1397,9 +1397,9 @@ function TPyDelphiCanvas.Get_CanvasOrientation(
Adjust(@Self);
with GetPythonEngine do begin
if DelphiObject.CanvasOrientation = coRightToLeft then
- Result := PyString_FromDelphiString('coRightToLeft')
+ Result := PyUnicode_FromString('coRightToLeft')
else
- Result := PyString_FromDelphiString('coLeftToRight');
+ Result := PyUnicode_FromString('coLeftToRight');
end;
end;
{$ENDIF FPC}
@@ -1413,7 +1413,7 @@ function TPyDelphiCanvas.Get_ClipRect(AContext: Pointer): PPyObject;
function TPyDelphiCanvas.Get_Handle(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.Handle);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.Handle);
end;
function TPyDelphiCanvas.Get_HandleAllocated(AContext: Pointer): PPyObject;
@@ -1425,7 +1425,7 @@ function TPyDelphiCanvas.Get_HandleAllocated(AContext: Pointer): PPyObject;
function TPyDelphiCanvas.Get_LockCount(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.LockCount);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.LockCount);
end;
function TPyDelphiCanvas.Get_OnChange(AContext: Pointer): PPyObject;
@@ -1450,7 +1450,7 @@ function TPyDelphiCanvas.Get_PenPos(AContext: Pointer): PPyObject;
function TPyDelphiCanvas.Get_TextFlags(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.TextFlags);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.TextFlags);
end;
{$ENDIF FPC}
@@ -1470,7 +1470,7 @@ function TPyDelphiCanvas.GetPixel(args: PPyObject): PPyObject;
y := 0;
if PyArg_ParseTuple( args, 'ii:GetPixel',@x, @y ) <> 0 then
begin
- Result := PyInt_FromLong(DelphiObject.Pixels[x, y]);
+ Result := PyLong_FromLong(DelphiObject.Pixels[x, y]);
end
else
Result := nil;
@@ -2022,7 +2022,7 @@ function TPyDelphiCanvas.TextExtent_Wrapper(args: PPyObject): PPyObject;
with GetPythonEngine do begin
if PyArg_ParseTuple( args, 'O:TextExtent',@_pText ) <> 0 then
begin
- Result := WrapSize(PyDelphiWrapper, DelphiObject.TextExtent(PyString_AsDelphiString(_pText)));
+ Result := WrapSize(PyDelphiWrapper, DelphiObject.TextExtent(PyObjectAsString(_pText)));
end
else
Result := nil;
@@ -2038,7 +2038,7 @@ function TPyDelphiCanvas.TextHeight_Wrapper(args: PPyObject): PPyObject;
with GetPythonEngine do begin
if PyArg_ParseTuple( args, 'O:TextHeight',@_pText ) <> 0 then
begin
- Result := PyInt_FromLong(DelphiObject.TextHeight(PyString_AsDelphiString(_pText)));
+ Result := PyLong_FromLong(DelphiObject.TextHeight(PyObjectAsString(_pText)));
end
else
Result := nil;
@@ -2101,7 +2101,7 @@ function TPyDelphiCanvas.TextWidth_Wrapper(args: PPyObject): PPyObject;
with GetPythonEngine do begin
if PyArg_ParseTuple( args, 'O:TextWidth',@_pText ) <> 0 then
begin
- Result := PyInt_FromLong(DelphiObject.TextWidth(PyString_AsDelphiString(_pText)));
+ Result := PyLong_FromLong(DelphiObject.TextWidth(PyObjectAsString(_pText)));
end
else
Result := nil;
@@ -2168,13 +2168,13 @@ function TPyDelphiMetaFile.GetDelphiObject: TMetaFile;
function TPyDelphiMetaFile.Get_CreatedBy(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyString_FromDelphiString(DelphiObject.CreatedBy);
+ Result := GetPythonEngine.PyUnicode_FromString(DelphiObject.CreatedBy);
end;
function TPyDelphiMetaFile.Get_Description(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyString_FromDelphiString(DelphiObject.Description);
+ Result := GetPythonEngine.PyUnicode_FromString(DelphiObject.Description);
end;
function TPyDelphiMetaFile.Get_Enhanced(AContext: Pointer): PPyObject;
@@ -2188,7 +2188,7 @@ function TPyDelphiMetaFile.Get_Enhanced(AContext: Pointer): PPyObject;
function TPyDelphiMetaFile.Get_Handle(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.Handle);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.Handle);
end;
function TPyDelphiMetaFile.Get_HandleAllocated(
@@ -2201,19 +2201,19 @@ function TPyDelphiMetaFile.Get_HandleAllocated(
function TPyDelphiMetaFile.Get_Inch(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.Inch);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.Inch);
end;
function TPyDelphiMetaFile.Get_MMHeight(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.MMHeight);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.MMHeight);
end;
function TPyDelphiMetaFile.Get_MMWidth(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.MMWidth);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.MMWidth);
end;
class procedure TPyDelphiMetaFile.RegisterGetSets(PythonType: TPythonType);
@@ -2259,7 +2259,7 @@ function TPyDelphiMetaFile.ReleaseHandle_Wrapper(
with GetPythonEngine do begin
if PyArg_ParseTuple( args, ':ReleaseHandle') <> 0 then
begin
- Result := PyInt_FromLong(DelphiObject.ReleaseHandle);
+ Result := PyLong_FromLong(DelphiObject.ReleaseHandle);
end
else
Result := nil;
@@ -2362,7 +2362,7 @@ function TPyDelphiIcon.GetDelphiObject: TIcon;
function TPyDelphiIcon.Get_Handle(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.Handle);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.Handle);
end;
function TPyDelphiIcon.Get_HandleAllocated(AContext: Pointer): PPyObject;
@@ -2398,7 +2398,7 @@ function TPyDelphiIcon.ReleaseHandle_Wrapper(args: PPyObject): PPyObject;
with GetPythonEngine do begin
if PyArg_ParseTuple( args, ':ReleaseHandle') <> 0 then
begin
- Result := PyInt_FromLong(DelphiObject.ReleaseHandle);
+ Result := PyLong_FromLong(DelphiObject.ReleaseHandle);
end
else
Result := nil;
@@ -2447,7 +2447,7 @@ function TPyDelphiPicture.Get_Graphic(AContext: Pointer): PPyObject;
function TPyDelphiPicture.Get_Height(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.Height);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.Height);
end;
function TPyDelphiPicture.Get_Icon(AContext: Pointer): PPyObject;
@@ -2467,7 +2467,7 @@ function TPyDelphiPicture.Get_MetaFile(AContext: Pointer): PPyObject;
function TPyDelphiPicture.Get_Width(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.Width);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.Width);
end;
function TPyDelphiPicture.GetDelphiObject: TPicture;
@@ -2484,7 +2484,7 @@ function TPyDelphiPicture.LoadFromFile_Wrapper(args: PPyObject): PPyObject;
with GetPythonEngine do begin
if PyArg_ParseTuple( args, 'O:LoadFromFile',@_pFileName ) <> 0 then
begin
- DelphiObject.LoadFromFile(PyString_AsDelphiString(_pFileName));
+ DelphiObject.LoadFromFile(PyObjectAsString(_pFileName));
Result := ReturnNone;
end
else
@@ -2534,7 +2534,7 @@ function TPyDelphiPicture.SaveToFile_Wrapper(args: PPyObject): PPyObject;
with GetPythonEngine do begin
if PyArg_ParseTuple( args, 'O:SaveToFile',@_pFileName ) <> 0 then
begin
- DelphiObject.SaveToFile(PyString_AsDelphiString(_pFileName));
+ DelphiObject.SaveToFile(PyObjectAsString(_pFileName));
Result := ReturnNone;
end
else
diff --git a/Source/WrapDelphiGrids.pas b/Source/WrapDelphiGrids.pas
index e2aaa27e..11e2889c 100644
--- a/Source/WrapDelphiGrids.pas
+++ b/Source/WrapDelphiGrids.pas
@@ -177,19 +177,19 @@ function MakeGridDrawState(AState : TGridDrawState) : PPyObject;
Result := PyList_New(0);
if gdSelected in AState then
begin
- _item := PyString_FromDelphiString('gdSelected');
+ _item := PyUnicode_FromString('gdSelected');
PyList_Append(Result, _item);
Py_DecRef(_item);
end;
if gdFocused in AState then
begin
- _item := PyString_FromDelphiString('gdFocused');
+ _item := PyUnicode_FromString('gdFocused');
PyList_Append(Result, _item);
Py_DecRef(_item);
end;
if gdFixed in AState then
begin
- _item := PyString_FromDelphiString('gdFixed');
+ _item := PyUnicode_FromString('gdFixed');
PyList_Append(Result, _item);
Py_DecRef(_item);
end;
@@ -218,8 +218,8 @@ procedure TDrawCellEventHandler.DoEvent(Sender: TObject; ACol,
if Assigned(Callable) and PythonOK then
with GetPythonEngine do begin
PyObject := PyDelphiWrapper.Wrap(Sender);
- PyCol := PyInt_FromLong(ACol);
- PyRow := PyInt_FromLong(ARow);
+ PyCol := PyLong_FromLong(ACol);
+ PyRow := PyLong_FromLong(ARow);
PyRect := WrapRect(PyDelphiWrapper, Rect);
PyState := MakeGridDrawState(State);
@@ -272,8 +272,8 @@ procedure TSelectCellEventHandler.DoEvent(Sender: TObject; ACol,
if Assigned(Callable) and PythonOK then
with GetPythonEngine do begin
PyObject := PyDelphiWrapper.Wrap(Sender);
- PyCol := PyInt_FromLong(ACol);
- PyRow := PyInt_FromLong(ARow);
+ PyCol := PyLong_FromLong(ACol);
+ PyRow := PyLong_FromLong(ARow);
PyCanSelect := CreateVarParam(PyDelphiWrapper, CanSelect);
_varParam := PythonToDelphi(PyCanSelect) as TPyDelphiVarParameter;
@@ -320,7 +320,7 @@ function TGridColWidthsAccess.GetContainer: TCustomDrawGrid;
function TGridColWidthsAccess.GetItem(AIndex: Integer): PPyObject;
begin
with GetPythonEngine do
- Result:=PyInt_FromLong(Container.ColWidths[AIndex]);
+ Result:=PyLong_FromLong(Container.ColWidths[AIndex]);
end;
type
@@ -341,7 +341,7 @@ function TGridColWidthsAccess.SetItem(AIndex: Integer;
begin
result:=True;
with GetPythonEngine do
- Container.ColWidths[AIndex]:=PyInt_AsLong(AValue);
+ Container.ColWidths[AIndex]:=PyLong_AsLong(AValue);
end;
class function TGridColWidthsAccess.SupportsWrite: Boolean;
@@ -396,7 +396,7 @@ function TPyDelphiCustomDrawGrid.Get_ColWidths(
function TPyDelphiCustomDrawGrid.Get_Col(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.Col);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.Col);
end;
function TPyDelphiCustomDrawGrid.Get_EditorMode(
@@ -410,26 +410,26 @@ function TPyDelphiCustomDrawGrid.Get_GridHeight(
AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.GridHeight);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.GridHeight);
end;
function TPyDelphiCustomDrawGrid.Get_GridWidth(
AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.GridWidth);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.GridWidth);
end;
function TPyDelphiCustomDrawGrid.Get_LeftCol(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.LeftCol);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.LeftCol);
end;
function TPyDelphiCustomDrawGrid.Get_Row(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.Row);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.Row);
end;
function TPyDelphiCustomDrawGrid.Get_Selection(
@@ -442,7 +442,7 @@ function TPyDelphiCustomDrawGrid.Get_Selection(
function TPyDelphiCustomDrawGrid.Get_TopRow(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.TopRow);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.TopRow);
end;
class function TPyDelphiCustomDrawGrid.GetTypeName : string;
@@ -638,7 +638,7 @@ function TPyDelphiStringGrid.GetCell(args: PPyObject): PPyObject;
Adjust(@Self);
with GetPythonEngine do begin
if PyArg_ParseTuple( args, 'ii:GetCell',@col, @row ) <> 0 then
- Result := PyString_FromDelphiString(DelphiObject.Cells[col, row])
+ Result := PyUnicode_FromString(DelphiObject.Cells[col, row])
else
Result := nil;
end;
@@ -654,7 +654,7 @@ function TPyDelphiStringGrid.SetCell(args: PPyObject): PPyObject;
Adjust(@Self);
if PyArg_ParseTuple( args, 'iiO:GetCell',@col, @row, @value ) <> 0 then
begin
- DelphiObject.Cells[col, row]:= PyString_AsDelphiString(value);
+ DelphiObject.Cells[col, row]:= PyObjectAsString(value);
result:=ReturnNone;
end
else
diff --git a/Source/WrapDelphiStdCtrls.pas b/Source/WrapDelphiStdCtrls.pas
index d42f1a81..ff1dc260 100644
--- a/Source/WrapDelphiStdCtrls.pas
+++ b/Source/WrapDelphiStdCtrls.pas
@@ -263,7 +263,7 @@ procedure TPyDelphiCustomEdit.SetDelphiObject(const Value: TCustomEdit);
function TPyDelphiCustomEdit.Get_SelStart(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.SelStart);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.SelStart);
end;
function TPyDelphiCustomEdit.Set_SelStart(AValue: PPyObject; AContext: Pointer): integer;
@@ -412,7 +412,7 @@ function TPyDelphiListBox.Set_ItemIndex(AValue: PPyObject; AContext: Pointer): i
function TPyDelphiListBox.Get_ItemIndex(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.ItemIndex);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.ItemIndex);
end;
class procedure TPyDelphiListBox.RegisterGetSets(PythonType: TPythonType);
diff --git a/Source/WrapDelphiTypes.pas b/Source/WrapDelphiTypes.pas
index 6a5a981d..04e02f52 100644
--- a/Source/WrapDelphiTypes.pas
+++ b/Source/WrapDelphiTypes.pas
@@ -251,13 +251,13 @@ constructor TPyDelphiPoint.CreateWith(APythonType: TPythonType;
function TPyDelphiPoint.Get_X(Acontext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(Value.X);
+ Result := GetPythonEngine.PyLong_FromLong(Value.X);
end;
function TPyDelphiPoint.Get_Y(Acontext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(Value.Y);
+ Result := GetPythonEngine.PyLong_FromLong(Value.Y);
end;
class procedure TPyDelphiPoint.RegisterGetSets(PythonType: TPythonType);
@@ -274,7 +274,7 @@ class procedure TPyDelphiPoint.RegisterGetSets(PythonType: TPythonType);
function TPyDelphiPoint.Repr: PPyObject;
begin
- Result := GetPythonEngine.PyString_FromDelphiString(Format('',
+ Result := GetPythonEngine.PyUnicode_FromString(Format('',
[Value.X, Value.Y]));
end;
@@ -350,7 +350,7 @@ constructor TPyDelphiRect.CreateWith(APythonType: TPythonType;
function TPyDelphiRect.Get_Bottom(Acontext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(Value.Bottom);
+ Result := GetPythonEngine.PyLong_FromLong(Value.Bottom);
end;
function TPyDelphiRect.Get_BottomRight(Acontext: Pointer): PPyObject;
@@ -362,19 +362,19 @@ function TPyDelphiRect.Get_BottomRight(Acontext: Pointer): PPyObject;
function TPyDelphiRect.Get_Left(Acontext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(Value.Left);
+ Result := GetPythonEngine.PyLong_FromLong(Value.Left);
end;
function TPyDelphiRect.Get_Right(Acontext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(Value.Right);
+ Result := GetPythonEngine.PyLong_FromLong(Value.Right);
end;
function TPyDelphiRect.Get_Top(Acontext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(Value.Top);
+ Result := GetPythonEngine.PyLong_FromLong(Value.Top);
end;
function TPyDelphiRect.Get_TopLeft(Acontext: Pointer): PPyObject;
@@ -405,7 +405,7 @@ class procedure TPyDelphiRect.RegisterGetSets(PythonType: TPythonType);
function TPyDelphiRect.Repr: PPyObject;
begin
- Result := GetPythonEngine.PyString_FromDelphiString(Format('',
+ Result := GetPythonEngine.PyUnicode_FromString(Format('',
[Value.Left, Value.Top, Value.Right, Value.Bottom]));
end;
@@ -544,13 +544,13 @@ constructor TPyDelphiSize.CreateWith(APythonType: TPythonType;
function TPyDelphiSize.Get_CX(Acontext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(Value.cx);
+ Result := GetPythonEngine.PyLong_FromLong(Value.cx);
end;
function TPyDelphiSize.Get_CY(Acontext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(Value.cy);
+ Result := GetPythonEngine.PyLong_FromLong(Value.cy);
end;
class procedure TPyDelphiSize.RegisterGetSets(PythonType: TPythonType);
@@ -567,7 +567,7 @@ class procedure TPyDelphiSize.RegisterGetSets(PythonType: TPythonType);
function TPyDelphiSize.Repr: PPyObject;
begin
- Result := GetPythonEngine.PyString_FromDelphiString(Format('',
+ Result := GetPythonEngine.PyUnicode_FromString(Format('',
[Value.cx, Value.cy]));
end;
diff --git a/Source/WrapFireDAC.pas b/Source/WrapFireDAC.pas
index fb1ed01c..7df1fec9 100644
--- a/Source/WrapFireDAC.pas
+++ b/Source/WrapFireDAC.pas
@@ -214,7 +214,7 @@ function TPyDBCommon.GetAttrO(key: PPyObject) : PPyObject;
SKey : string;
begin
try
- SKey := LowerCase(GetPythonEngine.PyString_AsDelphiString(Key));
+ SKey := LowerCase(GetPythonEngine.PyObjectAsString(Key));
if (SKey = '__properties__' ) or
(SKey = '__members__' ) then
Result := GetProperties
@@ -255,7 +255,7 @@ function TPyDBField.GetAttrO(key: PPyObject) : PPyObject;
Exit;
end;
try
- l_sUpperKey := UpperCase(PyString_AsDelphiString(Key));
+ l_sUpperKey := UpperCase(PyObjectAsString(Key));
if l_sUpperKey = 'ALIGNMENT' then
Result := VariantAsPyObject( Integer(DelphiObject.Alignment) )
else if l_sUpperKey = 'ASBOOLEAN' then
@@ -371,7 +371,7 @@ function TPyDBField.SetAttrO(key, value: PPyObject) : Integer;
if not CheckField then
Exit;
try
- l_sUpperKey := UpperCase(PyString_AsDelphiString(Key));
+ l_sUpperKey := UpperCase(PyObjectAsString(Key));
if l_sUpperKey = 'ALIGNMENT' then begin
DelphiObject.Alignment := TAlignment(PyObjectAsVariant( value ));
Result := 0;
@@ -804,7 +804,7 @@ class function TPyDBDataset.GetContainerAccessClass : TContainerAccessClass;
function TPyDBDataset.Get_RowsCount(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
- Result := GetPythonEngine.PyInt_FromLong(DelphiObject.RecordCount);
+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.RecordCount);
end;
function TPyDBDataset.Get_Rows(AContext: Pointer): PPyObject;
@@ -863,11 +863,10 @@ function TPyDBDataset.GetAttrO(key: PPyObject) : PPyObject;
l_sUpperKey: string;
l_oDataset: TFDDataset;
begin
- Result := nil;
with GetPythonEngine do begin
try
l_oDataset := DelphiObject;
- l_sUpperKey := UpperCase(PyString_AsDelphiString(Key));
+ l_sUpperKey := UpperCase(PyObjectAsString(Key));
if l_sUpperKey = 'BOF' then
Result := VariantAsPyObject( l_oDataset.BOF )
else if l_sUpperKey = 'CANMODIFY' then
@@ -894,11 +893,10 @@ function TPyDBDataset.SetAttrO(key, value: PPyObject) : Integer;
l_sUpperKey: string;
l_oDataset: TFDDataset;
begin
- Result := -1;
with GetPythonEngine do begin
try
l_oDataset := DelphiObject;
- l_sUpperKey := UpperCase(PyString_AsDelphiString(Key));
+ l_sUpperKey := UpperCase(PyObjectAsString(Key));
if l_sUpperKey = 'FILTER' then begin
l_oDataset.Filter := PyObjectAsVariant( value );
Result := 0;
@@ -1387,12 +1385,10 @@ function TPyDBTable.GetAttrO(key: PPyObject) : PPyObject;
l_oConn: TFDCustomConnection;
l_oTable: TFDTable;
begin
- Result := nil;
with GetPythonEngine do begin
- l_oConn := Nil;
try
l_oTable := DelphiObject;
- l_sUpperKey := UpperCase(PyString_AsDelphiString(Key));
+ l_sUpperKey := UpperCase(PyObjectAsString(Key));
if l_sUpperKey = 'CONNECTIONDEFNAME' then begin
l_oConn := DelphiObject.Connection;
l_sConnectionDefName := DelphiObject.ConnectionName;
@@ -1455,7 +1451,7 @@ function TPyDBTable.SetAttrO(key, value: PPyObject) : Integer;
l_oConn := Nil;
try
l_oTable := DelphiObject;
- l_sUpperKey := UpperCase(PyString_AsDelphiString(Key));
+ l_sUpperKey := UpperCase(PyObjectAsString(Key));
if l_sUpperKey = 'CONNECTIONDEFNAME' then begin
if CheckActiveDBTable(False) then begin
l_sConnectionDefName := UpperCase(PyObjectAsVariant(value));
@@ -1871,7 +1867,6 @@ function TPyDBTable.Do_GetIndexNames( args : PPyObject ) : PPyObject;
L : TStringList;
begin
Result := nil;
- L := nil;
Adjust(@Self);
with GetPythonEngine do begin
l_oTable := DelphiObject;
@@ -1956,12 +1951,10 @@ function TPyDBQuery.GetAttrO(key: PPyObject) : PPyObject;
l_oConn: TFDCustomConnection;
l_oQuery: TFDQuery;
begin
- Result := nil;
with GetPythonEngine do begin
- l_oConn := Nil;
try
l_oQuery := DelphiObject;
- l_sUpperKey := UpperCase(PyString_AsDelphiString(Key));
+ l_sUpperKey := UpperCase(PyObjectAsString(Key));
if l_sUpperKey = 'CONNECTIONDEFNAME' then begin
l_oConn := DelphiObject.Connection;
l_sConnectionDefName := DelphiObject.ConnectionName;
@@ -2005,7 +1998,7 @@ function TPyDBQuery.SetAttrO(key, value: PPyObject) : Integer;
l_oConn := Nil;
try
l_oQuery := DelphiObject;
- l_sUpperKey := UpperCase(PyString_AsDelphiString(Key));
+ l_sUpperKey := UpperCase(PyObjectAsString(Key));
if l_sUpperKey = 'CONNECTIONDEFNAME' then begin
if CheckActiveDBQuery(False) then begin
l_sConnectionDefName := UpperCase(PyObjectAsVariant(value));
diff --git a/Tutorials/Webinar II/README.md b/Tutorials/Webinar II/README.md
index a6909f44..542c2ef2 100644
--- a/Tutorials/Webinar II/README.md
+++ b/Tutorials/Webinar II/README.md
@@ -3,16 +3,16 @@

-- [Webinar Info]()
+- [Webinar Info](https://blogs.embarcadero.com/python-for-delphi-developers-webinar/)
-- [Video replay]()
+- [Video replay](https://blogs.embarcadero.com/combining-the-strengths-of-delphi-and-python/)
- [Slides]()
-- Source code is included in this folder. Demo33 is in the Demos directory and the python extension module demos are in the Modules directory.
+- Source code is included in this folder. [Demo33](https://github.com/pyscripter/python4delphi/tree/master/Demos/Demo33) is in the Demos directory and the python extension [module demos](https://github.com/pyscripter/python4delphi/tree/master/Modules/DemoModule) are in the Modules directory.
Please note that to compile the source code you need to install the [SVGIconLibrary](https://github.com/EtheaDev/SVGIconImageList).
-PyChartHTML uses the TEdgeBrowser control. So you need to use Delphi 10.4 or later and install the [WebView2 Runtime](https://developer.microsoft.com/en-us/microsoft-edge/webview2/). The required WebView2Loader.dll is already in the output folder. Finally the visualization and analytics demos make use of a range of python modules that need to be installed in python using the python package installer pip. These needed modules are listed below:
+PyChartHTML uses the [TEdgeBrowser](http://docwiki.embarcadero.com/RADStudio/Sydney/en/Using_TEdgeBrowser_Component_and_Changes_to_the_TWebBrowser_Component) control. So you need to use Delphi 10.4 or later and install the [WebView2 Runtime](https://developer.microsoft.com/en-us/microsoft-edge/webview2/). The required WebView2Loader.dll is already in the output folder. Finally the visualization and analytics demos make use of a range of python modules that need to be installed in python using the python package installer pip. These needed modules are listed below:
- numpy
- pandas
diff --git a/Unsupported/VCL/Demo10/pyDB.pas b/Unsupported/VCL/Demo10/pyDB.pas
index 00c17cf3..4c798bf9 100644
--- a/Unsupported/VCL/Demo10/pyDB.pas
+++ b/Unsupported/VCL/Demo10/pyDB.pas
@@ -469,7 +469,7 @@ procedure TCommon.AppendProp( List : PPyObject; const prop : String );
begin
with GetPythonEngine do
begin
- obj := PyString_FromString(PAnsiChar(AnsiString(prop)));
+ obj := PyUnicode_FromAnsiString(AnsiString(prop));
PyList_Append( List, obj );
Py_XDecRef(obj);
end;
@@ -2274,7 +2274,7 @@ function TPyDataset.DoMoveBy( args : PPyObject ) : PPyObject;
// Do action
rslt := Dataset.MoveBy( dist );
// Finally, we return nothing
- Result := PyInt_FromLong(rslt);
+ Result := PyLong_FromLong(rslt);
end
else
Result := nil;
@@ -2774,7 +2774,7 @@ function TVarArg.SetAttr(key : PAnsiChar; value : PPyObject) : Integer;
function TVarArg.Repr : PPyObject;
begin
with GetPythonEngine do
- Result := PyString_FromString( PAnsiChar(AnsiString(PyObjectAsString(FValue))) );
+ Result := PyUnicode_FromAnsiString(AnsiString(PyObjectAsString(FValue)));
end;
constructor TPythonVarArg.Create( AOwner : TComponent );
diff --git a/Unsupported/VCL/pyDB.pas b/Unsupported/VCL/pyDB.pas
index 810172cb..c15810c0 100644
--- a/Unsupported/VCL/pyDB.pas
+++ b/Unsupported/VCL/pyDB.pas
@@ -469,7 +469,7 @@ procedure TCommon.AppendProp( List : PPyObject; const prop : String );
begin
with GetPythonEngine do
begin
- obj := PyString_FromDelphiString(prop);
+ obj := PyUnicode_FromString(prop);
PyList_Append( List, obj );
Py_XDecRef(obj);
end;
@@ -2274,7 +2274,7 @@ function TPyDataset.DoMoveBy( args : PPyObject ) : PPyObject;
// Do action
rslt := Dataset.MoveBy( dist );
// Finally, we return nothing
- Result := PyInt_FromLong(rslt);
+ Result := PyLong_FromLong(rslt);
end
else
Result := nil;
@@ -2774,7 +2774,7 @@ function TVarArg.SetAttr(key : PAnsiChar; value : PPyObject) : Integer;
function TVarArg.Repr : PPyObject;
begin
with GetPythonEngine do
- Result := PyString_FromDelphiString( PyObjectAsString(FValue) );
+ Result := PyUnicode_FromString( PyObjectAsString(FValue) );
end;
constructor TPythonVarArg.Create( AOwner : TComponent );