diff options
| -rw-r--r-- | UCoreUtils.pas | 27 | ||||
| -rw-r--r-- | UEngines.pas | 6 | ||||
| -rw-r--r-- | ULibc.pas | 75 | ||||
| -rw-r--r-- | tuxcmd.dpr | 3 |
4 files changed, 99 insertions, 12 deletions
diff --git a/UCoreUtils.pas b/UCoreUtils.pas index 0bccb8b..93bbff0 100644 --- a/UCoreUtils.pas +++ b/UCoreUtils.pas @@ -195,13 +195,14 @@ begin if f < 0 then f := ConfSizeFormat; case f of 0 : begin // System default formatting - p := malloc(255); - memset(p, 0, 255); - if sprintf(p, '%''lu', Value div Base) < 1 then begin + p := g_strdup_printf('%''lu', Int64(Value div Base)); + if p = nil then begin DebugMsg(['FormatSize(0): sprintf() failed, using old format function.']); Result := FormatFloat('###,###,##0', Value div Base); - end else Result := StrToUTF8(p); - free(p); + end else begin + Result := StrToUTF8(p); + g_free(p); + end; end; 1 : begin // 123456 Result := IntToStr(Value div Base); @@ -308,7 +309,7 @@ begin placed := strftime(Buf, 254, PChar(DateFormat), time_tm); if placed <= 0 then DebugMsg(['FormatDate: error converting date. The result will be unpredictable.']); DateString := String(StrToUTF8(Buf)); - free(Buf); + libc_free(Buf); end; if FormatTime then begin @@ -332,7 +333,7 @@ begin placed := strftime(Buf, 254, PChar(TimeFormat), time_tm); if placed <= 0 then DebugMsg(['FormatDate: error converting time. The result will be unpredictable.']); TimeString := String(StrToUTF8(Buf)); - free(Buf); + libc_free(Buf); end; if FormatDate and FormatTime then begin @@ -1481,11 +1482,11 @@ end; function StrToUTF8(s: PChar): PChar; var bytes_read, bytes_written: gsize; error: PGError; - ns: PChar; + ns, nss: PChar; m: PChar; begin if g_utf8_validate(s, strlen(s), nil) then begin - Result := g_strndup(s, strlen(s)); + Result := strndup(s, strlen(s)); Exit; end; // DebugMsg(['StrToUTF8: string "', s, '" is not valid UTF-8.']); @@ -1502,9 +1503,11 @@ begin g_error_free(error); end; if @g_filename_display_name <> nil then begin - Result := g_filename_display_name(ns); - g_free(ns); - end else Result := ns; + nss := g_filename_display_name(ns); + Result := strdup(nss); // PPC compatibility + g_free(nss); + end else Result := strdup(ns); // PPC compatibility + g_free(ns); end; function UTF8ToStr(s: PChar): PChar; diff --git a/UEngines.pas b/UEngines.pas index b4dc319..1c51a62 100644 --- a/UEngines.pas +++ b/UEngines.pas @@ -1126,8 +1126,14 @@ begin if FName <> nil then libc_free(FName); if FDisplayName <> nil then libc_free(FDisplayName); if LnkPointTo <> nil then libc_free(LnkPointTo); +{$IFDEF CPUPOWERPC} + Writeln('FreeDataItem: before free ColumnData'); +{$ENDIF} for i := 0 to Length(ColumnData) - 1 do if ColumnData[i] <> nil then libc_free(ColumnData[i]); +{$IFDEF CPUPOWERPC} + Writeln('FreeDataItem: after free ColumnData'); +{$ENDIF} end; libc_free(DataItem); end; @@ -99,6 +99,7 @@ type Pstat64 = ^Tstat64; Tstat64 = packed record {$IFNDEF CPU64} // 32-bit platform +{$IFNDEF CPUPOWERPC} st_dev : __dev_t; __pad1 : dword; __st_ino : __ino_t; @@ -115,6 +116,24 @@ type st_mtim : Ttimespec; st_ctim : Ttimespec; st_ino : __ino64_t; +{$ELSE} // 32-bit PPC + st_dev : __dev_t; + st_ino : __ino64_t; + st_mode : __mode_t; + st_nlink : __nlink_t; + st_uid : __uid_t; + st_gid : __gid_t; + st_rdev : __dev_t; + __pad2 : ShortInt; + st_size : __off64_t; + st_blksize : __blksize_t; + st_blocks : __blkcnt64_t; + st_atim : Ttimespec; + st_mtim : Ttimespec; + st_ctim : Ttimespec; + __unused4 : DWORD; + __unused5 : DWORD; +{$ENDIF} {$ELSE} // 64-bit platform st_dev : QWORD; st_ino : Int64; @@ -621,11 +640,20 @@ 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'; +{$IFNDEF CPUPOWERPC} function malloc(size: size_t): Pointer; cdecl; external GLIBC_LIB name 'malloc'; +{$ELSE} +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'; +{$IFNDEF CPUPOWERPC} procedure free(ptr: Pointer); cdecl; external GLIBC_LIB name 'free'; procedure libc_free(ptr: Pointer); cdecl; external GLIBC_LIB name 'free'; +{$ELSE} +procedure free(ptr: Pointer); +procedure libc_free(ptr: Pointer); +{$ENDIF} procedure cfree(ptr: Pointer); cdecl; external GLIBC_LIB name 'cfree'; function memalign(boundary: size_t; size: size_t): Pointer; cdecl; external GLIBC_LIB name 'memalign'; function valloc(size: size_t): Pointer; cdecl; external GLIBC_LIB name 'valloc'; @@ -644,8 +672,13 @@ function strcmp(const s1: PChar; const s2: PChar): Longint; cdecl; external GLIB function strncmp(const s1: PChar; const s2: PChar; n: size_t): Longint; cdecl; external GLIBC_LIB name 'strncmp'; function strcasecmp(const s1: PChar; const s2: PChar): Longint; cdecl; external GLIBC_LIB name 'strcasecmp'; function strncasecmp(const s1: PChar; const s2: PChar; n: size_t): Longint; cdecl; external GLIBC_LIB name 'strncasecmp'; +{$IFNDEF CPUPOWERPC} function strdup(const s: PChar): PChar; cdecl; external GLIBC_LIB name 'strdup'; function strndup(const s: PChar; n: size_t): PChar; cdecl; external GLIBC_LIB name 'strndup'; +{$ELSE} +function strdup(const s: PChar): PChar; +function strndup(const s: PChar; n: size_t): PChar; +{$ENDIF} function strchr(const s: PChar; c: Longint): PChar; cdecl; external GLIBC_LIB name 'strchr'; function strrchr(const s: PChar; c: Longint): PChar; cdecl; external GLIBC_LIB name 'strrchr'; function strstr(const haystack: PChar; const needle: PChar): PChar; cdecl; external GLIBC_LIB name 'strstr'; @@ -819,6 +852,11 @@ function euidaccess(pathname: PChar; mode: Longint): Longint; cdecl; external GL implementation +{$IFDEF CPUPOWERPC} +uses SysUtils; +{$ENDIF} + + {$IFDEF KYLIX} function glibc__xstat64(ver: integer; const afile: PChar; buf: Pstat64): longint; cdecl; external GLIBC_LIB name '__xstat64'; function glibc__lxstat64(ver: integer; const path: PChar; buf: Pstat64): longint; cdecl; external GLIBC_LIB name '__lxstat64'; @@ -932,5 +970,42 @@ begin Result:=(Signal shl 8) or $7F; end; + +{$IFDEF CPUPOWERPC} +function xmalloc(size: size_t): Pointer; cdecl; external GLIBC_LIB name 'malloc'; +procedure xfree(ptr: Pointer); cdecl; external GLIBC_LIB name 'free'; + +function malloc(size: size_t): Pointer; +begin + Result := GetMem(size); +// Result := xmalloc(size); + WriteLn('malloc(', size, '): 0x', IntToHex(DWORD(Result), 4)); +end; + +procedure libc_free(ptr: Pointer); +begin + WriteLn('free(0x', IntToHex(DWORD(ptr), 4), ')'); + FreeMem(ptr); +// xfree(ptr); +end; + +procedure free(ptr: Pointer); +begin + libc_free(ptr); +end; + +function strdup(const s: PChar): PChar; +begin + Result := GetMem(strlen(s) + 1); + SysUtils.StrLCopy(Result, s, strlen(s) + 1); +end; + +function strndup(const s: PChar; n: size_t): PChar; +begin + Result := GetMem(n + 1); + SysUtils.StrLCopy(Result, s, n); +end; +{$ENDIF} + end. @@ -22,6 +22,9 @@ program tuxcmd; uses {$IFDEF FPC} +{$IFDEF CPUPOWERPC} +// cmem, +{$ENDIF} cthreads, cwstring, {$ENDIF} |
