Hi, I am trying to compile Tcl 8.6 with my own customized command and extension, using VS 2005. Then I got the error "result' : not a member of 'Tcl_Interp'". It seems like "result" is not a valid member of "Tcl_Interp" anymore. But it works fin with 8.5.13. So where is the member "result" now ? How can I do something like sprintf(interp->result, "123.456"); in 8.6 now ? Thanks for the help. Regards S-Y. Chen
Op dinsdag 25 juni 2013 12:32:58 UTC+2 schreef S-Y. Chen het volgende: > Hi, > > I am trying to compile Tcl 8.6 with my own customized command and extension, using VS 2005. > > Then I got the error "result' : not a member of 'Tcl_Interp'". > > It seems like "result" is not a valid member of "Tcl_Interp" anymore. But it works fin with 8.5.13. > > So where is the member "result" now ? How can I do something like > > sprintf(interp->result, "123.456"); > > in 8.6 now ? > > Thanks for the help. > > Regards > S-Y. Chen You are supposed to use Tcl_SetResult() and friends. If that is not possible (too much adjustments to an old extension for instance), there is a macro that re-exposes that field, but note that direct use of interp->result has been deprecated for several years now. Regards, Arjen
In article <d6cf5f5b-eb2b-4afd-9efb-81128f6e7cea@googlegroups.com>, S-Y. Chen <shenyeh_chen@hotmail.com> wrote: >Hi, > >I am trying to compile Tcl 8.6 with my own customized command and >extension, using VS 2005. > >Then I got the error "result' : not a member of 'Tcl_Interp'". > >It seems like "result" is not a valid member of "Tcl_Interp" anymore. >But it works fin with 8.5.13. > >So where is the member "result" now ? How can I do something like > >sprintf(interp->result, "123.456"); > >in 8.6 now ? > >Thanks for the help. > >Regards >S-Y. Chen Don't know about 8.6, but in 8.4/8.5 I've always done: char buf[1024]; resultPtr = Tcl_GetObjResult(interp); sprintf(buf, "123.456"); Tcl_SetStringObj(resultPtr, buf, -1); return TCL_OK; That's if you really want a string result. In your case you might consider a double result: resultPtr = Tcl_GetObjResult(interp); Tcl_SetDoubleObj(resultPtr, 123.456); return TCL_OK; -- ------ columbiaclosings.com What's not in Columbia anymore..
--yEPQxsgoJgBvi8ip Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2013-Jun-25, 12:12, Ted Nolan <tednolan> wrote: > In article <d6cf5f5b-eb2b-4afd-9efb-81128f6e7cea@googlegroups.com>, > S-Y. Chen <shenyeh_chen@hotmail.com> wrote: > >Hi, > > > >I am trying to compile Tcl 8.6 with my own customized command and > >extension, using VS 2005. > > > >Then I got the error "result' : not a member of 'Tcl_Interp'". > > > >It seems like "result" is not a valid member of "Tcl_Interp" anymore. > >But it works fin with 8.5.13. > > > >So where is the member "result" now ? How can I do something like > > > >sprintf(interp->result, "123.456"); > > > >in 8.6 now ? > > > >Thanks for the help. > > > >Regards > >S-Y. Chen >=20 > Don't know about 8.6, but in 8.4/8.5 I've always done: >=20 > char buf[1024]; >=20 > resultPtr =3D Tcl_GetObjResult(interp); >=20 > sprintf(buf, "123.456"); > Tcl_SetStringObj(resultPtr, buf, -1); > return TCL_OK; >=20 > That's if you really want a string result. In your case you might > consider a double result: >=20 > resultPtr =3D Tcl_GetObjResult(interp); >=20 > Tcl_SetDoubleObj(resultPtr, 123.456); > return TCL_OK; I'd go with the Tcl_SetObjResult(interp, Tcl_NewStringObj("123.456", -1)); and Tcl_SetObjResult(interp, Tcl_NewDoubleObj(123.456)); variants. --=20 Pietro Cerutti gahr@gahr.ch PGP Public Key: http://gahr.ch/pgp --yEPQxsgoJgBvi8ip Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.20 (FreeBSD) iEYEARECAAYFAlHJijwACgkQwMJqmJVx946tXwCfWumF2mDzskZiYn1brFFodiyh IH8An3Z+eSlMRmOGlo38OCYD99Nvpj6R =C201 -----END PGP SIGNATURE----- --yEPQxsgoJgBvi8ip--
Thanks a lot ! All the replies help a lot. I suppose that Tcl_GetObjResult return a pointer to the object Tcl_Obj. But, how do I access the result string (?) in this object and print it out ? Thanks again for the help. Regards S-Y. Chen
On 06/25/2013 11:25 AM, S-Y. Chen wrote: > I suppose that Tcl_GetObjResult return a pointer to the object Tcl_Obj. But, how do I access the result string (?) in this object and print it out ? If you've been reading from interp->result, make a call to Tcl_GetStringResult(interp) instead. -- | Don Porter Applied and Computational Mathematics Division | | donald.porter@nist.gov Information Technology Laboratory | | http://math.nist.gov/~DPorter/ NIST | |______________________________________________________________________|
On 25/06/2013 16:44, Don Porter wrote: > On 06/25/2013 11:25 AM, S-Y. Chen wrote: >> I suppose that Tcl_GetObjResult return a pointer to the object >> Tcl_Obj. But, how do I access the result string (?) in this object and >> print it out ? > > If you've been reading from interp->result, make a call to > Tcl_GetStringResult(interp) instead. But the "moral equivalent" is: const char *str = Tcl_GetString(Tcl_GetObjResult(interp)); It's then easy to print out (as long as you're happy with Tcl's internal almost-UTF8 encoding). Donal. -- Donal Fellows — Tcl user, Tcl maintainer, TIP editor.
Ted Nolan wrote: > S-Y. Chen wrote: >> [...] >>So where is the member "result" now ? How can I do something like >>sprintf(interp->result, "123.456"); >>in 8.6 now ? [ As others have noted, you should use Tcl_SetResult(), Tcl_SetObjResult(), or one of the other routines designed for that purpose. Direct access to interp->result has been deprecated since Tcl 8.0 -- that was in 1997 -- and finally officially went away (mostly) in 8.6. ] > Don't know about 8.6, but in 8.4/8.5 I've always done: > char buf[1024]; > resultPtr = Tcl_GetObjResult(interp); > sprintf(buf, "123.456"); > Tcl_SetStringObj(resultPtr, buf, -1); > return TCL_OK; Don't do that either! That will cause serious problems if the current result happens to be shared. Do something like this instead: | sprintf(buf, "123.456"); | Tcl_SetObjResult(interp, Tcl_NewStringObj(buf, -1)); Or, in this particular case: | Tcl_SetObjResult(interp, Tcl_NewDoubleObj(123.456)); --Joe English
On 06/26/2013 01:47 PM, Joe English wrote: > Do something like this instead: > > | sprintf(buf, "123.456"); > | Tcl_SetObjResult(interp, Tcl_NewStringObj(buf, -1)); > > Or, in this particular case: > > | Tcl_SetObjResult(interp, Tcl_NewDoubleObj(123.456)); For those cases where sprintf() does seem like the right thing, consider this instead: Tcl_SetObjResult(interp, Tcl_ObjPrintf("The answer is %d", 42)); String buffer housekeeping is rarely the best answer anymore. -- | Don Porter Applied and Computational Mathematics Division | | donald.porter@nist.gov Information Technology Laboratory | | http://math.nist.gov/~DPorter/ NIST | |______________________________________________________________________|
In article <kqf9j7$1gj$1@dont-email.me>, Don Porter <donald.porter@nist.gov> wrote: >On 06/26/2013 01:47 PM, Joe English wrote: >> Do something like this instead: >> >> | sprintf(buf, "123.456"); >> | Tcl_SetObjResult(interp, Tcl_NewStringObj(buf, -1)); >> >> Or, in this particular case: >> >> | Tcl_SetObjResult(interp, Tcl_NewDoubleObj(123.456)); > >For those cases where sprintf() does seem like the right thing, >consider this instead: > > Tcl_SetObjResult(interp, Tcl_ObjPrintf("The answer is %d", 42)); > >String buffer housekeeping is rarely the best answer anymore. Cool! Don't think I've ever seen that function before. -- ------ columbiaclosings.com What's not in Columbia anymore..
In article <slrnksmaa4.tvc.jenglish@eurydice.office.flightlab.com>, Joe English <jenglish@fdip.bad-monkeys.org> wrote: >Ted Nolan wrote: >> S-Y. Chen wrote: >>> [...] >>>So where is the member "result" now ? How can I do something like >>>sprintf(interp->result, "123.456"); >>>in 8.6 now ? > >[ As others have noted, you should use Tcl_SetResult(), > Tcl_SetObjResult(), or one of the other routines designed > for that purpose. Direct access to interp->result has been > deprecated since Tcl 8.0 -- that was in 1997 -- and finally > officially went away (mostly) in 8.6. ] > > >> Don't know about 8.6, but in 8.4/8.5 I've always done: >> char buf[1024]; >> resultPtr = Tcl_GetObjResult(interp); >> sprintf(buf, "123.456"); >> Tcl_SetStringObj(resultPtr, buf, -1); >> return TCL_OK; > > >Don't do that either! That will cause serious problems >if the current result happens to be shared. > >Do something like this instead: > >| sprintf(buf, "123.456"); >| Tcl_SetObjResult(interp, Tcl_NewStringObj(buf, -1)); > >Or, in this particular case: > >| Tcl_SetObjResult(interp, Tcl_NewDoubleObj(123.456)); > Could you expand on that a little? I'm defining a new Tcl command -- who would I be sharing the result with? (I know I got that result idiom many years ago from a source now forgotten..) Thanks! -- ------ columbiaclosings.com What's not in Columbia anymore..
--Nq2Wo0NMKNjxTN9z Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2013-Jun-26, 18:42, Ted Nolan <tednolan> wrote: > In article <kqf9j7$1gj$1@dont-email.me>, > Don Porter <donald.porter@nist.gov> wrote: > >On 06/26/2013 01:47 PM, Joe English wrote: > >> Do something like this instead: > >> > >> | sprintf(buf, "123.456"); > >> | Tcl_SetObjResult(interp, Tcl_NewStringObj(buf, -1)); > >> > >> Or, in this particular case: > >> > >> | Tcl_SetObjResult(interp, Tcl_NewDoubleObj(123.456)); > > > >For those cases where sprintf() does seem like the right thing, > >consider this instead: > > > > Tcl_SetObjResult(interp, Tcl_ObjPrintf("The answer is %d", 42)); > > > >String buffer housekeeping is rarely the best answer anymore. >=20 > Cool! Don't think I've ever seen that function before. It appeared in 8.5 IIRC.. pretty cool indeed! --=20 Pietro Cerutti gahr@gahr.ch PGP Public Key: http://gahr.ch/pgp --Nq2Wo0NMKNjxTN9z Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.20 (FreeBSD) iEYEARECAAYFAlHLN8cACgkQwMJqmJVx946ZTwCgmZuiwPo7ir3rkPDiKkb5N6hZ gMgAoJiM9Dc8OPwcEjX8Qkx10syUoHDD =LjRn -----END PGP SIGNATURE----- --Nq2Wo0NMKNjxTN9z--
On 26/06/2013 20:44, Ted Nolan <tednolan> wrote: > Could you expand on that a little? I'm defining a new Tcl command -- who > would I be sharing the result with? Probably nobody, since Tcl takes care to make sure that the result is an unshared empty object before calling a Tcl command, but it's better to not rely on that as it is rather too easy to get wrong. OK? Donal. -- Donal Fellows — Tcl user, Tcl maintainer, TIP editor.
In article <kqhpmb$gur$2@dont-email.me>, Donal K. Fellows <donal.k.fellows@manchester.ac.uk> wrote: >On 26/06/2013 20:44, Ted Nolan <tednolan> wrote: >> Could you expand on that a little? I'm defining a new Tcl command -- who >> would I be sharing the result with? > >Probably nobody, since Tcl takes care to make sure that the result is an >unshared empty object before calling a Tcl command, but it's better to >not rely on that as it is rather too easy to get wrong. OK? > >Donal. Fair enough! I'll try to take that into account the next time I do an extension.. -- ------ columbiaclosings.com What's not in Columbia anymore..