summaryrefslogtreecommitdiff
path: root/mg_vtable.h
Commit message (Collapse)AuthorAgeFilesLines
* fix incorrect vi filetype declarations in generated filesLukas Mai2023-03-241-1/+1
| | | | | Vim's filetype declarations are case sensitive. The correct types for Perl, C, and Pod are perl, c, and pod, respectively.
* pp_ctl.c - add support for hooking require.Yves Orton2023-03-181-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | This defines a new magic hash C<%{^HOOK}> which is intended to be used for hooking keywords. It is similar to %SIG in that the values it contains are validated on set, and it is not allowed to store something in C<%{^HOOK}> that isn't supposed to be there. Hooks are expected to be coderefs (people can use currying if they really want to put an object in there, the API is deliberately simple.) The C<%{^HOOK}> hash is documented to have keys of the form "${keyword}__${phase}" where $phase is either "before" or "after" and in this initial release two hooks are supported, "require__before" and "require__after": The C<require__before> hook is called before require is executed, including any @INC hooks that might be fired. It is called with the path of the file being required, just as would be stored in %INC. The hook may alter the filename by writing to $_[0] and it may return a coderef to be executed *after* the require has completed, otherwise the return is ignored. This coderef is also called with the path of the file which was required, and it will be called regardless as to whether the require (or its dependencies) die during execution. This mechanism makes it trivial and safe to share state between the initial hook and the coderef it returns. The C<require__after> hook is similar to the C<require__before> hook however except that it is called after the require completes (successfully or not), and its return is ignored always.
* scope.c - add mortal_destructor_sv() and mortal_svfunc_x()Yves Orton2023-03-181-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The function SAVEDESTRUCTOR_X() (save_destructor_x) can be used to execute a C function at the end of the current psuedo-block. Prior to this patch there was no "mortal" equivalent that would execute at the end of the current statement. We offer a collection of functions which are intended to free SV's at either point in time, but only support callbacks at the end of the current pseudo-block. This patch adds two such functions, "mortal_destructor_sv" which can be used to trigger a perl code reference to execute at the end of the current statement, and "mortal_svfunc_x" which can be used to trigger an SVFUNC_t C function at the end of the current statement. Both functions differ from save_destructor_x() in that instead of supporting a void pointer argument they both require their argument to be some sort of SV pointer. The Perl callback function triggered by "mortal_destructor_sv" may be provided no arguments, a single argument or a list of arguments, depending on the type of argument provided to mortal_destructor_sv(): when the argument is a raw AV (with no SV ref wrapping it), then the contents of the AV are passed in as a list of arguments. When the argument is anything else but NULL, the argument is provided as a single argument, and when it is NULL the perl function is called with no arguments. Both functions are implemented on top of a mortal SV (unseen by the user) which has PERL_MAGIC_destruct magic associated with it, which triggers the destructor behavior when the SV is freed. Both functions are provided with macros to match the normal SAVExx() API, with MORTALDESTRUCTOR_SV() wrapping mortal_destructor_sv() and MORTALSVFUNC_X() wrapping mortal_svfunc_x(). The heart of this logic cribbed from Leon Timmermans' Variable-OnDestruct. See the code at: https://metacpan.org/dist/Variable-OnDestruct/source/lib/Variable/OnDestruct.xs#L6-17 I am very grateful to him for his help on this. Any errors or omissions in this code are my fault, not his.
* generated files - update mode lines to specify file typeElvin Aslanov2023-02-191-2/+2
| | | | | | | | | | This updates the mode-line for most of our generated files so that they include file type information so they will be properly syntax highlighted on github. This does not make any other functional changes to the files. [Note: Commit message rewritten by Yves]
* Add PERL_MAGIC_extvalueLeon Timmermans2022-11-011-1/+2
| | | | | | A new magic type PERL_MAGIC_extvalue has been added. This is available for use like PERL_MAGIC_ext, but is a value magic: upon localization the new value will not be magical.
* Call magic on all elements on %SIG delocalizationLeon Timmermans2021-06-021-0/+4
|
* add Perl_magic_freemglob() magic vtable methodDavid Mitchell2020-10-231-1/+1
| | | | | | | | | | | | | S_mg_free_struct() has a workaround to never free mg->mg_ptr for PERL_MAGIC_regex_global. Move this logic into a new magic vtable free method instead, so that S_mg_free_struct() (which gets called for every type of magic) doesn't have the overhead of checking every time for mg->mg_type == PERL_MAGIC_regex_global. [ No, I don't know why PERL_MAGIC_regex_global's vtable and methods are suffixed mglob rather than regex_global or vice versa ]
* add Perl_magic_freeutf8() magic vtable methodDavid Mitchell2020-10-231-1/+1
| | | | | | | | | | S_mg_free_struct() has a workaround to free mg->mg_ptr in PERL_MAGIC_utf8 even if mg_len is zero. Move this logic into a new magic vtable free method instead, so that S_mg_free_struct() (which gets called for every type of magic) doesn't have the overhead of checking every time for mg->mg_type == PERL_MAGIC_utf8.
* add Perl_magic_freecollxfrm() magic vtable methodDavid Mitchell2020-10-231-1/+1
| | | | | | | | | | v5.29.9-139-g44955e7de8 added a workaround to S_mg_free_struct() to free mg->mg_ptr in PERL_MAGIC_collxfrm even if mg_len is zero. Move this logic into a new magic vtable free method instead, so that S_mg_free_struct() (which gets called for every type of magic) doesn't have the overhead of checking every time for mg->mg_type == PERL_MAGIC_collxfrm.
* ‘Nonelems’ for pushing sparse array on the stackFather Chrysostomos2018-02-181-0/+5
| | | | | | | | | | | | | | | | | To avoid having to create deferred elements every time a sparse array is pushed on to the stack, store a magic scalar in the array itself, which av_exists and refto recognise as not existing. This means there is only a one-time cost for putting such arrays on the stack. It also means that deferred elements that live long enough don’t start pointing to the wrong array entry if the array gets shifted (or unshifted/spliced) in the mean time. Instead, the scalar is already in the array, so it cannot lose its place. This fix only applies when the array as a whole is pushed on to the stack, but it could be extended in future commits to apply to other places where we currently use deferred elements.
* Remove proto magic typeFather Chrysostomos2014-11-301-1/+0
| | | | It is no longer in use, as of two commits ago.
* Rename lvalue referencesFather Chrysostomos2014-10-171-1/+1
| | | | | Also correct the description of lvref magic. When it was first added, it was for list assignments only, but that soon changed.
* Capitalise magic descriptions consistentlyFather Chrysostomos2014-10-101-6/+6
|
* Add lvref magic typeFather Chrysostomos2014-10-101-0/+5
| | | | | I just couldn’t resist using the backslash for the character, even though I had to tweak mg_vtable.pl to make it work.
* [perl #122445] use magic on $DB::single etc to avoid overload issuesTony Cook2014-10-091-0/+5
| | | | | | | | | This prevents perl recursing infinitely when an overloaded object is assigned to $DB::single, $DB::trace or $DB::signal This is done by referencing their values as IVs instead of as SVs in dbstate, and by adding magic to those variables so that assignments to the scalars update the PL_DBcontrol array.
* silence g++ warning with PL_magic_vtable_namesDavid Mitchell2012-12-181-2/+2
| | | | | | See this p5p thread for more details <20121218144018.GQ1842@iabyn.com>
* Remove length magic on scalarsFather Chrysostomos2012-10-011-1/+1
| | | | | | | | | It is not possible to know how to interpret the returned length without accessing the UTF8 flag, which is not reliable until the SV has been stringified, which requires get-magic. So length magic has not made senses since utf8 support was added. I have removed all uses of length magic from the core, so this is now dead code.
* Add proto magic typeFather Chrysostomos2012-09-151-0/+1
| | | | | | | | This will be used for storing the prototype CV of a ‘my’ sub. The clone needs to occupy the pad entry so that padcv ops will be able to find it. That means the clone has to displace its prototype. In case the same sub is called recursively, we still need to be able to access the prototype.
* Flatten vstrings modified in placeFather Chrysostomos2012-07-271-6/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A substitution forces its target to a string upon successful substitu- tion, even if the substitution did nothing: $ ./perl -Ilib -le '$a = *f; $a =~ s/f/f/; print ref \$a' SCALAR Notice that $a is no longer a glob after s///. But vstrings are different: $ ./perl -Ilib -le '$a = v102; $a =~ s/f/f/; print ref \$a' VSTRING I fixed this in 5.16 (1e6bda93) for those cases where the vstring ends up with a value that doesn’t correspond to the actual string: $ ./perl -Ilib -le '$a = v102; $a =~ s/f/o/; print ref \$a' SCALAR It works through vstring set-magic, that does the check and removes the magic if it doesn’t match. I did it that way because I couldn’t think of any other way to fix bug #29070, and I didn’t realise at the time that I hadn’t fixed all the bugs. By making SvTHINKFIRST true on a vstring, we force it through sv_force_normal before any in-place string operations. We can also make sv_force_normal handle vstrings as well. This fixes all the lin- gering-vstring-magic bugs in just two lines, making the vstring set- magic (which is also slow) redundant. It also allows the special case in sv_setsv_flags to be removed. Or at least that was what I had hoped. It turns out that pp_subst, twists and turns in tortuous ways, and needs special treatment for things like this. And do_trans functions wasn’t checking SvTHINKFIRST when arguably it should have. I tweaked sv_2pv{utf8,byte} to avoid copying magic variables that do not need copying.
* Reset the iterator when an array is clearedVincent Pit2012-06-221-1/+1
| | | | This fixes RT #75596.
* Expunge study magicFather Chrysostomos2012-05-291-1/+0
| | | | I’m running out of synonyms for ‘remove’.
* Annihilate ‘A’ magicFather Chrysostomos2012-05-211-10/+0
| | | | | | | | | How ironic! Overloading is called ‘A’ magic internally all over the place, because of the letter used as its magic type. But now it does not even use that magic. I left a comment in mg_vtable.pl, so that future maintainers will have some clue as to what AMAGIC means.
* Copy call checker when cloning closure prototypeFather Chrysostomos2012-05-211-0/+4
| | | | | Otherwise cv_set_call_checker has no effect inside an attribute han- dler for a closure.
* [perl #29070] Add vstring set-magicFather Chrysostomos2011-12-231-2/+6
| | | | | | | | | | | | Some operators, like pp_complement, assign their argument to TARG (which copies vstring magic), modify it in place, and then call set- magic. That’s supposed to work, but vstring magic was remaining as it was, such that ~v7 would still be treated as "v7" by vstring-aware code, even though the resulting string is not "\7". This commit adds vstring set-magic that checks to see whether the pv still matches the vstring. It cannot simply free the vstring magic, as that would prevent $x=v0 from working.
* Split out study magic from pos magic.Nicholas Clark2011-07-011-1/+2
| | | | | | study uses magic to call SvSCREAM_off() if the scalar is modified. Allocate it its own magic type ('G' for now - pos magic is 'g'). Share the same "set" routine and vtable as regexp/bm/fm (setregxp and vtbl_regexp).
* Sort magic and magic vtable names in files generated by mg_vtable.plNicholas Clark2011-06-111-73/+73
| | | | | Magic is sorted case insensitively, with upper case before lower case. vtable names are all lowercase letters.
* Generate the PERL_MAGIC_* defines using mg_vtable.pl.Nicholas Clark2011-06-111-0/+52
|
* Provide the names of the magic vtables in PL_magic_vtable_names[].Nicholas Clark2011-06-111-0/+37
| | | | | | As it's a 1 to 1 mapping with the vtables in PL_magic_vtables[], refactor Perl_do_magic_dump() to index into it directly to find the name for an arbitrary mg_virtual, avoiding a long switch statement.
* PL_vtbl_{bm,fm} can be aliases to PL_vtbl_regexp, instead of copies.Nicholas Clark2011-06-111-4/+3
| | | | | They became copies in 488344d27a84a21a, which merged Perl_magic_setbm() and Perl_magic_setfm() into Perl_magic_setregexp().
* Refactor Perl_get_vtbl() to a small array lookup from a large switch statement.Nicholas Clark2011-06-111-3/+4
| | | | Provide magic_vtable_max, the number of elements in PL_magic_vtables[].
* Replace PL_vtbl_* with an array PL_magic_vtables.Nicholas Clark2011-06-111-222/+73
| | | | | | Define each PL_vtbl_* name as a macro which expands to the correct array element. Using a single array instead of multiple named variables will allow the simplification of various pieces of code.
* Generate the enum for want_vtbl_* with regen/mg_vtable.plNicholas Clark2011-06-111-0/+35
|
* Move the work of MGVTBL_SET() from the C pre-processor to mg_vtable.plNicholas Clark2011-06-111-385/+224
| | | | | | Generating mg_vtable.h with MGVTBL_SET() effectively pre-expanded makes things clearer. This eliminates use of the macro MGVTBL_SET(), which can be deleted as nothing outside the core is relying on it.
* Move the cast for a magic vtable with const get into mg_vtable.hNicholas Clark2011-06-111-2/+2
| | | | | | Putting the cast inside the initialiser (the only initialiser using it) eliminates use of the macro MGVTBL_SET_CONST_MAGIC_GET(), which can be deleted as nothing outside the core is relying on it.
* Generate the definitions for magic vtables from data in a regen script.Nicholas Clark2011-06-111-0/+416
Previously perl.h contained a long section of MGVTBL_SET() macros declaring the core's various magic vtables. Convert the information into data structures in a new script regen/mg_table.pl, and use this to generate a new file mg_vtable.h, included by perl.h This is the first step in reducing the number of places that data relating to magic vtables is declared (and has to be kept in sync), and will allow more flexibility in parts of the core's implementation.