Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: e91be141e8f73aadefcd9c31cf295018cb4d8992
Ticket: 1787846fffffffffffffffffffffffffffffffff
"wideInt" objType registration
User & Date: das on 2007-09-04 22:23:40
Changes

  1. assignee changed to: "dgp"
  2. icomment:
    Logged In: YES 
    user_id=90580
    Originator: NO
    
    Discussion on chat with kbk from earlier today about this matter, he is ok with the change, is there anything further that needs to be discussed ?
    
    <kbk> das?
    <das> yes?
    <kbk> I'm looking at your round of changes to tclObj.c - and feeling a bit uneasy.
    <das> the wideInt change ?
    <kbk> Yes...
    <kbk> ... You realize that Tcl_GetWideIntFromObj isn't guaranteed to leave a wideInt int rep?
    <das> yes
    <das> SetIntFromAny does not guarantee an intRep either AFAICT ?
    <kbk> ok... now, does whatever extension is calling Tcl_ConvertToType know that?
    <kbk> No... we've been moving steadily into a world where intRep's are the business only of the code that owns them.
    <das> as mentioned, I don't care about Tcl_ConvertToType() in ffidl
    <das> all I need is to be able to compare a given objects' type to wideInt
    <das> SetWideIntFromAny is unimportant to me, as mentioned it can be reverted
    <das> all I care about is the type registration
    <kbk> ok... now, why is it that ffidl needs to compare the type?
    <kbk> (Strikes me as a little dangerous to have runtime behaviour that changes with shimmering... but maybe I misunderstand what ffidl is doing)
    <das> passing 64bits through tcl unmolested, i.e. an obj created with a 64bit int by Tcl_NewWideIntObj by ffidl should be able to be converted back without going through bignums or floats, in a way compatible with both 8.4 and 8.5
    <das> if there was shimmering, we accept there may be lossiness, on 8.4 at least
    <das> on 8.5, I'm working on fixing that by going through bignums
    <kbk> Right.  8.5 should be lossless, though.  Tcl_NewWideIntObj will create either an int or a wide (or a bignum only if NO_WIDE_TYPE is defined).
    <das> but I want to avoid the expense if there was no shimmering
    <kbk> Tcl_GetWideIntFromObj will retrieve exactly the wide that was stored.
    <kbk> Similarly, as long as you don't mess with tcl_precision, doubles are also lossless.
    <kbk> (except that signalling NaNs will be quieted, because nasal daemons lurk in that corner)
    <das> what ffidl does in 8.4 is use Tcl_GetWideIntFromObj only on objects of type wideInt...
    <das> otherwise use Tcl_GetDoubleFromObj
    <kbk> and presume that an int will fit in a double - which isn't true on a 64-bit machine.
    <das> right, the latter may be lossy e.g. if there was shimmering
    <das> this could be done differently on 8.5
    <das> but how to make an extension that works on both
    <das> with the same binary
    <das> in any case, existing ffidl binaries break due to the "wideInt" registration removal
    <kbk> Hmmm. You know the data type that you need?
    <das> I don't really see the harm in restoring it
    <kbk> Given that we've identified code that breaks, I'm inclined to agree... now I'm just thinking about what best to do moving forward.
    <das> it may well be that adding SetWideIntFromAny was a bad idea
    <kbk> SetFooFromAny in general is a bad idea.  It's better to let the type be determined by Tcl_GetFooFromObj.
    <kbk> Do you know the data type that you need in a given context?
    <das> I'll have to check, it should be possible, but currently that's not the way the code works
    <das> mind you this is not code I wrote... it dates from 99...
    <kbk> Yeah.  I  know that ffidl has a bloody history... and numbers in Tcl are almost equally bad.  (Bignums looked like the only way out because we repeated previous mistakes with unsigned wideInts)
    <kbk> (And the bignum library was going in anyway so that doubles could shimmer losslessly)
    <das> yes, and indeed ffidl has problems with both unsigned ints and unsigned wideints...
    <das> e.g. there is no way to distingush between -1, UINT_MAX and ULLONG_MAX and
    <das> at the tcl level...
    <das> looking to remedy that with the 8.5 rev, but staying compatible with 8.4 is tricky
    <kbk> Yeah.  I *think* we managed to get things so that 8.4 puts numbers between INT_MAX+1 and UINT_MAX into wides.  But unsigned wides are still a problem.
    <das> the problem is that ffidl forces such ints into an intrep, not a wideint (pre-8.4 code...)
    <kbk> *That* at least should be fixable.
    <das> yes
    <das> one issue is performance, often you just want quick roundtripping via tcl without any conversions, e.g. passing the return val of one ffidl callout as a param to another
    <das> I think that is the reason most of the type comparisons in ffidl are done currently
    <kbk> Again, 8.5 is getting reasonably smart about that.  Most of the Tcl_GetFooFromObj where Foo is a numeric type recognize all the numeric types and don't shimmer.
    <kbk> (And yes, I understand that you need 8.4 compat... :( )
    <das> I''try and rip out all of that ugliness and see what happens... at least when running against 8.5
    <das> it would certainly simplify the code a lot...
    <kbk> If you find places where we get it wrong, by all means log it.  "Shimmering" of numbers should now be 100% lossless (and in most cases won't shimmer)
    <das> of course I also wanted a minimal effort set of changes for 8.5...
    <das> great
    <kbk> In 8.6, I want to take out Tcl_ConvertToType, by the way.  It serves no useful purpose.
    <das> sounds like a good idea, that's one thing ffidl is not using at least ;-)
    <das> so should I revert the SetWideIntFromAny addition ?
    <das> and leave just the type registration ?
    <kbk> Uhm.  The way you've coded it, it's Mostly Harmless.
    <das> yes, intentionally ;-) the same as SetIntFromAny...
    <kbk> Oh, and don't register wideInt if NO_WIDE_INT_TYPE (or however it's spelt) is defined.
    <das> I don't think I do
    <das> the struct isn't even defined in that case
    <das> i.e. tclWideIntType
    <kbk> ok, cool.  And otherwise, if we've identified a known dependency in an extension, then I think I'm ok with this.  You might want to double-check with dgp as well.
    <das> ok
    <das> thanks
    
    
    
  3. login: "das"
  4. mimetype: "text/plain"
  5. username: "das"