Created
December 22, 2018 13:39
-
-
Save paulhankin/c174ae539ae7ebdc1912d8ed30cd1c08 to your computer and use it in GitHub Desktop.
patch for triangle.c to make it 64bit clean
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/triangle.c b/triangle.c | |
index f9e23fa..06cba71 100644 | |
--- a/triangle.c | |
+++ b/triangle.c | |
@@ -342,11 +342,8 @@ | |
#define ONETHIRD 0.333333333333333333333333333333333333333333333333333333333333 | |
- | |
-#include <inttypes.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
-#include <stdint.h> | |
#include <string.h> | |
#include <math.h> | |
#ifndef NO_TIMER | |
@@ -943,16 +940,16 @@ int minus1mod3[3] = {2, 0, 1}; | |
/* extracted from the two least significant bits of the pointer. */ | |
#define decode(ptr, otri) \ | |
- (otri).orient = (int) ((uintptr_t) (ptr) & (uintptr_t) 3l); \ | |
+ (otri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); \ | |
(otri).tri = (triangle *) \ | |
- ((uintptr_t) (ptr) ^ (uintptr_t) (otri).orient) | |
+ ((unsigned long) (ptr) ^ (unsigned long) (otri).orient) | |
/* encode() compresses an oriented triangle into a single pointer. It */ | |
/* relies on the assumption that all triangles are aligned to four-byte */ | |
/* boundaries, so the two least significant bits of (otri).tri are zero. */ | |
#define encode(otri) \ | |
- (triangle) ((uintptr_t) (otri).tri | (uintptr_t) (otri).orient) | |
+ (triangle) ((unsigned long) (otri).tri | (unsigned long) (otri).orient) | |
/* The following handle manipulation primitives are all described by Guibas */ | |
/* and Stolfi. However, Guibas and Stolfi use an edge-based data */ | |
@@ -1116,16 +1113,16 @@ int minus1mod3[3] = {2, 0, 1}; | |
#define infect(otri) \ | |
(otri).tri[6] = (triangle) \ | |
- ((uintptr_t) (otri).tri[6] | (uintptr_t) 2l) | |
+ ((unsigned long) (otri).tri[6] | (unsigned long) 2l) | |
#define uninfect(otri) \ | |
(otri).tri[6] = (triangle) \ | |
- ((uintptr_t) (otri).tri[6] & ~ (uintptr_t) 2l) | |
+ ((unsigned long) (otri).tri[6] & ~ (unsigned long) 2l) | |
/* Test a triangle for viral infection. */ | |
#define infected(otri) \ | |
- (((uintptr_t) (otri).tri[6] & (uintptr_t) 2l) != 0l) | |
+ (((unsigned long) (otri).tri[6] & (unsigned long) 2l) != 0l) | |
/* Check or set a triangle's attributes. */ | |
@@ -1163,16 +1160,16 @@ int minus1mod3[3] = {2, 0, 1}; | |
/* are masked out to produce the real pointer. */ | |
#define sdecode(sptr, osub) \ | |
- (osub).ssorient = (int) ((uintptr_t) (sptr) & (uintptr_t) 1l); \ | |
+ (osub).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); \ | |
(osub).ss = (subseg *) \ | |
- ((uintptr_t) (sptr) & ~ (uintptr_t) 3l) | |
+ ((unsigned long) (sptr) & ~ (unsigned long) 3l) | |
/* sencode() compresses an oriented subsegment into a single pointer. It */ | |
/* relies on the assumption that all subsegments are aligned to two-byte */ | |
/* boundaries, so the least significant bit of (osub).ss is zero. */ | |
#define sencode(osub) \ | |
- (subseg) ((uintptr_t) (osub).ss | (uintptr_t) (osub).ssorient) | |
+ (subseg) ((unsigned long) (osub).ss | (unsigned long) (osub).ssorient) | |
/* ssym() toggles the orientation of a subsegment. */ | |
@@ -3680,27 +3677,27 @@ struct otri *t; | |
struct osub printsh; | |
vertex printvertex; | |
- printf("triangle x%" PRIxPTR " with orientation %d:\n", (uintptr_t) t->tri, | |
+ printf("triangle x%lx with orientation %d:\n", (unsigned long) t->tri, | |
t->orient); | |
decode(t->tri[0], printtri); | |
if (printtri.tri == m->dummytri) { | |
printf(" [0] = Outer space\n"); | |
} else { | |
- printf(" [0] = x%" PRIxPTR " %d\n", (uintptr_t) printtri.tri, | |
+ printf(" [0] = x%lx %d\n", (unsigned long) printtri.tri, | |
printtri.orient); | |
} | |
decode(t->tri[1], printtri); | |
if (printtri.tri == m->dummytri) { | |
printf(" [1] = Outer space\n"); | |
} else { | |
- printf(" [1] = x%" PRIxPTR " %d\n", (uintptr_t) printtri.tri, | |
+ printf(" [1] = x%lx %d\n", (unsigned long) printtri.tri, | |
printtri.orient); | |
} | |
decode(t->tri[2], printtri); | |
if (printtri.tri == m->dummytri) { | |
printf(" [2] = Outer space\n"); | |
} else { | |
- printf(" [2] = x%" PRIxPTR " %d\n", (uintptr_t) printtri.tri, | |
+ printf(" [2] = x%lx %d\n", (unsigned long) printtri.tri, | |
printtri.orient); | |
} | |
@@ -3708,38 +3705,38 @@ struct otri *t; | |
if (printvertex == (vertex) NULL) | |
printf(" Origin[%d] = NULL\n", (t->orient + 1) % 3 + 3); | |
else | |
- printf(" Origin[%d] = x%" PRIxPTR " (%.12g, %.12g)\n", | |
- (t->orient + 1) % 3 + 3, (uintptr_t) printvertex, | |
+ printf(" Origin[%d] = x%lx (%.12g, %.12g)\n", | |
+ (t->orient + 1) % 3 + 3, (unsigned long) printvertex, | |
printvertex[0], printvertex[1]); | |
dest(*t, printvertex); | |
if (printvertex == (vertex) NULL) | |
printf(" Dest [%d] = NULL\n", (t->orient + 2) % 3 + 3); | |
else | |
- printf(" Dest [%d] = x%" PRIxPTR " (%.12g, %.12g)\n", | |
- (t->orient + 2) % 3 + 3, (uintptr_t) printvertex, | |
+ printf(" Dest [%d] = x%lx (%.12g, %.12g)\n", | |
+ (t->orient + 2) % 3 + 3, (unsigned long) printvertex, | |
printvertex[0], printvertex[1]); | |
apex(*t, printvertex); | |
if (printvertex == (vertex) NULL) | |
printf(" Apex [%d] = NULL\n", t->orient + 3); | |
else | |
- printf(" Apex [%d] = x%" PRIxPTR " (%.12g, %.12g)\n", | |
- t->orient + 3, (uintptr_t) printvertex, | |
+ printf(" Apex [%d] = x%lx (%.12g, %.12g)\n", | |
+ t->orient + 3, (unsigned long) printvertex, | |
printvertex[0], printvertex[1]); | |
if (b->usesegments) { | |
sdecode(t->tri[6], printsh); | |
if (printsh.ss != m->dummysub) { | |
- printf(" [6] = x%" PRIxPTR " %d\n", (uintptr_t) printsh.ss, | |
+ printf(" [6] = x%lx %d\n", (unsigned long) printsh.ss, | |
printsh.ssorient); | |
} | |
sdecode(t->tri[7], printsh); | |
if (printsh.ss != m->dummysub) { | |
- printf(" [7] = x%" PRIxPTR " %d\n", (uintptr_t) printsh.ss, | |
+ printf(" [7] = x%lx %d\n", (unsigned long) printsh.ss, | |
printsh.ssorient); | |
} | |
sdecode(t->tri[8], printsh); | |
if (printsh.ss != m->dummysub) { | |
- printf(" [8] = x%" PRIxPTR " %d\n", (uintptr_t) printsh.ss, | |
+ printf(" [8] = x%lx %d\n", (unsigned long) printsh.ss, | |
printsh.ssorient); | |
} | |
} | |
@@ -3774,20 +3771,20 @@ struct osub *s; | |
struct otri printtri; | |
vertex printvertex; | |
- printf("subsegment x%" PRIxPTR " with orientation %d and mark %d:\n", | |
- (uintptr_t) s->ss, s->ssorient, mark(*s)); | |
+ printf("subsegment x%lx with orientation %d and mark %d:\n", | |
+ (unsigned long) s->ss, s->ssorient, mark(*s)); | |
sdecode(s->ss[0], printsh); | |
if (printsh.ss == m->dummysub) { | |
printf(" [0] = No subsegment\n"); | |
} else { | |
- printf(" [0] = x%" PRIxPTR " %d\n", (uintptr_t) printsh.ss, | |
+ printf(" [0] = x%lx %d\n", (unsigned long) printsh.ss, | |
printsh.ssorient); | |
} | |
sdecode(s->ss[1], printsh); | |
if (printsh.ss == m->dummysub) { | |
printf(" [1] = No subsegment\n"); | |
} else { | |
- printf(" [1] = x%" PRIxPTR " %d\n", (uintptr_t) printsh.ss, | |
+ printf(" [1] = x%lx %d\n", (unsigned long) printsh.ss, | |
printsh.ssorient); | |
} | |
@@ -3795,29 +3792,29 @@ struct osub *s; | |
if (printvertex == (vertex) NULL) | |
printf(" Origin[%d] = NULL\n", 2 + s->ssorient); | |
else | |
- printf(" Origin[%d] = x%" PRIxPTR " (%.12g, %.12g)\n", | |
- 2 + s->ssorient, (uintptr_t) printvertex, | |
+ printf(" Origin[%d] = x%lx (%.12g, %.12g)\n", | |
+ 2 + s->ssorient, (unsigned long) printvertex, | |
printvertex[0], printvertex[1]); | |
sdest(*s, printvertex); | |
if (printvertex == (vertex) NULL) | |
printf(" Dest [%d] = NULL\n", 3 - s->ssorient); | |
else | |
- printf(" Dest [%d] = x%" PRIxPTR " (%.12g, %.12g)\n", | |
- 3 - s->ssorient, (uintptr_t) printvertex, | |
+ printf(" Dest [%d] = x%lx (%.12g, %.12g)\n", | |
+ 3 - s->ssorient, (unsigned long) printvertex, | |
printvertex[0], printvertex[1]); | |
decode(s->ss[6], printtri); | |
if (printtri.tri == m->dummytri) { | |
printf(" [6] = Outer space\n"); | |
} else { | |
- printf(" [6] = x%" PRIxPTR " %d\n", (uintptr_t) printtri.tri, | |
+ printf(" [6] = x%lx %d\n", (unsigned long) printtri.tri, | |
printtri.orient); | |
} | |
decode(s->ss[7], printtri); | |
if (printtri.tri == m->dummytri) { | |
printf(" [7] = Outer space\n"); | |
} else { | |
- printf(" [7] = x%" PRIxPTR " %d\n", (uintptr_t) printtri.tri, | |
+ printf(" [7] = x%lx %d\n", (unsigned long) printtri.tri, | |
printtri.orient); | |
} | |
@@ -3825,15 +3822,15 @@ struct osub *s; | |
if (printvertex == (vertex) NULL) | |
printf(" Segment origin[%d] = NULL\n", 4 + s->ssorient); | |
else | |
- printf(" Segment origin[%d] = x%" PRIxPTR " (%.12g, %.12g)\n", | |
- 4 + s->ssorient, (uintptr_t) printvertex, | |
+ printf(" Segment origin[%d] = x%lx (%.12g, %.12g)\n", | |
+ 4 + s->ssorient, (unsigned long) printvertex, | |
printvertex[0], printvertex[1]); | |
segdest(*s, printvertex); | |
if (printvertex == (vertex) NULL) | |
printf(" Segment dest [%d] = NULL\n", 5 - s->ssorient); | |
else | |
- printf(" Segment dest [%d] = x%" PRIxPTR " (%.12g, %.12g)\n", | |
- 5 - s->ssorient, (uintptr_t) printvertex, | |
+ printf(" Segment dest [%d] = x%lx (%.12g, %.12g)\n", | |
+ 5 - s->ssorient, (unsigned long) printvertex, | |
printvertex[0], printvertex[1]); | |
} | |
@@ -3896,7 +3893,7 @@ struct memorypool *pool; | |
#endif /* not ANSI_DECLARATORS */ | |
{ | |
- uintptr_t alignptr = 0; | |
+ unsigned long alignptr; | |
pool->items = 0; | |
pool->maxitems = 0; | |
@@ -3904,11 +3901,11 @@ struct memorypool *pool; | |
/* Set the currently active block. */ | |
pool->nowblock = pool->firstblock; | |
/* Find the first item in the pool. Increment by the size of (VOID *). */ | |
- alignptr = (uintptr_t) (pool->nowblock + 1); | |
+ alignptr = (unsigned long) (pool->nowblock + 1); | |
/* Align the item on an `alignbytes'-byte boundary. */ | |
pool->nextitem = (VOID *) | |
- (alignptr + (uintptr_t) pool->alignbytes - | |
- (alignptr % (uintptr_t) pool->alignbytes)); | |
+ (alignptr + (unsigned long) pool->alignbytes - | |
+ (alignptr % (unsigned long) pool->alignbytes)); | |
/* There are lots of unallocated items left in this block. */ | |
pool->unallocateditems = pool->itemsfirstblock; | |
/* The stack of deallocated items is empty. */ | |
@@ -4013,7 +4010,7 @@ struct memorypool *pool; | |
{ | |
VOID *newitem; | |
VOID **newblock; | |
- uintptr_t alignptr = 0; | |
+ unsigned long alignptr; | |
/* First check the linked list of dead items. If the list is not */ | |
/* empty, allocate an item from the list rather than a fresh one. */ | |
@@ -4038,11 +4035,11 @@ struct memorypool *pool; | |
pool->nowblock = (VOID **) *(pool->nowblock); | |
/* Find the first item in the block. */ | |
/* Increment by the size of (VOID *). */ | |
- alignptr = (uintptr_t) (pool->nowblock + 1); | |
+ alignptr = (unsigned long) (pool->nowblock + 1); | |
/* Align the item on an `alignbytes'-byte boundary. */ | |
pool->nextitem = (VOID *) | |
- (alignptr + (uintptr_t) pool->alignbytes - | |
- (alignptr % (uintptr_t) pool->alignbytes)); | |
+ (alignptr + (unsigned long) pool->alignbytes - | |
+ (alignptr % (unsigned long) pool->alignbytes)); | |
/* There are lots of unallocated items left in this block. */ | |
pool->unallocateditems = pool->itemsperblock; | |
} | |
@@ -4097,16 +4094,16 @@ struct memorypool *pool; | |
#endif /* not ANSI_DECLARATORS */ | |
{ | |
- uintptr_t alignptr = 0; | |
+ unsigned long alignptr; | |
/* Begin the traversal in the first block. */ | |
pool->pathblock = pool->firstblock; | |
/* Find the first item in the block. Increment by the size of (VOID *). */ | |
- alignptr = (uintptr_t) (pool->pathblock + 1); | |
+ alignptr = (unsigned long) (pool->pathblock + 1); | |
/* Align with item on an `alignbytes'-byte boundary. */ | |
pool->pathitem = (VOID *) | |
- (alignptr + (uintptr_t) pool->alignbytes - | |
- (alignptr % (uintptr_t) pool->alignbytes)); | |
+ (alignptr + (unsigned long) pool->alignbytes - | |
+ (alignptr % (unsigned long) pool->alignbytes)); | |
/* Set the number of items left in the current block. */ | |
pool->pathitemsleft = pool->itemsfirstblock; | |
} | |
@@ -4134,7 +4131,7 @@ struct memorypool *pool; | |
{ | |
VOID *newitem; | |
- uintptr_t alignptr = 0; | |
+ unsigned long alignptr; | |
/* Stop upon exhausting the list of items. */ | |
if (pool->pathitem == pool->nextitem) { | |
@@ -4146,11 +4143,11 @@ struct memorypool *pool; | |
/* Find the next block. */ | |
pool->pathblock = (VOID **) *(pool->pathblock); | |
/* Find the first item in the block. Increment by the size of (VOID *). */ | |
- alignptr = (uintptr_t) (pool->pathblock + 1); | |
+ alignptr = (unsigned long) (pool->pathblock + 1); | |
/* Align with item on an `alignbytes'-byte boundary. */ | |
pool->pathitem = (VOID *) | |
- (alignptr + (uintptr_t) pool->alignbytes - | |
- (alignptr % (uintptr_t) pool->alignbytes)); | |
+ (alignptr + (unsigned long) pool->alignbytes - | |
+ (alignptr % (unsigned long) pool->alignbytes)); | |
/* Set the number of items left in the current block. */ | |
pool->pathitemsleft = pool->itemsperblock; | |
} | |
@@ -4202,16 +4199,16 @@ int subsegbytes; | |
#endif /* not ANSI_DECLARATORS */ | |
{ | |
- uintptr_t alignptr = 0; | |
+ unsigned long alignptr; | |
/* Set up `dummytri', the `triangle' that occupies "outer space." */ | |
m->dummytribase = (triangle *) trimalloc(trianglebytes + | |
m->triangles.alignbytes); | |
/* Align `dummytri' on a `triangles.alignbytes'-byte boundary. */ | |
- alignptr = (uintptr_t) m->dummytribase; | |
+ alignptr = (unsigned long) m->dummytribase; | |
m->dummytri = (triangle *) | |
- (alignptr + (uintptr_t) m->triangles.alignbytes - | |
- (alignptr % (uintptr_t) m->triangles.alignbytes)); | |
+ (alignptr + (unsigned long) m->triangles.alignbytes - | |
+ (alignptr % (unsigned long) m->triangles.alignbytes)); | |
/* Initialize the three adjoining triangles to be "outer space." These */ | |
/* will eventually be changed by various bonding operations, but their */ | |
/* values don't really matter, as long as they can legally be */ | |
@@ -4231,10 +4228,10 @@ int subsegbytes; | |
m->dummysubbase = (subseg *) trimalloc(subsegbytes + | |
m->subsegs.alignbytes); | |
/* Align `dummysub' on a `subsegs.alignbytes'-byte boundary. */ | |
- alignptr = (uintptr_t) m->dummysubbase; | |
+ alignptr = (unsigned long) m->dummysubbase; | |
m->dummysub = (subseg *) | |
- (alignptr + (uintptr_t) m->subsegs.alignbytes - | |
- (alignptr % (uintptr_t) m->subsegs.alignbytes)); | |
+ (alignptr + (unsigned long) m->subsegs.alignbytes - | |
+ (alignptr % (unsigned long) m->subsegs.alignbytes)); | |
/* Initialize the two adjoining subsegments to be the omnipresent */ | |
/* subsegment. These will eventually be changed by various bonding */ | |
/* operations, but their values don't really matter, as long as they */ | |
@@ -4591,7 +4588,7 @@ int number; | |
{ | |
VOID **getblock; | |
char *foundvertex; | |
- uintptr_t alignptr = 0; | |
+ unsigned long alignptr; | |
int current; | |
getblock = m->vertices.firstblock; | |
@@ -4608,9 +4605,9 @@ int number; | |
} | |
/* Now find the right vertex. */ | |
- alignptr = (uintptr_t) (getblock + 1); | |
- foundvertex = (char *) (alignptr + (uintptr_t) m->vertices.alignbytes - | |
- (alignptr % (uintptr_t) m->vertices.alignbytes)); | |
+ alignptr = (unsigned long) (getblock + 1); | |
+ foundvertex = (char *) (alignptr + (unsigned long) m->vertices.alignbytes - | |
+ (alignptr % (unsigned long) m->vertices.alignbytes)); | |
return (vertex) (foundvertex + m->vertices.itembytes * (number - current)); | |
} | |
@@ -7654,7 +7651,7 @@ struct otri *searchtri; | |
char *firsttri; | |
struct otri sampletri; | |
vertex torg, tdest; | |
- uintptr_t alignptr = 0; | |
+ unsigned long alignptr; | |
REAL searchdist, dist; | |
REAL ahead; | |
long samplesperblock, totalsamplesleft, samplesleft; | |
@@ -7726,11 +7723,11 @@ struct otri *searchtri; | |
population = totalpopulation; | |
} | |
/* Find a pointer to the first triangle in the block. */ | |
- alignptr = (uintptr_t) (sampleblock + 1); | |
+ alignptr = (unsigned long) (sampleblock + 1); | |
firsttri = (char *) (alignptr + | |
- (uintptr_t) m->triangles.alignbytes - | |
+ (unsigned long) m->triangles.alignbytes - | |
(alignptr % | |
- (uintptr_t) m->triangles.alignbytes)); | |
+ (unsigned long) m->triangles.alignbytes)); | |
/* Choose `samplesleft' randomly sampled triangles in this block. */ | |
do { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment