Skip to content

Commit b743c90

Browse files
committed
Now passes all MethodCallBackTest and VarPythTest unit tests.
1 parent d95eaff commit b743c90

File tree

10 files changed

+398
-157
lines changed

10 files changed

+398
-157
lines changed

PythonForDelphi/Components/Sources/Core/MethodCallBack.pas

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,8 @@ interface
3434
type
3535
TCallType = (ctSTDCALL, ctCDECL);
3636
TCallBack = procedure of object;
37-
TDDEAPIfunc = function( CallType, Fmt: Integer; Conv: longint;
38-
hsz1, hsz2: longint;
39-
Data: longint; Data1, Data2: integer):
40-
longint of object; stdcall;
41-
// Method declaration for DDE(ML) interface. Callbackmethods for DDE(ML) have
42-
// to be declared according to this.
43-
44-
function GetDDECallBack(method: TDDEAPIfunc): Pointer;
45-
// Call for example with
46-
// GetDDECallBack(DDECallBackMethod);
4737

48-
function GetCallBack( self: TObject; method: Pointer;
38+
function GetCallBack( self: TObject; method: Pointer;
4939
argnum: Integer; calltype: tcalltype): Pointer;
5040
// Call for example with
5141
// CallBackProc := GetCallBack( self, @TSelfObject.Method, 2, ctSTDCALL);
@@ -129,16 +119,12 @@ implementation
129119

130120
var
131121
CodeMemPages: PCodeMemPage;
132-
122+
133123
type
134124
{$IFDEF FPC}
135125
PtrCalcType = PtrUInt;
136126
{$ELSE}
137-
{$IFDEF CPUX64}
138127
PtrCalcType = NativeInt;
139-
{$ELSE}
140-
PtrCalcType = Longint;
141-
{$ENDIF}
142128
{$ENDIF}
143129

144130
{$IFNDEF MSWINDOWS}
@@ -180,7 +166,9 @@ procedure GetCodeMem(var ptr: PByte; size: integer);
180166
page:=VirtualAlloc(nil, PageSize, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
181167
{$ELSE}
182168
//page := GetMem(PageSize);
169+
{$WARN SYMBOL_PLATFORM OFF}
183170
page := mmap(Pointer($10000000), PageSize, PROT_NONE, MAP_PRIVATE or MAP_ANON, -1, 0);
171+
{$WARN SYMBOL_PLATFORM ON}
184172
if page=Pointer(-1) then //MMAP_FAILED result?
185173
begin
186174
ptr := nil;
@@ -276,11 +264,6 @@ function CodeMemPageCount: integer;
276264
end;
277265
end;
278266

279-
function GetDDECallBack(method: TDDEAPIfunc): Pointer;
280-
begin
281-
result := GetOfObjectCallBack(TCallBack(method),8,ctSTDCALL);
282-
end;
283-
284267
function GetOfObjectCallBack( CallBack: TCallBack;
285268
argnum: Integer; calltype: TCallType): Pointer;
286269
begin

PythonForDelphi/Components/Sources/Core/PythonEngine.pas

Lines changed: 23 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -397,11 +397,6 @@ TPythonVersionProp = record
397397
TPWideChar = array[0..16000] of PWideChar;
398398
PPAnsiChar = ^TPAnsiChar;
399399
PPWideChar = ^TPWideChar;
400-
PInt = ^Integer;
401-
PDouble = ^Double;
402-
PFloat = ^Real;
403-
PLong = ^LongInt;
404-
PShort = ^ShortInt;
405400

406401

407402
//#######################################################
@@ -1536,17 +1531,17 @@ TPythonInterface=class(TDynamicDll)
15361531

15371532
public
15381533
// define Python flags. See file pyDebug.h
1539-
Py_DebugFlag: PInt;
1540-
Py_VerboseFlag: PInt;
1541-
Py_InteractiveFlag: PInt;
1542-
Py_OptimizeFlag: PInt;
1543-
Py_NoSiteFlag: PInt;
1544-
Py_UseClassExceptionsFlag: PInt;
1545-
Py_FrozenFlag: PInt;
1546-
Py_TabcheckFlag: PInt;
1547-
Py_UnicodeFlag: PInt;
1548-
Py_IgnoreEnvironmentFlag: PInt;
1549-
Py_DivisionWarningFlag: PInt;
1534+
Py_DebugFlag: PInteger;
1535+
Py_VerboseFlag: PInteger;
1536+
Py_InteractiveFlag: PInteger;
1537+
Py_OptimizeFlag: PInteger;
1538+
Py_NoSiteFlag: PInteger;
1539+
Py_UseClassExceptionsFlag: PInteger;
1540+
Py_FrozenFlag: PInteger;
1541+
Py_TabcheckFlag: PInteger;
1542+
Py_UnicodeFlag: PInteger;
1543+
Py_IgnoreEnvironmentFlag: PInteger;
1544+
Py_DivisionWarningFlag: PInteger;
15501545
//_PySys_TraceFunc: PPPyObject;
15511546
//_PySys_ProfileFunc: PPPPyObject;
15521547

@@ -1646,16 +1641,6 @@ TPythonInterface=class(TDynamicDll)
16461641
PyBool_Type: PPyTypeObject;
16471642
PyEnum_Type: PPyTypeObject;
16481643

1649-
//PyArg_GetObject: function(args : PPyObject; nargs, i: integer; p_a: PPPyObject): integer; cdecl;
1650-
//PyArg_GetLong: function(args : PPyObject; nargs, i: integer; p_a: PLong): integer; cdecl;
1651-
//PyArg_GetShort: function(args : PPyObject; nargs, i: integer; p_a: PShort): integer; cdecl;
1652-
//PyArg_GetFloat: function(args : PPyObject; nargs, i: integer; p_a: PFloat): integer; cdecl;
1653-
//PyArg_GetString: function(args : PPyObject; nargs, i: integer; p_a: PAnsiString): integer; cdecl;
1654-
//PyArgs_VaParse: function (args : PPyObject; format: PAnsiChar; va_list: array of const): integer; cdecl;
1655-
// Does not work!
1656-
// Py_VaBuildValue: function (format: PAnsiChar; va_list: array of const): PPyObject; cdecl;
1657-
//PyBuiltin_Init: procedure; cdecl;
1658-
16591644
PyComplex_FromCComplex: function(c: Py_complex):PPyObject; cdecl;
16601645
PyComplex_FromDoubles: function(realv,imag : double):PPyObject; cdecl;
16611646
PyComplex_RealAsDouble: function(op : PPyObject ): double; cdecl;
@@ -1748,14 +1733,14 @@ TPythonInterface=class(TDynamicDll)
17481733
PyFunction_New:function (ob1,ob2:PPyObject):PPyObject; cdecl;
17491734
PyImport_AddModule:function (name:PAnsiChar):PPyObject; cdecl;
17501735
PyImport_Cleanup:procedure; cdecl;
1751-
PyImport_GetMagicNumber:function :LONGINT; cdecl;
1736+
PyImport_GetMagicNumber:function :LongInt; cdecl;
17521737
PyImport_ImportFrozenModule:function (key:PAnsiChar):integer; cdecl;
17531738
PyImport_ImportModule:function (name:PAnsiChar):PPyObject; cdecl;
17541739
PyImport_Import:function (name:PPyObject):PPyObject; cdecl;
17551740
//PyImport_Init:procedure; cdecl;
17561741
PyImport_ReloadModule:function (ob:PPyObject):PPyObject; cdecl;
17571742
PyInstance_New:function (obClass, obArg, obKW:PPyObject):PPyObject; cdecl;
1758-
PyInt_AsLong:function (ob:PPyObject):LONGINT; cdecl;
1743+
PyInt_AsLong:function (ob:PPyObject):LongInt; cdecl;
17591744
PyList_Append:function (ob1,ob2:PPyObject):integer; cdecl;
17601745
PyList_AsTuple:function (ob:PPyObject):PPyObject; cdecl;
17611746
PyList_GetItem:function (ob:PPyObject;i:NativeInt):PPyObject; cdecl;
@@ -1768,9 +1753,9 @@ TPythonInterface=class(TDynamicDll)
17681753
PyList_Size:function (ob:PPyObject):NativeInt; cdecl;
17691754
PyList_Sort:function (ob:PPyObject):integer; cdecl;
17701755
PyLong_AsDouble:function (ob:PPyObject):DOUBLE; cdecl;
1771-
PyLong_AsLong:function (ob:PPyObject):LONGINT; cdecl;
1756+
PyLong_AsLong:function (ob:PPyObject):LongInt; cdecl;
17721757
PyLong_FromDouble:function (db:double):PPyObject; cdecl;
1773-
PyLong_FromLong:function (l:longint):PPyObject; cdecl;
1758+
PyLong_FromLong:function (l:LongInt):PPyObject; cdecl;
17741759
PyLong_FromString:function (pc:PAnsiChar;var ppc:PAnsiChar;i:integer):PPyObject; cdecl;
17751760
PyLong_FromUnsignedLong:function(val:cardinal) : PPyObject; cdecl;
17761761
PyLong_AsUnsignedLong:function(ob:PPyObject) : Cardinal; cdecl;
@@ -3292,12 +3277,12 @@ procedure TPythonInputOutput.AddPendingWrite;
32923277

32933278
function TPythonInputOutput.GetCurrentThreadSlotIdx : Integer;
32943279
var
3295-
thread_id : Longint;
3280+
thread_id : NativeInt;
32963281
i : Integer;
32973282
begin
32983283
thread_id := GetCurrentThreadId;
32993284
for i := 0 to FLinesPerThread.Count-1 do
3300-
if Longint(FLinesPerThread.Objects[i]) = thread_id then
3285+
if NativeInt(FLinesPerThread.Objects[i]) = thread_id then
33013286
begin
33023287
Result := i;
33033288
Exit;
@@ -3729,14 +3714,6 @@ procedure TPythonInterface.MapDll;
37293714
PyBool_Type := Import('PyBool_Type');
37303715
PyEnum_Type := Import('PyEnum_Type');
37313716

3732-
//@PyArg_GetObject := Import('PyArg_GetObject');
3733-
//@PyArg_GetLong := Import('PyArg_GetLong');
3734-
//@PyArg_GetShort := Import('PyArg_GetShort');
3735-
//@PyArg_GetFloat := Import('PyArg_GetFloat');
3736-
//@PyArg_GetString := Import('PyArg_GetString');
3737-
//@PyArgs_VaParse := Import('PyArgs_VaParse');
3738-
//@Py_VaBuildValue := Import('Py_VaBuildValue');
3739-
//@PyBuiltin_Init := Import('PyBuiltin_Init');
37403717
PyComplex_FromCComplex := Import('PyComplex_FromCComplex');
37413718
PyComplex_FromDoubles := Import('PyComplex_FromDoubles');
37423719
PyComplex_RealAsDouble := Import('PyComplex_RealAsDouble');
@@ -4747,7 +4724,7 @@ procedure TPythonEngine.DoOpenDll(const aDllName : string);
47474724

47484725
procedure TPythonEngine.AssignPyFlags;
47494726

4750-
procedure SetFlag( AFlag: PInt; AValue : Boolean );
4727+
procedure SetFlag( AFlag: PInteger; AValue : Boolean );
47514728
begin
47524729
if AValue then
47534730
AFlag^ := 1
@@ -5886,7 +5863,7 @@ function TPythonEngine.VariantAsPyObject( const V : Variant ) : PPyObject;
58865863
wStr := ''
58875864
else
58885865
wStr := DeRefV;
5889-
Result := PyUnicode_FromWideChar( PWideChar(wStr), Length(wStr) );
5866+
Result := PyUnicode_FromWideString(wStr);
58905867
end;
58915868
varString:
58925869
begin
@@ -5895,8 +5872,8 @@ function TPythonEngine.VariantAsPyObject( const V : Variant ) : PPyObject;
58955872
end;
58965873
varUString:
58975874
begin
5898-
wStr := DeRefV;
5899-
Result := PyUnicode_FromWideChar( PWideChar(wStr), Length(wStr) );
5875+
wStr := DeRefV;
5876+
Result := PyUnicode_FromWideString(wStr);
59005877
end;
59015878
else
59025879
if VarType(DeRefV) and varArray <> 0 then
@@ -9765,13 +9742,13 @@ procedure MaskFPUExceptions(ExceptionsMasked : boolean;
97659742
exOverflow, exUnderflow, exPrecision])
97669743
else
97679744
SetExceptionMask([exDenormalized, exUnderflow, exPrecision]);
9768-
{$IFNDEF NEXTGEN}{$WARN SYMBOL_PLATFORM OFF}
9745+
{$WARN SYMBOL_PLATFORM OFF}
97699746
{$IF Defined(FPC) or Defined(MSWINDOWS)}
97709747
if MatchPythonPrecision then
97719748
SetPrecisionMode(pmDouble)
97729749
else
97739750
SetPrecisionMode(pmExtended);
9774-
{$ENDIF !NEXTGEN}{$WARN SYMBOL_PLATFORM ON}
9751+
{$WARN SYMBOL_PLATFORM ON}
97759752
{$IFEND}
97769753
{$IFEND}
97779754
end;

PythonForDelphi/Components/Sources/Core/UnitTests/MethodCallBackTest.pas

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ procedure TMethodCallbackTest.Teardown;
123123

124124
procedure TMethodCallbackTest.TestBug01;
125125
const
126-
AllocCount = {$IFDEF CPUX64}51{$ELSE}90{$ENDIF};
126+
AllocCount = {$IFDEF CPUX64}{$IFDEF MSWINDOWS}51{$ELSE}88{$ENDIF}{$ELSE}90{$ENDIF};
127127
var
128128
i: integer;
129129
ptr: Pointer;
@@ -151,9 +151,6 @@ procedure TMethodCallbackTest.TestBug01;
151151

152152
//---Test the code-memory manager
153153

154-
// one ThreeArgDecl callback uses 33 bytes code + 4 bytes Next pointer = 37 bytes
155-
// we should be able to allocate 110 Callbacks per page
156-
157154
FreeCallBacks;
158155
Assert.AreEqual(0, CodeMemPageCount);
159156

@@ -260,7 +257,7 @@ procedure TMethodCallbackTest.TestFourArgStdFunction;
260257

261258
procedure TMethodCallbackTest.TestMemoryMgmt;
262259
const
263-
AllocCount = {$IFDEF CPUX64}101{$ELSE}110{$ENDIF};
260+
AllocCount = {$IFDEF CPUX64}{$IFDEF MSWINDOWS}101{$ELSE}88{$ENDIF}{$ELSE}110{$ENDIF};
264261
var
265262
i: integer;
266263
ptr, ptr1, ptr2: Pointer;

PythonForDelphi/Components/Sources/Core/UnitTests/P4DTests.dpr

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ uses
1515
DUnitX.StackTrace.Jcl,
1616
DUnitX.TestFramework,
1717
VarPythTest in 'VarPythTest.pas',
18-
MethodCallBackTest in 'MethodCallBackTest.pas';
18+
MethodCallBackTest in 'MethodCallBackTest.pas',
19+
WrapDelphiTest in 'WrapDelphiTest.pas';
1920

2021
var
2122
runner : ITestRunner;
@@ -36,7 +37,7 @@ begin
3637
runner.UseRTTI := True;
3738
//tell the runner how we will log things
3839
//Log to the console window
39-
logger := TDUnitXConsoleLogger.Create(true);
40+
logger := TDUnitXConsoleLogger.Create(False);
4041
runner.AddLogger(logger);
4142
//Generate an NUnit compatible XML File
4243
nunitLogger := TDUnitXXMLNUnitFileLogger.Create(TDUnitX.Options.XMLOutputFile);
@@ -48,8 +49,9 @@ begin
4849
if not results.AllPassed then
4950
System.ExitCode := EXIT_ERRORS;
5051

52+
//TDUnitX.Options.ExitBehavior := TDUnitXExitBehavior.Continue;
5153
{$IFNDEF CI}
52-
//We don't want this happening when running under CI.
54+
// We don't want this happening when running under CI.
5355
if TDUnitX.Options.ExitBehavior = TDUnitXExitBehavior.Pause then
5456
begin
5557
System.Write('Done.. press <Enter> key to quit.');

0 commit comments

Comments
 (0)