diff options
Diffstat (limited to 'Build/source/libs/xpdf/xpdf-src/goo')
-rw-r--r-- | Build/source/libs/xpdf/xpdf-src/goo/GMutex.h | 10 | ||||
-rw-r--r-- | Build/source/libs/xpdf/xpdf-src/goo/GString.cc | 8 | ||||
-rw-r--r-- | Build/source/libs/xpdf/xpdf-src/goo/gfile.cc | 45 | ||||
-rw-r--r-- | Build/source/libs/xpdf/xpdf-src/goo/gfile.h | 6 | ||||
-rw-r--r-- | Build/source/libs/xpdf/xpdf-src/goo/gmem.cc | 98 | ||||
-rw-r--r-- | Build/source/libs/xpdf/xpdf-src/goo/gmem.h | 11 |
6 files changed, 156 insertions, 22 deletions
diff --git a/Build/source/libs/xpdf/xpdf-src/goo/GMutex.h b/Build/source/libs/xpdf/xpdf-src/goo/GMutex.h index 972e4da7f97..d73366bddd0 100644 --- a/Build/source/libs/xpdf/xpdf-src/goo/GMutex.h +++ b/Build/source/libs/xpdf/xpdf-src/goo/GMutex.h @@ -68,8 +68,11 @@ static inline GAtomicCounter gAtomicIncrement(GAtomicCounter *counter) { #if defined(_WIN32) newVal = _InterlockedIncrement(counter); -#elif defined(__GNUC__) // this also works for LLVM/clang +#elif defined(__GNUC__) || defined(__xlC__) + // __GNUC__ also covers LLVM/clang newVal = __sync_add_and_fetch(counter, 1); +#elif defined(__SUNPRO_CC) + newVal = atomic_inc_ulong_nv((ulong_t *)counter); #else # error "gAtomicIncrement is not defined for this compiler/platform" #endif @@ -83,8 +86,11 @@ static inline GAtomicCounter gAtomicDecrement(GAtomicCounter *counter) { #if defined(_WIN32) newVal = _InterlockedDecrement(counter); -#elif defined(__GNUC__) // this also works for LLVM/clang +#elif defined(__GNUC__) || defined(__xlC__) + // __GNUC__ also covers LLVM/clang newVal = __sync_sub_and_fetch(counter, 1); +#elif defined(__SUNPRO_CC) + newVal = atomic_dec_ulong_nv((ulong_t *)counter); #else # error "gAtomicDecrement is not defined for this compiler/platform" #endif diff --git a/Build/source/libs/xpdf/xpdf-src/goo/GString.cc b/Build/source/libs/xpdf/xpdf-src/goo/GString.cc index b56ed58ba16..54de35b0a75 100644 --- a/Build/source/libs/xpdf/xpdf-src/goo/GString.cc +++ b/Build/source/libs/xpdf/xpdf-src/goo/GString.cc @@ -656,7 +656,7 @@ void GString::formatDouble(double x, char *buf, int bufSize, int prec, x2 = floor(0.1 * (x + 0.5)); d = (int)floor(x - 10 * x2 + 0.5); if (started || d != 0) { - buf[--i] = '0' + d; + buf[--i] = (char)('0' + d); started = gTrue; } x = x2; @@ -668,7 +668,7 @@ void GString::formatDouble(double x, char *buf, int bufSize, int prec, do { x2 = floor(0.1 * (x + 0.5)); d = (int)floor(x - 10 * x2 + 0.5); - buf[--i] = '0' + d; + buf[--i] = (char)('0' + d); x = x2; } while (i > 1 && x); } @@ -757,7 +757,7 @@ GString *GString::upperCase() { for (i = 0; i < length; ++i) { if (islower(s[i] & 0xff)) { - s[i] = toupper(s[i] & 0xff); + s[i] = (char)toupper(s[i] & 0xff); } } return this; @@ -768,7 +768,7 @@ GString *GString::lowerCase() { for (i = 0; i < length; ++i) { if (isupper(s[i] & 0xff)) { - s[i] = tolower(s[i] & 0xff); + s[i] = (char)tolower(s[i] & 0xff); } } return this; diff --git a/Build/source/libs/xpdf/xpdf-src/goo/gfile.cc b/Build/source/libs/xpdf/xpdf-src/goo/gfile.cc index b2e97e1b418..40cf9054153 100644 --- a/Build/source/libs/xpdf/xpdf-src/goo/gfile.cc +++ b/Build/source/libs/xpdf/xpdf-src/goo/gfile.cc @@ -32,6 +32,7 @@ # include <unixlib.h> # endif #endif // _WIN32 +#include "gmem.h" #include "gmempp.h" #include "GString.h" #include "gfile.h" @@ -291,7 +292,7 @@ GString *grabPath(char *fileName) { char *p; if ((p = strrchr(fileName, '/'))) - return new GString(fileName, p - fileName); + return new GString(fileName, (int)(p - fileName)); return new GString(); #endif } @@ -372,12 +373,12 @@ GString *makePathAbsolute(GString *path) { #else for (p2 = p1; *p2 && *p2 != '/'; ++p2) ; #endif - if ((n = p2 - p1) > PATH_MAX) + if ((n = (int)(p2 - p1)) > PATH_MAX) n = PATH_MAX; strncpy(buf, p1, n); buf[n] = '\0'; if ((pw = getpwnam(buf))) { - path->del(0, p2 - p1 + 1); + path->del(0, (int)(p2 - p1 + 1)); path->insert(0, pw->pw_dir); } } @@ -488,7 +489,7 @@ GBool openTempFile(GString **name, FILE **f, *name = new GString("/tmp"); } (*name)->append("/XXXXXX")->append(ext); - fd = mkstemps((*name)->getCString(), strlen(ext)); + fd = mkstemps((*name)->getCString(), (int)strlen(ext)); #else if (!(s = tmpnam(NULL))) { return gFalse; @@ -522,7 +523,7 @@ GBool openTempFile(GString **name, FILE **f, return gTrue; #endif } -#endif +#endif /* !PDF_PARSER_ONLY */ GBool createDir(char *path, int mode) { #ifdef _WIN32 @@ -579,7 +580,7 @@ GString *fileNameToUTF8(wchar_t *path) { #endif FILE *openFile(const char *path, const char *mode) { -#ifdef _WIN32 +#if defined(_WIN32) return fopen(path, mode); #if 0 OSVERSIONINFO version; @@ -612,7 +613,7 @@ FILE *openFile(const char *path, const char *mode) { } } wPath[i] = (wchar_t)0; - for (i = 0; mode[i] && i < sizeof(mode) - 1; ++i) { + for (i = 0; mode[i] && i < sizeof(wMode) - 1; ++i) { wMode[i] = (wchar_t)(mode[i] & 0xff); } wMode[i] = (wchar_t)0; @@ -639,6 +640,8 @@ FILE *openFile(const char *path, const char *mode) { return fopen(nPath, mode); } #endif /* 0 */ +#elif defined(VMS) + return fopen(path, mode, "ctx=stm"); #else return fopen(path, mode); #endif @@ -696,3 +699,31 @@ GFileOffset gftell(FILE *f) { return ftell(f); #endif } + +#ifndef PDF_PARSER_ONLY +void fixCommandLine(int *argc, char **argv[]) { +#ifdef _WIN32 + int argcw; + wchar_t **argvw; + GString *arg; + int i; + + argvw = CommandLineToArgvW(GetCommandLineW(), &argcw); + if (!argvw || argcw < 0) { + return; + } + + *argc = argcw; + + *argv = (char **)gmallocn(argcw + 1, sizeof(char *)); + for (i = 0; i < argcw; ++i) { + arg = fileNameToUTF8(argvw[i]); + (*argv)[i] = copyString(arg->getCString()); + delete arg; + } + (*argv)[argcw] = NULL; + + LocalFree(argvw); +#endif +} +#endif /* !PDF_PARSER_ONLY */ diff --git a/Build/source/libs/xpdf/xpdf-src/goo/gfile.h b/Build/source/libs/xpdf/xpdf-src/goo/gfile.h index bf4322dbcbe..6bd870ecb90 100644 --- a/Build/source/libs/xpdf/xpdf-src/goo/gfile.h +++ b/Build/source/libs/xpdf/xpdf-src/goo/gfile.h @@ -112,4 +112,10 @@ extern int gfseek(FILE *f, GFileOffset offset, int whence); // Like ftell, but returns a 64-bit file offset if available. extern GFileOffset gftell(FILE *f); +// On Windows, this gets the Unicode command line and converts it to +// UTF-8. On other systems, this is a nop. +#ifndef PDF_PARSER_ONLY +extern void fixCommandLine(int *argc, char **argv[]); +#endif /* !PDF_PARSER_ONLY */ + #endif diff --git a/Build/source/libs/xpdf/xpdf-src/goo/gmem.cc b/Build/source/libs/xpdf/xpdf-src/goo/gmem.cc index c28d3e07fd6..7cf9581321f 100644 --- a/Build/source/libs/xpdf/xpdf-src/goo/gmem.cc +++ b/Build/source/libs/xpdf/xpdf-src/goo/gmem.cc @@ -10,6 +10,9 @@ #include <stdio.h> #include <stdlib.h> #include <stddef.h> +// older compilers won't define SIZE_MAX in stdint.h without this +#define __STDC_LIMIT_MACROS 1 +#include <stdint.h> #include <string.h> #include <limits.h> #if MULTITHREADED && defined(_WIN32) @@ -21,8 +24,8 @@ typedef struct _GMemHdr { unsigned int magic; - int size; int index; + size_t size; struct _GMemHdr *next, *prev; } GMemHdr; @@ -39,15 +42,18 @@ typedef struct _GMemHdr { /* round data size so trailer will be aligned */ #define gMemDataSize(size) \ - ((((size) + gMemTrlSize - 1) / gMemTrlSize) * gMemTrlSize) + (int)(((((size) + gMemTrlSize - 1) / gMemTrlSize) * gMemTrlSize)) + +#define gMemDataSize64(size) \ + (size_t)(((((size) + gMemTrlSize - 1) / gMemTrlSize) * gMemTrlSize)) static GMemHdr *gMemHead = NULL; static GMemHdr *gMemTail = NULL; static int gMemIndex = 0; static int gMemAlloc = 0; -static int gMemInUse = 0; -static int gMaxMemInUse = 0; +static size_t gMemInUse = 0; +static size_t gMaxMemInUse = 0; #if MULTITHREADED # ifdef _WIN32 @@ -161,7 +167,7 @@ void *grealloc(void *p, int size) GMEM_EXCEP { } if (p) { hdr = (GMemHdr *)((char *)p - gMemHdrSize); - oldSize = hdr->size; + oldSize = (int)hdr->size; q = gmalloc(size); memcpy(q, p, size < oldSize ? size : oldSize); gfree(p); @@ -206,6 +212,80 @@ void *gmallocn(int nObjs, int objSize) GMEM_EXCEP { return gmalloc(n); } +#ifdef DEBUG_MEM +void *gmalloc64(size_t size, int ignore) GMEM_EXCEP { + size_t size1; + char *mem; + GMemHdr *hdr; + void *data; + unsigned long *trl, *p; + + gMemInitMutex; + if (size == 0) { + return NULL; + } + size1 = gMemDataSize64(size); + if (!(mem = (char *)malloc(size1 + gMemHdrSize + gMemTrlSize))) { + gMemError("Out of memory"); + } + hdr = (GMemHdr *)mem; + data = (void *)(mem + gMemHdrSize); + trl = (unsigned long *)(mem + gMemHdrSize + size1); + hdr->magic = gMemMagic; + hdr->size = size; + if (ignore) { + hdr->index = -1; + } else { + hdr->index = gMemIndex++; + } + gMemLock; + if (gMemTail) { + gMemTail->next = hdr; + hdr->prev = gMemTail; + gMemTail = hdr; + } else { + hdr->prev = NULL; + gMemHead = gMemTail = hdr; + } + hdr->next = NULL; + ++gMemAlloc; + gMemInUse += size; + if (gMemInUse > gMaxMemInUse) { + gMaxMemInUse = gMemInUse; + } + gMemUnlock; + for (p = (unsigned long *)data; p <= trl; ++p) { + *p = gMemDeadVal; + } + return data; +} +#else +void *gmalloc64(size_t size) GMEM_EXCEP { + void *p; + + if (size == 0) { + return NULL; + } + if (!(p = malloc(size))) { + gMemError("Out of memory"); + } + return p; +} +#endif + +void *gmallocn64(int nObjs, size_t objSize) GMEM_EXCEP { + size_t n; + + if (nObjs == 0) { + return NULL; + } + n = nObjs * objSize; + if (nObjs < 0 || (size_t)nObjs >= SIZE_MAX / objSize) { + gMemError("Bogus memory allocation size"); + } + return gmalloc64(n); +} + void *greallocn(void *p, int nObjs, int objSize) GMEM_EXCEP { int n; @@ -224,7 +304,7 @@ void *greallocn(void *p, int nObjs, int objSize) GMEM_EXCEP { void gfree(void *p) { #ifdef DEBUG_MEM - int size; + size_t size; GMemHdr *hdr; unsigned long *trl, *clr; @@ -247,7 +327,7 @@ void gfree(void *p) { --gMemAlloc; gMemInUse -= hdr->size; gMemUnlock; - size = gMemDataSize(hdr->size); + size = gMemDataSize64(hdr->size); trl = (unsigned long *)((char *)hdr + gMemHdrSize + size); if (*trl != gMemDeadVal) { fprintf(stderr, "Overwrite past end of block %d at address %p\n", @@ -284,7 +364,7 @@ void gMemReport(FILE *f) { int left; fprintf(f, "%d memory allocations in all\n", gMemIndex); - fprintf(f, "maximum memory in use: %d bytes\n", gMaxMemInUse); + fprintf(f, "maximum memory in use: %zd bytes\n", gMaxMemInUse); left = 0; if (gMemAlloc > 0) { for (p = gMemHead; p; p = p->next) { @@ -295,7 +375,7 @@ void gMemReport(FILE *f) { fprintf(f, "-------- --------\n"); left = 1; } - fprintf(f, "%8d %8d\n", p->index, p->size); + fprintf(f, "%8d %8zd\n", p->index, p->size); } } } diff --git a/Build/source/libs/xpdf/xpdf-src/goo/gmem.h b/Build/source/libs/xpdf/xpdf-src/goo/gmem.h index e836e2dd6e8..e152199325b 100644 --- a/Build/source/libs/xpdf/xpdf-src/goo/gmem.h +++ b/Build/source/libs/xpdf/xpdf-src/goo/gmem.h @@ -58,6 +58,17 @@ extern void *gmallocn(int nObjs, int objSize) GMEM_EXCEP; extern void *greallocn(void *p, int nObjs, int objSize) GMEM_EXCEP; /* + * Same as gmalloc and gmallocn, but allow a 64-bit size on 64-bit + * systems. + */ +#ifdef DEBUG_MEM +extern void *gmalloc64(size_t size, int ignore = 0) GMEM_EXCEP; +#else +extern void *gmalloc64(size_t size) GMEM_EXCEP; +#endif +extern void *gmallocn64(int nObjs, size_t objSize) GMEM_EXCEP; + +/* * Same as free, but checks for and ignores NULL pointers. */ extern void gfree(void *p); |