Minor cleanup

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@16 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Dave Beazley 1999-08-16 22:50:10 +00:00
commit c070fbcad8
5 changed files with 30 additions and 16 deletions

View file

@ -9,8 +9,8 @@
# Set your C++ compiler here. g++ works on most machines, # Set your C++ compiler here. g++ works on most machines,
# but you might have to change it depending on your installation. # but you might have to change it depending on your installation.
# #
CC = cc CC = cc -g
prefix = /usr/sandbox prefix = /usr/local
# Comment out the following line if you're on an SGI or don't have ranlib! # Comment out the following line if you're on an SGI or don't have ranlib!
RANLIB = ranlib RANLIB = ranlib

View file

@ -23,12 +23,12 @@
#include "doh.h" #include "doh.h"
static int debug_level = 0; int doh_debug_level = 0;
void DohError(int level, char *fmt, ...) { void DohError(int level, char *fmt, ...) {
va_list ap; va_list ap;
va_start(ap,fmt); va_start(ap,fmt);
if (level <= debug_level) { if (level <= doh_debug_level) {
printf("DOH %d:",level); printf("DOH %d:",level);
vprintf(fmt,ap); vprintf(fmt,ap);
} }
@ -36,7 +36,7 @@ void DohError(int level, char *fmt, ...) {
} }
void DohDebug(int d) { void DohDebug(int d) {
debug_level = d; doh_debug_level = d;
} }
static DohObjInfo DohBaseType = { static DohObjInfo DohBaseType = {
@ -86,7 +86,7 @@ static DOH *find_internal(DOH *co) {
char *c; char *c;
if (DohCheck(co)) return co; if (DohCheck(co)) return co;
c = (char *) co; c = (char *) co;
if (debug_level) { if (doh_debug_level) {
DohError(DOH_CONVERSION,"Unknown object %x being treated as 'char *'.\n", c); DohError(DOH_CONVERSION,"Unknown object %x being treated as 'char *'.\n", c);
} }
r = root; r = root;
@ -121,12 +121,19 @@ void DohDestroy(DOH *obj) {
if (!DohCheck(b)) return; if (!DohCheck(b)) return;
b->refcount--; b->refcount--;
if (b->refcount <= 0) { if (b->refcount <= 0) {
if (doh_debug_level >= DOH_MEMORY) {
if (DohFreeCheck(obj)) {
DohError(DOH_MEMORY,"DohFree. %x was already released! (ignoring for now)\n", obj);
return;
}
}
if (b->objinfo->doh_del) { if (b->objinfo->doh_del) {
(b->objinfo->doh_del)(obj); (b->objinfo->doh_del)(obj);
return; return;
} } else {
free(b); free(b);
} }
}
} }
/* Copy an object */ /* Copy an object */

View file

@ -43,7 +43,7 @@ DohvPrintf(DOH *so, char *format, va_list ap)
int maxwidth; int maxwidth;
char *w, *prec; char *w, *prec;
int ivalue; int ivalue;
int dvalue; double dvalue;
void *pvalue; void *pvalue;
char *stemp; char *stemp;
int nbytes = 0; int nbytes = 0;
@ -298,6 +298,7 @@ int DohCopyto(DOH *in, DOH *out) {
int nbytes = 0, ret; int nbytes = 0, ret;
char buffer[16384]; char buffer[16384];
if ((!in) || (!out)) return 0;
while (1) { while (1) {
ret = Read(in,buffer,16384); ret = Read(in,buffer,16384);
if (ret > 0) { if (ret > 0) {
@ -321,20 +322,20 @@ DOH *DohSplit(DOH *in, char *chs, int nsplits) {
Seek(in,0,SEEK_SET); Seek(in,0,SEEK_SET);
} }
while (1) { while (1) {
str = NewString("");
do { do {
c = Getc(in); c = Getc(in);
} while ((c != EOF) && (c == *chs)); } while ((c != EOF) && (c == *chs));
if (c != EOF) { if (c != EOF) {
str = NewString("");
Putc(c,str); Putc(c,str);
while (1) { while (1) {
c = Getc(in); c = Getc(in);
if ((c == EOF) || ((c == *chs) && (nsplits != 0))) break; if ((c == EOF) || ((c == *chs) && (nsplits != 0))) break;
Putc(c,str); Putc(c,str);
} }
Append(list,str);
nsplits--; nsplits--;
} }
Append(list,str);
if (c == EOF) break; if (c == EOF) break;
} }
return list; return list;

View file

@ -66,7 +66,6 @@ Pool *CreatePool(int size)
p->len = size; p->len = size;
p->current = 0; p->current = 0;
p->next = 0; p->next = 0;
printf("Created pool : %x, %d\n", p->ptr, size);
return p; return p;
} }
@ -79,7 +78,7 @@ Pool *CreatePool(int size)
static void InitPools() { static void InitPools() {
int i; int i;
if (pools_initialized) return; if (pools_initialized) return;
for (i = 0; i < 1024; i++) { for (i = 0; i < DOH_MAX_FRAG; i++) {
FreeFragments[i] = 0; FreeFragments[i] = 0;
} }
Pools = CreatePool(DOH_POOL_SIZE); /* Create initial pool */ Pools = CreatePool(DOH_POOL_SIZE); /* Create initial pool */
@ -154,7 +153,6 @@ void *DohMalloc(int size) {
} }
/* Pool is not large enough. Create a new pool */ /* Pool is not large enough. Create a new pool */
if (p->len - p->current > 0) { if (p->len - p->current > 0) {
f = (Fragment *) malloc(sizeof(Fragment)); f = (Fragment *) malloc(sizeof(Fragment));
f->ptr = (p->ptr + p->current); f->ptr = (p->ptr + p->current);
@ -178,11 +176,17 @@ void *DohMalloc(int size) {
void DohFree(DOH *ptr) { void DohFree(DOH *ptr) {
DohBase *b; DohBase *b;
Fragment *f; Fragment *f;
extern int doh_debug_level;
if (!DohCheck(ptr)) { if (!DohCheck(ptr)) {
DohError(DOH_MEMORY,"DohFree. %x not a DOH object!\n", ptr);
return; /* Oh well. Guess we're leaky */ return; /* Oh well. Guess we're leaky */
} }
b = (DohBase *) ptr; b = (DohBase *) ptr;
if (!b->objinfo) return; /* Improperly initialized object. leak some more */ if (!b->objinfo) {
DohError(DOH_MEMORY,"DohFree. %x not properly defined. No objinfo structure.\n", ptr);
return; /* Improperly initialized object. leak some more */
}
f = (Fragment *) malloc(sizeof(Fragment)); f = (Fragment *) malloc(sizeof(Fragment));
f->ptr = (char *) ptr; f->ptr = (char *) ptr;
f->len = b->objinfo->objsize; f->len = b->objinfo->objsize;

View file

@ -111,6 +111,7 @@ typedef struct DohObjInfo {
/* Memory management */ /* Memory management */
extern void *DohMalloc(int size); extern void *DohMalloc(int size);
extern void DohFree(DOH *ptr); extern void DohFree(DOH *ptr);
extern int DohFreeCheck(DOH *ptr);
extern int DohCheck(DOH *ptr); extern int DohCheck(DOH *ptr);
extern int DohFreeCheck(DOH *ptr); extern int DohFreeCheck(DOH *ptr);
@ -290,7 +291,8 @@ extern DOH *DohSplit(DOH *input, char *chs, int nsplits);
#define DOH_UNSUPPORTED 1 #define DOH_UNSUPPORTED 1
#define DOH_UNKNOWN 2 #define DOH_UNKNOWN 2
#define DOH_CONVERSION 3 #define DOH_MEMORY 3
#define DOH_CONVERSION 5
#define DOH_CALLS 10 #define DOH_CALLS 10