|
2011-09-06
| ||
| 21:49 | • Ticket [2308236fff] signature of Tcl_HashStats() wrong status still Closed w... artifact: 85489fe854 user: nijtmans | |
| 21:35 | • Ticket [2308236fff]: 4 changes artifact: 7bccbfc626 user: dgp | |
|
2008-11-19
| ||
| 05:04 | • Ticket [2308236fff]: 4 changes artifact: 97b8caf3cd user: nijtmans | |
| 05:02 | • Ticket [2308236fff]: 4 changes artifact: 8310d9f3dd user: nijtmans | |
|
2008-11-18
| ||
| 22:21 | • Ticket [2308236fff]: 4 changes artifact: 6ecc70810f user: dgp | |
| 14:04 | • Ticket [2308236fff]: 4 changes artifact: 56dd4040f3 user: nijtmans | |
| 14:04 | • Closed ticket [2308236fff]. artifact: 1fd5c1d89a user: nijtmans | |
| 06:32 | • New ticket [2308236fff]. artifact: a76d48f827 user: nijtmans | |
signature of Tcl_HashStats() wrong
Closed / Fixed2308236fffffffffffffffffffffffffffffffffCreated 18 years agoUpdated 15 years ago
Descriptionplain2008-11-18 06:32:51
Although the documentation states that this function returns a malloc'ed string, it's
return type was const char*. This means that, since Tcl 8.4, users are forced to
use an unsafe type cast to used it:
char *s = (char *)Tcl_HashStats(....)
....
ckfree(s);
Fixing the signature has the effect that this type cast is no longer
neccessary, so it is fully source and binary compatible.
The signature is wrong since the implementation of TIP #27
in Tcl 8.4
nijtmans Closed ticket [2308236fff].
[History diff]2008-11-18 14:04:19
nijtmansplain2008-11-18 14:04:34
fixed and backported to Tcl 8.5 branch
dgpplain2008-11-18 22:21:54
Just for the record, this change wasn't backported for 8.4.20, and I think that's the right decision.
nijtmansplain2008-11-19 05:02:37
Just for the record (2): This is how Tcl_HashStats() must be used in Tcl 8.5:
char *s = (char *)Tcl_HashStats(t);
...... do something with it
if (t->typePtr->flags & TCL_HASH_KEY_SYSTEM_HASH) {
TclpSysFree((char *) tablePtr->buckets);
} else {
ckfree((char *) tablePtr->buckets);
}
The documentation didn't mention this, and apart from that the
function TclpSysFree is not in the public API. So in Tcl 8.6 I modified
this simply to:
char *s = Tcl_HashStats(t);
...... do something with it
ckfree((char *) tablePtr->buckets);
I don't think that anyone would use Tcl_HashStats with
hash tables with the TCL_HASH_KEY_SYSTEM_HASH flag
set, so in practice it doesn't make a difference.
At least, in Tcl 8.6 the function works now as documented.
In Tcl 8.5 the signature is changed such that a type cast
is not needed any more, but the further behavior is unchanged.
nijtmansplain2008-11-19 05:04:48
Oops, here are the right code snappets:
In Tcl 8.5:
char *s = (char *)Tcl_HashStats(t);
...... do something with it
if (t->typePtr->flags & TCL_HASH_KEY_SYSTEM_HASH) {
TclpSysFree(s);
} else {
ckfree(s);
}
In Tcl 8.6:
char *s = Tcl_HashStats(t);
...... do something with it
ckfree(s);
dgpplain2011-09-06 21:35:06
Now backported for 8.4.20 for reasons that are unclear but not worth arguing about to me.
nijtmansplain2011-09-06 21:49:43
allow_comments - 1 >Now backported for 8.4.20 for reasons >that are unclear but not worth arguing about to me. The reason is simple: I totally forgot about this already existing issue, and at that time I didn't think there ever would be a new Tcl 8.4 release...
Log in (anonymous is fine) to add a comment.