mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-07 02:50:35 +01:00
TUTF8Process: workaround for the poNoConsole->poDetached change. Better hacks for old FPC versions without TProcessClassTemplate. Issue #35991
git-svn-id: trunk@63708 -
This commit is contained in:
parent
53e492ccd2
commit
3a6057e0a3
@ -381,7 +381,7 @@ begin
|
|||||||
FDbgProcess := TProcessUTF8.Create(nil);
|
FDbgProcess := TProcessUTF8.Create(nil);
|
||||||
try
|
try
|
||||||
FDbgProcess.ParseCmdLine(ExternalDebugger + ' ' + AOptions);
|
FDbgProcess.ParseCmdLine(ExternalDebugger + ' ' + AOptions);
|
||||||
FDbgProcess.Options:= [poUsePipes, poNoConsole, poStdErrToOutPut, poNewProcessGroup];
|
FDbgProcess.Options:= [poUsePipes, {$IF DECLARED(poDetached)}poDetached{$ELSE}poNoConsole{$ENDIF}, poStdErrToOutPut, poNewProcessGroup];
|
||||||
{$if defined(windows) and not defined(wince)}
|
{$if defined(windows) and not defined(wince)}
|
||||||
// under win9x and winMe should be created with console,
|
// under win9x and winMe should be created with console,
|
||||||
// otherwise no break can be sent.
|
// otherwise no break can be sent.
|
||||||
|
|||||||
@ -13,21 +13,17 @@ unit UTF8Process;
|
|||||||
|
|
||||||
{$mode objfpc}{$H+}
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
{$IFDEF MSWINDOWS}
|
|
||||||
{$IF FPC_FULLVERSION < 30200}
|
|
||||||
{$DEFINE UseTProcessW}
|
|
||||||
{$ENDIF}
|
|
||||||
{$ENDIF}
|
|
||||||
|
|
||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, Process,
|
Classes, SysUtils, Process,
|
||||||
{$IFDEF UseTProcessW}
|
|
||||||
pipes,
|
|
||||||
{$ENDIF}
|
|
||||||
FileUtil, LazFileUtils, LazUTF8, LazUtilsStrConsts;
|
FileUtil, LazFileUtils, LazUTF8, LazUtilsStrConsts;
|
||||||
|
|
||||||
|
{$IF DEFINED(MSWINDOWS) AND NOT DECLARED(poDetached)} // we need to work around the poNoConsole->poDetached change
|
||||||
|
// more info: issue #32055, #35991; FPC r45228, https://forum.lazarus.freepascal.org/index.php/topic,49631.0
|
||||||
|
{$DEFINE UseTProcessW}
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
{ TProcessUTF8 }
|
{ TProcessUTF8 }
|
||||||
|
|
||||||
{$IFDEF UseTProcessW}
|
{$IFDEF UseTProcessW}
|
||||||
@ -65,7 +61,11 @@ procedure Register;
|
|||||||
implementation
|
implementation
|
||||||
|
|
||||||
{$IF defined(windows)}
|
{$IF defined(windows)}
|
||||||
uses Windows;
|
uses Windows
|
||||||
|
{$IFDEF UseTProcessW}
|
||||||
|
,pipes
|
||||||
|
{$ENDIF}
|
||||||
|
;
|
||||||
{$ELSEIF defined(freebsd) or defined(darwin)}
|
{$ELSEIF defined(freebsd) or defined(darwin)}
|
||||||
uses ctypes, sysctl;
|
uses ctypes, sysctl;
|
||||||
{$ELSEIF defined(linux)}
|
{$ELSEIF defined(linux)}
|
||||||
@ -201,6 +201,9 @@ Const
|
|||||||
PriorityConstants : Array [TProcessPriority] of Cardinal =
|
PriorityConstants : Array [TProcessPriority] of Cardinal =
|
||||||
(HIGH_PRIORITY_CLASS,IDLE_PRIORITY_CLASS,
|
(HIGH_PRIORITY_CLASS,IDLE_PRIORITY_CLASS,
|
||||||
NORMAL_PRIORITY_CLASS,REALTIME_PRIORITY_CLASS
|
NORMAL_PRIORITY_CLASS,REALTIME_PRIORITY_CLASS
|
||||||
|
{$if (FPC_FULLVERSION >= 30200) and not defined(WinCE)}
|
||||||
|
,BELOW_NORMAL_PRIORITY_CLASS,ABOVE_NORMAL_PRIORITY_CLASS
|
||||||
|
{$endif}
|
||||||
);
|
);
|
||||||
|
|
||||||
function WStrAsUniquePWideChar(var s: UnicodeString): PWideChar; inline;
|
function WStrAsUniquePWideChar(var s: UnicodeString): PWideChar; inline;
|
||||||
@ -234,8 +237,15 @@ Function GetCreationFlags(P : TProcessUTF8) : Cardinal;
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
Result:=CREATE_UNICODE_ENVIRONMENT;
|
Result:=CREATE_UNICODE_ENVIRONMENT;
|
||||||
|
{$IF DECLARED(poDetached)}
|
||||||
|
if poNoConsole in P.Options then
|
||||||
|
Result:=Result or CREATE_NO_WINDOW;
|
||||||
|
if poDetached in P.Options then
|
||||||
|
Result:=Result or Detached_Process;
|
||||||
|
{$ELSE}
|
||||||
if poNoConsole in P.Options then
|
if poNoConsole in P.Options then
|
||||||
Result:=Result or Detached_Process;
|
Result:=Result or Detached_Process;
|
||||||
|
{$ENDIF}
|
||||||
if poNewConsole in P.Options then
|
if poNewConsole in P.Options then
|
||||||
Result:=Result or Create_new_console;
|
Result:=Result or Create_new_console;
|
||||||
if poNewProcessGroup in P.Options then
|
if poNewProcessGroup in P.Options then
|
||||||
@ -376,68 +386,39 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
type
|
|
||||||
TProcessClassTemplate = class(TComponent)
|
|
||||||
private
|
|
||||||
{$if fpc_fullversion < 30101}
|
|
||||||
{%H-}FProcessOptions : TProcessOptions;
|
|
||||||
{%H-}FStartupOptions : TStartupOptions;
|
|
||||||
FProcessID : Integer;
|
|
||||||
{%H-}FTerminalProgram: String;
|
|
||||||
{$else}
|
|
||||||
{%H-}FOnRunCommandEvent: TOnRunCommandEvent;
|
|
||||||
{%H-}FProcessOptions : TProcessOptions;
|
|
||||||
FRunCommandSleepTime: Integer;
|
|
||||||
{%H-}FStartupOptions : TStartupOptions;
|
|
||||||
FProcessID : Integer;
|
|
||||||
{$ifend}
|
|
||||||
{%H-}FThreadID : Integer;
|
|
||||||
FProcessHandle : Thandle;
|
|
||||||
FThreadHandle : Thandle;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ TProcessUTF8 }
|
{ TProcessUTF8 }
|
||||||
|
|
||||||
|
type
|
||||||
|
PHandle = ^THandle;
|
||||||
|
|
||||||
procedure TProcessUTF8.SetProcessHandle(aProcessHandle: THandle);
|
procedure TProcessUTF8.SetProcessHandle(aProcessHandle: THandle);
|
||||||
var
|
var
|
||||||
o: TProcessClassTemplate;
|
P: PHandle;
|
||||||
begin
|
begin
|
||||||
o:=TProcessClassTemplate.Create(nil);
|
P := @Self.ProcessHandle;
|
||||||
if (@o.FProcessHandle-Pointer(o) <= TProcessUTF8.InstanceSize - SizeOf(HANDLE)) and
|
P^ := aProcessHandle;
|
||||||
(PHANDLE(Pointer(Self)+(@o.FProcessHandle-Pointer(o)))^ = ProcessHandle)
|
|
||||||
then
|
|
||||||
PHANDLE(Pointer(Self)+(@o.FProcessHandle-Pointer(o)))^:=aProcessHandle;
|
|
||||||
if aProcessHandle<>ProcessHandle then
|
if aProcessHandle<>ProcessHandle then
|
||||||
raise Exception.Create('TProcessUTF8.SetProcessHandle failed');
|
raise Exception.Create('TProcessUTF8.SetProcessHandle failed');
|
||||||
o.Free;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TProcessUTF8.SetThreadHandle(aThreadHandle: THandle);
|
procedure TProcessUTF8.SetThreadHandle(aThreadHandle: THandle);
|
||||||
var
|
var
|
||||||
o: TProcessClassTemplate;
|
P: PHandle;
|
||||||
begin
|
begin
|
||||||
o:=TProcessClassTemplate.Create(nil);
|
P := @Self.ThreadHandle;
|
||||||
if (@o.FThreadHandle-Pointer(o) <= TProcessUTF8.InstanceSize - SizeOf(HANDLE)) and
|
P^ := aThreadHandle;
|
||||||
(PHANDLE(Pointer(Self)+(@o.FThreadHandle-Pointer(o)))^ = ThreadHandle)
|
|
||||||
then
|
|
||||||
PHANDLE(Pointer(Self)+(@o.FThreadHandle-Pointer(o)))^:=aThreadHandle;
|
|
||||||
if aThreadHandle<>ThreadHandle then
|
if aThreadHandle<>ThreadHandle then
|
||||||
raise Exception.Create('TProcessUTF8.SetThreadHandle failed');
|
raise Exception.Create('TProcessUTF8.SetThreadHandle failed');
|
||||||
o.Free;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TProcessUTF8.SetProcessID(aProcessID: Integer);
|
procedure TProcessUTF8.SetProcessID(aProcessID: Integer);
|
||||||
var
|
var
|
||||||
o: TProcessClassTemplate;
|
P: PInteger;
|
||||||
begin
|
begin
|
||||||
o:=TProcessClassTemplate.Create(nil);
|
P := @Self.ProcessID;
|
||||||
if (@o.FProcessID-Pointer(o) <= TProcessUTF8.InstanceSize - SizeOf(HANDLE)) and
|
P^ := aProcessID;
|
||||||
(PHANDLE(Pointer(Self)+(@o.FProcessID-Pointer(o)))^ = ProcessID)
|
|
||||||
then
|
|
||||||
PHANDLE(Pointer(Self)+(@o.FProcessID-Pointer(o)))^:=aProcessID;
|
|
||||||
if aProcessID<>ProcessID then
|
if aProcessID<>ProcessID then
|
||||||
raise Exception.Create('TProcessUTF8.SetProcessID failed');
|
raise Exception.Create('TProcessUTF8.SetProcessID failed');
|
||||||
o.Free;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TProcessUTF8.Execute;
|
procedure TProcessUTF8.Execute;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user