From d1244c8001e8c681def4c0ff25a91136845c2a75 Mon Sep 17 00:00:00 2001
From: John Ellson <ellson@research.att.com>
Date: Tue, 23 Aug 2016 10:45:02 -0400
Subject: [PATCH] convert 'unsigned long' to 'uint64_t' for Windows portability

---
 cmd/lefty/common.h               |  1 +
 cmd/lefty/g.c                    |  6 +++---
 cmd/lefty/g.h                    |  6 +++---
 cmd/lefty/gfxview.c              | 10 +++++-----
 cmd/lefty/tbl.c                  | 10 +++++-----
 cmd/lefty/txtview.c              | 10 +++++-----
 cmd/tools/Makefile.am            |  8 ++++++--
 cmd/tools/gv2gml.c               |  7 ++++---
 contrib/prune/generic_list.c     |  5 +++--
 contrib/prune/generic_list.h     |  6 +++---
 lib/cgraph/Makefile.am           |  8 ++++++--
 lib/cgraph/cghdr.h               |  2 +-
 lib/cgraph/cgraph.h              | 17 ++++-------------
 lib/cgraph/edge.c                |  2 +-
 lib/cgraph/graph.c               |  2 +-
 lib/cgraph/node.c                |  6 +++---
 lib/cgraph/pend.c                |  2 +-
 lib/cgraph/refstr.c              |  6 +++---
 lib/cgraph/write.c               |  4 ++--
 lib/common/Makefile.am           |  8 ++++++--
 lib/common/ns.c                  | 10 +++++-----
 lib/common/render.h              |  2 ++
 lib/dotgen2/minc.c               |  2 +-
 lib/expr/Makefile.am             |  7 ++++++-
 lib/expr/expr.h                  |  9 +++++----
 lib/fdpgen/layout.c              |  5 +++--
 lib/gvc/gvdevice.c               |  3 ++-
 lib/inkpot/inkpot_value.h        |  6 +++---
 lib/sfio/sfhdr.h                 |  4 +++-
 lib/sparse/general.c             |  2 +-
 lib/twopigen/circle.h            |  8 ++++----
 lib/vmalloc/vmhdr.h              |  4 +++-
 plugin/core/gvrender_core_vml.c  |  3 ++-
 plugin/glitz/gvdevice_glitz.c    | 11 +++--------
 plugin/xlib/gvdevice_xlib.c      | 11 +++--------
 tclpkg/tcldot/tcldot-id.c        | 10 +++++-----
 tclpkg/tcldot/tcldot.h           |  4 ++--
 tclpkg/tclhandle/tclhandle.c     | 21 +++++++++++----------
 tclpkg/tclhandle/tclhandle.h     | 12 ++++++------
 tclpkg/tclpathplan/tclpathplan.c |  3 ++-
 40 files changed, 138 insertions(+), 125 deletions(-)

diff --git a/cmd/lefty/common.h b/cmd/lefty/common.h
index 7c93eef87..55fea7af4 100644
--- a/cmd/lefty/common.h
+++ b/cmd/lefty/common.h
@@ -59,6 +59,7 @@ extern "C" {
 #endif
 #endif
 
+#include <inttypes.h>
 #include <math.h>
 #include <stdio.h>
 #include <setjmp.h>
diff --git a/cmd/lefty/g.c b/cmd/lefty/g.c
index bd3e6c382..b4d85c979 100644
--- a/cmd/lefty/g.c
+++ b/cmd/lefty/g.c
@@ -791,18 +791,18 @@ found:
     return new;
 }
 
