diff options
author | Akira Kakuto <kakuto@fuk.kindai.ac.jp> | 2017-08-13 07:14:48 +0000 |
---|---|---|
committer | Akira Kakuto <kakuto@fuk.kindai.ac.jp> | 2017-08-13 07:14:48 +0000 |
commit | 4b4995cda35627e06c43e25ecbe07c1bc1859bb5 (patch) | |
tree | 143ed02a389bab62f44043a54cbc70f69e312e2f /Build/source/libs/xpdf/xpdf-src/goo | |
parent | 00d00899c484b81967558f43c4fe4a896ffdf610 (diff) |
xpdf 4.00
git-svn-id: svn://tug.org/texlive/trunk@45031 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/libs/xpdf/xpdf-src/goo')
-rw-r--r-- | Build/source/libs/xpdf/xpdf-src/goo/CMakeLists.txt | 27 | ||||
-rw-r--r-- | Build/source/libs/xpdf/xpdf-src/goo/FixedPoint.cc | 3 | ||||
-rw-r--r-- | Build/source/libs/xpdf/xpdf-src/goo/FixedPoint.h | 59 | ||||
-rw-r--r-- | Build/source/libs/xpdf/xpdf-src/goo/GHash.cc | 1 | ||||
-rw-r--r-- | Build/source/libs/xpdf/xpdf-src/goo/GList.cc | 1 | ||||
-rw-r--r-- | Build/source/libs/xpdf/xpdf-src/goo/GMutex.h | 55 | ||||
-rw-r--r-- | Build/source/libs/xpdf/xpdf-src/goo/GString.cc | 19 | ||||
-rw-r--r-- | Build/source/libs/xpdf/xpdf-src/goo/Makefile.dep | 0 | ||||
-rw-r--r-- | Build/source/libs/xpdf/xpdf-src/goo/Makefile.in | 71 | ||||
-rw-r--r-- | Build/source/libs/xpdf/xpdf-src/goo/gfile.cc | 216 | ||||
-rw-r--r-- | Build/source/libs/xpdf/xpdf-src/goo/gfile.h | 64 | ||||
-rw-r--r-- | Build/source/libs/xpdf/xpdf-src/goo/gmem.cc | 67 | ||||
-rw-r--r-- | Build/source/libs/xpdf/xpdf-src/goo/gmem.h | 4 | ||||
-rw-r--r-- | Build/source/libs/xpdf/xpdf-src/goo/gmempp.cc | 23 | ||||
-rw-r--r-- | Build/source/libs/xpdf/xpdf-src/goo/gmempp.h | 48 | ||||
-rw-r--r-- | Build/source/libs/xpdf/xpdf-src/goo/parseargs.c | 13 |
16 files changed, 276 insertions, 395 deletions
diff --git a/Build/source/libs/xpdf/xpdf-src/goo/CMakeLists.txt b/Build/source/libs/xpdf/xpdf-src/goo/CMakeLists.txt new file mode 100644 index 00000000000..7302dbbe08c --- /dev/null +++ b/Build/source/libs/xpdf/xpdf-src/goo/CMakeLists.txt @@ -0,0 +1,27 @@ +#======================================================================== +# +# goo/CMakeLists.txt +# +# CMake script for the goo library. +# +# Copyright 2015 Glyph & Cog, LLC +# +#======================================================================== + +include_directories("${PROJECT_SOURCE_DIR}") +include_directories("${PROJECT_BINARY_DIR}") + +add_library(goo_objs OBJECT + FixedPoint.cc + GHash.cc + GList.cc + GString.cc + gfile.cc + gmem.cc + gmempp.cc + parseargs.c +) + +add_library(goo + $<TARGET_OBJECTS:goo_objs> +) diff --git a/Build/source/libs/xpdf/xpdf-src/goo/FixedPoint.cc b/Build/source/libs/xpdf/xpdf-src/goo/FixedPoint.cc index 34661ad0f30..503a06aa9c7 100644 --- a/Build/source/libs/xpdf/xpdf-src/goo/FixedPoint.cc +++ b/Build/source/libs/xpdf/xpdf-src/goo/FixedPoint.cc @@ -16,6 +16,7 @@ #pragma implementation #endif +#include "gmempp.h" #include "FixedPoint.h" #define ln2 ((FixedPoint)0.69314718) @@ -113,7 +114,7 @@ GBool FixedPoint::divCheck(FixedPoint x, FixedPoint y, FixedPoint *result) { z >= ((FixPtInt64)1 << 31) || z < -((FixPtInt64)1 << 31)) { return gFalse; } - result->val = z; + result->val = (int)z; return gTrue; } diff --git a/Build/source/libs/xpdf/xpdf-src/goo/FixedPoint.h b/Build/source/libs/xpdf/xpdf-src/goo/FixedPoint.h index 1f4be7095d0..438343fc585 100644 --- a/Build/source/libs/xpdf/xpdf-src/goo/FixedPoint.h +++ b/Build/source/libs/xpdf/xpdf-src/goo/FixedPoint.h @@ -49,35 +49,35 @@ public: FixedPoint operator =(FixedPoint x) { val = x.val; return *this; } - int operator ==(FixedPoint x) const { return val == x.val; } - int operator ==(double x) const { return *this == (FixedPoint)x; } - int operator ==(int x) const { return *this == (FixedPoint)x; } - int operator ==(long x) const { return *this == (FixedPoint)x; } - - int operator !=(FixedPoint x) const { return val != x.val; } - int operator !=(double x) const { return *this != (FixedPoint)x; } - int operator !=(int x) const { return *this != (FixedPoint)x; } - int operator !=(long x) const { return *this != (FixedPoint)x; } - - int operator <(FixedPoint x) const { return val < x.val; } - int operator <(double x) const { return *this < (FixedPoint)x; } - int operator <(int x) const { return *this < (FixedPoint)x; } - int operator <(long x) const { return *this < (FixedPoint)x; } - - int operator <=(FixedPoint x) const { return val <= x.val; } - int operator <=(double x) const { return *this <= (FixedPoint)x; } - int operator <=(int x) const { return *this <= (FixedPoint)x; } - int operator <=(long x) const { return *this <= (FixedPoint)x; } - - int operator >(FixedPoint x) const { return val > x.val; } - int operator >(double x) const { return *this > (FixedPoint)x; } - int operator >(int x) const { return *this > (FixedPoint)x; } - int operator >(long x) const { return *this > (FixedPoint)x; } - - int operator >=(FixedPoint x) const { return val >= x.val; } - int operator >=(double x) const { return *this >= (FixedPoint)x; } - int operator >=(int x) const { return *this >= (FixedPoint)x; } - int operator >=(long x) const { return *this >= (FixedPoint)x; } + bool operator ==(FixedPoint x) const { return val == x.val; } + bool operator ==(double x) const { return *this == (FixedPoint)x; } + bool operator ==(int x) const { return *this == (FixedPoint)x; } + bool operator ==(long x) const { return *this == (FixedPoint)x; } + + bool operator !=(FixedPoint x) const { return val != x.val; } + bool operator !=(double x) const { return *this != (FixedPoint)x; } + bool operator !=(int x) const { return *this != (FixedPoint)x; } + bool operator !=(long x) const { return *this != (FixedPoint)x; } + + bool operator <(FixedPoint x) const { return val < x.val; } + bool operator <(double x) const { return *this < (FixedPoint)x; } + bool operator <(int x) const { return *this < (FixedPoint)x; } + bool operator <(long x) const { return *this < (FixedPoint)x; } + + bool operator <=(FixedPoint x) const { return val <= x.val; } + bool operator <=(double x) const { return *this <= (FixedPoint)x; } + bool operator <=(int x) const { return *this <= (FixedPoint)x; } + bool operator <=(long x) const { return *this <= (FixedPoint)x; } + + bool operator >(FixedPoint x) const { return val > x.val; } + bool operator >(double x) const { return *this > (FixedPoint)x; } + bool operator >(int x) const { return *this > (FixedPoint)x; } + bool operator >(long x) const { return *this > (FixedPoint)x; } + + bool operator >=(FixedPoint x) const { return val >= x.val; } + bool operator >=(double x) const { return *this >= (FixedPoint)x; } + bool operator >=(int x) const { return *this >= (FixedPoint)x; } + bool operator >=(long x) const { return *this >= (FixedPoint)x; } FixedPoint operator -() { return make(-val); } @@ -136,7 +136,6 @@ public: static FixedPoint avg(FixedPoint x, FixedPoint y) { return make((x.val >> 1) + (y.val >> 1) + ((x.val | y.val) & 1)); } - static FixedPoint sqrt(FixedPoint x); static FixedPoint pow(FixedPoint x, FixedPoint y); diff --git a/Build/source/libs/xpdf/xpdf-src/goo/GHash.cc b/Build/source/libs/xpdf/xpdf-src/goo/GHash.cc index 32e85b41dea..e6b32440fb9 100644 --- a/Build/source/libs/xpdf/xpdf-src/goo/GHash.cc +++ b/Build/source/libs/xpdf/xpdf-src/goo/GHash.cc @@ -13,6 +13,7 @@ #endif #include "gmem.h" +#include "gmempp.h" #include "GString.h" #include "GHash.h" diff --git a/Build/source/libs/xpdf/xpdf-src/goo/GList.cc b/Build/source/libs/xpdf/xpdf-src/goo/GList.cc index 5d9cba3787e..c194818a743 100644 --- a/Build/source/libs/xpdf/xpdf-src/goo/GList.cc +++ b/Build/source/libs/xpdf/xpdf-src/goo/GList.cc @@ -15,6 +15,7 @@ #include <stdlib.h> #include <string.h> #include "gmem.h" +#include "gmempp.h" #include "GList.h" //------------------------------------------------------------------------ diff --git a/Build/source/libs/xpdf/xpdf-src/goo/GMutex.h b/Build/source/libs/xpdf/xpdf-src/goo/GMutex.h index 5d5621af2ae..972e4da7f97 100644 --- a/Build/source/libs/xpdf/xpdf-src/goo/GMutex.h +++ b/Build/source/libs/xpdf/xpdf-src/goo/GMutex.h @@ -3,14 +3,26 @@ // GMutex.h // // Portable mutex macros. +// Portable atomic increment/decrement. // -// Copyright 2002-2003 Glyph & Cog, LLC +// Copyright 2002-2014 Glyph & Cog, LLC // //======================================================================== #ifndef GMUTEX_H #define GMUTEX_H +#ifdef _WIN32 +# include <windows.h> +# include <intrin.h> +#else +# include <pthread.h> +#endif + +//------------------------------------------------------------------------ +// GMutex +//------------------------------------------------------------------------ + // Usage: // // GMutex m; @@ -24,8 +36,6 @@ #ifdef _WIN32 -#include <windows.h> - typedef CRITICAL_SECTION GMutex; #define gInitMutex(m) InitializeCriticalSection(m) @@ -35,8 +45,6 @@ typedef CRITICAL_SECTION GMutex; #else // assume pthreads -#include <pthread.h> - typedef pthread_mutex_t GMutex; #define gInitMutex(m) pthread_mutex_init(m, NULL) @@ -46,4 +54,41 @@ typedef pthread_mutex_t GMutex; #endif +//------------------------------------------------------------------------ +// atomic increment/decrement +//------------------------------------------------------------------------ + +// NB: this must be "long" to work on Windows +typedef long GAtomicCounter; + +// Increment *counter by one and return the final value (after the +// increment). +static inline GAtomicCounter gAtomicIncrement(GAtomicCounter *counter) { + GAtomicCounter newVal; + +#if defined(_WIN32) + newVal = _InterlockedIncrement(counter); +#elif defined(__GNUC__) // this also works for LLVM/clang + newVal = __sync_add_and_fetch(counter, 1); +#else +# error "gAtomicIncrement is not defined for this compiler/platform" +#endif + return newVal; +} + +// Decrement *counter by one and return the final value (after the +// decrement). +static inline GAtomicCounter gAtomicDecrement(GAtomicCounter *counter) { + GAtomicCounter newVal; + +#if defined(_WIN32) + newVal = _InterlockedDecrement(counter); +#elif defined(__GNUC__) // this also works for LLVM/clang + newVal = __sync_sub_and_fetch(counter, 1); +#else +# error "gAtomicDecrement is not defined for this compiler/platform" #endif + return newVal; +} + +#endif // GMUTEX_H diff --git a/Build/source/libs/xpdf/xpdf-src/goo/GString.cc b/Build/source/libs/xpdf/xpdf-src/goo/GString.cc index adf7739c9aa..b56ed58ba16 100644 --- a/Build/source/libs/xpdf/xpdf-src/goo/GString.cc +++ b/Build/source/libs/xpdf/xpdf-src/goo/GString.cc @@ -21,6 +21,7 @@ #include <math.h> #include <limits.h> #include "gmem.h" +#include "gmempp.h" #include "GString.h" //------------------------------------------------------------------------ @@ -755,8 +756,9 @@ GString *GString::upperCase() { int i; for (i = 0; i < length; ++i) { - if (islower(s[i])) - s[i] = toupper(s[i]); + if (islower(s[i] & 0xff)) { + s[i] = toupper(s[i] & 0xff); + } } return this; } @@ -765,8 +767,9 @@ GString *GString::lowerCase() { int i; for (i = 0; i < length; ++i) { - if (isupper(s[i])) - s[i] = tolower(s[i]); + if (isupper(s[i] & 0xff)) { + s[i] = tolower(s[i] & 0xff); + } } return this; } @@ -778,7 +781,7 @@ int GString::cmp(GString *str) { n1 = length; n2 = str->length; for (i = 0, p1 = s, p2 = str->s; i < n1 && i < n2; ++i, ++p1, ++p2) { - x = *p1 - *p2; + x = (*p1 & 0xff) - (*p2 & 0xff); if (x != 0) { return x; } @@ -795,7 +798,7 @@ int GString::cmpN(GString *str, int n) { for (i = 0, p1 = s, p2 = str->s; i < n1 && i < n2 && i < n; ++i, ++p1, ++p2) { - x = *p1 - *p2; + x = (*p1 & 0xff) - (*p2 & 0xff); if (x != 0) { return x; } @@ -812,7 +815,7 @@ int GString::cmp(const char *sA) { n1 = length; for (i = 0, p1 = s, p2 = sA; i < n1 && *p2; ++i, ++p1, ++p2) { - x = *p1 - *p2; + x = (*p1 & 0xff) - (*p2 & 0xff); if (x != 0) { return x; } @@ -832,7 +835,7 @@ int GString::cmpN(const char *sA, int n) { n1 = length; for (i = 0, p1 = s, p2 = sA; i < n1 && *p2 && i < n; ++i, ++p1, ++p2) { - x = *p1 - *p2; + x = (*p1 & 0xff) - (*p2 & 0xff); if (x != 0) { return x; } diff --git a/Build/source/libs/xpdf/xpdf-src/goo/Makefile.dep b/Build/source/libs/xpdf/xpdf-src/goo/Makefile.dep deleted file mode 100644 index e69de29bb2d..00000000000 --- a/Build/source/libs/xpdf/xpdf-src/goo/Makefile.dep +++ /dev/null diff --git a/Build/source/libs/xpdf/xpdf-src/goo/Makefile.in b/Build/source/libs/xpdf/xpdf-src/goo/Makefile.in deleted file mode 100644 index f61d4030f60..00000000000 --- a/Build/source/libs/xpdf/xpdf-src/goo/Makefile.in +++ /dev/null @@ -1,71 +0,0 @@ -#======================================================================== -# -# Goo library Makefile -# -# Copyright 1996-2003 Glyph & Cog, LLC -# -#======================================================================== - -SHELL = /bin/sh - -srcdir = @srcdir@ -VPATH = @srcdir@ - -CFLAGS = @CFLAGS@ @DEFS@ -I.. -I$(srcdir)/.. -I$(srcdir) -CXXFLAGS = @CXXFLAGS@ @DEFS@ -I.. -I$(srcdir)/.. -I$(srcdir) - -CC = @CC@ -CXX = @CXX@ -AR = @AR@ -RANLIB = @RANLIB@ - -LIBPREFIX = @LIBPREFIX@ - -#------------------------------------------------------------------------ - -.SUFFIXES: .cc - -.cc.o: - $(CXX) $(CXXFLAGS) -c $< - -#------------------------------------------------------------------------ - -CXX_SRC = \ - $(srcdir)/GHash.cc \ - $(srcdir)/GList.cc \ - $(srcdir)/GString.cc \ - $(srcdir)/gmem.cc \ - $(srcdir)/gmempp.cc \ - $(srcdir)/gfile.cc \ - $(srcdir)/FixedPoint.cc - -C_SRC = \ - $(srcdir)/parseargs.c - -#------------------------------------------------------------------------ - -all: $(LIBPREFIX)Goo.a - -#------------------------------------------------------------------------ - -GOO_CXX_OBJS = GHash.o GList.o GString.o gmem.o gmempp.o gfile.o FixedPoint.o -GOO_C_OBJS = parseargs.o -GOO_OBJS = $(GOO_CXX_OBJS) $(GOO_C_OBJS) - -$(LIBPREFIX)Goo.a: $(GOO_OBJS) - rm -f $(LIBPREFIX)Goo.a - $(AR) $(LIBPREFIX)Goo.a $(GOO_OBJS) - $(RANLIB) $(LIBPREFIX)Goo.a - -#------------------------------------------------------------------------ - -clean: - rm -f $(GOO_OBJS) $(LIBPREFIX)Goo.a - -#------------------------------------------------------------------------ - -depend: - $(CXX) $(CXXFLAGS) -MM $(CXX_SRC) >Makefile.dep - $(CC) $(CFLAGS) -MM $(C_SRC) >>Makefile.dep - --include Makefile.dep diff --git a/Build/source/libs/xpdf/xpdf-src/goo/gfile.cc b/Build/source/libs/xpdf/xpdf-src/goo/gfile.cc index 777870df71b..f51dbe36100 100644 --- a/Build/source/libs/xpdf/xpdf-src/goo/gfile.cc +++ b/Build/source/libs/xpdf/xpdf-src/goo/gfile.cc @@ -17,9 +17,7 @@ # include <time.h> # include <direct.h> #else -# if defined(MACOS) -# include <sys/stat.h> -# elif !defined(ACORN) +# if !defined(ACORN) # include <sys/types.h> # include <sys/stat.h> # include <fcntl.h> @@ -27,13 +25,14 @@ # include <time.h> # include <limits.h> # include <string.h> -# if !defined(VMS) && !defined(ACORN) && !defined(MACOS) +# if !defined(VMS) && !defined(ACORN) # include <pwd.h> # endif # if defined(VMS) && (__DECCXX_VER < 50200000) # include <unixlib.h> # endif #endif // _WIN32 +#include "gmempp.h" #include "GString.h" #include "gfile.h" @@ -69,10 +68,6 @@ GString *getHomeDir() { //---------- RISCOS ---------- return new GString("@"); -#elif defined(MACOS) - //---------- MacOS ---------- - return new GString(":"); - #else //---------- Unix ---------- char *s; @@ -104,8 +99,6 @@ GString *getCurrentDir() { if (GetCurrentDirectoryA(sizeof(buf), buf)) #elif defined(ACORN) if (strcpy(buf, "@")) -#elif defined(MACOS) - if (strcpy(buf, ":")) #else if (getcwd(buf, sizeof(buf))) #endif @@ -186,23 +179,6 @@ GString *appendToPath(GString *path, const char *fileName) { } return path; -#elif defined(MACOS) - //---------- MacOS ---------- - char *p; - int i; - - path->append(":"); - i = path->getLength(); - path->append(fileName); - for (p = path->getCString() + i; *p; ++p) { - if (*p == '/') { - *p = ':'; - } else if (*p == '.') { - *p = ':'; - } - } - return path; - #elif defined(__EMX__) //---------- OS/2+EMX ---------- int i; @@ -310,14 +286,6 @@ GString *grabPath(char *fileName) { return new GString(fileName, p - fileName); return new GString(); -#elif defined(MACOS) - //---------- MacOS ---------- - char *p; - - if ((p = strrchr(fileName, ':'))) - return new GString(fileName, p - fileName); - return new GString(); - #else //---------- Unix ---------- char *p; @@ -342,10 +310,6 @@ GBool isAbsolutePath(char *path) { //---------- RISCOS ---------- return path[0] == '$'; -#elif defined(MACOS) - //---------- MacOS ---------- - return path[0] != ':'; - #else //---------- Unix ---------- return path[0] == '/'; @@ -383,11 +347,6 @@ GString *makePathAbsolute(GString *path) { path->insert(0, '@'); return path; -#elif defined(MACOS) - //---------- MacOS ---------- - path->del(0, 1); - return path; - #else //---------- Unix and OS/2+EMX ---------- struct passwd *pw; @@ -453,25 +412,29 @@ GBool openTempFile(GString **name, FILE **f, const char *mode, const char *ext) { #if defined(_WIN32) //---------- Win32 ---------- - char *tempDir; + char tempPath[MAX_PATH + 1]; GString *s, *s2; FILE *f2; + DWORD n; int t, i; // this has the standard race condition problem, but I haven't found // a better way to generate temp file names with extensions on // Windows - if ((tempDir = getenv("TEMP"))) { - s = new GString(tempDir); - s->append('\\'); + n = GetTempPathA(sizeof(tempPath), tempPath); + if (n > 0 && n <= sizeof(tempPath)) { + s = new GString(tempPath); + if (tempPath[n-1] != '\\') { + s->append('\\'); + } } else { - s = new GString(); + s = new GString(".\\"); } - s->appendf("x_{0:d}_{1:d}_", + s->appendf("xpdf_{0:d}_{1:d}_", (int)GetCurrentProcessId(), (int)GetCurrentThreadId()); t = (int)time(NULL); for (i = 0; i < 1000; ++i) { - s2 = s->copy()->appendf("{0:d}", t + i); + s2 = GString::format("{0:t}{1:d}", s, t + i); if (ext) { s2->append(ext); } @@ -491,7 +454,7 @@ GBool openTempFile(GString **name, FILE **f, } delete s; return gFalse; -#elif defined(VMS) || defined(__EMX__) || defined(ACORN) || defined(MACOS) +#elif defined(VMS) || defined(__EMX__) || defined(ACORN) //---------- non-Unix ---------- char *s; @@ -730,152 +693,3 @@ GFileOffset gftell(FILE *f) { return ftell(f); #endif } - -//------------------------------------------------------------------------ -// GDir and GDirEntry -//------------------------------------------------------------------------ - -GDirEntry::GDirEntry(char *dirPath, char *nameA, GBool doStat) { -#ifdef VMS - char *p; -#elif defined(_WIN32) - int fa; - GString *s; -#elif defined(ACORN) -#else - struct stat st; - GString *s; -#endif - - name = new GString(nameA); - dir = gFalse; - if (doStat) { -#ifdef VMS - if (!strcmp(nameA, "-") || - ((p = strrchr(nameA, '.')) && !strncmp(p, ".DIR;", 5))) - dir = gTrue; -#elif defined(ACORN) -#else - s = new GString(dirPath); - appendToPath(s, nameA); -#ifdef _WIN32 - fa = GetFileAttributesA(s->getCString()); - dir = (fa != 0xFFFFFFFF && (fa & FILE_ATTRIBUTE_DIRECTORY)); -#else - if (stat(s->getCString(), &st) == 0) - dir = S_ISDIR(st.st_mode); -#endif - delete s; -#endif - } -} - -GDirEntry::~GDirEntry() { - delete name; -} - -GDir::GDir(char *name, GBool doStatA) { - path = new GString(name); - doStat = doStatA; -#if defined(_WIN32) - GString *tmp; - - tmp = path->copy(); - tmp->append("/*.*"); - hnd = FindFirstFileA(tmp->getCString(), &ffd); - delete tmp; -#elif defined(ACORN) -#elif defined(MACOS) -#elif defined(ANDROID) -#else - dir = opendir(name); -#ifdef VMS - needParent = strchr(name, '[') != NULL; -#endif -#endif -} - -GDir::~GDir() { - delete path; -#if defined(_WIN32) - if (hnd) { - FindClose(hnd); - hnd = NULL; - } -#elif defined(ACORN) -#elif defined(MACOS) -#elif defined(ANDROID) -#else - if (dir) - closedir(dir); -#endif -} - -GDirEntry *GDir::getNextEntry() { - GDirEntry *e; - -#if defined(_WIN32) - if (hnd) { - e = new GDirEntry(path->getCString(), ffd.cFileName, doStat); - if (hnd && !FindNextFileA(hnd, &ffd)) { - FindClose(hnd); - hnd = NULL; - } - } else { - e = NULL; - } -#elif defined(ACORN) -#elif defined(MACOS) -#elif defined(ANDROID) -#elif defined(VMS) - struct dirent *ent; - e = NULL; - if (dir) { - if (needParent) { - e = new GDirEntry(path->getCString(), "-", doStat); - needParent = gFalse; - return e; - } - ent = readdir(dir); - if (ent) { - e = new GDirEntry(path->getCString(), ent->d_name, doStat); - } - } -#else - struct dirent *ent; - e = NULL; - if (dir) { - ent = (struct dirent *)readdir(dir); - if (ent && !strcmp(ent->d_name, ".")) { - ent = (struct dirent *)readdir(dir); - } - if (ent) { - e = new GDirEntry(path->getCString(), ent->d_name, doStat); - } - } -#endif - - return e; -} - -void GDir::rewind() { -#ifdef _WIN32 - GString *tmp; - - if (hnd) - FindClose(hnd); - tmp = path->copy(); - tmp->append("/*.*"); - hnd = FindFirstFileA(tmp->getCString(), &ffd); - delete tmp; -#elif defined(ACORN) -#elif defined(MACOS) -#elif defined(ANDROID) -#else - if (dir) - rewinddir(dir); -#ifdef VMS - needParent = strchr(path->getCString(), '[') != NULL; -#endif -#endif -} diff --git a/Build/source/libs/xpdf/xpdf-src/goo/gfile.h b/Build/source/libs/xpdf/xpdf-src/goo/gfile.h index 5b171e62089..bf4322dbcbe 100644 --- a/Build/source/libs/xpdf/xpdf-src/goo/gfile.h +++ b/Build/source/libs/xpdf/xpdf-src/goo/gfile.h @@ -22,30 +22,10 @@ # include <windows.h> # endif #elif defined(ACORN) -#elif defined(MACOS) -# include <ctime.h> #elif defined(ANDROID) #else # include <unistd.h> # include <sys/types.h> -# ifdef VMS -# include "vms_dirent.h" -# elif HAVE_DIRENT_H -# include <dirent.h> -# define NAMLEN(d) strlen((d)->d_name) -# else -# define dirent direct -# define NAMLEN(d) (d)->d_namlen -# if HAVE_SYS_NDIR_H -# include <sys/ndir.h> -# endif -# if HAVE_SYS_DIR_H -# include <sys/dir.h> -# endif -# if HAVE_NDIR_H -# include <ndir.h> -# endif -# endif #endif #include "gtypes.h" @@ -132,48 +112,4 @@ 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); -//------------------------------------------------------------------------ -// GDir and GDirEntry -//------------------------------------------------------------------------ - -class GDirEntry { -public: - - GDirEntry(char *dirPath, char *nameA, GBool doStat); - ~GDirEntry(); - GString *getName() { return name; } - GBool isDir() { return dir; } - -private: - - GString *name; // dir/file name - GBool dir; // is it a directory? -}; - -class GDir { -public: - - GDir(char *name, GBool doStatA = gTrue); - ~GDir(); - GDirEntry *getNextEntry(); - void rewind(); - -private: - - GString *path; // directory path - GBool doStat; // call stat() for each entry? -#if defined(_WIN32) - WIN32_FIND_DATAA ffd; - HANDLE hnd; -#elif defined(ACORN) -#elif defined(MACOS) -#elif defined(ANDROID) -#else - DIR *dir; // the DIR structure from opendir() -#ifdef VMS - GBool needParent; // need to return an entry for [-] -#endif -#endif -}; - #endif diff --git a/Build/source/libs/xpdf/xpdf-src/goo/gmem.cc b/Build/source/libs/xpdf/xpdf-src/goo/gmem.cc index 6fd51364071..c28d3e07fd6 100644 --- a/Build/source/libs/xpdf/xpdf-src/goo/gmem.cc +++ b/Build/source/libs/xpdf/xpdf-src/goo/gmem.cc @@ -12,6 +12,9 @@ #include <stddef.h> #include <string.h> #include <limits.h> +#if MULTITHREADED && defined(_WIN32) +# include <windows.h> +#endif #include "gmem.h" #ifdef DEBUG_MEM @@ -28,7 +31,7 @@ typedef struct _GMemHdr { #define gMemMagic 0xabcd9999 -#if gmemTrlSize==8 +#if ULONG_MAX > 0xffffffffL #define gMemDeadVal 0xdeadbeefdeadbeefUL #else #define gMemDeadVal 0xdeadbeefUL @@ -46,16 +49,43 @@ static int gMemAlloc = 0; static int gMemInUse = 0; static int gMaxMemInUse = 0; +#if MULTITHREADED +# ifdef _WIN32 + static CRITICAL_SECTION gMemMutex; + static INIT_ONCE gMemMutexInitStruct = INIT_ONCE_STATIC_INIT; + static BOOL CALLBACK gMemMutexInitFunc(PINIT_ONCE initOnce, PVOID param, + PVOID *context) { + InitializeCriticalSection(&gMemMutex); + return TRUE; + } +# define gMemInitMutex InitOnceExecuteOnce(&gMemMutexInitStruct, \ + &gMemMutexInitFunc, NULL, NULL) +# define gMemLock EnterCriticalSection(&gMemMutex); +# define gMemUnlock LeaveCriticalSection(&gMemMutex); +# else +# include <pthread.h> + static pthread_mutex_t gMemMutex = PTHREAD_MUTEX_INITIALIZER; +# define gMemInitMutex +# define gMemLock pthread_mutex_lock(&gMemMutex) +# define gMemUnlock pthread_mutex_unlock(&gMemMutex) +# endif +#else +# define gMemInitMutex +# define gMemLock +# define gMemUnlock +#endif + #endif /* DEBUG_MEM */ -void *gmalloc(int size) GMEM_EXCEP { #ifdef DEBUG_MEM +void *gmalloc(int size, int ignore) GMEM_EXCEP { int size1; char *mem; GMemHdr *hdr; void *data; unsigned long *trl, *p; + gMemInitMutex; if (size < 0) { gMemError("Invalid memory allocation size"); } @@ -71,7 +101,12 @@ void *gmalloc(int size) GMEM_EXCEP { trl = (unsigned long *)(mem + gMemHdrSize + size1); hdr->magic = gMemMagic; hdr->size = size; - hdr->index = gMemIndex++; + if (ignore) { + hdr->index = -1; + } else { + hdr->index = gMemIndex++; + } + gMemLock; if (gMemTail) { gMemTail->next = hdr; hdr->prev = gMemTail; @@ -86,11 +121,14 @@ void *gmalloc(int size) GMEM_EXCEP { if (gMemInUse > gMaxMemInUse) { gMaxMemInUse = gMemInUse; } + gMemUnlock; for (p = (unsigned long *)data; p <= trl; ++p) { *p = gMemDeadVal; } return data; +} #else +void *gmalloc(int size) GMEM_EXCEP { void *p; if (size < 0) { @@ -103,8 +141,8 @@ void *gmalloc(int size) GMEM_EXCEP { gMemError("Out of memory"); } return p; -#endif } +#endif void *grealloc(void *p, int size) GMEM_EXCEP { #ifdef DEBUG_MEM @@ -192,6 +230,7 @@ void gfree(void *p) { if (p) { hdr = (GMemHdr *)((char *)p - gMemHdrSize); + gMemLock; if (hdr->magic == gMemMagic && ((hdr->prev == NULL) == (hdr == gMemHead)) && ((hdr->next == NULL) == (hdr == gMemTail))) { @@ -207,6 +246,7 @@ void gfree(void *p) { } --gMemAlloc; gMemInUse -= hdr->size; + gMemUnlock; size = gMemDataSize(hdr->size); trl = (unsigned long *)((char *)hdr + gMemHdrSize + size); if (*trl != gMemDeadVal) { @@ -218,6 +258,7 @@ void gfree(void *p) { } free(hdr); } else { + gMemUnlock; fprintf(stderr, "Attempted to free bad address %p\n", p); } } @@ -240,17 +281,25 @@ void gMemError(const char *msg) GMEM_EXCEP { #ifdef DEBUG_MEM void gMemReport(FILE *f) { GMemHdr *p; + int left; fprintf(f, "%d memory allocations in all\n", gMemIndex); fprintf(f, "maximum memory in use: %d bytes\n", gMaxMemInUse); + left = 0; if (gMemAlloc > 0) { - fprintf(f, "%d memory blocks left allocated:\n", gMemAlloc); - fprintf(f, " index size\n"); - fprintf(f, "-------- --------\n"); for (p = gMemHead; p; p = p->next) { - fprintf(f, "%8d %8d\n", p->index, p->size); + if (p->index >= 0) { + if (!left) { + fprintf(f, "%d memory blocks left allocated:\n", gMemAlloc); + fprintf(f, " index size\n"); + fprintf(f, "-------- --------\n"); + left = 1; + } + fprintf(f, "%8d %8d\n", p->index, p->size); + } } - } else { + } + if (!left) { fprintf(f, "No memory blocks left allocated\n"); } } diff --git a/Build/source/libs/xpdf/xpdf-src/goo/gmem.h b/Build/source/libs/xpdf/xpdf-src/goo/gmem.h index bfa9658e451..e836e2dd6e8 100644 --- a/Build/source/libs/xpdf/xpdf-src/goo/gmem.h +++ b/Build/source/libs/xpdf/xpdf-src/goo/gmem.h @@ -36,7 +36,11 @@ extern "C" { * Same as malloc, but prints error message and exits if malloc() * returns NULL. */ +#ifdef DEBUG_MEM +extern void *gmalloc(int size, int ignore = 0) GMEM_EXCEP; +#else extern void *gmalloc(int size) GMEM_EXCEP; +#endif /* * Same as realloc, but prints error message and exits if realloc() diff --git a/Build/source/libs/xpdf/xpdf-src/goo/gmempp.cc b/Build/source/libs/xpdf/xpdf-src/goo/gmempp.cc index b1ee970d38a..fe5790b1f58 100644 --- a/Build/source/libs/xpdf/xpdf-src/goo/gmempp.cc +++ b/Build/source/libs/xpdf/xpdf-src/goo/gmempp.cc @@ -10,23 +10,42 @@ #include <aconf.h> #include "gmem.h" +// NB: do not include gmempp.h here. #ifdef DEBUG_MEM void *operator new(size_t size) { - return gmalloc((int)size); + return gmalloc((int)size, 1); +} + +void *operator new(size_t size, int dummy) { + return gmalloc((int)size, 0); } void *operator new[](size_t size) { - return gmalloc((int)size); + return gmalloc((int)size, 1); +} + +void *operator new[](size_t size, int dummy) { + return gmalloc((int)size, 0); } void operator delete(void *p) { gfree(p); } +// This is only called if a constructor throws an exception. +void operator delete(void *p, int dummy) { + gfree(p); +} + void operator delete[](void *p) { gfree(p); } +// This is only called if a constructor throws an exception. +void operator delete[](void *p, int dummy) { + gfree(p); +} + #endif diff --git a/Build/source/libs/xpdf/xpdf-src/goo/gmempp.h b/Build/source/libs/xpdf/xpdf-src/goo/gmempp.h new file mode 100644 index 00000000000..27f7fe786c5 --- /dev/null +++ b/Build/source/libs/xpdf/xpdf-src/goo/gmempp.h @@ -0,0 +1,48 @@ +//======================================================================== +// +// gmempp.h +// +// Redefine the new and delete operators to call the debugging malloc. +// +// This is a hack: some libraries (Qt) allocate global objects and +// never free them, so this file #define's new to have an argument, so +// that we can differentiate our new calls from external library new +// calls. Calls from external libraries will not be counted when +// un-freed memory is listed. There's no guarantee that this will +// work in all cases: if some external library also defines a new +// operator that takes the same extra argument, things will break +// horribly. +// +// This entire .h file is wrapped in '#ifdef DEBUG_MEM'. I.e., if you +// don't define DEBUG_MEM, this hack goes away and can't cause any +// problems. Do not define DEBUG_MEM in production code. +// +// To use this .h file, it must be #included *after* all system +// includes. Calls to new in any modules that do not include this .h +// file will not be counted as un-freed memory. +// +//======================================================================== + +#ifndef GMEMPP_H +#define GMEMPP_H + +#ifdef DEBUG_MEM + +#include <stdlib.h> + +extern void *operator new(size_t size, int dummy); +extern void *operator new[](size_t size, int dummy); + +// These have to be defined (and declared) to avoid a compiler warning +// with Visual Studio. +extern void operator delete(void *p, int dummy); +extern void operator delete[](void *p, int dummy); + +// This transforms 'new Foo(...)' into 'new (1) Foo(...)', which +// forces a call to the operator new variant with the 'int dummy' arg. +#define debug_new new (1) +#define new debug_new + +#endif // DEBUG_MEM + +#endif // GMEMPP_H diff --git a/Build/source/libs/xpdf/xpdf-src/goo/parseargs.c b/Build/source/libs/xpdf/xpdf-src/goo/parseargs.c index fdefa6c3351..2f5844f06d4 100644 --- a/Build/source/libs/xpdf/xpdf-src/goo/parseargs.c +++ b/Build/source/libs/xpdf/xpdf-src/goo/parseargs.c @@ -26,14 +26,19 @@ GBool parseArgs(ArgDesc *args, int *argc, char *argv[]) { while (i < *argc) { if (!strcmp(argv[i], "--")) { --*argc; - for (j = i; j < *argc; ++j) + for (j = i; j < *argc; ++j) { argv[j] = argv[j+1]; + } break; } else if ((arg = findArg(args, argv[i]))) { - if (!grabArg(arg, i, argc, argv)) + if (!grabArg(arg, i, argc, argv)) { ok = gFalse; + } + } else if (argv[i][0] == '-') { + ok = gFalse; + break; } else { - ++i; + break; } } return ok; @@ -65,7 +70,7 @@ void printUsage(const char *program, const char *otherArgs, ArgDesc *args) { break; case argFP: case argFPDummy: - typ = " <fp>"; + typ = " <number>"; break; case argString: case argStringDummy: |