-
Notifications
You must be signed in to change notification settings - Fork 601
Add sv_vstring_get API around PERL_MAGIC_vstring
#23075
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| #!perl | ||
|
|
||
| use Test::More tests => 2; | ||
| use XS::APItest; | ||
|
|
||
| { | ||
| my $vstr = v1.23.456; | ||
| ok SvVOK($vstr), '$vstr has SvVOK'; | ||
| is SvVSTRING($vstr), "v1.23.456", 'SvVSTRING()'; | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is retval of
Perl_sv_vstring_getof typebooland not of typeSTRLEN?What does
if(SvVOK(sv) && SvVCUR(sv) == 0) { NOOP; }mean on a PP/XS/C level?why not move arg 3
STRLEN *lenptoretval?Code like
if(!len) { die("bad input"); }has universal meaning.is very rare in Perl/all SW dev.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It matches the similar API shape I added with
sv_regex_global_pos_get().There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea of more use of
retvals where no ambiguity is possible. Shouldsv_regex_global_pos_get()also return itsSTRLEN?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HELL YEAH.

Although
int Perl_magic_getpos(interpreter *my_perl, sv *sv, magic *mg)is too tiny and too simple to have this defect. MSVC forlenas inpv = SvPV(sv, len);will redundantly re-readlenover and over from C stack memory, because C stack auto varlenESCAPED!!!! any and all C functions in Perl's virtual address space can unpredictably rewrite the value inside C stack autolenstored in real C stack memory (not a register).So it would be beneficial on all ABI/CPU arcs, to return
STRLEN *pospeither as the 1 and only retval, and eliminate thebool. or say retval-1is failure, everything else is success (retval0length is success ??? idk this area of API).Backup option, return by copy a C struct with 2 members,
boolandSTRLEN. Now caller func frame has ABI proof nothing can ever rewriteSTRLEN, andSTRLENcan be upgraded to a non-vol register for the rest of this func body.Also lets us be reasonable, unless
STRLENtype is transporting a ptr size integer holding a CSRNG value, we know the sign bit aka 0x8000_0000 2GB or 0x8000_0000_0000_0000 aka 9,223,372,036,854,775,808 9 quintillionB will always be zero in the retval, and not the user's string length. After that assumption, STRLEN can transport a 1 bit bool, and a 31 bit or 63 bit integer, inside 1 CPU register, inside 1 C retval.