*** empty log message ***
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@18 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
2ed1b755ad
commit
facfcadae6
11 changed files with 261 additions and 68 deletions
|
|
@ -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 -g
|
CC = gcc
|
||||||
prefix = /usr/local
|
prefix = /home/beazley/Projects
|
||||||
|
|
||||||
# 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
|
||||||
|
|
|
||||||
|
|
@ -99,8 +99,8 @@ static DOH *find_internal(DOH *co) {
|
||||||
if (d < 0) r = r->left;
|
if (d < 0) r = r->left;
|
||||||
else r = r->right;
|
else r = r->right;
|
||||||
}
|
}
|
||||||
r = (StringNode *) malloc(sizeof(StringNode));
|
r = (StringNode *) DohMalloc(sizeof(StringNode));
|
||||||
r->cstr = (char *) malloc(strlen(c)+1);
|
r->cstr = (char *) DohMalloc(strlen(c)+1);
|
||||||
strcpy(r->cstr,c);
|
strcpy(r->cstr,c);
|
||||||
r->sstr = NewString(c);
|
r->sstr = NewString(c);
|
||||||
Incref(r->sstr);
|
Incref(r->sstr);
|
||||||
|
|
@ -122,8 +122,8 @@ void DohDestroy(DOH *obj) {
|
||||||
b->refcount--;
|
b->refcount--;
|
||||||
if (b->refcount <= 0) {
|
if (b->refcount <= 0) {
|
||||||
if (doh_debug_level >= DOH_MEMORY) {
|
if (doh_debug_level >= DOH_MEMORY) {
|
||||||
if (DohFreeCheck(obj)) {
|
if (DohObjFreeCheck(obj)) {
|
||||||
DohError(DOH_MEMORY,"DohFree. %x was already released! (ignoring for now)\n", obj);
|
DohError(DOH_MEMORY,"DohDestroy. %x was already released! (ignoring for now)\n", obj);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -131,7 +131,7 @@ void DohDestroy(DOH *obj) {
|
||||||
(b->objinfo->doh_del)(obj);
|
(b->objinfo->doh_del)(obj);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
free(b);
|
/* free(b); */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@ NewFile(char *filename, char *mode)
|
||||||
file = fopen(filename,mode);
|
file = fopen(filename,mode);
|
||||||
if (!file) return 0;
|
if (!file) return 0;
|
||||||
|
|
||||||
f = (File *) DohMalloc(sizeof(File));
|
f = (File *) DohObjMalloc(sizeof(File));
|
||||||
if (!f) {
|
if (!f) {
|
||||||
fclose(file);
|
fclose(file);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -109,7 +109,7 @@ DOH *
|
||||||
NewFileFromFile(FILE *file)
|
NewFileFromFile(FILE *file)
|
||||||
{
|
{
|
||||||
File *f;
|
File *f;
|
||||||
f = (File *) DohMalloc(sizeof(File));
|
f = (File *) DohObjMalloc(sizeof(File));
|
||||||
if (!f) return 0;
|
if (!f) return 0;
|
||||||
DohInit(f);
|
DohInit(f);
|
||||||
f->objinfo = &FileType;
|
f->objinfo = &FileType;
|
||||||
|
|
@ -127,7 +127,7 @@ DOH *
|
||||||
NewFileFromFd(int fd)
|
NewFileFromFd(int fd)
|
||||||
{
|
{
|
||||||
File *f;
|
File *f;
|
||||||
f = (File *) DohMalloc(sizeof(File));
|
f = (File *) DohObjMalloc(sizeof(File));
|
||||||
if (!f) return 0;
|
if (!f) return 0;
|
||||||
DohInit(f);
|
DohInit(f);
|
||||||
f->objinfo = &FileType;
|
f->objinfo = &FileType;
|
||||||
|
|
@ -146,7 +146,7 @@ DelFile(DOH *so) {
|
||||||
assert(f->refcount <= 0);
|
assert(f->refcount <= 0);
|
||||||
if (f->closeondel)
|
if (f->closeondel)
|
||||||
fclose(f->filep);
|
fclose(f->filep);
|
||||||
DohFree(f);
|
DohObjFree(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -214,7 +214,7 @@ DohvPrintf(DOH *so, char *format, va_list ap)
|
||||||
if ((maxwidth + 1) < OBUFLEN) {
|
if ((maxwidth + 1) < OBUFLEN) {
|
||||||
stemp = obuffer;
|
stemp = obuffer;
|
||||||
} else {
|
} else {
|
||||||
stemp = (char *) malloc(maxwidth+1);
|
stemp = (char *) DohMalloc(maxwidth+1);
|
||||||
}
|
}
|
||||||
nbytes+=sprintf(stemp,newformat,Data(Sval));
|
nbytes+=sprintf(stemp,newformat,Data(Sval));
|
||||||
if (Writen(so,stemp,strlen(stemp)) < 0) return -1;
|
if (Writen(so,stemp,strlen(stemp)) < 0) return -1;
|
||||||
|
|
@ -225,7 +225,7 @@ DohvPrintf(DOH *so, char *format, va_list ap)
|
||||||
Delete(doh);
|
Delete(doh);
|
||||||
}
|
}
|
||||||
if (stemp != obuffer) {
|
if (stemp != obuffer) {
|
||||||
free(stemp);
|
DohFree(stemp);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
maxwidth = maxwidth+strlen(newformat)+strlen((char *) doh);
|
maxwidth = maxwidth+strlen(newformat)+strlen((char *) doh);
|
||||||
|
|
@ -234,12 +234,12 @@ DohvPrintf(DOH *so, char *format, va_list ap)
|
||||||
if ((maxwidth+1) < OBUFLEN) {
|
if ((maxwidth+1) < OBUFLEN) {
|
||||||
stemp = obuffer;
|
stemp = obuffer;
|
||||||
} else {
|
} else {
|
||||||
stemp = (char *) malloc(maxwidth + 1);
|
stemp = (char *) DohMalloc(maxwidth + 1);
|
||||||
}
|
}
|
||||||
nbytes+=sprintf(stemp,newformat,doh);
|
nbytes+=sprintf(stemp,newformat,doh);
|
||||||
if (Writen(so,stemp,strlen(stemp)) < 0) return -1;
|
if (Writen(so,stemp,strlen(stemp)) < 0) return -1;
|
||||||
if (stemp != obuffer) {
|
if (stemp != obuffer) {
|
||||||
free(stemp);
|
DohFree(stemp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -253,7 +253,7 @@ DohvPrintf(DOH *so, char *format, va_list ap)
|
||||||
if (maxwidth < OBUFLEN)
|
if (maxwidth < OBUFLEN)
|
||||||
stemp = obuffer;
|
stemp = obuffer;
|
||||||
else
|
else
|
||||||
stemp = (char *) malloc(maxwidth+1);
|
stemp = (char *) DohMalloc(maxwidth+1);
|
||||||
switch(*p) {
|
switch(*p) {
|
||||||
case 'd':
|
case 'd':
|
||||||
case 'i':
|
case 'i':
|
||||||
|
|
@ -281,7 +281,7 @@ DohvPrintf(DOH *so, char *format, va_list ap)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (Writen(so,stemp,strlen(stemp)) < 0) return -1;
|
if (Writen(so,stemp,strlen(stemp)) < 0) return -1;
|
||||||
if (stemp != obuffer) free(stemp);
|
if (stemp != obuffer) DohFree(stemp);
|
||||||
}
|
}
|
||||||
state = 0;
|
state = 0;
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ int Hash_len(DOH *h);
|
||||||
|
|
||||||
static HashNode *NewNode(DOH *k, void *obj)
|
static HashNode *NewNode(DOH *k, void *obj)
|
||||||
{
|
{
|
||||||
HashNode *hn = (HashNode *) malloc(sizeof(HashNode));
|
HashNode *hn = (HashNode *) DohMalloc(sizeof(HashNode));
|
||||||
hn->key = k;
|
hn->key = k;
|
||||||
Incref(hn->key);
|
Incref(hn->key);
|
||||||
hn->object = obj;
|
hn->object = obj;
|
||||||
|
|
@ -69,7 +69,7 @@ static void DelNode(HashNode *hn)
|
||||||
{
|
{
|
||||||
Delete(hn->key);
|
Delete(hn->key);
|
||||||
Delete(hn->object);
|
Delete(hn->object);
|
||||||
free(hn);
|
DohFree(hn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -121,10 +121,10 @@ int Hash_check(DOH *so) {
|
||||||
DOH *NewHash() {
|
DOH *NewHash() {
|
||||||
Hash *h;
|
Hash *h;
|
||||||
int i;
|
int i;
|
||||||
h = (Hash *) DohMalloc(sizeof(Hash));
|
h = (Hash *) DohObjMalloc(sizeof(Hash));
|
||||||
DohInit(h);
|
DohInit(h);
|
||||||
h->hashsize = HASH_INIT_SIZE;
|
h->hashsize = HASH_INIT_SIZE;
|
||||||
h->hashtable = (HashNode **) malloc(h->hashsize*sizeof(HashNode *));
|
h->hashtable = (HashNode **) DohMalloc(h->hashsize*sizeof(HashNode *));
|
||||||
for (i = 0; i < h->hashsize; i++) {
|
for (i = 0; i < h->hashsize; i++) {
|
||||||
h->hashtable[i] = 0;
|
h->hashtable[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
@ -146,11 +146,11 @@ DOH *CopyHash(DOH *ho) {
|
||||||
DOH *key;
|
DOH *key;
|
||||||
|
|
||||||
h = (Hash *) ho;
|
h = (Hash *) ho;
|
||||||
nh = (Hash *) DohMalloc(sizeof(Hash));
|
nh = (Hash *) DohObjMalloc(sizeof(Hash));
|
||||||
DohInit(nh);
|
DohInit(nh);
|
||||||
|
|
||||||
nh->hashsize = h->hashsize;
|
nh->hashsize = h->hashsize;
|
||||||
nh->hashtable = (HashNode **) malloc(nh->hashsize*sizeof(HashNode *));
|
nh->hashtable = (HashNode **) DohMalloc(nh->hashsize*sizeof(HashNode *));
|
||||||
for (i = 0; i < nh->hashsize; i++) {
|
for (i = 0; i < nh->hashsize; i++) {
|
||||||
nh->hashtable[i] = 0;
|
nh->hashtable[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
@ -190,8 +190,8 @@ void DelHash(DOH *ho)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(h->hashtable);
|
DohFree(h->hashtable);
|
||||||
DohFree(h);
|
DohObjFree(h);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
|
|
@ -244,7 +244,7 @@ static void resize(Hash *h) {
|
||||||
p = p + 2;
|
p = p + 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
table = (HashNode **) malloc(newsize*sizeof(HashNode *));
|
table = (HashNode **) DohMalloc(newsize*sizeof(HashNode *));
|
||||||
for (i = 0; i < newsize; i++ ) {
|
for (i = 0; i < newsize; i++ ) {
|
||||||
table[i] = 0;
|
table[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
@ -262,7 +262,7 @@ static void resize(Hash *h) {
|
||||||
n = next;
|
n = next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(h->hashtable);
|
DohFree(h->hashtable);
|
||||||
h->hashtable = table;
|
h->hashtable = table;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@ void more(List *l) {
|
||||||
int i;
|
int i;
|
||||||
void **newitems;
|
void **newitems;
|
||||||
|
|
||||||
newitems = (void **) malloc(l->maxitems*2*sizeof(void *));
|
newitems = (void **) DohMalloc(l->maxitems*2*sizeof(void *));
|
||||||
for (i = 0; i < l->maxitems; i++) {
|
for (i = 0; i < l->maxitems; i++) {
|
||||||
newitems[i] = l->items[i];
|
newitems[i] = l->items[i];
|
||||||
}
|
}
|
||||||
|
|
@ -96,7 +96,7 @@ void more(List *l) {
|
||||||
newitems[i] = (void *) 0;
|
newitems[i] = (void *) 0;
|
||||||
}
|
}
|
||||||
l->maxitems *= 2;
|
l->maxitems *= 2;
|
||||||
free(l->items);
|
DohFree(l->items);
|
||||||
l->items = newitems;
|
l->items = newitems;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -121,12 +121,12 @@ DOH *
|
||||||
NewList() {
|
NewList() {
|
||||||
List *l;
|
List *l;
|
||||||
int i;
|
int i;
|
||||||
l = (List *) DohMalloc(sizeof(List));
|
l = (List *) DohObjMalloc(sizeof(List));
|
||||||
DohInit(l);
|
DohInit(l);
|
||||||
l->objinfo = &ListType;
|
l->objinfo = &ListType;
|
||||||
l->nitems = 0;
|
l->nitems = 0;
|
||||||
l->maxitems = MAXLISTITEMS;
|
l->maxitems = MAXLISTITEMS;
|
||||||
l->items = (void **) malloc(l->maxitems*sizeof(void *));
|
l->items = (void **) DohMalloc(l->maxitems*sizeof(void *));
|
||||||
for (i = 0; i < MAXLISTITEMS; i++) {
|
for (i = 0; i < MAXLISTITEMS; i++) {
|
||||||
l->items[i] = 0;
|
l->items[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
@ -143,12 +143,12 @@ CopyList(DOH *lo) {
|
||||||
List *l,*nl;
|
List *l,*nl;
|
||||||
int i;
|
int i;
|
||||||
l = (List *) lo;
|
l = (List *) lo;
|
||||||
nl = (List *) DohMalloc(sizeof(List));
|
nl = (List *) DohObjMalloc(sizeof(List));
|
||||||
DohInit(nl);
|
DohInit(nl);
|
||||||
nl->objinfo = l->objinfo;
|
nl->objinfo = l->objinfo;
|
||||||
nl->nitems = l->nitems;
|
nl->nitems = l->nitems;
|
||||||
nl->maxitems = l->maxitems;
|
nl->maxitems = l->maxitems;
|
||||||
nl->items = (void **) malloc(l->maxitems*sizeof(void *));
|
nl->items = (void **) DohMalloc(l->maxitems*sizeof(void *));
|
||||||
nl->iter = 0;
|
nl->iter = 0;
|
||||||
for (i = 0; i < l->maxitems; i++) {
|
for (i = 0; i < l->maxitems; i++) {
|
||||||
nl->items[i] = l->items[i];
|
nl->items[i] = l->items[i];
|
||||||
|
|
@ -172,8 +172,8 @@ DelList(DOH *lo) {
|
||||||
for (i = 0; i < l->nitems; i++) {
|
for (i = 0; i < l->nitems; i++) {
|
||||||
Delete(l->items[i]);
|
Delete(l->items[i]);
|
||||||
}
|
}
|
||||||
free(l->items);
|
DohFree(l->items);
|
||||||
DohFree(l);
|
DohObjFree(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,9 @@
|
||||||
#define DOH_MAX_FRAG 1024
|
#define DOH_MAX_FRAG 1024
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
int _DohMemoryCurrent = 0;
|
||||||
|
int _DohMemoryHigh = 0;
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* memory.c
|
* memory.c
|
||||||
*
|
*
|
||||||
|
|
@ -58,10 +61,10 @@ Pool *CreatePool(int size)
|
||||||
{
|
{
|
||||||
Pool *p = 0;
|
Pool *p = 0;
|
||||||
char *c;
|
char *c;
|
||||||
c = (char *) malloc(size);
|
c = (char *) DohMalloc(size);
|
||||||
if (!c) return 0;
|
if (!c) return 0;
|
||||||
|
|
||||||
p = (Pool *) malloc(sizeof(Pool));
|
p = (Pool *) DohMalloc(sizeof(Pool));
|
||||||
p->ptr = c;
|
p->ptr = c;
|
||||||
p->len = size;
|
p->len = size;
|
||||||
p->current = 0;
|
p->current = 0;
|
||||||
|
|
@ -102,12 +105,12 @@ int DohCheck(DOH *ptr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
* int DohFreeCheck(DOH *ptr)
|
* int DohObjFreeCheck(DOH *ptr)
|
||||||
*
|
*
|
||||||
* Check if ptr is an object that has been deleted.
|
* Check if ptr is an object that has been deleted.
|
||||||
* ---------------------------------------------------------------------- */
|
* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
int DohFreeCheck(DOH *ptr) {
|
int DohObjFreeCheck(DOH *ptr) {
|
||||||
int i;
|
int i;
|
||||||
Fragment *f;
|
Fragment *f;
|
||||||
char *cptr = (char *) ptr;
|
char *cptr = (char *) ptr;
|
||||||
|
|
@ -122,12 +125,12 @@ int DohFreeCheck(DOH *ptr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
* void *DohMalloc(int size)
|
* void *DohObjMalloc(size_t size)
|
||||||
*
|
*
|
||||||
* Allocate an object
|
* Allocate an object
|
||||||
* ---------------------------------------------------------------------- */
|
* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
void *DohMalloc(int size) {
|
void *DohObjMalloc(size_t size) {
|
||||||
Pool *p;
|
Pool *p;
|
||||||
Fragment *f;
|
Fragment *f;
|
||||||
void *ptr;
|
void *ptr;
|
||||||
|
|
@ -140,7 +143,7 @@ void *DohMalloc(int size) {
|
||||||
if (f) {
|
if (f) {
|
||||||
ptr = (void *) f->ptr;
|
ptr = (void *) f->ptr;
|
||||||
FreeFragments[size] = f->next;
|
FreeFragments[size] = f->next;
|
||||||
free(f);
|
DohFree(f);
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -154,7 +157,7 @@ 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 *) DohMalloc(sizeof(Fragment));
|
||||||
f->ptr = (p->ptr + p->current);
|
f->ptr = (p->ptr + p->current);
|
||||||
f->len = (p->len - p->current);
|
f->len = (p->len - p->current);
|
||||||
f->next = FreeFragments[f->len];
|
f->next = FreeFragments[f->len];
|
||||||
|
|
@ -163,36 +166,97 @@ void *DohMalloc(int size) {
|
||||||
p = CreatePool(DOH_POOL_SIZE);
|
p = CreatePool(DOH_POOL_SIZE);
|
||||||
p->next = Pools;
|
p->next = Pools;
|
||||||
Pools = p;
|
Pools = p;
|
||||||
return DohMalloc(size);
|
return DohObjMalloc(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
* void DohFree(DOH *ptr)
|
* void DohObjFree(DOH *ptr)
|
||||||
*
|
*
|
||||||
* Free a DOH object. Important! It must be a properly allocated
|
* Free a DOH object. Important! It must be a properly allocated
|
||||||
* DOH object. Not something else.
|
* DOH object. Not something else.
|
||||||
* ---------------------------------------------------------------------- */
|
* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
void DohFree(DOH *ptr) {
|
void DohObjFree(DOH *ptr) {
|
||||||
DohBase *b;
|
DohBase *b;
|
||||||
Fragment *f;
|
Fragment *f;
|
||||||
extern int doh_debug_level;
|
extern int doh_debug_level;
|
||||||
|
|
||||||
if (!DohCheck(ptr)) {
|
if (!DohCheck(ptr)) {
|
||||||
DohError(DOH_MEMORY,"DohFree. %x not a DOH object!\n", ptr);
|
DohError(DOH_MEMORY,"DohObjFree. %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) {
|
if (!b->objinfo) {
|
||||||
DohError(DOH_MEMORY,"DohFree. %x not properly defined. No objinfo structure.\n", ptr);
|
DohError(DOH_MEMORY,"DohObjFree. %x not properly defined. No objinfo structure.\n", ptr);
|
||||||
return; /* Improperly initialized object. leak some more */
|
return; /* Improperly initialized object. leak some more */
|
||||||
}
|
}
|
||||||
f = (Fragment *) malloc(sizeof(Fragment));
|
f = (Fragment *) DohMalloc(sizeof(Fragment));
|
||||||
f->ptr = (char *) ptr;
|
f->ptr = (char *) ptr;
|
||||||
f->len = b->objinfo->objsize;
|
f->len = b->objinfo->objsize;
|
||||||
f->next = FreeFragments[f->len];
|
f->next = FreeFragments[f->len];
|
||||||
FreeFragments[f->len] = f;
|
FreeFragments[f->len] = f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* void *DohMalloc(size_t nbytes)
|
||||||
|
*
|
||||||
|
* Wrapper around malloc() function. Records memory usage.
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
void *DohMalloc(size_t nbytes) {
|
||||||
|
char *ptr;
|
||||||
|
ptr = (char *) malloc(nbytes+8);
|
||||||
|
if (!ptr) return 0;
|
||||||
|
_DohMemoryCurrent += (nbytes+8);
|
||||||
|
if (_DohMemoryCurrent > _DohMemoryHigh) _DohMemoryHigh = _DohMemoryCurrent;
|
||||||
|
*((int *) ptr) = nbytes;
|
||||||
|
return (void *) (ptr+8);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* void *DohRealloc(void *ptr, size_t newsize)
|
||||||
|
*
|
||||||
|
* Wrapper around realloc() function.
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
void *DohRealloc(void *ptr, size_t newsize) {
|
||||||
|
char *cptr = (char *) ptr;
|
||||||
|
char *nptr;
|
||||||
|
int size;
|
||||||
|
|
||||||
|
size = *((int *) (cptr - 8));
|
||||||
|
nptr = (char *) realloc(cptr-8,newsize+8);
|
||||||
|
if (!nptr) return 0;
|
||||||
|
*((int *) nptr) = newsize;
|
||||||
|
_DohMemoryCurrent += (newsize - size);
|
||||||
|
if (_DohMemoryCurrent > _DohMemoryHigh) _DohMemoryHigh = _DohMemoryCurrent;
|
||||||
|
return (void *) (nptr+8);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* void DohFree(void *ptr)
|
||||||
|
*
|
||||||
|
* Wrapper around free() function. Records memory usage.
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
void DohFree(void *ptr) {
|
||||||
|
char *cptr = (char *) ptr;
|
||||||
|
int size;
|
||||||
|
size = *((int *) (cptr - 8));
|
||||||
|
free(cptr-8);
|
||||||
|
_DohMemoryCurrent -= (size+8);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* int DohMemoryUse()
|
||||||
|
*
|
||||||
|
* Return bytes currently in use by Doh
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
int DohMemoryUse() {
|
||||||
|
return _DohMemoryCurrent;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DohMemoryHigh() {
|
||||||
|
return _DohMemoryHigh;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -142,7 +142,7 @@ NewString(char *s)
|
||||||
{
|
{
|
||||||
int l, max;
|
int l, max;
|
||||||
String *str;
|
String *str;
|
||||||
str = (String *) DohMalloc(sizeof(String));
|
str = (String *) DohObjMalloc(sizeof(String));
|
||||||
DohInit(str);
|
DohInit(str);
|
||||||
str->objinfo = &StringType;
|
str->objinfo = &StringType;
|
||||||
str->hashkey = -1;
|
str->hashkey = -1;
|
||||||
|
|
@ -155,7 +155,7 @@ NewString(char *s)
|
||||||
l = (int) strlen(s);
|
l = (int) strlen(s);
|
||||||
if ((l+1) > max) max = l+1;
|
if ((l+1) > max) max = l+1;
|
||||||
}
|
}
|
||||||
str->str = (char *) malloc(max);
|
str->str = (char *) DohMalloc(max);
|
||||||
str->maxsize = max;
|
str->maxsize = max;
|
||||||
if (s) {
|
if (s) {
|
||||||
strcpy(str->str,s);
|
strcpy(str->str,s);
|
||||||
|
|
@ -176,7 +176,7 @@ CopyString(DOH *so) {
|
||||||
int l, max;
|
int l, max;
|
||||||
String *str;
|
String *str;
|
||||||
s = (String *) so;
|
s = (String *) so;
|
||||||
str = (String *) DohMalloc(sizeof(String));
|
str = (String *) DohObjMalloc(sizeof(String));
|
||||||
DohInit(str);
|
DohInit(str);
|
||||||
str->objinfo = &StringType;
|
str->objinfo = &StringType;
|
||||||
str->hashkey = -1;
|
str->hashkey = -1;
|
||||||
|
|
@ -185,7 +185,7 @@ CopyString(DOH *so) {
|
||||||
str->line = 1;
|
str->line = 1;
|
||||||
str->pbi = 0;
|
str->pbi = 0;
|
||||||
max = s->maxsize;
|
max = s->maxsize;
|
||||||
str->str = (char *) malloc(max);
|
str->str = (char *) DohMalloc(max);
|
||||||
memmove(str->str, s->str, max);
|
memmove(str->str, s->str, max);
|
||||||
str->maxsize= max;
|
str->maxsize= max;
|
||||||
str->len = s->len;
|
str->len = s->len;
|
||||||
|
|
@ -201,8 +201,8 @@ DelString(DOH *so) {
|
||||||
String *s;
|
String *s;
|
||||||
s = (String *) so;
|
s = (String *) so;
|
||||||
assert(s->refcount <= 0);
|
assert(s->refcount <= 0);
|
||||||
free(s->str);
|
DohFree(s->str);
|
||||||
DohFree(s);
|
DohObjFree(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
|
|
@ -293,7 +293,7 @@ add(String *s, const char *newstr) {
|
||||||
if (newlen >= s->maxsize-1) {
|
if (newlen >= s->maxsize-1) {
|
||||||
newmaxsize = 2*s->maxsize;
|
newmaxsize = 2*s->maxsize;
|
||||||
if (newlen >= newmaxsize -1) newmaxsize = newlen + 1;
|
if (newlen >= newmaxsize -1) newmaxsize = newlen + 1;
|
||||||
assert(s->str = (char *) realloc(s->str,newmaxsize));
|
assert(s->str = (char *) DohRealloc(s->str,newmaxsize));
|
||||||
s->maxsize = newmaxsize;
|
s->maxsize = newmaxsize;
|
||||||
}
|
}
|
||||||
strcpy(s->str+s->len,newstr);
|
strcpy(s->str+s->len,newstr);
|
||||||
|
|
@ -311,7 +311,7 @@ addstr(String *s, String *s1) {
|
||||||
if (newlen >= s->maxsize-1) {
|
if (newlen >= s->maxsize-1) {
|
||||||
newmaxsize = 2*s->maxsize;
|
newmaxsize = 2*s->maxsize;
|
||||||
if (newlen >= newmaxsize -1) newmaxsize = newlen + 1;
|
if (newlen >= newmaxsize -1) newmaxsize = newlen + 1;
|
||||||
assert(s->str = (char *) realloc(s->str,newmaxsize));
|
assert(s->str = (char *) DohRealloc(s->str,newmaxsize));
|
||||||
s->maxsize = newmaxsize;
|
s->maxsize = newmaxsize;
|
||||||
}
|
}
|
||||||
memmove(s->str+s->len,s1->str,s1->len);
|
memmove(s->str+s->len,s1->str,s1->len);
|
||||||
|
|
@ -327,7 +327,7 @@ String_addchar(DOH *so, char c) {
|
||||||
String *s = (String *) so;
|
String *s = (String *) so;
|
||||||
s->hashkey = -1;
|
s->hashkey = -1;
|
||||||
if ((s->len+1) > (s->maxsize-1)) {
|
if ((s->len+1) > (s->maxsize-1)) {
|
||||||
assert(s->str = (char *) realloc(s->str,2*s->maxsize));
|
assert(s->str = (char *) DohRealloc(s->str,2*s->maxsize));
|
||||||
s->maxsize *= 2;
|
s->maxsize *= 2;
|
||||||
}
|
}
|
||||||
s->str[s->len] = c;
|
s->str[s->len] = c;
|
||||||
|
|
@ -342,7 +342,7 @@ String_addchar(DOH *so, char c) {
|
||||||
void
|
void
|
||||||
String_expand(String *s, int width) {
|
String_expand(String *s, int width) {
|
||||||
if ((s->len + width) > (s->maxsize-1)) {
|
if ((s->len + width) > (s->maxsize-1)) {
|
||||||
assert(s->str = (char *) realloc(s->str,(s->len + width)+1));
|
assert(s->str = (char *) DohRealloc(s->str,(s->len + width)+1));
|
||||||
s->maxsize = s->len + width + 1;
|
s->maxsize = s->len + width + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -381,7 +381,7 @@ raw_insert(String *s, int pos, char *data, int len)
|
||||||
/* See if there is room to insert the new data */
|
/* See if there is room to insert the new data */
|
||||||
|
|
||||||
while (s->maxsize <= s->len+len) {
|
while (s->maxsize <= s->len+len) {
|
||||||
assert(s->str = (char *) realloc(s->str,2*s->maxsize));
|
assert(s->str = (char *) DohRealloc(s->str,2*s->maxsize));
|
||||||
s->maxsize *= 2;
|
s->maxsize *= 2;
|
||||||
}
|
}
|
||||||
memmove(s->str+pos+len, s->str+pos, (s->len - pos));
|
memmove(s->str+pos+len, s->str+pos, (s->len - pos));
|
||||||
|
|
@ -482,7 +482,7 @@ String_write(DOH *so, void *buffer, int len) {
|
||||||
s->hashkey = -1;
|
s->hashkey = -1;
|
||||||
newlen = s->sp + len+1;
|
newlen = s->sp + len+1;
|
||||||
if (newlen > s->maxsize) {
|
if (newlen > s->maxsize) {
|
||||||
assert(s->str = (char *) realloc(s->str,newlen));
|
assert(s->str = (char *) DohRealloc(s->str,newlen));
|
||||||
s->maxsize = newlen;
|
s->maxsize = newlen;
|
||||||
s->len = s->sp + len;
|
s->len = s->sp + len;
|
||||||
}
|
}
|
||||||
|
|
@ -622,7 +622,7 @@ void replace_internal(String *str, char *token, char *rep, int flags, char *star
|
||||||
t = strstr(c,token);
|
t = strstr(c,token);
|
||||||
if (t) {
|
if (t) {
|
||||||
str->len = 0;
|
str->len = 0;
|
||||||
str->str = (char *) malloc(str->maxsize);
|
str->str = (char *) DohMalloc(str->maxsize);
|
||||||
if (start) {
|
if (start) {
|
||||||
char temp = *start;
|
char temp = *start;
|
||||||
*start = 0;
|
*start = 0;
|
||||||
|
|
@ -697,7 +697,7 @@ void replace_internal(String *str, char *token, char *rep, int flags, char *star
|
||||||
} else {
|
} else {
|
||||||
add(str,t);
|
add(str,t);
|
||||||
}
|
}
|
||||||
free(s);
|
DohFree(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ static DohObjInfo DohVoidType = {
|
||||||
|
|
||||||
DOH *NewVoid(void *obj, void (*del)(void *)) {
|
DOH *NewVoid(void *obj, void (*del)(void *)) {
|
||||||
VoidObj *v;
|
VoidObj *v;
|
||||||
v = (VoidObj *) DohMalloc(sizeof(VoidObj));
|
v = (VoidObj *) DohObjMalloc(sizeof(VoidObj));
|
||||||
DohInit(v);
|
DohInit(v);
|
||||||
v->objinfo = &DohVoidType;
|
v->objinfo = &DohVoidType;
|
||||||
v->ptr = obj;
|
v->ptr = obj;
|
||||||
|
|
@ -73,7 +73,7 @@ void Void_delete(DOH *vo) {
|
||||||
if (v->del) {
|
if (v->del) {
|
||||||
(*v->del)(v->ptr);
|
(*v->del)(v->ptr);
|
||||||
}
|
}
|
||||||
free(v);
|
DohObjFree(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
DOH *Void_copy(DOH *vo) {
|
DOH *Void_copy(DOH *vo) {
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,12 @@
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
#define DOH_MAJOR_VERSION 0
|
||||||
|
#define DOH_MINOR_VERSION 1
|
||||||
|
|
||||||
|
extern int _DohMemoryCurrent;
|
||||||
|
extern int _DohMemoryHigh;
|
||||||
|
|
||||||
typedef void DOH;
|
typedef void DOH;
|
||||||
|
|
||||||
#define DOH_BEGIN -1
|
#define DOH_BEGIN -1
|
||||||
|
|
@ -109,11 +115,15 @@ typedef struct DohObjInfo {
|
||||||
} DohObjInfo;
|
} DohObjInfo;
|
||||||
|
|
||||||
/* Memory management */
|
/* Memory management */
|
||||||
extern void *DohMalloc(int size);
|
extern void *DohMalloc(size_t size);
|
||||||
|
extern void *DohObjMalloc(size_t size);
|
||||||
extern void DohFree(DOH *ptr);
|
extern void DohFree(DOH *ptr);
|
||||||
extern int DohFreeCheck(DOH *ptr);
|
extern void DohObjFree(DOH *ptr);
|
||||||
|
extern int DohObjFreeCheck(DOH *ptr);
|
||||||
extern int DohCheck(DOH *ptr);
|
extern int DohCheck(DOH *ptr);
|
||||||
extern int DohFreeCheck(DOH *ptr);
|
extern int DohFreeCheck(DOH *ptr);
|
||||||
|
extern int DohMemoryUse();
|
||||||
|
extern int DohMemoryHigh();
|
||||||
|
|
||||||
/* Low-level doh methods. Do not call directly (well, unless you want to). */
|
/* Low-level doh methods. Do not call directly (well, unless you want to). */
|
||||||
extern void DohError(int level, char *fmt,...);
|
extern void DohError(int level, char *fmt,...);
|
||||||
|
|
|
||||||
119
Source/DOH/install-sh
Executable file
119
Source/DOH/install-sh
Executable file
|
|
@ -0,0 +1,119 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
#
|
||||||
|
# install - install a program, script, or datafile
|
||||||
|
# This comes from X11R5; it is not part of GNU.
|
||||||
|
#
|
||||||
|
# $XConsortium: install.sh,v 1.2 89/12/18 14:47:22 jim Exp $
|
||||||
|
#
|
||||||
|
# This script is compatible with the BSD install script, but was written
|
||||||
|
# from scratch.
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
|
# set DOITPROG to echo to test this script
|
||||||
|
|
||||||
|
# Don't use :- since 4.3BSD and earlier shells don't like it.
|
||||||
|
doit="${DOITPROG-}"
|
||||||
|
|
||||||
|
|
||||||
|
# put in absolute paths if you don't have them in your path; or use env. vars.
|
||||||
|
|
||||||
|
mvprog="${MVPROG-mv}"
|
||||||
|
cpprog="${CPPROG-cp}"
|
||||||
|
chmodprog="${CHMODPROG-chmod}"
|
||||||
|
chownprog="${CHOWNPROG-chown}"
|
||||||
|
chgrpprog="${CHGRPPROG-chgrp}"
|
||||||
|
stripprog="${STRIPPROG-strip}"
|
||||||
|
rmprog="${RMPROG-rm}"
|
||||||
|
|
||||||
|
instcmd="$mvprog"
|
||||||
|
chmodcmd=""
|
||||||
|
chowncmd=""
|
||||||
|
chgrpcmd=""
|
||||||
|
stripcmd=""
|
||||||
|
rmcmd="$rmprog -f"
|
||||||
|
mvcmd="$mvprog"
|
||||||
|
src=""
|
||||||
|
dst=""
|
||||||
|
|
||||||
|
while [ x"$1" != x ]; do
|
||||||
|
case $1 in
|
||||||
|
-c) instcmd="$cpprog"
|
||||||
|
shift
|
||||||
|
continue;;
|
||||||
|
|
||||||
|
-m) chmodcmd="$chmodprog $2"
|
||||||
|
shift
|
||||||
|
shift
|
||||||
|
continue;;
|
||||||
|
|
||||||
|
-o) chowncmd="$chownprog $2"
|
||||||
|
shift
|
||||||
|
shift
|
||||||
|
continue;;
|
||||||
|
|
||||||
|
-g) chgrpcmd="$chgrpprog $2"
|
||||||
|
shift
|
||||||
|
shift
|
||||||
|
continue;;
|
||||||
|
|
||||||
|
-s) stripcmd="$stripprog"
|
||||||
|
shift
|
||||||
|
continue;;
|
||||||
|
|
||||||
|
*) if [ x"$src" = x ]
|
||||||
|
then
|
||||||
|
src=$1
|
||||||
|
else
|
||||||
|
dst=$1
|
||||||
|
fi
|
||||||
|
shift
|
||||||
|
continue;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ x"$src" = x ]
|
||||||
|
then
|
||||||
|
echo "install: no input file specified"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ x"$dst" = x ]
|
||||||
|
then
|
||||||
|
echo "install: no destination specified"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# If destination is a directory, append the input filename; if your system
|
||||||
|
# does not like double slashes in filenames, you may need to add some logic
|
||||||
|
|
||||||
|
if [ -d $dst ]
|
||||||
|
then
|
||||||
|
dst="$dst"/`basename $src`
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Make a temp file name in the proper directory.
|
||||||
|
|
||||||
|
dstdir=`dirname $dst`
|
||||||
|
dsttmp=$dstdir/#inst.$$#
|
||||||
|
|
||||||
|
# Move or copy the file name to the temp name
|
||||||
|
|
||||||
|
$doit $instcmd $src $dsttmp
|
||||||
|
|
||||||
|
# and set any options; do chmod last to preserve setuid bits
|
||||||
|
|
||||||
|
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; fi
|
||||||
|
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; fi
|
||||||
|
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; fi
|
||||||
|
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; fi
|
||||||
|
|
||||||
|
# Now rename the file to the real destination.
|
||||||
|
|
||||||
|
$doit $rmcmd $dst
|
||||||
|
$doit $mvcmd $dsttmp $dst
|
||||||
|
|
||||||
|
|
||||||
|
exit 0
|
||||||
Loading…
Add table
Add a link
Reference in a new issue