Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^4: Reverting the internals of an IV to their original states

by syphilis (Archbishop)
on Dec 28, 2021 at 00:45 UTC ( [id://11139968]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Reverting the internals of an IV to their original states
in thread Reverting the internals of an IV to their original states

think you'd have to give a practical example of real harm being caused by these flag changes.

I don't have such an example.
I do note that, with the demo I provided, you'd be in for a nasty surprise if you omit the second Dump() and go on to pass the perl scalar to an XSub that acts differently when the IsUV flag is set.
But then, of course, that XSub should have been checking SvUOK(sv), not SvISUV(sv).
I do have XSubs that behave differently, based on the UV status. Luckily, they look at SvUOK(sv) and not SvIsUV(sv).

I think I'll restrict this notion of manually reverting flags "for emergency use only" - things like asteroid strikes, extreme geophysical disturbances, alien invasions, etc ;-)

Cheers,
Rob
  • Comment on Re^4: Reverting the internals of an IV to their original states

Replies are listed 'Best First'.
Re^5: Reverting the internals of an IV to their original states
by NERDVANA (Deacon) on Dec 30, 2021 at 22:21 UTC
    I think we're all aware of the problem with round-tripping JSON, where it decodes a JSON number as a scalar, then if you use a string operation on it (such as a regex) and write it back out, you get a string instead of a number. And I think we all agree that it's unfortunate, but just a part of the philosophical mismatch between Perl and JavaScript, and not really anything that can be "fixed".

    So, I would say that it is generally a problem to have any code that makes assumptions based on the corrent flags of a scalar. Ideally, you should change the XS code's API to expect a string or number rather than guessing, and let the user tell you which type it is. (and I realize this is generally hard for nested data structures.)

      I think we're all aware of the problem with round-tripping JSON

      Yes, I've heard of it.
      I think this is a "data serialisers" issue that dave_the_m alluded to in his last post to this thread.
      There's an open perl issue about this, where changes to the way that perl's numeric flags are set/unset is being considered.
      I don't know what, if anything, will come of it ....

      Cheers,
      Rob
Re^5: Reverting the internals of an IV to their original states
by Anonymous Monk on Dec 30, 2021 at 22:23 UTC
    I think we're all aware of the problem with round-tripping JSON, where it decodes a JSON number as a scalar, then if you use a string operation on it (such as a regex) and write it back out, you get a string instead of a number. And I think we all agree that it's unfortunate, but just a part of the philosophical mismatch between Perl and JavaScript, and not really anything that can be "fixed".

    So, I would say that it is generally a problem to have any code that makes assumptions based on the corrent flags of a scalar. Ideally, you should change the XS code's API to expect a string or number rather than guessing, and let the user tell you which type it is. (and I realize this is generally hard for nested data structures.)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11139968]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2024-04-19 09:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found