@@ -2670,6 +2670,8 @@ procedure PyObjectDestructor( pSelf : PPyObject); cdecl;
2670
2670
procedure FreeSubtypeInst (ob:PPyObject); cdecl;
2671
2671
procedure Register ;
2672
2672
function PyType_HasFeature (AType : PPyTypeObject; AFlag : Integer) : Boolean;
2673
+ function SysVersionFromDLLName (const DLLFileName : string): string;
2674
+ procedure PythonVersionFromDLLName (const LibName: string; out MajorVersion, MinorVersion: integer);
2673
2675
2674
2676
{ Helper functions}
2675
2677
(*
@@ -2698,8 +2700,6 @@ procedure MaskFPUExceptions(ExceptionsMasked : boolean;
2698
2700
*)
2699
2701
function CleanString (const s : AnsiString; AppendLF : Boolean = True) : AnsiString; overload;
2700
2702
2701
- procedure DetectPythonVersionFromLibName (const LibName: string; out MajorVersion, MinorVersion: integer);
2702
-
2703
2703
implementation
2704
2704
2705
2705
{ $R *.dcr} // AT
@@ -2723,29 +2723,6 @@ function _IsBufferAscii(buf: PAnsiChar): boolean; inline;
2723
2723
Result := true;
2724
2724
end ;
2725
2725
2726
- procedure DetectPythonVersionFromLibName (const LibName: string; out MajorVersion, MinorVersion: integer);
2727
- var
2728
- NPos: integer;
2729
- S: String;
2730
- begin
2731
- // Win: "python310.dll"
2732
- // Linux: "libpython3.10.so"
2733
- S := LibName;
2734
- NPos := Pos(' python' , LowerCase(S));
2735
- if NPos>0 then
2736
- begin
2737
- Inc(NPos, Length(' python' ));
2738
- MajorVersion := StrToIntDef(S[NPos], 3 );
2739
- Inc(NPos);
2740
- if LibName[NPos]=' .' then
2741
- Inc(NPos);
2742
- S := Copy(S, NPos);
2743
- NPos := Pos(' .' , S);
2744
- if NPos > 1 then
2745
- MinorVersion := StrToIntDef(Copy(S, 1 , NPos-1 ), 3 );
2746
- end ;
2747
- end ;
2748
-
2749
2726
(* ******************************************************)
2750
2727
(* * **)
2751
2728
(* * Globals **)
@@ -3124,8 +3101,8 @@ constructor TPythonInterface.Create(AOwner: TComponent);
3124
3101
procedure TPythonInterface.AfterLoad ;
3125
3102
begin
3126
3103
inherited ;
3104
+ PythonVersionFromDLLName(DLLName, FMajorVersion, FMinorVersion);
3127
3105
3128
- DetectPythonVersionFromLibName(DLLName, FMajorVersion, FMinorVersion);
3129
3106
FBuiltInModuleName := ' builtins' ;
3130
3107
3131
3108
try
@@ -4055,10 +4032,7 @@ procedure TPythonEngine.DoOpenDll(const aDllName : String);
4055
4032
end ;
4056
4033
end
4057
4034
else
4058
- begin
4059
- DetectPythonVersionFromLibName(aDllName, NMajor, NMinor);
4060
- RegVersion := Format(' %d.%d' , [NMajor, NMinor]);
4061
- end ;
4035
+ RegVersion := SysVersionFromDLLName(aDllName);
4062
4036
inherited ;
4063
4037
end ;
4064
4038
@@ -8774,6 +8748,14 @@ procedure Register;
8774
8748
TPythonType, TPythonModule, TPythonDelphiVar]);
8775
8749
end ;
8776
8750
8751
+ function SysVersionFromDLLName (const DLLFileName : string): string;
8752
+ var
8753
+ Minor, Major: integer;
8754
+ begin
8755
+ PythonVersionFromDLLName(DLLFileName, Major, Minor);
8756
+ Result := Format(' %d.%d' , [Major, Minor]);
8757
+ end ;
8758
+
8777
8759
function PyType_HasFeature (AType : PPyTypeObject; AFlag : Integer) : Boolean;
8778
8760
begin
8779
8761
// (((t)->tp_flags & (f)) != 0)
@@ -8853,5 +8835,29 @@ function IsPythonVersionRegistered(PythonVersion : AnsiString;
8853
8835
end ;
8854
8836
{ $ENDIF}
8855
8837
8838
+ procedure PythonVersionFromDLLName (const LibName: string; out MajorVersion, MinorVersion: integer);
8839
+ var
8840
+ NPos: integer;
8841
+ S: String;
8842
+ begin
8843
+ // Win: "python310.dll"
8844
+ // Linux: "libpython3.10.so"
8845
+ S := LibName;
8846
+ NPos := Pos(' python' , LowerCase(S));
8847
+ if NPos>0 then
8848
+ begin
8849
+ Inc(NPos, Length(' python' ));
8850
+ MajorVersion := StrToIntDef(S[NPos], 3 );
8851
+ Inc(NPos);
8852
+ if LibName[NPos]=' .' then
8853
+ Inc(NPos);
8854
+ S := Copy(S, NPos);
8855
+ NPos := Pos(' .' , S);
8856
+ if NPos > 1 then
8857
+ MinorVersion := StrToIntDef(Copy(S, 1 , NPos-1 ), 3 );
8858
+ end ;
8859
+ end ;
8860
+
8861
+
8856
8862
end .
8857
8863
0 commit comments