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,
# but you might have to change it depending on your installation.
#
CC = cc
prefix = /usr/sandbox
CC = cc -g
prefix = /usr/local
# Comment out the following line if you're on an SGI or don't have ranlib!
RANLIB = ranlib

View file

@ -23,12 +23,12 @@
#include "doh.h"
static int debug_level = 0;
int doh_debug_level = 0;
void DohError(int level, char *fmt, ...) {
va_list ap;
va_start(ap,fmt);
if (level <= debug_level) {
if (level <= doh_debug_level) {
printf("DOH %d:",level);
vprintf(fmt,ap);
}
@ -36,7 +36,7 @@ void DohError(int level, char *fmt, ...) {
}
void DohDebug(int d) {
debug_level = d;
doh_debug_level = d;
}
static DohObjInfo DohBaseType = {
@ -86,7 +86,7 @@ static DOH *find_internal(DOH *co) {
char *c;
if (DohCheck(co)) return co;
c = (char *) co;
if (debug_level) {
if (doh_debug_level) {
DohError(DOH_CONVERSION,"Unknown object %x being treated as 'char *'.\n", c);
}
r = root;
@ -121,11 +121,18 @@ void DohDestroy(DOH *obj) {
if (!DohCheck(b)) return;
b->refcount--;
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) {
(b->objinfo->doh_del)(obj);
return;
}
free(b);
} else {
free(b);
}
}
}

View file

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

View file

@ -66,7 +66,6 @@ Pool *CreatePool(int size)
p->len = size;
p->current = 0;
p->next = 0;
printf("Created pool : %x, %d\n", p->ptr, size);
return p;
}
@ -79,7 +78,7 @@ Pool *CreatePool(int size)
static void InitPools() {
int i;
if (pools_initialized) return;
for (i = 0; i < 1024; i++) {
for (i = 0; i < DOH_MAX_FRAG; i++) {
FreeFragments[i] = 0;
}
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 */
if (p->len - p->current > 0) {
f = (Fragment *) malloc(sizeof(Fragment));
f->ptr = (p->ptr + p->current);
@ -178,11 +176,17 @@ void *DohMalloc(int size) {
void DohFree(DOH *ptr) {
DohBase *b;
Fragment *f;
extern int doh_debug_level;
if (!DohCheck(ptr)) {
DohError(DOH_MEMORY,"DohFree. %x not a DOH object!\n", ptr);
return; /* Oh well. Guess we're leaky */
}
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->ptr = (char *) ptr;
f->len = b->objinfo->objsize;

View file

@ -111,6 +111,7 @@ typedef struct DohObjInfo {
/* Memory management */
extern void *DohMalloc(int size);
extern void DohFree(DOH *ptr);
extern int DohFreeCheck(DOH *ptr);
extern int DohCheck(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_UNKNOWN 2
#define DOH_CONVERSION 3
#define DOH_MEMORY 3
#define DOH_CONVERSION 5
#define DOH_CALLS 10