Re: Problem with Tcl_SetResult and Tclkit under Windows

Pat Thoyts <[email protected]> Tue, 12 Apr 2011 16:39:13 +0100
Newsgroups gmane.comp.lang.tcl.starkit
Message-ID <[email protected]>
On 12 April 2011 15:18, Gerard Durand <[email protected]> wr=
ote:
> Hi,
> I'm trying to return a long chain from C to Tcl.
> If I use :
> sprintf(interp->result,"%s",Message) ; with Message containing my charact=
er

Don't do that. Its been deprecated for about 12 years or more.

> chain, it works. But Message can not be more than 200 characters long
> (TCL_RESULT_SIZE limit).
> Normally the solution is to use Tcl_SetResult (and it will be the only on=
e with
> tcl 8.6 I think ! even for short strings) :
> Tcl_SetResult(interp,Message,TCL_VOLATILE);
>
> Like that, it works on Linux, it works too on Windows if my tcl code call=
s
> directly my compiled C code inside a dll. But it does not work if my dll =
is
> included in a kit (though the 1st solution with sprintf is OK, except whe=
n my
> Message is too long of course).
> I use tclkit and tclkitsh 8.5.9 on Windows XP and my compiler is gcc (TDM=
 4.5.2
> version on Windows).
> I have tried others solutions like :
> Tcl_SetVar(interp,"v1_out",Message,TCL_GLOBAL_ONLY);
> or :
> =A0 =A0Tcl_Obj * ResultObj ;
> =A0 =A0ResultObj =3D Tcl_NewStringObj(Message,-1);
> =A0 =A0Tcl_SetObjResult(interp,ResultObj);
>
> It's always OK when my tcl code calls directly the dll, but never work wh=
en It's
> inside a kit. I obtain this error :
> Microsoft Visual C++ Runtime Library
> Runtime Error !
> This application has requested the Runtime to terminate it in an unusual =
way, ...
>
> Apparently, I have not such problems under Linux and tclkit (though versi=
ons are
> a little bit different).
>
> So, what is wrong ?
> Thanks for your help.
>
> Gerard

Tcl_SetObjResult(interp, Tcl_NewStringObj(Message, -1));
should be the way to do this. This should take a copy of the string
and allocate it into a new Tcl object. I'd suspect the other failures
are due to memory for the string being allocated by one heap while the
Tcl copy used another heap.

Make sure that your extension DLL is compiled with TCL_STUBS and
linked to tclstub8[456].lib. Tclkit cannot work with non-stubs linked
extensions.

--=20
You received this message because you are subscribed to the "starkit" group=
.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to starkit-unsubscribe@googlegro=
ups.com
For more options, visit this group at http://groups.google.com/group/starki=
t?hl=3Den