From: SourceForge.net <no...@so...> - 2010-12-01 19:39:38
|
Bugs item #2485751, was opened at 2009-01-04 09:59 Message generated for change (Comment added) made by pdokj You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=101645&aid=2485751&group_id=1645 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: tcl Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Vera (vera_soft) Assigned to: Nobody/Anonymous (nobody) Summary: Tcl wrong int64 parameter Initial Comment: I wrote a C function, expecting "long long" as parameter: int c_my (long long big_offset); With SWIG I have an interface to Tcl. In Tcl I call: c_my 3000000000 in C (c_my) I got: big_offset = -1294967296. There is an bug in SWIG_AsVal_long_SS_long. The whole discussion is in comp.lang.tcl Subj:"64 bit integers (long long)" Here is my (working) hotfix. Replace all the code in SWIG_AsVal_long_SS_long with: SWIGINTERN int SWIG_AsVal_long_SS_long SWIG_TCL_DECL_ARGS_2(Tcl_Obj *obj, long long *val) { if (Tcl_GetWideIntFromObj(0, obj, val) != TCL_OK) { return SWIG_TypeError; } return SWIG_OK; } ---------------------------------------------------------------------- Comment By: Kjell Wooding (pdokj) Date: 2010-12-01 12:39 Message: --- tclprimtypes.swg.orig 2010-12-01 12:11:23.000000000 -0700 +++ tclprimtypes.swg 2010-12-01 12:30:40.000000000 -0700 @@ -133,11 +133,11 @@ SWIGINTERN int SWIG_AsVal_dec(long long)(Tcl_Obj *obj, long long *val) { - long v; - if (Tcl_GetLongFromObj(0,obj, &v) == TCL_OK) { - if (val) *val = v; - return SWIG_OK; - } else { + /* + * XXX Bug - remove incorrect optimization. + * Optimized fix needs GetWideIntFromObj (tcl >=8.4), so + * just remove it for now + */ int len = 0; const char *nptr = Tcl_GetStringFromObj(obj, &len); if (nptr && len > 0) { @@ -157,7 +157,6 @@ } } } - } return SWIG_TypeError; } } ---------------------------------------------------------------------- Comment By: Kjell Wooding (pdokj) Date: 2010-12-01 12:38 Message: This is still a bug in 2.0.1. The problem is in tclprimtypes.swg: SWIGINTERN int SWIG_AsVal_dec(long long)(Tcl_Obj *obj, long long *val) { long v; if (Tcl_GetLongFromObj(0,obj, &v) == TCL_OK) { if (val) *val = v; return SWIG_OK; } else { ... When trying to convert a signed int64 (long long), this code attempts to convert first to a signed int32 (long). If the input is positive, but between 2^31 and 2^32, the conversion attempt will appear to succeed (at least, with the supplied test), but will cast the result to a negative quantity) The solution is to not do this silly optimization at all, or to require Tcl >=8.4, and change this call to Tcl_GetWideIntFromObj Patch attached. Please fix this, as spending a day chasing a bug that was identified back in 2009 is no kind of fun. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=101645&aid=2485751&group_id=1645 |