[Tcl] Fix handling of long long on 32-bit platforms

Fixes https://sourceforge.net/p/swig/bugs/977/ reported by Vera and
Kjell Wooding.

Closes #2331
This commit is contained in:
Olly Betts 2022-07-26 14:59:42 +12:00
commit 06d375cdab
4 changed files with 38 additions and 25 deletions

View file

@ -7,6 +7,12 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
Version 4.1.0 (in progress)
===========================
2022-07-26: olly
[Tcl] https://sourceforge.net/p/swig/bugs/977/
Fix handling of long long on 32-bit platforms. This fix raises
SWIG's minimum supported Tcl version to 8.4.0 (which was released
just under 20 years ago).
2022-07-26: olly
Fix incorrect operator precedence in preprocessor expressions.

View file

@ -79,9 +79,9 @@
</p>
<p>
This chapter discusses SWIG's support of Tcl. SWIG currently requires
Tcl 8.0 or a later release. Earlier releases of SWIG supported Tcl 7.x, but
this is no longer supported.
This chapter discusses SWIG's support of Tcl. Since SWIG 4.1.0, Tcl 8.4 or a
later release is required. Prior to that earlier Tcl 8.x releases were also
supported.
</p>
<H2><a name="Tcl_nn2">37.1 Preliminaries</a></H2>

View file

@ -0,0 +1,24 @@
if [ catch { load ./integers[info sharedlibextension] integers} err_msg ] {
puts stderr "Could not load shared object:\n$err_msg"
}
set val 3902408827
if {[signed_long_identity $val] != $val} {
puts stderr "Runtime test 1 failed"
exit 1
}
if {[unsigned_long_identity $val] != $val} {
puts stderr "Runtime test 2 failed"
exit 1
}
if {[signed_long_long_identity $val] != $val} {
puts stderr "Runtime test 3 failed"
exit 1
}
if {[unsigned_long_long_identity $val] != $val} {
puts stderr "Runtime test 4 failed"
exit 1
}

View file

@ -136,30 +136,13 @@ SWIG_From_dec(long long)(long long value)
SWIGINTERN int
SWIG_AsVal_dec(long long)(Tcl_Obj *obj, long long *val)
{
long v;
if (Tcl_GetLongFromObj(0,obj, &v) == TCL_OK) {
Tcl_WideInt v;
if (Tcl_GetWideIntFromObj(0, obj, &v) == TCL_OK) {
if (sizeof(v) > sizeof(*val) && (v < LLONG_MIN || v > LLONG_MAX)) {
return SWIG_OverflowError;
}
if (val) *val = v;
return SWIG_OK;
} else {
int len = 0;
const char *nptr = Tcl_GetStringFromObj(obj, &len);
if (nptr && len > 0) {
char *endptr;
long long v;
errno = 0;
v = strtoll(nptr, &endptr,0);
if (nptr[0] == '\0' || *endptr != '\0')
return SWIG_TypeError;
if ((v == LLONG_MAX || v == LLONG_MIN) && errno == ERANGE) {
errno = 0;
return SWIG_OverflowError;
} else {
if (*endptr == '\0') {
if (val) *val = v;
return SWIG_OK;
}
}
}
}
return SWIG_TypeError;
}