diff options
Diffstat (limited to 'fitz')
-rw-r--r-- | fitz/Jamfile | 3 | ||||
-rw-r--r-- | fitz/base_cleanname.c | 52 | ||||
-rw-r--r-- | fitz/base_memory.c | 66 | ||||
-rw-r--r-- | fitz/base_unicode.c (renamed from fitz/base_rune.c) | 0 | ||||
-rw-r--r-- | fitz/filt_flate.c | 14 | ||||
-rw-r--r-- | fitz/fitz_base.h | 22 |
6 files changed, 24 insertions, 133 deletions
diff --git a/fitz/Jamfile b/fitz/Jamfile index 61f2583d..c0d0fb2d 100644 --- a/fitz/Jamfile +++ b/fitz/Jamfile @@ -16,9 +16,8 @@ Library libfitz : base_matrix.c base_memory.c base_rect.c - base_rune.c base_string.c - base_cleanname.c + base_unicode.c ; if $(NEED_GETOPT) { Library libfitz : util_getopt.c ; } diff --git a/fitz/base_cleanname.c b/fitz/base_cleanname.c deleted file mode 100644 index 54764630..00000000 --- a/fitz/base_cleanname.c +++ /dev/null @@ -1,52 +0,0 @@ -/* - * In place, rewrite name to compress multiple /, eliminate ., and process .. - */ - -#define SEP(x) ((x)=='/' || (x) == 0) - -char * -cleanname(char *name) -{ - char *p, *q, *dotdot; - int rooted; - - rooted = name[0] == '/'; - - /* - * invariants: - * p points at beginning of path element we're considering. - * q points just past the last path element we wrote (no slash). - * dotdot points just past the point where .. cannot backtrack - * any further (no slash). - */ - p = q = dotdot = name+rooted; - while(*p) { - if(p[0] == '/') /* null element */ - p++; - else if(p[0] == '.' && SEP(p[1])) - p += 1; /* don't count the separator in case it is nul */ - else if(p[0] == '.' && p[1] == '.' && SEP(p[2])) { - p += 2; - if(q > dotdot) { /* can backtrack */ - while(--q > dotdot && *q != '/') - ; - } else if(!rooted) { /* /.. is / but ./../ is .. */ - if(q != name) - *q++ = '/'; - *q++ = '.'; - *q++ = '.'; - dotdot = q; - } - } else { /* real path element */ - if(q != name+rooted) - *q++ = '/'; - while((*q = *p) != '/' && *q != 0) - p++, q++; - } - } - if(q == name) /* empty string is really ``.'' */ - *q++ = '.'; - *q = '\0'; - return name; -} - diff --git a/fitz/base_memory.c b/fitz/base_memory.c index cd6de8cb..21effdc1 100644 --- a/fitz/base_memory.c +++ b/fitz/base_memory.c @@ -1,71 +1,31 @@ #include "fitz_base.h" -/* Make this thread local storage if you wish. */ - -static void *stdmalloc(fz_memorycontext *mem, int n) -{ - return malloc(n); -} - -static void *stdrealloc(fz_memorycontext *mem, void *p, int n) -{ - return realloc(p, n); -} - -static void stdfree(fz_memorycontext *mem, void *p) -{ - free(p); -} - -static fz_memorycontext defmem = { stdmalloc, stdrealloc, stdfree }; -static fz_memorycontext *curmem = &defmem; - -fz_memorycontext * -fz_currentmemorycontext() -{ - return curmem; -} - -void -fz_setmemorycontext(fz_memorycontext *mem) -{ - curmem = mem; -} - -void * -fz_malloc(int n) +void * fz_malloc(int n) { - fz_memorycontext *mem = fz_currentmemorycontext(); - void *p = mem->malloc(mem, n); + void *p = malloc(n); if (!p) - fz_warn("cannot malloc %d bytes", n); + fz_throw("cannot malloc %d bytes", n); return p; } -void * -fz_realloc(void *p, int n) +void * fz_realloc(void *p, int n) { - fz_memorycontext *mem = fz_currentmemorycontext(); - void *np = mem->realloc(mem, p, n); + void *np = realloc(p, n); if (np == nil) - fz_warn("cannot realloc %d bytes", n); + fz_throw("cannot realloc %d bytes", n); return np; } -void -fz_free(void *p) +void fz_free(void *p) { - fz_memorycontext *mem = fz_currentmemorycontext(); - mem->free(mem, p); + free(p); } -char * -fz_strdup(char *s) +char * fz_strdup(char *s) { - int len = strlen(s); - char *ns = fz_malloc(len + 1); - if (ns) - strcpy(ns, s); - return ns; + char *ns = strdup(s); + if (!ns) + fz_throw("cannot strdup %d bytes", strlen(s) + 1); + return ns; } diff --git a/fitz/base_rune.c b/fitz/base_unicode.c index 32168792..32168792 100644 --- a/fitz/base_rune.c +++ b/fitz/base_unicode.c diff --git a/fitz/filt_flate.c b/fitz/filt_flate.c index 73105800..65a84711 100644 --- a/fitz/filt_flate.c +++ b/fitz/filt_flate.c @@ -17,6 +17,12 @@ zmalloc(void *opaque, unsigned int items, unsigned int size) return fz_malloc(items * size); } +static void +zfree(void *opaque, void *ptr) +{ + fz_free(ptr); +} + fz_error fz_newflated(fz_filter **fp, fz_obj *params) { @@ -28,8 +34,8 @@ fz_newflated(fz_filter **fp, fz_obj *params) FZ_NEWFILTER(fz_flate, f, flated); f->z.zalloc = zmalloc; - f->z.zfree = (void(*)(void*,void*))fz_currentmemorycontext()->free; - f->z.opaque = fz_currentmemorycontext(); + f->z.zfree = zfree; + f->z.opaque = nil; f->z.next_in = nil; f->z.avail_in = 0; @@ -133,8 +139,8 @@ fz_newflatee(fz_filter **fp, fz_obj *params) } f->z.zalloc = zmalloc; - f->z.zfree = (void(*)(void*,void*))fz_currentmemorycontext()->free; - f->z.opaque = fz_currentmemorycontext(); + f->z.zfree = zfree; + f->z.opaque = nil; f->z.next_in = nil; f->z.avail_in = 0; diff --git a/fitz/fitz_base.h b/fitz/fitz_base.h index 211ed8dc..6bee3ecb 100644 --- a/fitz/fitz_base.h +++ b/fitz/fitz_base.h @@ -173,12 +173,9 @@ int runetochar(char *str, int *rune); int runelen(long c); int runenlen(int *r, int nrune); int fullrune(char *str, int n); -char *cleanname(char *name); typedef int fz_error; -#define fz_outofmem ((fz_error)-1) - #define fz_throw(...) fz_throwimp(__func__, __FILE__, __LINE__, __VA_ARGS__) #define fz_rethrow(cause, ...) fz_rethrowimp(cause, __func__, __FILE__, __LINE__, __VA_ARGS__) #define fz_catch(cause, ...) fz_catchimp(cause, __func__, __FILE__, __LINE__, __VA_ARGS__) @@ -189,22 +186,9 @@ fz_error fz_throwimp(const char *func, const char *file, int line, char *fmt, .. fz_error fz_rethrowimp(fz_error cause, const char *func, const char *file, int line, char *fmt, ...) __printflike(5, 6); fz_error fz_catchimp(fz_error cause, const char *func, const char *file, int line, char *fmt, ...) __printflike(5, 6); -typedef struct fz_memorycontext_s fz_memorycontext; - -struct fz_memorycontext_s -{ - void * (*malloc)(fz_memorycontext *, int); - void * (*realloc)(fz_memorycontext *, void *, int); - void (*free)(fz_memorycontext *, void *); -}; - -fz_memorycontext *fz_currentmemorycontext(void); -void fz_setmemorycontext(fz_memorycontext *memorycontext); - void *fz_malloc(int n); void *fz_realloc(void *p, int n); void fz_free(void *p); - char *fz_strdup(char *s); /* @@ -232,12 +216,6 @@ void *fz_hashgetval(fz_hashtable *table, int idx); #define fz_floor(x) floor(x) #define fz_ceil(x) ceil(x) -/* divide and floor towards -inf */ -static inline int fz_idiv(int a, int b) -{ - return a < 0 ? (a - b + 1) / b : a / b; -} - typedef struct fz_matrix_s fz_matrix; typedef struct fz_point_s fz_point; typedef struct fz_rect_s fz_rect; |