-Gwidget_t *findwidget (unsigned long w, int type) {
+Gwidget_t *findwidget (uint64_t w, int type) {
     int wi;
 
     if (type == G_WTYPESIZE) {
         for (wi = 0; wi < Gwidgetn; wi++)
-            if (Gwidgets[wi].inuse && (unsigned long) Gwidgets[wi].w == w)
+            if (Gwidgets[wi].inuse && (uint64_t) Gwidgets[wi].w == w)
                 return &Gwidgets[wi];
     } else {
         for (wi = 0; wi < Gwidgetn; wi++)
             if (
                 Gwidgets[wi].inuse && Gwidgets[wi].type == type &&
-                (unsigned long) Gwidgets[wi].w == w
+                (uint64_t) Gwidgets[wi].w == w
             )
                 return &Gwidgets[wi];
     }
diff --git a/cmd/lefty/g.h b/cmd/lefty/g.h
index 565f3935c..1ff88a058 100644
--- a/cmd/lefty/g.h
+++ b/cmd/lefty/g.h
@@ -177,7 +177,7 @@ typedef struct Gwattr_t {
         Grect_t r;
         Gcolor_t c;
         void *func;
-        unsigned long u;
+        uint64_t u;
     } u;
 } Gwattr_t;
 typedef struct Gwlist_t {
@@ -429,7 +429,7 @@ typedef struct Gwidget_t {
         Gtw_t *t;
         Gvw_t *v;
     } u;
-    unsigned long udata;
+    uint64_t udata;
 } Gwidget_t;
 #define WIDGETINCR 20
 #define WIDGETSIZE sizeof (Gwidget_t)
@@ -523,7 +523,7 @@ int Gawgetmode (Gwidget_t *);
 void Gawdefcoordscb (int, Gawdata_t *);
 
 Gwidget_t *newwidget (int);
-Gwidget_t *findwidget (unsigned long, int);
+Gwidget_t *findwidget (uint64_t, int);
 Gbitmap_t *newbitmap (void);
 void Gerr (char *, int, int, ...);
 
diff --git a/cmd/lefty/gfxview.c b/cmd/lefty/gfxview.c
index f2f2a84fc..9f1c4ff17 100644
--- a/cmd/lefty/gfxview.c
+++ b/cmd/lefty/gfxview.c
@@ -1581,7 +1581,7 @@ static void rectinsert (int ni, Tobj ko, Grect_t r) {
     gfxrect_t **rp;
     gfxrect_t *crp;
 
-    rp = &gfxnodes[ni].rect[(unsigned long) ko % LISTSIZE];
+    rp = &gfxnodes[ni].rect[(uint64_t) ko % LISTSIZE];
     for (crp = *rp; crp; crp = crp->next)
         if (crp->ko == ko) {
             crp->r.o.x = min (r.o.x, r.c.x);
@@ -1606,7 +1606,7 @@ static void rectmerge (int ni, Tobj ko, Grect_t r) {
     gfxrect_t **rp;
     gfxrect_t *crp;
 
-    rp = &gfxnodes[ni].rect[(unsigned long) ko % LISTSIZE];
+    rp = &gfxnodes[ni].rect[(uint64_t) ko % LISTSIZE];
     for (crp = *rp; crp; crp = crp->next)
         if (crp->ko == ko) {
             crp->r.o.x = min (crp->r.o.x, min (r.o.x, r.c.x));
@@ -1648,7 +1648,7 @@ static void rectdelete (int ni, Tobj ko) {
     gfxrect_t **rp;
     gfxrect_t *crp, *prp;
 
-    rp = &gfxnodes[ni].rect[(unsigned long) ko % LISTSIZE];
+    rp = &gfxnodes[ni].rect[(uint64_t) ko % LISTSIZE];
     for (crp = *rp, prp = NULL; crp; prp = crp, crp = crp->next)
         if (crp->ko == ko) {
             if (crp == *rp)
@@ -1683,7 +1683,7 @@ static void menuinsert (int ni, Tobj ko, long time, int mi) {
     gfxmenu_t **mp;
     gfxmenu_t *cmp;
 
-    mp = &gfxnodes[ni].menu[(unsigned long) ko % LISTSIZE];
+    mp = &gfxnodes[ni].menu[(uint64_t) ko % LISTSIZE];
     for (cmp = *mp; cmp; cmp = cmp->next)
         if (cmp->ko == ko) {
             cmp->time = time, cmp->mi = mi;
@@ -1703,7 +1703,7 @@ static int menufind (int ni, Tobj ko, long time) {
     gfxmenu_t **mp;
     gfxmenu_t *cmp;
 
-    mp = &gfxnodes[ni].menu[(unsigned long) ko % LISTSIZE];
+    mp = &gfxnodes[ni].menu[(uint64_t) ko % LISTSIZE];
     for (cmp = *mp; cmp; cmp = cmp->next)
         if (cmp->ko == ko && cmp->time == time)
             return cmp->mi;
diff --git a/cmd/lefty/tbl.c b/cmd/lefty/tbl.c
index 37bd57e81..052d09881 100644
--- a/cmd/lefty/tbl.c
+++ b/cmd/lefty/tbl.c
@@ -32,9 +32,9 @@ Tobj Ttrue, Tfalse;
     T_ISSTRING (ko)  && strcmp (((Tstring_t *) (ko))->s, (sk)) == 0 \
 )
 
-#define GETIKINDEX(tp, ik) (unsigned long) ik  % tp->ln
-#define GETRKINDEX(tp, rk) (unsigned long) rk  % tp->ln
-#define GETSKINDEX(tp, sk) (unsigned long) *sk % tp->ln
+#define GETIKINDEX(tp, ik) (uint64_t) ik  % tp->ln
+#define GETRKINDEX(tp, rk) (uint64_t) rk  % tp->ln
+#define GETSKINDEX(tp, sk) (uint64_t) *sk % tp->ln
 
 typedef struct mapentry_t {
     struct mapentry_t *next;
@@ -655,7 +655,7 @@ static void mapinsert (Tobj fmo, Tobj too) {
     mapentry_t **lp;
     mapentry_t *cep;
 
-    lp = &map.list[(unsigned long) fmo % MAPLISTN];
+    lp = &map.list[(uint64_t) fmo % MAPLISTN];
     if (!(cep = Mallocate (MAPENTRYSIZE)))
         panic1 (POS, "mapinsert", "cannot allocate mapentry");
     cep->fmo = fmo, cep->too = too;
@@ -666,7 +666,7 @@ static Tobj mapfind (Tobj fmo) {
     mapentry_t **lp;
     mapentry_t *cep;
 
-    lp = &map.list[(unsigned long) fmo % MAPLISTN];
+    lp = &map.list[(uint64_t) fmo % MAPLISTN];
     for (cep = *lp; cep; cep = cep->next)
         if (cep->fmo == fmo)
             return cep->too;
diff --git a/cmd/lefty/txtview.c b/cmd/lefty/txtview.c
index 0861574d9..974c1c283 100644
--- a/cmd/lefty/txtview.c
+++ b/cmd/lefty/txtview.c
@@ -486,7 +486,7 @@ static void fillnode (txtnode_t *pnode, txtnode_t *cnode) {
     case TXT_SEEN:
         cnode->u.s.text = Sseen (cnode->ko, cnode->u.s.txtnode->path);
         buttondata[3].u.t = cnode->u.s.text;
-        buttondata[4].u.u = (unsigned long) cnode->vo;
+        buttondata[4].u.u = (uint64_t) cnode->vo;
         cnode->u.s.wi = Gcreatewidget (
             pnode->u.f.t.mwi, G_BUTTONWIDGET, 5, &buttondata[0]
         );
@@ -494,7 +494,7 @@ static void fillnode (txtnode_t *pnode, txtnode_t *cnode) {
     case TXT_ABSTRACT:
         cnode->u.a.text = Sabstract (cnode->ko, cnode->vo);
         buttondata[3].u.t = cnode->u.a.text;
-        buttondata[4].u.u = (unsigned long) cnode->vo;
+        buttondata[4].u.u = (uint64_t) cnode->vo;
         cnode->u.a.wi = Gcreatewidget (
             pnode->u.f.t.mwi, G_BUTTONWIDGET, 5, &buttondata[0]
         );
@@ -504,7 +504,7 @@ static void fillnode (txtnode_t *pnode, txtnode_t *cnode) {
             cnode->u.f.t.ftext = Stfull (cnode->ko);
             cnode->u.f.t.ltext = "];";
             buttondata[3].u.t = cnode->u.f.t.ftext;
-            buttondata[4].u.u = (unsigned long) cnode->vo;
+            buttondata[4].u.u = (uint64_t) cnode->vo;
             cnode->u.f.t.fwi = Gcreatewidget (
                 pnode->u.f.t.mwi, G_BUTTONWIDGET, 5, &buttondata[0]
             );
@@ -512,14 +512,14 @@ static void fillnode (txtnode_t *pnode, txtnode_t *cnode) {
                 pnode->u.f.t.mwi, G_ARRAYWIDGET, 2, &arraydata[0]
             );
             buttondata[3].u.t = cnode->u.f.t.ltext;
-            buttondata[4].u.u = (unsigned long) cnode->vo;
+            buttondata[4].u.u = (uint64_t) cnode->vo;
             cnode->u.f.t.lwi = Gcreatewidget (
                 pnode->u.f.t.mwi, G_BUTTONWIDGET, 5, &buttondata[0]
             );
         } else {
             cnode->u.f.s.text = Ssfull (cnode->ko, cnode->vo);
             buttondata[3].u.t = cnode->u.f.s.text;
-            buttondata[4].u.u = (unsigned long) cnode->vo;
+            buttondata[4].u.u = (uint64_t) cnode->vo;
             cnode->u.f.s.wi = Gcreatewidget (
                 pnode->u.f.t.mwi, G_BUTTONWIDGET, 5, &buttondata[0]
             );
diff --git a/cmd/tools/Makefile.am b/cmd/tools/Makefile.am
index 44fd9fc9d..cf98872df 100644
--- a/cmd/tools/Makefile.am
+++ b/cmd/tools/Makefile.am
@@ -191,10 +191,14 @@ gv2gml_LDADD = \
 gml2gv_SOURCES = gml2gv.c gmlparse.y gmlscan.l
 
 gmlparse.c: y.tab.c
-	@SED@ "s/yy/gml/g" < y.tab.c > gmlparse.c
+	@SED@ "s/yy/gml/g" < y.tab.c | \
+		@SED@ "s/unsigned long int/uint64_t/g" | \
+                @SED@ "s/unsigned long/uint64_t/g"  > gmlparse.c
 
 gmlparse.h: y.tab.h
-	@SED@ "s/yy/gml/g" < y.tab.h > gmlparse.h
+	@SED@ "s/yy/gml/g" < y.tab.h | \
+		@SED@ "s/unsigned long int/uint64_t/g" | \
+                @SED@ "s/unsigned long/uint64_t/g"  > gmlparse.h
 
 y.tab.c y.tab.h : y.output
 
diff --git a/cmd/tools/gv2gml.c b/cmd/tools/gv2gml.c
index e98f7c7ca..7d55efb1c 100644
--- a/cmd/tools/gv2gml.c
+++ b/cmd/tools/gv2gml.c
@@ -27,6 +27,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <inttypes.h>
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
@@ -44,7 +45,7 @@
 static FILE *outFile;
 static char *CmdName;
 static char **Files;
-static unsigned long id;
+static uint64_t id;
 
 #define streq(s,t) (!strcmp(s,t))
 
@@ -94,7 +95,7 @@ typedef struct {
 
 typedef struct Agnodeinfo_t {
     Agrec_t h;
-    unsigned long id;
+    uint64_t id;
 } Agnodeinfo_t;
 
 #define ID(n)  (((Agnodeinfo_t*)(n->base.data))->id)
@@ -615,7 +616,7 @@ emitEdgeAttrs (Agraph_t* G, Agedge_t* ep, FILE* outFile, int ix)
 static void 
 emitEdge (Agraph_t* G, Agedge_t* e, FILE* outFile)
 {
-    fprintf (outFile, "  edge [\n    id %lu\n", (unsigned long)AGSEQ(e));
+    fprintf (outFile, "  edge [\n    id %lu\n", (uint64_t)AGSEQ(e));
     fprintf (outFile, "    source %lu\n", ID(agtail(e)));
     fprintf (outFile, "    target %lu\n", ID(aghead(e)));
     emitEdgeAttrs (G, e, outFile, 2);
diff --git a/contrib/prune/generic_list.c b/contrib/prune/generic_list.c
index f4b83eae4..cc856f426 100644
--- a/contrib/prune/generic_list.c
+++ b/contrib/prune/generic_list.c
@@ -14,13 +14,14 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <inttypes.h>
 #include <errno.h>
 
 #include <generic_list.h>
 
 #define DFLT_SIZE 100
 
-generic_list_t *new_generic_list(unsigned long size)
+generic_list_t *new_generic_list(uint64_t size)
 {
     generic_list_t *list;
 
@@ -52,7 +53,7 @@ void free_generic_list(generic_list_t * list)
 
 generic_list_t *add_to_generic_list(generic_list_t * list, gl_data element)
 {
-    unsigned long new_size;
+    uint64_t new_size;
     gl_data *new_data;
 
     if (list->size == list->used) {
diff --git a/contrib/prune/generic_list.h b/contrib/prune/generic_list.h
index 92fc431cd..dd8c4130f 100644
--- a/contrib/prune/generic_list.h
+++ b/contrib/prune/generic_list.h
@@ -22,12 +22,12 @@ extern "C" {
     typedef void *gl_data;
 
     typedef struct generic_list_s {
-	unsigned long used;	/* number of elements in the list */
-	unsigned long size;	/* number of elements that the list can hold */
+	uint64_t used;	/* number of elements in the list */
+	uint64_t size;	/* number of elements that the list can hold */
 	gl_data *data;		/* pointer to first element */
     } generic_list_t;
 
-    extern generic_list_t *new_generic_list(unsigned long size);
+    extern generic_list_t *new_generic_list(uint64_t size);
     extern generic_list_t *add_to_generic_list(generic_list_t * list,
 					       gl_data element);
     extern void free_generic_list(generic_list_t * list);
diff --git a/lib/cgraph/Makefile.am b/lib/cgraph/Makefile.am
index 750a34230..226a0f26b 100644
--- a/lib/cgraph/Makefile.am
+++ b/lib/cgraph/Makefile.am
@@ -34,10 +34,14 @@ scan.c: $(top_srcdir)/lib/cgraph/scan.l
 	rm @LEX_OUTPUT_ROOT@.c
 
 grammar.c: y.tab.c
-	@SED@ "s/yy/aag/g" < y.tab.c > grammar.c
+	@SED@ "s/yy/aag/g" < y.tab.c | \
+		@SED@ "s/unsigned long int/uint64_t/g" | \
+                @SED@ "s/unsigned long/uint64_t/g" > grammar.c
 
 grammar.h: y.tab.h
-	@SED@ "s/yy/aag/g" < y.tab.h > grammar.h
+	@SED@ "s/yy/aag/g" < y.tab.h | \
+		@SED@ "s/unsigned long int/uint64_t/g" | \
+                @SED@ "s/unsigned long/uint64_t/g" > grammar.h
 
 y.tab.c y.tab.h: y.output
 
diff --git a/lib/cgraph/cghdr.h b/lib/cgraph/cghdr.h
index 883ef2363..e9feccf81 100644
--- a/lib/cgraph/cghdr.h
+++ b/lib/cgraph/cghdr.h
@@ -115,7 +115,7 @@ 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);
 void agset_node_disc(Agraph_t * g, Dtdisc_t * disc);
-unsigned long agnextseq(Agraph_t * g, int objtype);
+uint64_t agnextseq(Agraph_t * g, int objtype);
 
 /* dict helper functions */
 Dict_t *agdtopen(Agraph_t * g, Dtdisc_t * disc, Dtmethod_t * method);
diff --git a/lib/cgraph/cgraph.h b/lib/cgraph/cgraph.h
index 61a3650cc..8bbcad68c 100644
--- a/lib/cgraph/cgraph.h
+++ b/lib/cgraph/cgraph.h
@@ -14,7 +14,8 @@
 #ifndef ATT_GRAPH_H
 #define ATT_GRAPH_H
 
-#include		"cdt.h"
+#include <inttypes.h>
+#include "cdt.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -37,17 +38,7 @@ extern "C" {
 #define NILedge			NIL(Agedge_t*)
 #define NILsym			NIL(Agsym_t*)
 
-#if 0
-// FIXME  -  I didn't understand this comment about Win64.
-//    - What is that loss?
-//    - Do we ever cast a pointer to an IDTYPE in graphviz?
-//    - Is uintptr_t is available on all architectures/compilers? 
-
-/* avoid loss when casting pointer to unsigned long on Win64 */
-typedef uintptr_t IDTYPE;
-#else
-typedef unsigned long IDTYPE;
-#endif
+typedef uint64_t IDTYPE;
 
 /* forward struct type declarations */
 typedef struct Agtag_s Agtag_t;
@@ -235,7 +226,7 @@ struct Agclos_s {
     Agdisc_t disc;		/* resource discipline functions */
     Agdstate_t state;		/* resource closures */
     Dict_t *strdict;		/* shared string dict */
-    unsigned long seq[3];	/* local object sequence number counter */
+    uint64_t seq[3];	/* local object sequence number counter */
     Agcbstack_t *cb;		/* user and system callback function stacks */
     unsigned char callbacks_enabled;	/* issue user callbacks or hold them? */
     Dict_t *lookup_by_name[3];
diff --git a/lib/cgraph/edge.c b/lib/cgraph/edge.c
index cd57cddf5..d8d5ab3d9 100644
--- a/lib/cgraph/edge.c
+++ b/lib/cgraph/edge.c
@@ -523,7 +523,7 @@ Agedge_t *agopp(Agedge_t * e)
 static Agedge_t *agfindedge_by_name(Agraph_t * g, Agnode_t * t,
 				    Agnode_t * h, char *name)
 {
-    unsigned long id;
+    uint64_t id;
 
     if (agmapnametoid(agraphof(t), AGEDGE, name, &id, FALSE))
 	return agfindedge_by_id(g, t, h, id);
diff --git a/lib/cgraph/graph.c b/lib/cgraph/graph.c
index 71875e2c8..4bd161ccb 100644
--- a/lib/cgraph/graph.c
+++ b/lib/cgraph/graph.c
@@ -154,7 +154,7 @@ int agclose(Agraph_t * g)
     return SUCCESS;
 }
 
-unsigned long agnextseq(Agraph_t * g, int objtype)
+uint64_t agnextseq(Agraph_t * g, int objtype)
 {
     return ++(g->clos->seq[objtype]);
 }
diff --git a/lib/cgraph/node.c b/lib/cgraph/node.c
index c44ed6486..b43e8bcff 100644
--- a/lib/cgraph/node.c
+++ b/lib/cgraph/node.c
@@ -67,7 +67,7 @@ Agnode_t *agprvnode(Agraph_t * g, Agnode_t * n)
 
 
 /* internal node constructor */
-static Agnode_t *newnode(Agraph_t * g, IDTYPE id, unsigned long seq)
+static Agnode_t *newnode(Agraph_t * g, IDTYPE id, uint64_t seq)
 {
     Agnode_t *n;
 
@@ -217,10 +217,10 @@ int agdelnode(Agraph_t * g, Agnode_t * n)
 static void dict_relabel(Agnode_t * n, void *arg)
 {
     Agraph_t *g;
-    unsigned long new_id;
+    uint64_t new_id;
 
     g = agraphof(n);
-    new_id = *(unsigned long *) arg;
+    new_id = *(uint64_t *) arg;
     dtdelete(g->n_id, n);	/* wrong, should be subrep */
     AGID(n) = new_id;
     dtinsert(g->n_id, n);	/* also wrong */
diff --git a/lib/cgraph/pend.c b/lib/cgraph/pend.c
index 6df7a9634..ac91938f9 100644
--- a/lib/cgraph/pend.c
+++ b/lib/cgraph/pend.c
@@ -59,7 +59,7 @@ static void freef(Dict_t * dict, void *ptr, Dtdisc_t * disc)
 
 static Dtdisc_t Disc = {
     offsetof(pending_cb_t, key),	/* sort by 'key' */
-    sizeof(unsigned long),
+    sizeof(uint64_t),
     0,				/* link offset */
     NIL(Dtmake_f),
     freef,
diff --git a/lib/cgraph/refstr.c b/lib/cgraph/refstr.c
index 60f4fd39b..0144ccfaf 100644
--- a/lib/cgraph/refstr.c
+++ b/lib/cgraph/refstr.c
@@ -21,12 +21,12 @@
  * reference counted strings.
  */
 
-static unsigned long HTML_BIT;	/* msbit of unsigned long */
-static unsigned long CNT_BITS;	/* complement of HTML_BIT */
+static uint64_t HTML_BIT;	/* msbit of uint64_t */
+static uint64_t CNT_BITS;	/* complement of HTML_BIT */
 
 typedef struct refstr_t {
     Dtlink_t link;
-    unsigned long refcnt;
+    uint64_t refcnt;
     char *s;
     char store[1];		/* this is actually a dynamic array */
 } refstr_t;
diff --git a/lib/cgraph/write.c b/lib/cgraph/write.c
index fb74f7106..6fe2e6df6 100644
--- a/lib/cgraph/write.c
+++ b/lib/cgraph/write.c
@@ -397,7 +397,7 @@ static int has_no_edges(Agraph_t * g, Agnode_t * n)
 }
 
 static int has_no_predecessor_below(Agraph_t * g, Agnode_t * n,
-				    unsigned long val)
+				    uint64_t val)
 {
     Agedge_t *e;
 
@@ -547,7 +547,7 @@ static int write_node(Agnode_t * n, iochan_t * ofile, Dict_t * d)
  * or has non-default attributes.
  */
 static int write_node_test(Agraph_t * g, Agnode_t * n,
-			   unsigned long pred_id)
+			   uint64_t pred_id)
 {
     if (NOT(node_in_subg(g, n)) && has_no_predecessor_below(g, n, pred_id)) {
 	if (has_no_edges(g, n) || not_default_attrs(g, n))
diff --git a/lib/common/Makefile.am b/lib/common/Makefile.am
index 16769eba6..acb85b903 100644
--- a/lib/common/Makefile.am
+++ b/lib/common/Makefile.am
@@ -59,10 +59,14 @@ htmllex.o htmllex.lo: htmllex.c htmllex.h htmlparse.h
 htmlparse.o htmlparse.lo: htmlparse.c htmlparse.h
                                                                                 
 htmlparse.c: y.tab.c
-	@SED@ "s/yy/html/g" < y.tab.c > htmlparse.c
+	@SED@ "s/yy/html/g" < y.tab.c | \
+		@SED@ "s/unsigned long int/uint64_t/g" | \
+                @SED@ "s/unsigned long/uint64_t/g" > htmlparse.c
 
 htmlparse.h: y.tab.h
-	@SED@ "s/yy/html/g" < y.tab.h > htmlparse.h
+	@SED@ "s/yy/html/g" < y.tab.h | \
+		@SED@ "s/unsigned long int/uint64_t/g" | \
+                @SED@ "s/unsigned long/uint64_t/g"> htmlparse.h
 
 y.tab.c y.tab.h: y.output
 
diff --git a/lib/common/ns.c b/lib/common/ns.c
index b0c2b445d..b302581e4 100644
--- a/lib/common/ns.c
+++ b/lib/common/ns.c
@@ -917,9 +917,9 @@ static node_t *checkdfs(graph_t* g, node_t * n)
 	if (ND_onstack(w)) {
 	    dump_graph (g);
 	    fprintf(stderr, "cycle: last edge %lx %s(%lx) %s(%lx)\n",
-		(unsigned long int)e,
-	       	agnameof(n), (unsigned long int)n,
-		agnameof(w), (unsigned long int)w);
+		(uint64_t)e,
+	       	agnameof(n), (uint64_t)n,
+		agnameof(w), (uint64_t)w);
 	    return w;
 	}
 	else {
@@ -927,8 +927,8 @@ static node_t *checkdfs(graph_t* g, node_t * n)
 		x = checkdfs(g, w);
 		if (x) {
 		    fprintf(stderr,"unwind %lx %s(%lx)\n",
-			(unsigned long int)e,
-			agnameof(n), (unsigned long int)n);
+			(uint64_t)e,
+			agnameof(n), (uint64_t)n);
 		    if (x != n) return x;
 		    fprintf(stderr,"unwound to root\n");
 		    fflush(stderr);
diff --git a/lib/common/render.h b/lib/common/render.h
index 5decf830e..8448c7a49 100644
--- a/lib/common/render.h
+++ b/lib/common/render.h
@@ -43,6 +43,8 @@ extern "C" {
 #include <string.h>
 #endif
 
+#include <inttypes.h>
+
 #include "types.h"
 #include "macros.h"
 #include "const.h"
diff --git a/lib/dotgen2/minc.c b/lib/dotgen2/minc.c
index cdf83e6f9..5653e4e4a 100644
--- a/lib/dotgen2/minc.c
+++ b/lib/dotgen2/minc.c
@@ -1325,7 +1325,7 @@ static void cluster_ranksetup(Agraph_t *ug)
 static int printfn(Dict_t *dict, void *arg, void *data)
 {
 	repkey_t *rk = arg;
-	printf("%lx=>%d,%lx\n",(long unsigned int)(rk->key),rk->val.type,(long unsigned int)(rk->val.p));
+	printf("%lx=>%d,%lx\n",(uint64_t)(rk->key),rk->val.type,(uint64_t)(rk->val.p));
 	return 0;
 }
 static void dumpdict(Agraph_t *model)
diff --git a/lib/expr/Makefile.am b/lib/expr/Makefile.am
index 38980c278..6ac10c53d 100644
--- a/lib/expr/Makefile.am
+++ b/lib/expr/Makefile.am
@@ -53,6 +53,8 @@ exop.h: exparse.h
 exparse.c: y.tab.c 
 	@SED@ "s/yy/ex/g" <y.tab.c | \
 		@SED@ "s/YY/EX/g" | \
+		@SED@ "s/unsigned long int/uint64_t/g" | \
+		@SED@ "s/unsigned long/uint64_t/g" | \
 		@SED@ "s/fprintf/sfprintf/g" | \
 		@SED@ "s/FILE/Sfio_t/g" | \
 		@SED@ "s/stderr/sfstderr/g" > exparse.c
@@ -60,7 +62,10 @@ exparse.c: y.tab.c
 exparse.h: y.tab.h
 	echo "#ifndef _EXPARSE_H" > exparse.h
 	echo "#define _EXPARSE_H" >> exparse.h
-	@SED@ "s/yy/ex/g" < y.tab.h | @SED@ "s/YY/EX/g" >> exparse.h
+	@SED@ "s/yy/ex/g" < y.tab.h | \
+		@SED@ "s/unsigned long int/uint64_t/g" | \
+		@SED@ "s/unsigned long/uint64_t/g" | \
+		@SED@ "s/YY/EX/g" >> exparse.h
 	echo "#endif /* _EXPARSE_H */" >> exparse.h
 
 y.tab.c y.tab.h: y.output
diff --git a/lib/expr/expr.h b/lib/expr/expr.h
index d9d5b514e..6ed431602 100644
--- a/lib/expr/expr.h
+++ b/lib/expr/expr.h
@@ -26,6 +26,7 @@ extern "C" {
 #define _EXPR_H
 
 #include <ast.h>
+#include <inttypes.h>
 
 #undef	RS	/* hp.pa <signal.h> grabs this!! */
 
@@ -159,7 +160,7 @@ struct Exref_s				/* . reference list		*/
 
 typedef struct Exbuf_s			/* sized buffer			*/
 {
-	unsigned long	size;		/* buffer size			*/
+	uint64_t	size;		/* buffer size			*/
 	char*		data;		/* buffer data			*/
 } Exbuf_t;
 
@@ -223,8 +224,8 @@ struct Exnode_s				/* expression tree node		*/
 
 struct Exdisc_s				/* discipline			*/
 {
-	unsigned long	version;	/* EX_VERSION			*/
-	unsigned long	flags;		/* EX_* flags			*/
+	uint64_t	version;	/* EX_VERSION			*/
+	uint64_t	flags;		/* EX_* flags			*/
 	Exid_t*		symbols;	/* static symbols		*/
 	char**		data;		/* compiled function arg data	*/
 	char*		lib;		/* pathfind() lib		*/
@@ -276,7 +277,7 @@ struct Exccdisc_s			/* excc() discipline		*/
 {
 	Sfio_t*		text;		/* text output stream		*/
 	char*		id;		/* symbol prefix		*/
-	unsigned long	flags;		/* EXCC_* flags			*/
+	uint64_t	flags;		/* EXCC_* flags			*/
 	int		(*ccf)(Excc_t*, Exnode_t*, Exid_t*, Exref_t*, Exnode_t*, Exccdisc_t*);
 					/* program generator function	*/
 };
diff --git a/lib/fdpgen/layout.c b/lib/fdpgen/layout.c
index e85bff86c..0910e52b8 100644
--- a/lib/fdpgen/layout.c
+++ b/lib/fdpgen/layout.c
@@ -41,6 +41,7 @@
 #include <values.h>
 #endif
 #endif
+#include <inttypes.h>
 #include <assert.h>
 #include "tlayout.h"
 #include "neatoprocs.h"
@@ -334,10 +335,10 @@ static char *portName(graph_t * g, bport_t * p)
     len += strlen(agnameof(g)) + strlen(agnameof(h)) + strlen(agnameof(t));
     if (len >= BSZ)
 	sprintf(buf, "_port_%s_%s_%s_%ld", agnameof(g), agnameof(t), agnameof(h),
-		(unsigned long)AGSEQ(e));
+		(uint64_t)AGSEQ(e));
     else
 	sprintf(buf, "_port_%s_(%d)_(%d)_%ld",agnameof(g), ND_id(t), ND_id(h),
-		(unsigned long)AGSEQ(e));
+		(uint64_t)AGSEQ(e));
     return buf;
 }
 
diff --git a/lib/gvc/gvdevice.c b/lib/gvc/gvdevice.c
index fdd8c905a..b9f6e794a 100644
--- a/lib/gvc/gvdevice.c
+++ b/lib/gvc/gvdevice.c
@@ -22,6 +22,7 @@
 #include <stdarg.h>
 #include <stdlib.h>
 #include <string.h>
+#include <inttypes.h>
 
 #ifdef HAVE_ERRNO_H
 #include <errno.h>
@@ -48,7 +49,7 @@ static char z_file_header[] =
 static z_stream z_strm;
 static unsigned char *df;
 static unsigned int dfallocated;
-static unsigned long int crc;
+static uint64_t crc;
 #endif /* HAVE_LIBZ */
 
 #include "const.h"
diff --git a/lib/inkpot/inkpot_value.h b/lib/inkpot/inkpot_value.h
index aa56a63ed..fb9736d70 100644
--- a/lib/inkpot/inkpot_value.h
+++ b/lib/inkpot/inkpot_value.h
@@ -30,9 +30,9 @@ typedef enum {
 typedef struct inkpot_values_s {
 #if 0
 /* FIXME - not sure about all this ... */
-    unsigned long *         named[SZT_VTYPE];
-    unsigned long *       unnamed[SZT_VTYPE];
-    unsigned long *       palette[SZT_VTYPE];
+    uint64_t *         named[SZT_VTYPE];
+    uint64_t *       unnamed[SZT_VTYPE];
+    uint64_t *       palette[SZT_VTYPE];
     size_t          named_64_size[SZT_VTYPE];
     size_t          named_48_size[SZT_VTYPE];
     size_t          named_32_size[SZT_VTYPE];
diff --git a/lib/sfio/sfhdr.h b/lib/sfio/sfhdr.h
index 0ca6b1aa3..b9a3bb68f 100644
--- a/lib/sfio/sfhdr.h
+++ b/lib/sfio/sfhdr.h
@@ -21,6 +21,8 @@ extern "C" {
 #define _BLD_sfio	1
 #endif
 
+#include <inttypes.h>
+
 /*	Internal definitions for sfio.
 **	Written by Kiem-Phong Vo
 */
@@ -375,7 +377,7 @@ extern "C" {
 #define uchar		unsigned char
 #endif
 #ifndef ulong
-#define ulong		unsigned long
+#define ulong		uint64_t
 #endif
 #ifndef uint
 #define uint		unsigned int
diff --git a/lib/sparse/general.c b/lib/sparse/general.c
index ac9f18c18..dc1140b6b 100644
--- a/lib/sparse/general.c
+++ b/lib/sparse/general.c
@@ -354,7 +354,7 @@ int digitsQ(char *s){
 int validQ_int_string(char *to_convert, int *v){
   /* check to see if this is a string is integer */
   char *p = to_convert;
-  unsigned long val;
+  uint64_t val;
   errno = 0;
   val = strtoul(to_convert, &p, 10);
   if (errno != 0 ||// conversion failed (EINVAL, ERANGE)
diff --git a/lib/twopigen/circle.h b/lib/twopigen/circle.h
index 822f5015f..870b32252 100644
--- a/lib/twopigen/circle.h
+++ b/lib/twopigen/circle.h
@@ -21,10 +21,10 @@ extern "C" {
 #endif
 
     typedef struct {
-	unsigned long nStepsToLeaf;
-	unsigned long subtreeSize;
-	unsigned long nChildren;
-	unsigned long nStepsToCenter;
+	uint64_t nStepsToLeaf;
+	uint64_t subtreeSize;
+	uint64_t nChildren;
+	uint64_t nStepsToCenter;
 	node_t *parent;
 	double span;
 	double theta;
diff --git a/lib/vmalloc/vmhdr.h b/lib/vmalloc/vmhdr.h
index 3a2595490..5a0fe8776 100644
--- a/lib/vmalloc/vmhdr.h
+++ b/lib/vmalloc/vmhdr.h
@@ -24,6 +24,8 @@ extern "C" {
 #include <io.h>
 #endif
 
+#include <inttypes.h>
+
 /*	Common types, and macros for vmalloc functions.
 **
 **	Written by Kiem-Phong Vo, kpv@research.att.com, 01/16/94.
@@ -59,7 +61,7 @@ extern "C" {
 #undef BITS
 
     typedef unsigned char Vmuchar_t;
-    typedef unsigned long Vmulong_t;
+    typedef uint64_t Vmulong_t;
 
     typedef union _head_u Head_t;
     typedef union _body_u Body_t;
diff --git a/plugin/core/gvrender_core_vml.c b/plugin/core/gvrender_core_vml.c
index ca1f26d88..189b45db6 100644
--- a/plugin/core/gvrender_core_vml.c
+++ b/plugin/core/gvrender_core_vml.c
@@ -18,6 +18,7 @@
 #include <stdarg.h>
 #include <stdlib.h>
 #include <string.h>
+#include <inttypes.h>
 
 #include "macros.h"
 #include "const.h"
@@ -135,7 +136,7 @@ char *html_string(char *s)
     int len, pos = 0;
     int temp,cnt,remaining=0;
     char workstr[16];
-    long unsigned int charnum=0;
+    uint64_t charnum=0;
     unsigned char byte;
     unsigned char mask;
 
diff --git a/plugin/glitz/gvdevice_glitz.c b/plugin/glitz/gvdevice_glitz.c
index 192fadfc6..a9853d6a6 100644
--- a/plugin/glitz/gvdevice_glitz.c
+++ b/plugin/glitz/gvdevice_glitz.c
@@ -16,15 +16,10 @@
 #endif
 
 #include <stdio.h>
-#ifdef HAVE_STDLIB_H
 #include <stdlib.h>
-#endif
-#ifdef HAVE_STRING_H
 #include <string.h>
-#endif
-#ifdef HAVE_UNISTD_H
+#include <inttypes.h>
 #include <unistd.h>
-#endif
 #ifdef HAVE_SYS_TIME_H
 #include <sys/time.h>
 #endif
@@ -70,7 +65,7 @@
 
 typedef struct window_glitz_s {
     Window win;
-    unsigned long event_mask;
+    uint64_t event_mask;
     Pixmap pix;
     GC gc;
     Visual *visual;
@@ -283,7 +278,7 @@ static void init_window(GVJ_t *job, Display *dpy, int scr)
     XWMHints *wmhints;
     XSizeHints *normalhints;
     XClassHint *classhint;
-    unsigned long attributemask = 0;
+    uint64_t attributemask = 0;
     char *name;
     window_t *window;
 
diff --git a/plugin/xlib/gvdevice_xlib.c b/plugin/xlib/gvdevice_xlib.c
index f1a894173..56c4ec7b0 100644
--- a/plugin/xlib/gvdevice_xlib.c
+++ b/plugin/xlib/gvdevice_xlib.c
@@ -16,15 +16,10 @@
 #endif
 
 #include <stdio.h>
-#ifdef HAVE_STDLIB_H
 #include <stdlib.h>
-#endif
-#ifdef HAVE_STRING_H
 #include <string.h>
-#endif
-#ifdef HAVE_UNISTD_H
+#include <inttypes.h>
 #include <unistd.h>
-#endif
 #ifdef HAVE_SYS_TIME_H
 #include <sys/time.h>
 #endif
@@ -61,7 +56,7 @@
 
 typedef struct window_xlib_s {
     Window win;
-    unsigned long event_mask;
+    uint64_t event_mask;
     Pixmap pix;
     GC gc;
     Visual *visual;
@@ -275,7 +270,7 @@ static void init_window(GVJ_t *job, Display *dpy, int scr)
     XWMHints *wmhints;
     XSizeHints *normalhints;
     XClassHint *classhint;
-    unsigned long attributemask = 0;
+    uint64_t attributemask = 0;
     char *name;
     window_t *window;
     int w, h;
diff --git a/tclpkg/tcldot/tcldot-id.c b/tclpkg/tcldot/tcldot-id.c
index 564081177..096b2b318 100644
--- a/tclpkg/tcldot/tcldot-id.c
+++ b/tclpkg/tcldot/tcldot-id.c
@@ -24,7 +24,7 @@ static void *myiddisc_open(Agraph_t *g, Agdisc_t *disc) {
     gctx->ictx = ictx;
     return (void *)gctx;
 }
-static long myiddisc_map(void *state, int objtype, char *str, unsigned long *id, int createflag) {
+static long myiddisc_map(void *state, int objtype, char *str, uint64_t *id, int createflag) {
     gctx_t *gctx = (gctx_t *)state;
     ictx_t *ictx = gctx->ictx;
     char *s;
@@ -34,7 +34,7 @@ static long myiddisc_map(void *state, int objtype, char *str, unsigned long *id,
             s = agstrdup(gctx->g, str);
         else
             s = agstrbind(gctx->g, str);
-        *id = (unsigned long) s;
+        *id = (uint64_t) s;
     } else {
         *id = ictx->ctr;  /* counter maintained in per-interp space, so that
 		ids are unique across all graphs in the interp */
@@ -43,13 +43,13 @@ static long myiddisc_map(void *state, int objtype, char *str, unsigned long *id,
     return TRUE;
 }
 /* we don't allow users to explicitly set IDs, either */
-static long myiddisc_alloc(void *state, int objtype, unsigned long request_id) {
+static long myiddisc_alloc(void *state, int objtype, uint64_t request_id) {
     NOTUSED(state);
     NOTUSED(objtype);
     NOTUSED(request_id);
     return FALSE;
 }
-static void myiddisc_free(void *state, int objtype, unsigned long id) {
+static void myiddisc_free(void *state, int objtype, uint64_t id) {
     gctx_t *gctx = (gctx_t *)state;
 
 /* FIXME no obj* available
@@ -67,7 +67,7 @@ static void myiddisc_free(void *state, int objtype, unsigned long id) {
     if (id % 2 == 0)
         agstrfree(gctx->g, (char *) id);
 }
-static char *myiddisc_print(void *state, int objtype, unsigned long id) {
+static char *myiddisc_print(void *state, int objtype, uint64_t id) {
     NOTUSED(state);
     NOTUSED(objtype);
     if (id % 2 == 0)
diff --git a/tclpkg/tcldot/tcldot.h b/tclpkg/tcldot/tcldot.h
index 8415c0e84..2fbe49a90 100644
--- a/tclpkg/tcldot/tcldot.h
+++ b/tclpkg/tcldot/tcldot.h
@@ -46,7 +46,7 @@ Tcl_GetString(Tcl_Obj *obj) {
 typedef struct {
     Agdisc_t mydisc;    /* must be first to allow casting mydisc to ictx */
     Agiodisc_t myioDisc;
-    unsigned long ctr;  /* odd number counter for anon objects over all g's in interp */
+    uint64_t ctr;  /* odd number counter for anon objects over all g's in interp */
     Tcl_Interp *interp;
     GVC_t *gvc;
 } ictx_t;
@@ -57,7 +57,7 @@ typedef struct {
 typedef struct {
     Agraph_t *g;        /* the graph */
     ictx_t *ictx;
-    unsigned long idx; 
+    uint64_t idx; 
 } gctx_t;
 
 #if HAVE_LIBGD
diff --git a/tclpkg/tclhandle/tclhandle.c b/tclpkg/tclhandle/tclhandle.c
index eec7b8017..09962b70d 100644
--- a/tclpkg/tclhandle/tclhandle.c
+++ b/tclpkg/tclhandle/tclhandle.c
@@ -39,6 +39,7 @@
 
 #include <stdlib.h>
 #include <stdio.h>
+#include <inttypes.h>
 #include "tclhandle.h"
 /* Added 2000-09-19 by KG for memcpy, ... decls */
 #include <string.h>
@@ -128,7 +129,7 @@ static void tclhandleExpandTable(tblHeader_pt tblHdrPtr, int neededIdx)
  *-----------------------------------------------------------------------------
  */
 entryHeader_pt tclhandleAlloc(tblHeader_pt headerPtr, char *handle,
-			      unsigned long *entryIdxPtr)
+			      uint64_t *entryIdxPtr)
 {
     tblHeader_pt tblHdrPtr = (tblHeader_pt) headerPtr;
     entryHeader_pt entryPtr;
@@ -171,8 +172,8 @@ tblHeader_pt tclhandleInit(char *prefix, int entrySize, int initEntries)
      */
     if (tclhandleEntryAlignment == 0) {
 	tclhandleEntryAlignment = sizeof(void *);
-	if (sizeof(unsigned long) > tclhandleEntryAlignment)
-	    tclhandleEntryAlignment = sizeof(unsigned long);
+	if (sizeof(uint64_t) > tclhandleEntryAlignment)
+	    tclhandleEntryAlignment = sizeof(uint64_t);
 	if (sizeof(double) > tclhandleEntryAlignment)
 	    tclhandleEntryAlignment = sizeof(double);
     }
@@ -274,9 +275,9 @@ int tclhandleReset(tblHeader_pt tblHdrPtr, int initEntries)
  *-----------------------------------------------------------------------------
  */
 int tclhandleIndex(tblHeader_pt tblHdrPtr, char *handle,
-		   unsigned long *entryIdxPtr)
+		   uint64_t *entryIdxPtr)
 {
-    unsigned long entryIdx;
+    uint64_t entryIdx;
 
     if ((sscanf(handle, tblHdrPtr->handleFormat, &entryIdx)) != 1)
 	return TCL_ERROR;
@@ -297,7 +298,7 @@ int tclhandleIndex(tblHeader_pt tblHdrPtr, char *handle,
  *-----------------------------------------------------------------------------
  */
 void tclhandleString(tblHeader_pt tblHdrPtr, char *handle,
-		     unsigned long entryIdx)
+		     uint64_t entryIdx)
 {
     sprintf(handle, tblHdrPtr->handleFormat, entryIdx);
 }
@@ -314,7 +315,7 @@ void tclhandleString(tblHeader_pt tblHdrPtr, char *handle,
  *   A pointer to the entry, or NULL if an error occured.
  *-----------------------------------------------------------------------------
  */
-void *tclhandleXlateIndex(tblHeader_pt headerPtr, unsigned long entryIdx)
+void *tclhandleXlateIndex(tblHeader_pt headerPtr, uint64_t entryIdx)
 {
     tblHeader_pt tblHdrPtr = headerPtr;
     entryHeader_pt entryPtr;
@@ -342,7 +343,7 @@ void *tclhandleXlateIndex(tblHeader_pt headerPtr, unsigned long entryIdx)
  */
 void *tclhandleXlate(tblHeader_pt tblHdrPtr, char *handle)
 {
-    unsigned long entryIdx;
+    uint64_t entryIdx;
 
     if ((tclhandleIndex(tblHdrPtr, handle, &entryIdx)) != TCL_OK)
 	return NULL;
@@ -361,7 +362,7 @@ void *tclhandleXlate(tblHeader_pt tblHdrPtr, char *handle)
  *   The contents of the entry, if success, or NULL if an error occured.
  *----------------------------------------------------------------------------
  */
-void *tclhandleFreeIndex(tblHeader_pt headerPtr, unsigned long entryIdx)
+void *tclhandleFreeIndex(tblHeader_pt headerPtr, uint64_t entryIdx)
 {
     tblHeader_pt tblHdrPtr = headerPtr;
     entryHeader_pt entryPtr, freeentryPtr;
@@ -396,7 +397,7 @@ void *tclhandleFreeIndex(tblHeader_pt headerPtr, unsigned long entryIdx)
  */
 void *tclhandleFree(tblHeader_pt tblHdrPtr, char *handle)
 {
-    unsigned long entryIdx;
+    uint64_t entryIdx;
 
     if ((tclhandleIndex(tblHdrPtr, handle, &entryIdx)) != TCL_OK)
 	return NULL;
diff --git a/tclpkg/tclhandle/tclhandle.h b/tclpkg/tclhandle/tclhandle.h
index d5cf6671a..e933658ff 100644
--- a/tclpkg/tclhandle/tclhandle.h
+++ b/tclpkg/tclhandle/tclhandle.h
@@ -79,7 +79,7 @@ extern "C" {
  *    **** This macro provides no checks *****
  */
 #define TBL_ENTRY(hdrPtr, entryPtr) \
-    ((unsigned long) ((entryPtr - (hdrPtr->bodyPtr)) / (hdrPtr->entrySize)))
+    ((uint64_t) ((entryPtr - (hdrPtr->bodyPtr)) / (hdrPtr->entrySize)))
 
 /*
  * This macros to convert between pointers to the user and header area of
@@ -95,21 +95,21 @@ extern "C" {
  */
 
     void *tclhandleFreeIndex(tblHeader_pt headerPtr,
-			     unsigned long entryIdx);
+			     uint64_t entryIdx);
     void *tclhandleFree(tblHeader_pt headerPtr, char *handle);
     tblHeader_pt tclhandleInit(char *prefix, int entrySize,
 			       int initEntries);
     int tclhandleReset(tblHeader_pt tblHdrPtr, int initEntries);
     int tclhandleDestroy(tblHeader_pt tblHdrPtr);
     void *tclhandleXlateIndex(tblHeader_pt headerPtr,
-			      unsigned long entryIdx);
+			      uint64_t entryIdx);
     void *tclhandleXlate(tblHeader_pt headerPtr, char *handle);
     entryHeader_pt tclhandleAlloc(tblHeader_pt tblHdrPtr, char *handle,
-				  unsigned long *entryIdxPtr);
+				  uint64_t *entryIdxPtr);
     void tclhandleString(tblHeader_pt tblHdrPtr, char *handle,
-			 unsigned long entryIdx);
+			 uint64_t entryIdx);
     int tclhandleIndex(tblHeader_pt tblHdrPtr, char *handle,
-		       unsigned long *entryIdxPtr);
+		       uint64_t *entryIdxPtr);
 
 #ifdef __cplusplus
 }
diff --git a/tclpkg/tclpathplan/tclpathplan.c b/tclpkg/tclpathplan/tclpathplan.c
index 8a66b6a99..3d893217e 100644
--- a/tclpkg/tclpathplan/tclpathplan.c
+++ b/tclpkg/tclpathplan/tclpathplan.c
@@ -39,6 +39,7 @@
 #include                <unistd.h>
 #endif
 
+#include <inttypes.h>
 #include <assert.h>
 #include <math.h>
 #include <pathutil.h>
@@ -205,7 +206,7 @@ void triangle_callback(void *vgparg, point pqr[])
 
     if (vgp->triangle_cmd) {
 	sprintf(vbuf, "vgpane%lu",
-		(unsigned long) (((ubyte_pt) vgp - (vgpaneTable->bodyPtr))
+		(uint64_t) (((ubyte_pt) vgp - (vgpaneTable->bodyPtr))
 				 / (vgpaneTable->entrySize)));
 	expandPercentsEval(vgp->interp, vgp->triangle_cmd, vbuf, 3, pqr);
     }
-- 
2.40.0