From 9cd94c3f5e9914a64e3f7a082c3eaba124348016 Mon Sep 17 00:00:00 2001 From: Andreas Pehnack Date: Wed, 4 Feb 2015 21:43:51 +0100 Subject: [PATCH] Fixed ID type for Win64 --- lib/cgraph/agxbuf.c | 14 +++++++------- lib/cgraph/agxbuf.h | 6 +++--- lib/cgraph/cghdr.h | 16 ++++++++-------- lib/cgraph/cgraph.h | 19 +++++++++++-------- lib/cgraph/edge.c | 12 ++++++------ lib/cgraph/graph.c | 4 ++-- lib/cgraph/id.c | 34 +++++++++++++++++----------------- lib/cgraph/imap.c | 38 ++++++++++++++++++++++++++++++-------- lib/cgraph/node.c | 14 +++++++------- lib/cgraph/obj.c | 2 +- lib/cgraph/pend.c | 4 ++-- lib/cgraph/subg.c | 8 ++++---- lib/cgraph/write.c | 4 ++-- 13 files changed, 100 insertions(+), 75 deletions(-) diff --git a/lib/cgraph/agxbuf.c b/lib/cgraph/agxbuf.c index c12ab6558..3b2bd3a7c 100644 --- a/lib/cgraph/agxbuf.c +++ b/lib/cgraph/agxbuf.c @@ -41,11 +41,11 @@ void agxbinit(agxbuf * xb, unsigned int hint, unsigned char *init) /* agxbmore; * Expand buffer to hold at least ssz more bytes. */ -int agxbmore(agxbuf * xb, unsigned int ssz) +int agxbmore(agxbuf * xb, size_t ssz) { - int cnt; /* current no. of characters in buffer */ - int size; /* current buffer size */ - int nsize; /* new buffer size */ + size_t cnt; /* current no. of characters in buffer */ + size_t size; /* current buffer size */ + size_t nsize; /* new buffer size */ unsigned char *nbuf; /* new buffer */ size = xb->eptr - xb->buf; @@ -69,7 +69,7 @@ int agxbmore(agxbuf * xb, unsigned int ssz) /* agxbput_n: * Append string s of length n onto xb */ -int agxbput_n(agxbuf * xb, const char *s, unsigned int ssz) +size_t agxbput_n(agxbuf * xb, const char *s, size_t ssz) { if (xb->ptr + ssz > xb->eptr) agxbmore(xb, ssz); @@ -81,9 +81,9 @@ int agxbput_n(agxbuf * xb, const char *s, unsigned int ssz) /* agxbput: * Append string s into xb */ -int agxbput(agxbuf * xb, const char *s) +size_t agxbput(agxbuf * xb, const char *s) { - unsigned int ssz = strlen(s); + size_t ssz = strlen(s); return agxbput_n(xb, s, ssz); } diff --git a/lib/cgraph/agxbuf.h b/lib/cgraph/agxbuf.h index 9ffc39026..36203f2ce 100644 --- a/lib/cgraph/agxbuf.h +++ b/lib/cgraph/agxbuf.h @@ -38,12 +38,12 @@ extern "C" { /* agxbput_n: * Append string s of length n into xb */ - extern int agxbput_n(agxbuf * xb, const char *s, unsigned int n); + extern size_t agxbput_n(agxbuf * xb, const char *s, size_t n); /* agxbput: * Append string s into xb */ - extern int agxbput(agxbuf * xb, const char *s); + extern size_t agxbput(agxbuf * xb, const char *s); /* agxbfree: * Free any malloced resources. @@ -58,7 +58,7 @@ extern "C" { /* agxbmore: * Expand buffer to hold at least ssz more bytes. */ - extern int agxbmore(agxbuf * xb, int unsigned ssz); + extern int agxbmore(agxbuf * xb, size_t ssz); /* agxbputc: * Add character to buffer. diff --git a/lib/cgraph/cghdr.h b/lib/cgraph/cghdr.h index be7063e98..883ef2363 100644 --- a/lib/cgraph/cghdr.h +++ b/lib/cgraph/cghdr.h @@ -110,7 +110,7 @@ int agstrclose(Agraph_t * g); void agmarkhtmlstr(char *s); /* object set management */ -Agnode_t *agfindnode_by_id(Agraph_t * g, unsigned long id); +Agnode_t *agfindnode_by_id(Agraph_t * g, IDTYPE id); Dtcompar_f agdictorder(Agraph_t *, Dict_t *, Dtcompar_f); int agedgecmpf(Dict_t * d, void *arg_e0, void *arg_e1, Dtdisc_t * disc); int agnamecmpf(Dict_t * d, void *, void *, Dtdisc_t * disc); @@ -146,16 +146,16 @@ void aglexbad(void); /* ID management */ int agmapnametoid(Agraph_t * g, int objtype, char *str, - unsigned long *result, int allocflag); -int agallocid(Agraph_t * g, int objtype, unsigned long request); -void agfreeid(Agraph_t * g, int objtype, unsigned long id); + IDTYPE *result, int allocflag); +int agallocid(Agraph_t * g, int objtype, IDTYPE request); +void agfreeid(Agraph_t * g, int objtype, IDTYPE id); char *agprintid(Agobj_t * obj); int aginternalmaplookup(Agraph_t * g, int objtype, char *str, - unsigned long *result); + IDTYPE *result); void aginternalmapinsert(Agraph_t * g, int objtype, char *str, - unsigned long result); -char *aginternalmapprint(Agraph_t * g, int objtype, unsigned long id); -int aginternalmapdelete(Agraph_t * g, int objtype, unsigned long id); + IDTYPE result); +char *aginternalmapprint(Agraph_t * g, int objtype, IDTYPE id); +int aginternalmapdelete(Agraph_t * g, int objtype, IDTYPE id); void aginternalmapclose(Agraph_t * g); void agregister(Agraph_t * g, int objtype, void *obj); diff --git a/lib/cgraph/cgraph.h b/lib/cgraph/cgraph.h index f1e2bde02..4acd88a1e 100644 --- a/lib/cgraph/cgraph.h +++ b/lib/cgraph/cgraph.h @@ -37,6 +37,9 @@ extern "C" { #define NILedge NIL(Agedge_t*) #define NILsym NIL(Agsym_t*) +/* avoid loss when casting pointer to unsigned long on Win64 */ +typedef uintptr_t IDTYPE; + /* forward struct type declarations */ typedef struct Agtag_s Agtag_t; typedef struct Agobj_s Agobj_t; /* generic object header */ @@ -80,7 +83,7 @@ struct Agtag_s { unsigned mtflock:1; /* move-to-front lock, see above */ unsigned attrwf:1; /* attrs written (parity, write.c) */ unsigned seq:(sizeof(unsigned) * 8 - 4); /* sequence no. */ - unsigned long id; /* client ID */ + IDTYPE id; /* client ID */ }; /* object tags */ @@ -157,11 +160,11 @@ struct Agmemdisc_s { /* memory allocator */ struct Agiddisc_s { /* object ID allocator */ void *(*open) (Agraph_t * g, Agdisc_t*); /* associated with a graph */ - long (*map) (void *state, int objtype, char *str, unsigned long *id, + long (*map) (void *state, int objtype, char *str, IDTYPE *id, int createflag); - long (*alloc) (void *state, int objtype, unsigned long id); - void (*free) (void *state, int objtype, unsigned long id); - char *(*print) (void *state, int objtype, unsigned long id); + long (*alloc) (void *state, int objtype, IDTYPE id); + void (*free) (void *state, int objtype, IDTYPE id); + char *(*print) (void *state, int objtype, IDTYPE id); void (*close) (void *state); void (*idregister) (void *state, int objtype, void *obj); }; @@ -273,7 +276,7 @@ extern int agissimple(Agraph_t * g); /* nodes */ extern Agnode_t *agnode(Agraph_t * g, char *name, int createflag); -extern Agnode_t *agidnode(Agraph_t * g, unsigned long id, int createflag); +extern Agnode_t *agidnode(Agraph_t * g, IDTYPE id, int createflag); extern Agnode_t *agsubnode(Agraph_t * g, Agnode_t * n, int createflag); extern Agnode_t *agfstnode(Agraph_t * g); extern Agnode_t *agnxtnode(Agraph_t * g, Agnode_t * n); @@ -286,7 +289,7 @@ extern Agsubnode_t *agsubrep(Agraph_t * g, Agnode_t * n); extern Agedge_t *agedge(Agraph_t * g, Agnode_t * t, Agnode_t * h, char *name, int createflag); extern Agedge_t *agidedge(Agraph_t * g, Agnode_t * t, Agnode_t * h, - unsigned long id, int createflag); + IDTYPE id, int createflag); extern Agedge_t *agsubedge(Agraph_t * g, Agedge_t * e, int createflag); extern Agedge_t *agfstin(Agraph_t * g, Agnode_t * n); extern Agedge_t *agnxtin(Agraph_t * g, Agedge_t * e); @@ -363,7 +366,7 @@ extern int agsafeset(void* obj, char* name, char* value, char* def); /* defintions for subgraphs */ extern Agraph_t *agsubg(Agraph_t * g, char *name, int cflag); /* constructor */ -extern Agraph_t *agidsubg(Agraph_t * g, unsigned long id, int cflag); /* constructor */ +extern Agraph_t *agidsubg(Agraph_t * g, IDTYPE id, int cflag); /* constructor */ extern Agraph_t *agfstsubg(Agraph_t * g), *agnxtsubg(Agraph_t * subg); extern Agraph_t *agparent(Agraph_t * g); diff --git a/lib/cgraph/edge.c b/lib/cgraph/edge.c index 1a60e7ac8..4810f3f1d 100644 --- a/lib/cgraph/edge.c +++ b/lib/cgraph/edge.c @@ -144,7 +144,7 @@ static Agedge_t *agfindedge_by_key(Agraph_t * g, Agnode_t * t, Agnode_t * h, } static Agedge_t *agfindedge_by_id(Agraph_t * g, Agnode_t * t, Agnode_t * h, - unsigned long id) + IDTYPE id) { Agtag_t tag; @@ -211,7 +211,7 @@ static void subedge(Agraph_t * g, Agedge_t * e) } static Agedge_t *newedge(Agraph_t * g, Agnode_t * t, Agnode_t * h, - unsigned long id) + IDTYPE id) { Agedgepair_t *e2; Agedge_t *in, *out; @@ -257,7 +257,7 @@ static int ok_to_make_edge(Agraph_t * g, Agnode_t * t, Agnode_t * h) } Agedge_t *agidedge(Agraph_t * g, Agnode_t * t, Agnode_t * h, - unsigned long id, int cflag) + IDTYPE id, int cflag) { Agraph_t *root; Agedge_t *e; @@ -282,7 +282,7 @@ Agedge_t *agedge(Agraph_t * g, Agnode_t * t, Agnode_t * h, char *name, int cflag) { Agedge_t *e; - unsigned long id; + IDTYPE id; int have_id; have_id = agmapnametoid(g, AGEDGE, name, &id, FALSE); @@ -404,7 +404,7 @@ Agedge_t *agsubedge(Agraph_t * g, Agedge_t * e, int cflag) /* edge comparison. OBJTYPE(e) == 0 means ID is a wildcard. */ int agedgeidcmpf(Dict_t * d, void *arg_e0, void *arg_e1, Dtdisc_t * disc) { - long v; + long long v; Agedge_t *e0, *e1; NOTUSED(d); @@ -424,7 +424,7 @@ int agedgeidcmpf(Dict_t * d, void *arg_e0, void *arg_e1, Dtdisc_t * disc) /* edge comparison. for ordered traversal. */ int agedgeseqcmpf(Dict_t * d, void *arg_e0, void *arg_e1, Dtdisc_t * disc) { - long v; + long long v; Agedge_t *e0, *e1; NOTUSED(d); diff --git a/lib/cgraph/graph.c b/lib/cgraph/graph.c index bb892d3c7..71875e2c8 100644 --- a/lib/cgraph/graph.c +++ b/lib/cgraph/graph.c @@ -45,7 +45,7 @@ Agraph_t *agopen(char *name, Agdesc_t desc, Agdisc_t * arg_disc) { Agraph_t *g; Agclos_t *clos; - unsigned long gid; + IDTYPE gid; clos = agclos(arg_disc); g = clos->disc.mem->alloc(clos->state.mem, sizeof(Agraph_t)); @@ -241,7 +241,7 @@ int agdegree(Agraph_t * g, Agnode_t * n, int want_in, int want_out) int agraphidcmpf(Dict_t * d, void *arg0, void *arg1, Dtdisc_t * disc) { - long v; + ptrdiff_t v; Agraph_t *sg0, *sg1; sg0 = (Agraph_t *) arg0; sg1 = (Agraph_t *) arg1; diff --git a/lib/cgraph/id.c b/lib/cgraph/id.c index cde61ada7..694220ef3 100644 --- a/lib/cgraph/id.c +++ b/lib/cgraph/id.c @@ -21,30 +21,30 @@ static void *idopen(Agraph_t * g, Agdisc_t* disc) return g; } -static long idmap(void *state, int objtype, char *str, unsigned long *id, +static long idmap(void *state, int objtype, char *str, IDTYPE *id, int createflag) { char *s; - static unsigned long ctr = 1; + static IDTYPE ctr = 1; NOTUSED(objtype); if (str) { - Agraph_t *g; - g = state; - if (createflag) - s = agstrdup(g, str); - else - s = agstrbind(g, str); - *id = (unsigned long) s; + Agraph_t *g; + g = state; + if (createflag) + s = agstrdup(g, str); + else + s = agstrbind(g, str); + *id = (IDTYPE) s; } else { - *id = ctr; - ctr += 2; + *id = ctr; + ctr += 2; } return TRUE; } /* we don't allow users to explicitly set IDs, either */ -static long idalloc(void *state, int objtype, unsigned long request) +static long idalloc(void *state, int objtype, IDTYPE request) { NOTUSED(state); NOTUSED(objtype); @@ -52,14 +52,14 @@ static long idalloc(void *state, int objtype, unsigned long request) return FALSE; } -static void idfree(void *state, int objtype, unsigned long id) +static void idfree(void *state, int objtype, IDTYPE id) { NOTUSED(objtype); if (id % 2 == 0) agstrfree((Agraph_t *) state, (char *) id); } -static char *idprint(void *state, int objtype, unsigned long id) +static char *idprint(void *state, int objtype, IDTYPE id) { NOTUSED(state); NOTUSED(objtype); @@ -94,7 +94,7 @@ Agiddisc_t AgIdDisc = { /* aux functions incl. support for disciplines with anonymous IDs */ int agmapnametoid(Agraph_t * g, int objtype, char *str, - unsigned long *result, int createflag) + IDTYPE *result, int createflag) { int rv; @@ -123,12 +123,12 @@ int agmapnametoid(Agraph_t * g, int objtype, char *str, return rv; } -int agallocid(Agraph_t * g, int objtype, unsigned long request) +int agallocid(Agraph_t * g, int objtype, IDTYPE request) { return AGDISC(g, id)->alloc(AGCLOS(g, id), objtype, request); } -void agfreeid(Agraph_t * g, int objtype, unsigned long id) +void agfreeid(Agraph_t * g, int objtype, IDTYPE id) { (void) aginternalmapdelete(g, objtype, id); (AGDISC(g, id)->free) (AGCLOS(g, id), objtype, id); diff --git a/lib/cgraph/imap.c b/lib/cgraph/imap.c index 2ba4a0bd1..7b006e1fb 100644 --- a/lib/cgraph/imap.c +++ b/lib/cgraph/imap.c @@ -16,7 +16,7 @@ typedef struct IMapEntry_s { Dtlink_t namedict_link; Dtlink_t iddict_link; - unsigned long id; + IDTYPE id; char *str; } IMapEntry_t; @@ -28,7 +28,18 @@ static int idcmpf(Dict_t * d, void *arg_p0, void *arg_p1, Dtdisc_t * disc) p0 = arg_p0; p1 = arg_p1; NOTUSED(disc); - return (p0->id - p1->id); + if (p0->id > p1->id) + { + return 1; + } + else if (p0->id < p1->id) + { + return -1; + } + else + { + return 0; + } } /* note, OK to compare pointers into shared string pool @@ -43,7 +54,18 @@ static int namecmpf(Dict_t * d, void *arg_p0, void *arg_p1, p0 = arg_p0; p1 = arg_p1; NOTUSED(disc); - return (p0->str - p1->str); + if (p0->str > p1->str) + { + return 1; + } + else if (p0->str < p1->str) + { + return -1; + } + else + { + return 0; + } } static Dtdisc_t LookupByName = { @@ -71,7 +93,7 @@ static Dtdisc_t LookupById = { }; int aginternalmaplookup(Agraph_t * g, int objtype, char *str, - unsigned long *result) + IDTYPE *result) { Dict_t *d; IMapEntry_t *sym, template; @@ -94,7 +116,7 @@ int aginternalmaplookup(Agraph_t * g, int objtype, char *str, /* caller GUARANTEES that this is a new entry */ void aginternalmapinsert(Agraph_t * g, int objtype, char *str, - unsigned long id) + IDTYPE id) { IMapEntry_t *ent; Dict_t *d_name_to_id, *d_id_to_name; @@ -115,7 +137,7 @@ void aginternalmapinsert(Agraph_t * g, int objtype, char *str, dtinsert(d_id_to_name, ent); } -static IMapEntry_t *find_isym(Agraph_t * g, int objtype, unsigned long id) +static IMapEntry_t *find_isym(Agraph_t * g, int objtype, IDTYPE id) { Dict_t *d; IMapEntry_t *isym, itemplate; @@ -130,7 +152,7 @@ static IMapEntry_t *find_isym(Agraph_t * g, int objtype, unsigned long id) return isym; } -char *aginternalmapprint(Agraph_t * g, int objtype, unsigned long id) +char *aginternalmapprint(Agraph_t * g, int objtype, IDTYPE id) { IMapEntry_t *isym; @@ -140,7 +162,7 @@ char *aginternalmapprint(Agraph_t * g, int objtype, unsigned long id) } -int aginternalmapdelete(Agraph_t * g, int objtype, unsigned long id) +int aginternalmapdelete(Agraph_t * g, int objtype, IDTYPE id) { IMapEntry_t *isym; diff --git a/lib/cgraph/node.c b/lib/cgraph/node.c index 3d9c483ba..ecc99ce4e 100644 --- a/lib/cgraph/node.c +++ b/lib/cgraph/node.c @@ -13,7 +13,7 @@ #include -Agnode_t *agfindnode_by_id(Agraph_t * g, unsigned long id) +Agnode_t *agfindnode_by_id(Agraph_t * g, IDTYPE id) { Agsubnode_t *sn; static Agsubnode_t template; @@ -27,7 +27,7 @@ Agnode_t *agfindnode_by_id(Agraph_t * g, unsigned long id) Agnode_t *agfindnode_by_name(Agraph_t * g, char *name) { - unsigned long id; + IDTYPE id; if (agmapnametoid(g, AGNODE, name, &id, FALSE)) return agfindnode_by_id(g, id); @@ -67,7 +67,7 @@ Agnode_t *agprvnode(Agraph_t * g, Agnode_t * n) /* internal node constructor */ -static Agnode_t *newnode(Agraph_t * g, unsigned long id, unsigned long seq) +static Agnode_t *newnode(Agraph_t * g, IDTYPE id, unsigned long seq) { Agnode_t *n; @@ -116,7 +116,7 @@ static void initnode(Agraph_t * g, Agnode_t * n) } /* external node constructor - create by id */ -Agnode_t *agidnode(Agraph_t * g, unsigned long id, int cflag) +Agnode_t *agidnode(Agraph_t * g, IDTYPE id, int cflag) { Agraph_t *root; Agnode_t *n; @@ -143,7 +143,7 @@ Agnode_t *agnode(Agraph_t * g, char *name, int cflag) { Agraph_t *root; Agnode_t *n; - unsigned long id; + IDTYPE id; root = agroot(g); /* probe for existing node */ @@ -231,7 +231,7 @@ static void dict_relabel(Agnode_t * n, void *arg) int agrelabel_node(Agnode_t * n, char *newname) { Agraph_t *g; - unsigned long new_id; + IDTYPE new_id; g = agroot(agraphof(n)); if (agfindnode_by_name(g, newname)) @@ -273,7 +273,7 @@ Agnode_t *agsubnode(Agraph_t * g, Agnode_t * n0, int cflag) int agsubnodeidcmpf(Dict_t * d, void *arg0, void *arg1, Dtdisc_t * disc) { - long v; + long long v; Agsubnode_t *sn0, *sn1; sn0 = (Agsubnode_t *) arg0; sn1 = (Agsubnode_t *) arg1; diff --git a/lib/cgraph/obj.c b/lib/cgraph/obj.c index b5141aa04..7b1c8c101 100755 --- a/lib/cgraph/obj.c +++ b/lib/cgraph/obj.c @@ -37,7 +37,7 @@ int agdelete(Agraph_t * g, void *obj) int agrename(Agobj_t * obj, char *newname) { Agraph_t *g; - unsigned long old_id, new_id; + IDTYPE old_id, new_id; switch (AGTYPE(obj)) { case AGRAPH: diff --git a/lib/cgraph/pend.c b/lib/cgraph/pend.c index d42f87b84..6df7a9634 100644 --- a/lib/cgraph/pend.c +++ b/lib/cgraph/pend.c @@ -23,7 +23,7 @@ typedef struct symlist_s { /* this record describes one pending callback on one object */ typedef struct { Dtlink_t link; - unsigned long key; /* universal key for main or sub-object */ + IDTYPE key; /* universal key for main or sub-object */ Agraph_t *g; Agobj_t *obj; symlist_t *symlist; /* attributes involved */ @@ -129,7 +129,7 @@ static Dict_t *dictof(pendingset_t * ds, Agobj_t * obj, int kind) return *dict_ref; } -static unsigned long genkey(Agobj_t * obj) +static IDTYPE genkey(Agobj_t * obj) { return obj->tag.id; } diff --git a/lib/cgraph/subg.c b/lib/cgraph/subg.c index 6ef5d02d2..4d0d3da05 100644 --- a/lib/cgraph/subg.c +++ b/lib/cgraph/subg.c @@ -13,7 +13,7 @@ #include -static Agraph_t *agfindsubg_by_id(Agraph_t * g, unsigned long id) +static Agraph_t *agfindsubg_by_id(Agraph_t * g, IDTYPE id) { Agraph_t template; @@ -22,7 +22,7 @@ static Agraph_t *agfindsubg_by_id(Agraph_t * g, unsigned long id) return (Agraph_t *) dtsearch(g->g_dict, &template); } -static Agraph_t *localsubg(Agraph_t * g, unsigned long id) +static Agraph_t *localsubg(Agraph_t * g, IDTYPE id) { Agraph_t *subg; @@ -40,7 +40,7 @@ static Agraph_t *localsubg(Agraph_t * g, unsigned long id) return agopen1(subg); } -Agraph_t *agidsubg(Agraph_t * g, unsigned long id, int cflag) +Agraph_t *agidsubg(Agraph_t * g, IDTYPE id, int cflag) { Agraph_t *subg; subg = agfindsubg_by_id(g, id); @@ -51,7 +51,7 @@ Agraph_t *agidsubg(Agraph_t * g, unsigned long id, int cflag) Agraph_t *agsubg(Agraph_t * g, char *name, int cflag) { - unsigned long id; + IDTYPE id; Agraph_t *subg; if (name && agmapnametoid(g, AGRAPH, name, &id, FALSE)) { diff --git a/lib/cgraph/write.c b/lib/cgraph/write.c index 671819be4..77ffbffc7 100644 --- a/lib/cgraph/write.c +++ b/lib/cgraph/write.c @@ -185,8 +185,8 @@ char *agstrcanon(char *arg, char *buf) static char *getoutputbuffer(char *str) { static char *rv; - static int len; - int req; + static size_t len = 0; + size_t req; req = MAX(2 * strlen(str) + 2, BUFSIZ); if (req > len) { -- 2.40.0