Tcl_Free vs ckfree

0 views
Skip to first unread message

Cary O'Brien

unread,
Apr 22, 1999, 3:00:00 AM4/22/99
to
I'm having trouble getting a loadable module to load. The problem
is that it can't resolve Tcl_Free in the stand-alone tcl program.
I do some digging and find that in identical situations, libraries
use ckfree rather than Tcl_Free. I.E. tclX, after a Tcl_SplitList,
uses ckfree rather than Tcl_Free. And tcl itself (i.e. tcl + tclX
in this case) doesn't use Tcl_Free at all!!??

So....

1) What is the difference between Tcl_Free and ckfree?
2) Why doesn't it show up in tcl executables?

Ok. Tcl 8.0, w/ TclX, Linux Platform. Module is tnm, from scotty, with
some stuff I've added (which uses Tcl_Free).

-- cary


Jeffrey Hobbs

unread,
Apr 23, 1999, 3:00:00 AM4/23/99
to Cary O'Brien
Cary O'Brien wrote:
> use ckfree rather than Tcl_Free. I.E. tclX, after a Tcl_SplitList,
> uses ckfree rather than Tcl_Free. And tcl itself (i.e. tcl + tclX
> in this case) doesn't use Tcl_Free at all!!??
...
> 1) What is the difference between Tcl_Free and ckfree?
> 2) Why doesn't it show up in tcl executables?
>
> Ok. Tcl 8.0, w/ TclX, Linux Platform. Module is tnm, from scotty, with

Look in the tcl.h and you'll see. Tcl uses the ck* functions on Unix,
but not Mac/Win (wasn't it pointed out that Tcl picked up a faster
mem allocator for the Mac than the compiler provided one?).

In general, it is important to use them on non-Unix platforms, or when
using Tcl with mem debugging. The man page gives the reasons why.

** Jeffrey Hobbs jeff.hobbs @SPAM acm.org **
** I'm really just a Tcl-bot My opinions are MY opinions **

Paul Duffin

unread,
Apr 23, 1999, 3:00:00 AM4/23/99
to
Cary O'Brien wrote:
>
> I'm having trouble getting a loadable module to load. The problem
> is that it can't resolve Tcl_Free in the stand-alone tcl program.
> I do some digging and find that in identical situations, libraries
> use ckfree rather than Tcl_Free. I.E. tclX, after a Tcl_SplitList,
> uses ckfree rather than Tcl_Free. And tcl itself (i.e. tcl + tclX
> in this case) doesn't use Tcl_Free at all!!??
>
> So....

>
> 1) What is the difference between Tcl_Free and ckfree?
> 2) Why doesn't it show up in tcl executables?
>
> Ok. Tcl 8.0, w/ TclX, Linux Platform. Module is tnm, from scotty, with
> some stuff I've added (which uses Tcl_Free).
>

I always use Tcl_Free, Tcl_Alloc and Tcl_Realloc, the main reason is
that if I need to turn on memory debugging I do not need to rebuild all
of my extensions because internally Tcl redirects them to the memory
debug versions. This means that it is easier to debug memory leaks and
corruption.

Another reason is that I think that Tcl should provide a nice error
message if an application runs out of memory instead of crashing in
some place in the code. One way to do this is for everyone to call
Tcl_Alloc and have that check whether any memory was allocated and if
not it could panic.

--
Paul Duffin
DT/6000 Development Email: pdu...@hursley.ibm.com
IBM UK Laboratories Ltd., Hursley Park nr. Winchester
Internal: 7-246880 International: +44 1962-816880

Cary O'Brien

unread,
Apr 23, 1999, 3:00:00 AM4/23/99
to
In article <372072...@mailserver.hursley.ibm.com>,

Paul Duffin <pdu...@mailserver.hursley.ibm.com> wrote:
>Cary O'Brien wrote:
>>
>> I'm having trouble getting a loadable module to load. The problem
>> is that it can't resolve Tcl_Free in the stand-alone tcl program.
>> I do some digging and find that in identical situations, libraries
>> use ckfree rather than Tcl_Free. I.E. tclX, after a Tcl_SplitList,
>> uses ckfree rather than Tcl_Free. And tcl itself (i.e. tcl + tclX
>> in this case) doesn't use Tcl_Free at all!!??
>>
>> So....
>>
>> 1) What is the difference between Tcl_Free and ckfree?
>> 2) Why doesn't it show up in tcl executables?
>>
>> Ok. Tcl 8.0, w/ TclX, Linux Platform. Module is tnm, from scotty, with
>> some stuff I've added (which uses Tcl_Free).
>>
>
>I always use Tcl_Free, Tcl_Alloc and Tcl_Realloc, the main reason is
>that if I need to turn on memory debugging I do not need to rebuild all
>of my extensions because internally Tcl redirects them to the memory
>debug versions. This means that it is easier to debug memory leaks and
>corruption.
>
>Another reason is that I think that Tcl should provide a nice error
>message if an application runs out of memory instead of crashing in
>some place in the code. One way to do this is for everyone to call
>Tcl_Alloc and have that check whether any memory was allocated and if
>not it could panic.
>

Ok, so if I use Tcl_Free, I've got a compilation problem. Well, a
linking problem. If I build tcl (i.e. stock tcl + tclx) there is *no*
Tcl_Free() function in the base interpreter. Honest. Checked with
nm.

If I build a loadable module that calls Tcl_Free(), when I load it I
get an error message saying 'can't find Tcl_Free()'. I could add
-ltcl to the end of the link that makes the shared library, but
then it is huge.

I looked through the tcl and tclX source and didn't see Tcl_Free() anywhere
except in the *.h file.

Any ideas?

-- cary


Paul Duffin

unread,
Apr 26, 1999, 3:00:00 AM4/26/99
to

As you are building a standalone version I would assume that because Tcl
does not use any of the functions from the tclCkalloc object file it is
not included in the executable. The solution is to change one of the
uses of ckalloc to Tcl_Alloc.

BTW
What version of Tcl are you using ?
Are you using Tcl's Stub mechanism ?

Reply all
Reply to author
Forward
0 new messages