summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@redhat.com>2009-10-04 21:22:09 +0200
committerTomas Bzatek <tbzatek@redhat.com>2009-10-04 21:22:09 +0200
commitf02993636a68e2a611acf6c4519cf6f139ab4737 (patch)
tree0ded518f2aa00163772322264c64f1ec1269a0ce
parent47208d263f3940ec65e7f94b9cc8f4c588234ac5 (diff)
downloadtuxcmd-f02993636a68e2a611acf6c4519cf6f139ab4737.tar.xz
Force use glibc malloc() and free() for plugin-related allocations on PPC
FreePascal sucks ass on PowerPC!!
-rw-r--r--ULibc.pas3
-rw-r--r--vfs/UVFSCore.pas98
2 files changed, 52 insertions, 49 deletions
diff --git a/ULibc.pas b/ULibc.pas
index 5ff010f..0cdac2b 100644
--- a/ULibc.pas
+++ b/ULibc.pas
@@ -680,6 +680,7 @@ function dlclose(handle: Pointer): Longint; cdecl; external DL_LIB name 'dlclose
function dlsym(handle: Pointer; const symbol: PChar): Pointer; cdecl; external DL_LIB name 'dlsym';
function dlerror: PChar; cdecl; external GLIBC_LIB name 'dlerror';
+function real_libc_malloc(size: size_t): Pointer; cdecl; external GLIBC_LIB name 'malloc';
{$IFNDEF CPUPOWERPC}
function malloc(size: size_t): Pointer; cdecl; external GLIBC_LIB name 'malloc';
{$ELSE}
@@ -687,6 +688,8 @@ function malloc(size: size_t): Pointer;
{$ENDIF}
function calloc(nmemb: size_t; size: size_t): Pointer; cdecl; external GLIBC_LIB name 'calloc';
function realloc(ptr: Pointer; size: size_t): Pointer; cdecl; external GLIBC_LIB name 'realloc';
+
+procedure real_libc_free(ptr: Pointer); cdecl; external GLIBC_LIB name 'free';
{$IFNDEF CPUPOWERPC}
procedure free(ptr: Pointer); cdecl; external GLIBC_LIB name 'free';
procedure libc_free(ptr: Pointer); cdecl; external GLIBC_LIB name 'free';
diff --git a/vfs/UVFSCore.pas b/vfs/UVFSCore.pas
index 45bfc83..ae752c8 100644
--- a/vfs/UVFSCore.pas
+++ b/vfs/UVFSCore.pas
@@ -182,7 +182,7 @@ const ConstGlobalModulePath1 = '/usr/lib/tuxcmd';
var BinaryPath: string;
-procedure VFSLogFunc(s: PChar); cdecl;
+procedure VFSLogFunc(const s: PChar); cdecl;
begin
DebugMsg([' ### VFS ###: ', s]);
end;
@@ -244,14 +244,14 @@ begin
s := FVFSGetExts;
if s <> nil then begin
ParseString(String(s), ';', Extensions);
- libc_free(s);
+ real_libc_free(s);
end;
end;
if @FVFSGetServices <> nil then begin
s := FVFSGetServices;
if s <> nil then begin
ParseString(String(s), ';', Services);
- libc_free(s);
+ real_libc_free(s);
end;
end;
end;
@@ -274,10 +274,10 @@ end;
procedure _free_PVFSInfo(Info: PVFSInfo);
begin
if Info <> nil then begin
- if Info^.Name <> nil then libc_free(Info^.Name);
- if Info^.ID <> nil then libc_free(Info^.ID);
- if Info^.About <> nil then libc_free(Info^.About);
- if Info^.Copyright <> nil then libc_free(Info^.Copyright);
+ if Info^.Name <> nil then real_libc_free(Info^.Name);
+ if Info^.ID <> nil then real_libc_free(Info^.ID);
+ if Info^.About <> nil then real_libc_free(Info^.About);
+ if Info^.Copyright <> nil then real_libc_free(Info^.Copyright);
end;
end;
@@ -392,7 +392,7 @@ begin
Result := 0;
try
if @FSourcePlugin.FVFSListFirst = nil then Exit;
- P := malloc(SizeOf(TVFSItem));
+ P := real_libc_malloc(SizeOf(TVFSItem));
memset(P, 0, SizeOf(TVFSItem));
// DebugMsg(['Item = ', Int64(P)]);
// DebugMsg(['FVFSListFirst']);
@@ -401,7 +401,7 @@ begin
FSourcePlugin.FVFSListClose(FGlobs);
if Res = cVFS_Not_More_Files then Result := 0
else Result := Res;
- libc_free(P);
+ real_libc_free(P);
Exit;
end;
@@ -453,12 +453,12 @@ begin
DebugMsg(['^^VFS (EE): GetListing: Item-Exception: ', E.Message]);
end;
end; // of if AddDotFiles
- if P^.FName <> nil then libc_free(P^.FName);
- if P^.FDisplayName <> nil then libc_free(P^.FDisplayName);
- if P^.sLinkTo <> nil then libc_free(P^.sLinkTo);
- libc_free(P); // Not needed - just zero-erase the memory
+ if P^.FName <> nil then real_libc_free(P^.FName);
+ if P^.FDisplayName <> nil then real_libc_free(P^.FDisplayName);
+ if P^.sLinkTo <> nil then real_libc_free(P^.sLinkTo);
+ real_libc_free(P); // Not needed - just zero-erase the memory
// DebugMsg(['Checkpoint 13']);
- P := malloc(SizeOf(TVFSItem));
+ P := real_libc_malloc(SizeOf(TVFSItem));
memset(P, 0, SizeOf(TVFSItem));
// DebugMsg(['Item = ', Int64(P)]);
// DebugMsg(['Checkpoint 14']);
@@ -469,7 +469,7 @@ begin
until (Res <> cVFS_OK) or (BreakProcessingKind = 2);
if BreakProcessingKind <> 0 then DebugMsg(['^^VFS (WW): GetListing: stopped by BreakProcessing']);
- libc_free(P);
+ real_libc_free(P);
FSourcePlugin.FVFSListClose(FGlobs);
if Res <> cVFS_Not_More_Files then Result := Res;
except
@@ -543,7 +543,7 @@ begin
s := FSourcePlugin.FVFSGetPrefix(FGlobs);
if s <> nil then begin
Result := String(s);
- libc_free(s);
+ real_libc_free(s);
end;
end;
end;
@@ -556,7 +556,7 @@ begin
s := FSourcePlugin.FVFSGetPath(FGlobs);
if s <> nil then begin
Result := String(s);
- libc_free(s);
+ real_libc_free(s);
end;
end;
end;
@@ -569,7 +569,7 @@ begin
s := FSourcePlugin.FVFSGetPathURI(FGlobs);
if s <> nil then begin
Result := String(s);
- libc_free(s);
+ real_libc_free(s);
end;
end;
end;
@@ -617,11 +617,11 @@ begin
if @FSourcePlugin.FVFSFileExists <> nil then begin
Result := FSourcePlugin.FVFSFileExists(FGlobs, PChar(FileName), Use_lstat);
if Result and (@FSourcePlugin.FVFSFileInfo <> nil) then begin
- P := malloc(SizeOf(TVFSItem));
+ P := real_libc_malloc(SizeOf(TVFSItem));
memset(P, 0, SizeOf(TVFSItem));
Res := FSourcePlugin.FVFSFileInfo(FGlobs, PChar(FileName), P);
if (Res <> cVFS_OK) or (P = nil) or (TVFSItemType(P^.ItemType) <> vDirectory) then Result := False;
- libc_free(P);
+ real_libc_free(P);
end;
end else Result := False;
end;
@@ -633,7 +633,7 @@ var P: PVFSItem;
begin
Result := nil;
if @FSourcePlugin.FVFSFileInfo = nil then Exit;
- P := malloc(SizeOf(TVFSItem));
+ P := real_libc_malloc(SizeOf(TVFSItem));
memset(P, 0, SizeOf(TVFSItem));
Res := FSourcePlugin.FVFSFileInfo(FGlobs, PChar(APath), P);
@@ -670,10 +670,10 @@ begin
GID := P^.iGID;
Size := P^.iSize;
PackedSize := P^.iPackedSize;
- if P^.FName <> nil then libc_free(P^.FName);
- if P^.FDisplayName <> nil then libc_free(P^.FDisplayName);
- if P^.sLinkTo <> nil then libc_free(P^.sLinkTo);
- libc_free(P);
+ if P^.FName <> nil then real_libc_free(P^.FName);
+ if P^.FDisplayName <> nil then real_libc_free(P^.FDisplayName);
+ if P^.sLinkTo <> nil then real_libc_free(P^.sLinkTo);
+ real_libc_free(P);
end;
Result := Item;
except
@@ -748,15 +748,15 @@ begin
LocalList := TStringList.Create;
try
try
- P := malloc(SizeOf(TVFSItem));
+ P := real_libc_malloc(SizeOf(TVFSItem));
memset(P, 0, SizeOf(TVFSItem));
Res := FSourcePlugin.FVFSFileInfo(FGlobs, PChar(APath), P);
if Res <> cVFS_OK then DebugMsg(['*** FillDirFiles - VFSFileInfo(', APath, ') failed. Code = ', Res]);
AddEntry(APath, True, True);
- if P^.FName <> nil then libc_free(P^.FName);
- if P^.FDisplayName <> nil then libc_free(P^.FDisplayName);
- if P^.sLinkTo <> nil then libc_free(P^.sLinkTo);
- libc_free(P);
+ if P^.FName <> nil then real_libc_free(P^.FName);
+ if P^.FDisplayName <> nil then real_libc_free(P^.FDisplayName);
+ if P^.sLinkTo <> nil then real_libc_free(P^.sLinkTo);
+ real_libc_free(P);
APath := IncludeTrailingPathDelimiter(APath);
if @FSourcePlugin.FVFSChangeDir <> nil then Res := FSourcePlugin.FVFSChangeDir(FGlobs, PChar(APath))
@@ -764,15 +764,15 @@ begin
if Res <> 0 then Exit;
if @FSourcePlugin.FVFSListFirst = nil then Exit;
- P := malloc(SizeOf(TVFSItem));
+ P := real_libc_malloc(SizeOf(TVFSItem));
memset(P, 0, SizeOf(TVFSItem));
Res := FSourcePlugin.FVFSListFirst(FGlobs, PChar(APath), P);
if Res <> cVFS_OK then begin
FSourcePlugin.FVFSListClose(FGlobs);
- if P^.FName <> nil then libc_free(P^.FName);
- if P^.FDisplayName <> nil then libc_free(P^.FDisplayName);
- if P^.sLinkTo <> nil then libc_free(P^.sLinkTo);
- libc_free(P);
+ if P^.FName <> nil then real_libc_free(P^.FName);
+ if P^.FDisplayName <> nil then real_libc_free(P^.FDisplayName);
+ if P^.sLinkTo <> nil then real_libc_free(P^.sLinkTo);
+ real_libc_free(P);
Exit;
end;
@@ -780,19 +780,19 @@ begin
if TVFSItemType(P^.ItemType) = vDirectory
then LocalList.Add(APath + String(P^.FName))
else AddEntry(APath + String(P^.FName), False, True);
- if P^.FName <> nil then libc_free(P^.FName);
- if P^.FDisplayName <> nil then libc_free(P^.FDisplayName);
- if P^.sLinkTo <> nil then libc_free(P^.sLinkTo);
- libc_free(P);
- P := malloc(SizeOf(TVFSItem));
+ if P^.FName <> nil then real_libc_free(P^.FName);
+ if P^.FDisplayName <> nil then real_libc_free(P^.FDisplayName);
+ if P^.sLinkTo <> nil then real_libc_free(P^.sLinkTo);
+ real_libc_free(P);
+ P := real_libc_malloc(SizeOf(TVFSItem));
memset(P, 0, SizeOf(TVFSItem));
Res := FSourcePlugin.FVFSListNext(FGlobs, PChar(GetPath), P);
until (Res <> cVFS_OK);
- if P^.FName <> nil then libc_free(P^.FName);
- if P^.FDisplayName <> nil then libc_free(P^.FDisplayName);
- if P^.sLinkTo <> nil then libc_free(P^.sLinkTo);
- libc_free(P);
+ if P^.FName <> nil then real_libc_free(P^.FName);
+ if P^.FDisplayName <> nil then real_libc_free(P^.FDisplayName);
+ if P^.sLinkTo <> nil then real_libc_free(P^.sLinkTo);
+ real_libc_free(P);
FSourcePlugin.FVFSListClose(FGlobs);
if LocalList.Count > 0 then
@@ -806,15 +806,15 @@ begin
on E: Exception do DebugMsg(['*** TVFSEngine.FillDirFiles(APath=', APath, ', Level=', ALevel, ') -Exception: ', E.Message]);
end;
finally
- P := malloc(SizeOf(TVFSItem));
+ P := real_libc_malloc(SizeOf(TVFSItem));
memset(P, 0, SizeOf(TVFSItem));
Res := FSourcePlugin.FVFSFileInfo(FGlobs, PChar(APath), P);
if Res <> cVFS_OK then DebugMsg(['*** FillDirFiles - VFSFileInfo(', APath, ') failed. Code = ', Res]);
AddEntry(APath, True, False);
- if P^.FName <> nil then libc_free(P^.FName);
- if P^.FDisplayName <> nil then libc_free(P^.FDisplayName);
- if P^.sLinkTo <> nil then libc_free(P^.sLinkTo);
- libc_free(P);
+ if P^.FName <> nil then real_libc_free(P^.FName);
+ if P^.FDisplayName <> nil then real_libc_free(P^.FDisplayName);
+ if P^.sLinkTo <> nil then real_libc_free(P^.sLinkTo);
+ real_libc_free(P);
LocalList.Free;
FilesList.Free;