From: Donald G P. <dg...@em...> - 2003-07-01 20:07:22
|
> During the Initialization we request TCL to allocate a pointer "p_tcl_c_str" (say 1024 bytes) using the Tcl_Alloc call. When we later write to this variable from a TCL Script, TCL reallocates this variable memory which is equal to length of the string that is being written. For Example if we do a "set p_tcl_c_str Hello_World", It will reallocate this variable only 12 bytes and release the previous chunk. As, in the C code we are not aware of this change we write to the C variable expecting that it would be able to support the write upto 1024 bytes and hence the process crashes. It sounds like you are attempting to program based on a mistaken assumption that a C variable of a particular name is somehow tied to a Tcl variable (a Tcl_Var) of that same name. No such automatic connection exists. If you need access to the same variable at both Tcl and C levels, you should be working with Tcl_Var's all the time and use the procedures like Tcl_SetVar() and Tcl_GetVar() to read and write them. Another option that might be suitable for certain situations is to create a "link" between a C variable and a Tcl variable using the Tcl_LinkVar() family of routines. If these pointers do not answer your problem, then try again with some specific code examples of what you are attempting to do. | Don Porter Mathematical and Computational Sciences Division | | don...@ni... Information Technology Laboratory | | http://math.nist.gov/~DPorter/ NIST | |______________________________________________________________________| |