Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2002-11-15
23:23 • Closed ticket [443938ffff]: malloc routines use wrong cast plus 7 other chan... artifact: f8479d0274 user: dkf
2002-04-25
19:18 • Ticket [443938ffff]: 4 changes artifact: 360e8e5995 user: dkf
2002-02-26
22:58 • Ticket [443938ffff]: 4 changes artifact: d35289bb8e user: dkf
05:11 • Ticket [443938ffff]: 5 changes artifact: d559f867e5 user: hobbs
2001-11-14
16:35 • Ticket [443938ffff]: 4 changes artifact: bc5db33c18 user: dkf
04:52 • Ticket [443938ffff]: 4 changes artifact: 005e8e4927 user: sabbahillel
00:55 • Ticket [443938ffff]: 5 changes artifact: c0a1f72a1b user: hobbs
2001-11-13
14:48 • Ticket [443938ffff]: 4 changes artifact: 80cec71a6d user: davygrvy
2001-08-08
03:17 • Ticket [443938ffff]: 4 changes artifact: 18d2bfd015 user: sabbahillel
00:15 • Open ticket [443938ffff]. artifact: 94ce9327f0 user: hobbs
2001-08-07
20:32 • Ticket [443938ffff]: 4 changes artifact: 0fc6b79ab9 user: sabbahillel
06:40 • Closed ticket [443938ffff]. artifact: f81a0efa78 user: hobbs
2001-07-25
05:47 • Ticket [443938ffff]: 1 change artifact: 497c4b71bd user: dgp
2001-07-23
22:34 • New ticket [443938ffff]. artifact: a31a6b7b9e user: nobody

malloc routines use wrong cast

Closed / Later443938ffffffffffffffffffffffffffffffffffCreated 25 years agoUpdated 24 years ago
Descriptionplain2001-07-23 22:34:35
The malloc/ckalloc routines such as tcl_Allooc are defined with the size variable explicitly set to 
"unsigned int".  They should be set to "size_t" (typdef in stdlib.h).  When built on a 64 bit platform 
such as DEC TRU-64 or Solaris 8 (64 bit mode), this definition causes the programs to build 
improperly. There were also usages of strncmp and sizeof that were coded as if they were 
expected to return "unsigne int" instead of "size_t" (unsigned long).

Compiled with gcc 3.0 as well as Solaris 8 Workshop 6.0 cc and DEC V5.1 cc
dgp Ticket [443938ffff]: 1 change [History diff]2001-07-25 05:47:44
hobbsplain2001-08-07 06:40:26
Logged In: YES 
user_id=72656

Unfortunately you can't change those procedures because 
changing size decls would cause binary incompatability in 
the stubs mechanism.  That they are declared as uints might 
not be optimal, but it is perfectly OK.
sabbahillelplain2001-08-07 20:32:32
Logged In: YES 
user_id=286923

The point is that when compiled in 64 bit mode, uint is actually fatal.  In order to prevent errors, these 
"unsigned int" declarations must be changed to "unsigned long".  When compiled in 32 bit mode, uint an 
ulong are the same.  However, when compiled in DEC TRU64, or on Solaris 7 or 8 (gcc -m64), there is abinary 
incompatibility and it is a fatal compilation error not to use unsigned long.

-- 
Said the fox to the fish, "Join me ashore".
The fish are the Jews, Torah is our water.

Hillel (Sabba) Markowitz
[email protected], [email protected]
hobbsplain2001-08-08 00:15:48
Logged In: YES 
user_id=72656

I'm still inclined to call this invalid, because I have 
compiled Tcl countless times on Solaris64 in 64-bit mode 
without fatal compilation errors (and it works), as well as 
Tru64.  I'll look into it though (and make sure gcc isn't 
blowing smoke where the native compilers are OK).
sabbahillelplain2001-08-08 03:17:12
Logged In: YES 
user_id=286923

The main problem seems to be that the size_t variables are declared as "(unsigned)" which defaults to 
"unsigned int". gcc points out that the parameters are a different width when long and int are different (in 
64 bit mode). Even if it happens to work out, it should still be cased explicitly as (unsigned long) just to be 
certain. When compiled in 32 bit mode, it won't make a difference (since long = int) but it will make certain 
that 64 bit does not go bad.

Even if it were not fatal, it would be better to do it correctly as the actual data passed through gets 
corrupted.
davygrvyplain2001-11-13 14:48:29
Logged In: YES 
user_id=7549

I agree with sabbahillel.

If we let the native size of "The maximum number of bytes to 
which a pointer can refer" that size_t is (at least in ISO
C), and express it to the outside, porting to 64 shouldn't
be this hard as it is.

Jeff, you refer to binary compatibility, but what is int???
Would that be the same as long, or __int32?  Same problem for WIN64, too.
hobbsplain2001-11-14 00:55:10
Logged In: YES 
user_id=72656

int is 4 bytes on most systems, whereas size_t is 8.  This 
will break binary compatability with all stubs-based 
extensions.  IOW, no can do in 8.x.
sabbahillelplain2001-11-14 04:52:55
Logged In: YES 
user_id=286923

Then at the very least the "(unsigned) ckalloc" references should be changed to "(unsigned long) ckalloc"

I went through the code by hand and the changes do appear to work correctly.

[email protected] or [email protected]
dkfplain2001-11-14 16:35:16
Logged In: YES 
user_id=79902

It is possible to upgrade the stub table so that new
compilations use the new-type API but existing extensions
use the old-type API (this is one of the things that Stubs
gives us that no ordinary link mechanism can) but it is
quite a bit of work.
hobbsplain2002-02-26 05:11:55
Logged In: YES 
user_id=72656

It has to be noted that ckalloc != malloc, so sticking with 
unsigned int is OK.  You can't just always cast to long and 
think you are going to be able to alloc > 4GB of data on 
LP64 machines.  This looks like something that may fall 
into the TIP 72 64-bit updates.
dkfplain2002-02-26 22:58:37
Logged In: YES 
user_id=79902

Not really; TIP#72 only really covers changes to get 64bits
on 32bit machines. I'll have a look at fixing up *alloc
sometime though.
dkfplain2002-04-25 19:18:37
Logged In: YES 
user_id=79902

See also Bug #219196
dkfplain2002-11-15 23:23:19
Logged In: YES 
user_id=79902

Addressed as part of TIP #115 - closing this bug because the 
fix will be driven from a different direction.
Log in (anonymous is fine) to add a comment.