[MINC-development] "Amusing" mincblur issue...
Andrew Janke
a.janke at gmail.com
Wed Nov 26 19:07:42 EST 2008
Hrm, seems like this is more endemic than I originally thought...
Get this:
http://mavis.anu.edu.au/minc-beta/parsetest.tar.gz
Make it. (or use my prebuilt intrepid ones) then do this:
(on 64 bit)
ben:parsetest$ ./parsetest64 -a -b; ./parsetest64 -b -a
result a:1 b:1
result a:1 b:0
(on 32 bit)
mavis:parsetest$ ./parsetest32 -a -b; ./parsetest64 -b -a
result a:1 b:1
result a:1 b:1
oops.
As for a fix I went digging to see what the tcl/tk people do (given
that this is their library to start with) and found this:
http://tktoolkit.cvs.sourceforge.net/viewvc/tktoolkit/tk/generic/tkArgv.c?revision=1.17&view=markup
Specifically:
173 switch (infoPtr->type) {
174 case TK_ARGV_CONSTANT:
175 *((int *) infoPtr->dst) = PTR2INT(infoPtr->src);
176 break;
Interesting, Macros... and what pray tell are these macros?
http://tktoolkit.cvs.sourceforge.net/viewvc/tktoolkit/tk/generic/tkInt.h?view=markup
Gives us this little bit of blah:
69 /*
70 * Macros used to cast between pointers and integers (e.g. when
storing an int
71 * in ClientData), on 64-bit architectures they avoid gcc
warning about "cast
72 * to/from pointer from/to integer of different size".
73 */
74
75 #if !defined(INT2PTR) && !defined(PTR2INT)
76 # if defined(HAVE_INTPTR_T) || defined(intptr_t)
77 # define INT2PTR(p) ((void*)(intptr_t)(p))
78 # define PTR2INT(p) ((int)(intptr_t)(p))
79 # else
80 # define INT2PTR(p) ((void*)(p))
81 # define PTR2INT(p) ((int)(p))
82 # endif
83 #endif
84 #if !defined(UINT2PTR) && !defined(PTR2UINT)
85 # if defined(HAVE_UINTPTR_T) || defined(uintptr_t)
86 # define UINT2PTR(p) ((void*)(uintptr_t)(p))
87 # define PTR2UINT(p) ((unsigned int)(uintptr_t)(p))
88 # else
89 # define UINT2PTR(p) ((void*)(p))
90 # define PTR2UINT(p) ((unsigned int)(p))
91 # endif
92 #endif
So do we just do this:
ben:libsrc$ cvs diff ParseArgv.c
Index: ParseArgv.c
===================================================================
RCS file: /private-cvsroot/minc/libsrc/ParseArgv.c,v
retrieving revision 6.9
diff -u -b -B -r6.9 ParseArgv.c
--- ParseArgv.c 12 Aug 2008 05:00:23 -0000 6.9
+++ ParseArgv.c 27 Nov 2008 00:05:45 -0000
@@ -27,6 +27,8 @@
#include <math.h>
#include <ParseArgv.h>
+#define PTR2INT(p) ((int)(p))
+
/*
* Default table of argument descriptors. These are normally available
* in every application.
@@ -174,7 +176,7 @@
infoPtr = matchPtr;
switch (infoPtr->type) {
case ARGV_CONSTANT:
- *((long *) infoPtr->dst) = (long) infoPtr->src;
+ *((int *) infoPtr->dst) = PTR2INT(infoPtr->src);
break;
case ARGV_INT:
nargs = (int) infoPtr->src;
Which then gives up this result:
ben:parsetest$ ./parsetest -a -b
result a:1 b:1
ben:parsetest$ ./parsetest -b -a
result a:1 b:1
Which is "correct", but now spits a compiler warning for minc (amongst
others). The question is will this cause other bugs to creep in.
blah.
Thoughts?
a
More information about the MINC-development
mailing list