Skip to content

Commit 1a32148

Browse files
committed
Removed compilation warnings.
1 parent 393a509 commit 1a32148

File tree

4 files changed

+45
-35
lines changed

4 files changed

+45
-35
lines changed

PythonForDelphi/Components/Sources/Core/Definition.Inc

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
/////////////////////////////////////////////////////////////////////////////
2828

2929
//{$DEFINE PYTHON24}
30-
//{$DEFINE PYTHON25}
31-
{$DEFINE PYTHON26`}
30+
{$DEFINE PYTHON25}
31+
//{$DEFINE PYTHON26}
3232
//{$DEFINE PYTHON27}
3333
//{$DEFINE PYTHON30}
3434
//{$DEFINE PYTHON31}

PythonForDelphi/Components/Sources/Core/PythonEngine.pas

+2-4
Original file line numberDiff line numberDiff line change
@@ -6076,8 +6076,6 @@ function TPythonEngine.PyObjectAsVariant( obj : PPyObject ) : Variant;
60766076
end;
60776077

60786078
function TPythonEngine.VarRecAsPyObject( v : TVarRec ) : PPyObject;
6079-
var
6080-
buff : array [0..256] of AnsiChar;
60816079
begin
60826080
case v.VType of
60836081
vtInteger: Result := PyInt_FromLong( v.VInteger );
@@ -6087,7 +6085,7 @@ function TPythonEngine.VarRecAsPyObject( v : TVarRec ) : PPyObject;
60876085
vtString:
60886086
begin
60896087
if Assigned(v.VString) then
6090-
Result := PyString_FromString( StrPCopy( buff, v.VString^) )
6088+
Result := PyString_FromString(PAnsiChar(AnsiString(v.VString^)))
60916089
else
60926090
Result := PyString_FromString( '' );
60936091
end;
@@ -6213,7 +6211,7 @@ function TPythonEngine.ArrayToPyDict( items : array of const) : PPyObject;
62136211
vtAnsiString:
62146212
begin
62156213
if Assigned(v.VAnsiString) then
6216-
Result := StrPas(PAnsiChar(Ansistring(v.VAnsiString)))
6214+
Result := Ansistring(v.VAnsiString)
62176215
else
62186216
Result := '';
62196217
end;

PythonForDelphi/Components/Sources/Core/PythonVersions.pas

+24-11
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ TPythonVersion = record
2020
private
2121
FDisplayName: string;
2222
FHelpFile: string;
23+
fSysArchitecture : string;
2324
function GetDLLName: string;
24-
function GetSysArchitecture:string;
25+
function ExpectedArchitecture:string;
2526
function GetIsPython3K: Boolean;
2627
function GetHelpFile: string;
2728
function GetDisplayName: string;
2829
function GetApiVersion: integer;
30+
function GetSysArchitecture: string;
2931
public
3032
IsRegistered: Boolean;
3133
IsAllUsers: Boolean;
@@ -55,12 +57,12 @@ TPythonVersion = record
5557

5658
{$IFDEF MSWINDOWS}
5759
(* Checks whether a Python version is registered and returns the related info *)
58-
function GetRegisterPythonVersion(SysVersion: string;
60+
function GetRegisteredPythonVersion(SysVersion: string;
5961
out PythonVersion: TPythonVersion): Boolean;
6062
(* Returns all registered Python versions *)
6163
function GetRegisteredPythonVersions : TPythonVersions;
6264
(* Returns the highest numbered registered Python version *)
63-
function GetLatestRegisteredPythonVersion(PythonVersion: TPythonVersion): Boolean;
65+
function GetLatestRegisteredPythonVersion(out PythonVersion: TPythonVersion): Boolean;
6466
{$ENDIF}
6567

6668
implementation
@@ -85,7 +87,7 @@ function TPythonVersion.GetDLLName: string;
8587
{$ENDIF}
8688
end;
8789

88-
function TPythonVersion.GetSysArchitecture: string;
90+
function TPythonVersion.ExpectedArchitecture: string;
8991
begin
9092
Result := '';
9193
{$IFDEF CPUX64}
@@ -154,6 +156,13 @@ function TPythonVersion.GetIsPython3K: Boolean;
154156
end;
155157
end;
156158

159+
function TPythonVersion.GetSysArchitecture: string;
160+
begin
161+
Result := fSysArchitecture;
162+
if Result = '' then
163+
Result := 'Unknown';
164+
end;
165+
157166
function CompareVersions(A, B : String) : Integer;
158167

159168
function GetNextNumber(var Version: string): Integer;
@@ -197,7 +206,7 @@ function CompareVersions(A, B : String) : Integer;
197206
end;
198207

199208
{$IFDEF MSWINDOWS}
200-
function GetRegisterPythonVersion(SysVersion: string;
209+
function GetRegisteredPythonVersion(SysVersion: string;
201210
out PythonVersion: TPythonVersion): Boolean;
202211
// Python provides for All user and Current user installations
203212
// All User installations place the Python DLL in the Windows System directory
@@ -233,6 +242,7 @@ function GetRegisterPythonVersion(SysVersion: string;
233242
if OpenKey(Key, False) then begin
234243
PythonVersion.DisplayName := ReadString('DisplayName');
235244
PythonVersion.Version := ReadString('Version');
245+
PythonVersion.fSysArchitecture := ReadString('SysArchitecture');
236246
CloseKey;
237247
end;
238248
if OpenKey(Key + '\PythonPath', False) then begin
@@ -260,10 +270,10 @@ function GetRegisterPythonVersion(SysVersion: string;
260270
FillChar(PythonVersion, SizeOf(TPythonVersion), 0);
261271

262272
VersionSuffix := '';
263-
{$IFDEF CPUX86}
273+
{$IFDEF CPUX86}
264274
if CompareVersions(SysVersion, '3.5') <= 0 then
265275
VersionSuffix := '-32';
266-
{$ENDIF}
276+
{$ENDIF}
267277
key := Format('\Software\Python\PythonCore\%s%s', [SysVersion, VersionSuffix]);
268278

269279

@@ -276,6 +286,10 @@ function GetRegisterPythonVersion(SysVersion: string;
276286
if not Result then begin
277287
PythonVersion.IsAllUsers := True;
278288
Result := ReadFromRegistry(HKEY_LOCAL_MACHINE, key);
289+
if PythonVersion.fSysArchitecture = '' then
290+
// for all user installations we can be sure.
291+
/// But not for local user installations
292+
PythonVersion.fSysArchitecture := PythonVersion.ExpectedArchitecture;
279293
end;
280294

281295
PythonVersion.IsRegistered := Result;
@@ -290,22 +304,21 @@ function GetRegisteredPythonVersions : TPythonVersions;
290304
Count := 0;
291305
SetLength(Result, High(PYTHON_KNOWN_VERSIONS) - COMPILED_FOR_PYTHON_VERSION_INDEX + 1);
292306
for I := High(PYTHON_KNOWN_VERSIONS) downto COMPILED_FOR_PYTHON_VERSION_INDEX do
293-
if GetRegisterPythonVersion(PYTHON_KNOWN_VERSIONS[I].RegVersion, PythonVersion) then
307+
if GetRegisteredPythonVersion(PYTHON_KNOWN_VERSIONS[I].RegVersion, PythonVersion) then
294308
begin
295309
Result[Count] := PythonVersion;
296310
Inc(Count);
297311
end;
298312
SetLength(Result, Count);
299313
end;
300314

301-
function GetLatestRegisteredPythonVersion(PythonVersion: TPythonVersion): Boolean;
315+
function GetLatestRegisteredPythonVersion(out PythonVersion: TPythonVersion): Boolean;
302316
Var
303317
I: Integer;
304318
begin
305-
Result := False;
306319
for I := High(PYTHON_KNOWN_VERSIONS) downto COMPILED_FOR_PYTHON_VERSION_INDEX do
307320
begin
308-
Result := GetRegisterPythonVersion(PYTHON_KNOWN_VERSIONS[I].RegVersion, PythonVersion);
321+
Result := GetRegisteredPythonVersion(PYTHON_KNOWN_VERSIONS[I].RegVersion, PythonVersion);
309322
if Result then break;
310323
end;
311324
end;

PythonForDelphi/Components/Sources/Core/VarPyth.pas

+17-18
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,7 @@ TStringDesc = record
968968
begin
969969
// Grab the identifier
970970
LArgCount := CallDesc^.ArgCount;
971-
LIdent := FixupIdent(AnsiString(PAnsiChar(@CallDesc^.ArgTypes[LArgCount])));
971+
LIdent := FixupIdent(string(AnsiString(PAnsiChar(@CallDesc^.ArgTypes[LArgCount]))));
972972

973973
FillChar(Strings, SizeOf(Strings), 0);
974974
VarParams := GetDispatchInvokeArgs(CallDesc, Params, Strings, true);
@@ -1052,7 +1052,7 @@ TStringDesc = record
10521052
SetLength(fNamedParams, CallDesc^.NamedArgCount);
10531053
// Skip function Name
10541054
for I := 0 to CallDesc^.NamedArgCount - 1 do begin
1055-
LNamePtr := LNamePtr + Succ(StrLen(LNamePtr));
1055+
LNamePtr := LNamePtr + Succ(Length(LNamePtr));
10561056
fNamedParams[I].Index := I+LNamedArgStart;
10571057
fNamedParams[I].Name := AnsiString(LNamePtr);
10581058
end;
@@ -1427,7 +1427,6 @@ function TPythonVariantType.EvalPython(const V: TVarData;
14271427
_key, _value : PPyObject;
14281428
_result : Integer;
14291429
begin
1430-
Result := nil;
14311430
with GetPythonEngine do
14321431
begin
14331432
PyErr_Clear;
@@ -1438,21 +1437,21 @@ function TPythonVariantType.EvalPython(const V: TVarData;
14381437
_value := VarDataToPythonObject(AValue);
14391438
if not Assigned(_value) then
14401439
raise Exception.Create(SCantConvertValueToPythonObject);
1441-
if PyList_Check(AObject) then
1442-
_result := PyList_SetItem( AObject, Variant(AKey), _value )
1443-
else if PyTuple_Check(AObject) then
1444-
_result := PyTuple_SetItem( AObject, Variant(AKey), _value )
1445-
else
1446-
try
1447-
if PySequence_Check(AObject) <> 0 then
1448-
_result := PySequence_SetItem(AObject, Variant(AKey), _value)
1449-
else
1450-
_result := PyObject_SetItem( AObject, _key, _value );
1451-
finally
1452-
Py_XDecRef(_value);
1453-
end; // of try
1454-
CheckError;
1455-
Result := PyInt_FromLong(_result);
1440+
if PyList_Check(AObject) then
1441+
_result := PyList_SetItem( AObject, Variant(AKey), _value )
1442+
else if PyTuple_Check(AObject) then
1443+
_result := PyTuple_SetItem( AObject, Variant(AKey), _value )
1444+
else
1445+
try
1446+
if PySequence_Check(AObject) <> 0 then
1447+
_result := PySequence_SetItem(AObject, Variant(AKey), _value)
1448+
else
1449+
_result := PyObject_SetItem( AObject, _key, _value );
1450+
finally
1451+
Py_XDecRef(_value);
1452+
end; // of try
1453+
CheckError;
1454+
Result := PyInt_FromLong(_result);
14561455
finally
14571456
Py_XDecRef(_key);
14581457
end; // of try

0 commit comments

Comments
 (0)