* Try to fix go32v2 problems related to DJGPP code using C free on _environ ppchar by reallcating with malloc

git-svn-id: trunk@20111 -
This commit is contained in:
pierre 2012-01-19 14:01:47 +00:00
parent a088820cfe
commit bf321b72c7

View File

@ -855,8 +855,11 @@ type
jmp_buf = dpmi_jmp_buf;
pjmp_buf = pdpmi_jmp_buf;
function setjmp(var rec : jmp_buf) : longint;cdecl;external;
function malloc(size : longint) : pointer;cdecl;external;
procedure longjmp(var rec : jmp_buf;return_value : longint);cdecl;external;
procedure reload_fs;assembler;
@ -3102,6 +3105,32 @@ var
c_environ : ppchar;external name '_environ';
c_argc : longint;external name '___crt0_argc';
c_argv : ppchar;external name '___crt0_argv';
procedure ReallocateEnvironUsingCMalloc;
var
neededsize , count : longint;
penv : pchar;
newenv : ppchar;
begin
if not assigned(c_environ) then
neededsize:=0
else
begin
count:=0;
penv:=c_environ^;
while assigned(penv) do
begin
inc(count);
inc(penv,sizeof(pchar));
end;
neededsize:=count*sizeof(pchar);
end;
newenv:=malloc(neededsize);
system.move(c_environ,newenv,neededsize);
c_environ:=newenv;
end;
{$endif def go32v2}
var
current_directory : pchar; cvar; external;
@ -3140,7 +3169,9 @@ var
save_gdb_stderr : pui_file;
begin
{$ifdef go32v2}
c_environ:=system.envp;
{ c_environ:=system.envp; }
{ DJGPP libC presupposes the c_enivron was malloc'ated }
ReallocateEnvironUsingCMalloc;
c_argc:=system.argc;
c_argv:=system.argv;
{$endif def go32v2}