diff --git a/PythonForDelphi/Components/P4DFpc.lpk b/PythonForDelphi/Components/P4DFpc.lpk new file mode 100644 index 00000000..63a050ce --- /dev/null +++ b/PythonForDelphi/Components/P4DFpc.lpk @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <_ExternHelp Items="Count"/> + + + diff --git a/PythonForDelphi/Components/P4DFpc.pas b/PythonForDelphi/Components/P4DFpc.pas new file mode 100644 index 00000000..e1a1c690 --- /dev/null +++ b/PythonForDelphi/Components/P4DFpc.pas @@ -0,0 +1,15 @@ +{ This file was automatically created by Lazarus. Do not edit! + This source is only used to compile and install the package. + } + +unit P4DFpc; + +interface + +uses + PythonEngine, MethodCallBack, TinyWideStrings, VarPyth, WrapDelphiClasses, + WrapDelphiTypes; + +implementation + +end. diff --git a/PythonForDelphi/Components/Sources/Core/MethodCallBack.pas b/PythonForDelphi/Components/Sources/Core/MethodCallBack.pas index c4797620..9e3ebfd0 100644 --- a/PythonForDelphi/Components/Sources/Core/MethodCallBack.pas +++ b/PythonForDelphi/Components/Sources/Core/MethodCallBack.pas @@ -182,11 +182,11 @@ procedure GetCodeMem(var ptr: PByte; size: integer); //page := GetMem(PageSize); page := mmap(Pointer($10000000), PageSize, PROT_NONE, MAP_PRIVATE or MAP_ANON, -1, 0); if page=Pointer(-1) then //MMAP_FAILED result? - begin - ptr := nil; - exit; - end; - mprotect(page, PageSize, PROT_READ or PROT_WRITE or PROT_EXEC); + begin + ptr := nil; + exit; + end; + mprotect(page, PageSize, PROT_READ or PROT_WRITE or PROT_EXEC); {$ENDIF} page^.next:=CodeMemPages; CodeMemPages:=page; diff --git a/PythonForDelphi/Components/Sources/Core/PythonEngine.pas b/PythonForDelphi/Components/Sources/Core/PythonEngine.pas index 588e8ddd..cbc0dc30 100644 --- a/PythonForDelphi/Components/Sources/Core/PythonEngine.pas +++ b/PythonForDelphi/Components/Sources/Core/PythonEngine.pas @@ -3175,7 +3175,9 @@ procedure MaskFPUExceptions(ExceptionsMasked : boolean; Converts line breaks to LF and optionally adds a line break at the end *) function CleanString(const s : AnsiString; AppendLF : Boolean = True) : AnsiString; overload; +{$ifndef FPC} function CleanString(const s : string; AppendLF : Boolean = True) : string; overload; +{$ENDIF} //####################################################### //## ## @@ -5349,12 +5351,12 @@ function TPythonEngine.Run_CommandAsObjectWithDict(const command : AnsiString; m procedure TPythonEngine.ExecStrings( strings : TStrings ); begin - Py_XDecRef( Run_CommandAsObject( EncodeString(strings.Text) , file_input ) ); + Py_XDecRef( Run_CommandAsObject( EncodeString(strings.Text) , file_input ) ); end; function TPythonEngine.EvalStrings( strings : TStrings ) : PPyObject; begin - Result := Run_CommandAsObject( EncodeString(strings.Text) , eval_input ); + Result := Run_CommandAsObject( EncodeString(strings.Text) , eval_input ); end; procedure TPythonEngine.ExecString(const command : AnsiString; locals, globals : PPyObject ); @@ -5364,7 +5366,7 @@ procedure TPythonEngine.ExecString(const command : AnsiString; locals, globals : procedure TPythonEngine.ExecStrings( strings : TStrings; locals, globals : PPyObject ); begin - Py_XDecRef( Run_CommandAsObjectWithDict( EncodeString(strings.Text), file_input, locals, globals ) ); + Py_XDecRef( Run_CommandAsObjectWithDict( EncodeString(strings.Text), file_input, locals, globals ) ); end; function TPythonEngine.EvalString( const command : AnsiString; locals, globals : PPyObject ) : PPyObject; @@ -5374,12 +5376,12 @@ function TPythonEngine.EvalString( const command : AnsiString; locals, globals : function TPythonEngine.EvalStrings( strings : TStrings; locals, globals : PPyObject ) : PPyObject; begin - Result := Run_CommandAsObjectWithDict( EncodeString(strings.Text), eval_input, locals, globals ); + Result := Run_CommandAsObjectWithDict( EncodeString(strings.Text), eval_input, locals, globals ); end; function TPythonEngine.EvalStringsAsStr( strings : TStrings ) : String; begin - Result := Run_CommandAsString( EncodeString(strings.Text), eval_input ); + Result := Run_CommandAsString( EncodeString(strings.Text), eval_input ); end; function TPythonEngine.CheckEvalSyntax( const str : AnsiString ) : Boolean; @@ -5971,7 +5973,7 @@ function TPythonEngine.VariantAsPyObject( const V : Variant ) : PPyObject; // detect if the variant supports this special property if Assigned(Disp) and (Disp.GetIDsOfNames(GUID_NULL, @wStr, 1, 0, @DispID) = S_OK) then begin - myInt := DeRefV.__asPPyObject__; //Returns the address to PPyObject as integer. (See impl. in PythonAtom.pas) + myInt := Integer(DeRefV.__asPPyObject__); //Returns the address to PPyObject as integer. (See impl. in PythonAtom.pas) Result := PPyObject(myInt); Py_XIncRef(Result); end @@ -9859,14 +9861,14 @@ function CleanString(const s : AnsiString; AppendLF : Boolean) : AnsiString; if AppendLF and (result[length(result)] <> LF) then Result := Result + LF; end; - +{$ifndef FPC} function CleanString(const s : string; AppendLF : Boolean) : string; begin Result := AdjustLineBreaks(s, tlbsLF); if AppendLF and (result[length(result)] <> LF) then Result := Result + LF; end; - +{$endif} {$IFDEF MSWINDOWS} function IsPythonVersionRegistered(PythonVersion : string; out InstallPath: string; out AllUserInstall: Boolean) : Boolean; diff --git a/PythonForDelphi/Components/Sources/Core/VarPyth.pas b/PythonForDelphi/Components/Sources/Core/VarPyth.pas index da3e5a2b..c83ba94c 100644 --- a/PythonForDelphi/Components/Sources/Core/VarPyth.pas +++ b/PythonForDelphi/Components/Sources/Core/VarPyth.pas @@ -181,14 +181,14 @@ TPythonVariantType = class(TInvokeableVariantType, IVarInstanceReference) const Arguments: TVarDataArray): Boolean; override; function GetProperty(var Dest: TVarData; const V: TVarData; const AName: string): Boolean; override; - function SetProperty({$IFDEF FPC}var{$ELSE}const{$ENDIF} V: TVarData; const AName: string; + function SetProperty({$IF FPC_FULLVERSION >= 30000}var{$ELSE}const{$ENDIF} V: TVarData; const AName: string; const Value: TVarData): Boolean; override; {$IFDEF DELPHIXE7_OR_HIGHER} procedure DispInvoke(Dest: PVarData; [Ref] const Source: TVarData; CallDesc: PCallDesc; Params: Pointer);override; {$ELSE} procedure DispInvoke(Dest: PVarData; - var Source: TVarData; CallDesc: PCallDesc; Params: Pointer);override; + {$IF FPC_FULLVERSION >= 30000}var{$ELSE}const{$ENDIF}Source: TVarData; CallDesc: PCallDesc; Params: Pointer);override; {$ENDIF} end; @@ -942,7 +942,7 @@ procedure TPythonVariantType.DispInvoke(Dest: PVarData; [Ref] const Source: TVarData; CallDesc: PCallDesc; Params: Pointer); {$ELSE} procedure TPythonVariantType.DispInvoke(Dest: PVarData; - var Source: TVarData; CallDesc: PCallDesc; Params: Pointer); + {$IF FPC_FULLVERSION >= 30000}var{$ELSE}const{$ENDIF}Source: TVarData; CallDesc: PCallDesc; Params: Pointer); {$ENDIF} {$IFDEF USESYSTEMDISPINVOKE} {$IFDEF PATCHEDSYSTEMDISPINVOKE} @@ -1114,8 +1114,11 @@ procedure TPythonVariantType.DispInvoke(Dest: PVarData; end; {$ELSE USESYSTEMDISPINVOKE} +var + aSource: tvardata; begin - DoDispInvoke(Dest, Source, CallDesc, Params); + aSource := Source; + DoDispInvoke(Dest, aSource, CallDesc, Params); end; procedure TPythonVariantType.DoDispInvoke(Dest: PVarData; @@ -1379,7 +1382,7 @@ function TPythonVariantType.GetPropertyWithArg(var Dest: TVarData; // So: myList[0] won't work, but myObj.MyList[0] will!!! if PySequence_Check(_prop) <> 0 then begin - _result := PySequence_GetItem(_prop, Variant(AArg)); + _result := PySequence_GetItem(_prop, Integer(Variant(AArg))); CheckError; end; // of if end; // of if @@ -1469,13 +1472,13 @@ function TPythonVariantType.EvalPython(const V: TVarData; if not Assigned(_value) then raise Exception.Create(SCantConvertValueToPythonObject); if PyList_Check(AObject) then - _result := PyList_SetItem( AObject, Variant(AKey), _value ) + _result := PyList_SetItem( AObject, Integer(Variant(AKey)), _value ) else if PyTuple_Check(AObject) then - _result := PyTuple_SetItem( AObject, Variant(AKey), _value ) + _result := PyTuple_SetItem( AObject, Integer(Variant(AKey)), _value ) else try if PySequence_Check(AObject) <> 0 then - _result := PySequence_SetItem(AObject, Variant(AKey), _value) + _result := PySequence_SetItem(AObject, Integer(Variant(AKey)), _value) else _result := PyObject_SetItem( AObject, _key, _value ); finally @@ -1893,7 +1896,7 @@ function TPythonVariantType.RightPromotion(const V: TVarData; Result := False; end; -function TPythonVariantType.SetProperty({$IFDEF FPC}var{$ELSE}const{$ENDIF} V: TVarData; +function TPythonVariantType.SetProperty({$IF FPC_FULLVERSION >= 30000}var{$ELSE}const{$ENDIF} V: TVarData; const AName: string; const Value: TVarData): Boolean; var _newValue : PPyObject; diff --git a/PythonForDelphi/Components/Sources/Core/WrapDelphi.pas b/PythonForDelphi/Components/Sources/Core/WrapDelphi.pas index 08015544..71194c96 100644 --- a/PythonForDelphi/Components/Sources/Core/WrapDelphi.pas +++ b/PythonForDelphi/Components/Sources/Core/WrapDelphi.pas @@ -331,7 +331,7 @@ interface uses SysUtils, Classes, PythonEngine, TypInfo, Variants, -{$IFNDEF FPC} + {$IFNDEF FPC} {$IFDEF EXTENDED_RTTI} Rtti, {$ELSE} @@ -835,7 +835,7 @@ TPyDelphiWrapper = class(TEngineClient, IFreeNotificationSubscriber) function SetToPython(APropInfo: PPropInfo; AValue : Integer) : PPyObject; overload; function SetToPython(AInstance: TObject; APropInfo: PPropInfo) : PPyObject; overload; function PythonToSet(APropInfo: PPropInfo; ASet : PPyObject) : Integer; overload; - function PythonToSet(ATypeInfo: PTypeInfo; ASet : PPyObject) : Integer; overload + function PythonToSet(ATypeInfo: PTypeInfo; ASet : PPyObject) : Integer; overload; function SupportsFreeNotification(AObject : TObject) : Boolean; procedure RaiseNotifyEvent(PyDelphiWrapper : TPyDelphiWrapper; ACallable : PPyObject; Sender: TObject); @@ -1246,7 +1246,7 @@ function SetToPython(AInstance: TObject; APropInfo: PPropInfo) : PPyObject; over Result := SetToPython(APropInfo, GetOrdProp(AInstance, APropInfo)); end; -function PythonToSet(ATypeInfo: PTypeInfo; ASet : PPyObject) : Integer; overload +function PythonToSet(ATypeInfo: PTypeInfo; ASet : PPyObject) : Integer; overload; var i : Integer; EnumObj: PPyObject; @@ -1292,12 +1292,20 @@ function PythonToSet(APropInfo: PPropInfo; ASet : PPyObject) : Integer; overload {$IFDEF FPC} function GetPropValue(Instance: TObject; PropInfo: PPropInfo): Variant; begin + {$IF FPC_FULLVERSION<=30000} + Result := Variants.GetPropValue(Instance, PropInfo^.Name); + {$ELSE} Result := Variants.GetPropValue(Instance, PropInfo, False); + {$ENDIF} end; procedure SetPropValue(Instance: TObject; PropInfo: PPropInfo; const Value: Variant); begin + {$IF FPC_FULLVERSION<=30000} + Variants.SetPropValue(Instance, PropInfo^.Name, Value); + {$ELSE} Variants.SetPropValue(Instance, PropInfo, Value); + {$ENDIF} end; {$ENDIF} @@ -1769,11 +1777,16 @@ function TPyDelphiObject.GetAttrO(key: PPyObject): PPyObject; var KeyName: string; ErrMsg : string; +{$ifndef FPC} {$IFNDEF EXTENDED_RTTI} Info: PMethodInfoHeader; PropInfo: PPropInfo; Obj : TObject; {$ENDIF} +{$else} + PropInfo: PPropInfo; + Obj : TObject; +{$endif} begin Result := inherited GetAttrO(key); if GetPythonEngine.PyErr_Occurred = nil then Exit; // We found what we wanted diff --git a/PythonForDelphi/Components/p4dlaz.lpk b/PythonForDelphi/Components/p4dlaz.lpk index c910748b..e210b8a5 100644 --- a/PythonForDelphi/Components/p4dlaz.lpk +++ b/PythonForDelphi/Components/p4dlaz.lpk @@ -1,84 +1,87 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - <_ExternHelp Items="Count"/> - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <_ExternHelp Items="Count"/> + + + diff --git a/PythonForDelphi/Components/p4dlaz.pas b/PythonForDelphi/Components/p4dlaz.pas index de2e1a12..dc842e31 100644 --- a/PythonForDelphi/Components/p4dlaz.pas +++ b/PythonForDelphi/Components/p4dlaz.pas @@ -1,26 +1,26 @@ -{ This file was automatically created by Lazarus. Do not edit! - This source is only used to compile and install the package. - } - -unit P4DLaz; - -{$warn 5023 off : no warning about unused units} -interface - -uses - PythonEngine, PythonGUIInputOutput, MethodCallBack, VarPyth, WrapDelphi, - WrapDelphiButtons, WrapDelphiClasses, WrapDelphiControls, WrapDelphiTypes, - LazarusPackageIntf; - -implementation - -procedure Register; -begin - RegisterUnit('PythonEngine', @PythonEngine.Register); - RegisterUnit('PythonGUIInputOutput', @PythonGUIInputOutput.Register); - RegisterUnit('WrapDelphi', @WrapDelphi.Register); -end; - -initialization - RegisterPackage('P4DLaz', @Register); -end. +{ This file was automatically created by Lazarus. Do not edit! + This source is only used to compile and install the package. + } + +unit P4DLaz; + +{$warn 5023 off : no warning about unused units} +interface + +uses + PythonEngine, PythonGUIInputOutput, MethodCallBack, VarPyth, WrapDelphi, + WrapDelphiButtons, WrapDelphiClasses, WrapDelphiControls, WrapDelphiTypes, + LazarusPackageIntf; + +implementation + +procedure Register; +begin + RegisterUnit('PythonEngine', @PythonEngine.Register); + RegisterUnit('PythonGUIInputOutput', @PythonGUIInputOutput.Register); + RegisterUnit('WrapDelphi', @WrapDelphi.Register); +end; + +initialization + RegisterPackage('P4DLaz', @Register); +end. diff --git a/PythonForDelphi/Demos/FPC/Demo01/fpc-res.or b/PythonForDelphi/Demos/FPC/Demo01/fpc-res.or deleted file mode 100644 index 17d61c85..00000000 Binary files a/PythonForDelphi/Demos/FPC/Demo01/fpc-res.or and /dev/null differ diff --git a/PythonForDelphi/Demos/FPC/Demo25/fpc-res.or b/PythonForDelphi/Demos/FPC/Demo25/fpc-res.or deleted file mode 100644 index 3676804f..00000000 Binary files a/PythonForDelphi/Demos/FPC/Demo25/fpc-res.or and /dev/null differ