summaryrefslogtreecommitdiff
path: root/mg.c
Commit message (Collapse)AuthorAgeFilesLines
* Better handling of magic methods freeing the SVDavid Mitchell2010-12-301-19/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a fix for RT #81230 (and more). Currently, mg_get() works around the case where the called magic (e.g. FETCH) frees the magic SV. It does this by unconditionally pushing the SV on the tmps stack before invoking the method. There are two issues with this. Firstly, it may artificially extend the life of the SV. This was the root of the problem with #81230. There, the DB_File code, under -T, created a tainted tied object. Accessing the object (within FETCH as it happens), caused mg_get() to be invoked on the object (due to the taint magic), and thus extend the life of the object. This then caused c<untie %h if $h{k}> to give the warning untie attempted while 1 inner references still exist. This only became noticeable after efaf36747029c85b4d8825318cb4d485a0bb350e, which stopped wrapping magic method calls in SAVETMPS/FREETMPS. The second issue issue that this protection only applies to mg_get(); functions like mg_set() can still segfault if the SV is deleted. This commit fixes both problems as follows: First, the protection mechanism is moved out of mg_get() and into save_magic() / restore_magic(), so that it protects more things. Secondly, the protection is now: * in save_magic(), SvREFCNT_inc() the SV, thus protecting it from being freed during FETCH (or whatever) * in restore_magic(), SvREFCNT_dec() the SV, undoing the protection without extending the life of the SV, *except* if the refcount is 1 (ie FETCH tried to free it), then push it on the mortals stack to extend it life a bit so our callers wont choke on it.
* Remove lots of unused, VMS-specific variables.Craig A. Berry2010-12-021-1/+0
| | | | Brought to you by -Duser_c_flags=/WARN=(ENABLE=LEVEL5,INFORMATIONAL=ALL)
* Add mg_findextFlorian Ragwitz2010-11-301-9/+36
|
* Implement $^A taintingNiko Tyni2010-11-141-0/+10
| | | | | | | | | The format accumulator $^A now becomes tainted when formline() is called with tainted data. There is still one failing test from the TODO set; it seems that the $^A get magic is handled too late for the taintedness to show up.
* Eliminate PL_dirtyFlorian Ragwitz2010-11-141-1/+1
| | | | | It now only exists as a compatibility macro for extensions that want to introspect it.
* Add ${^GLOBAL_PHASE}Florian Ragwitz2010-11-141-1/+7
| | | | This exposes the current top-level interpreter phase to perl space.
* [perl #77238] Aliased @ISA does not workFather Chrysostomos2010-11-131-11/+17
| | | | | This makes aliased @ISA arrays work by storing a non-magical AV as the mg_obj if there need to be multiple entries.
* tidy code in Perl_sighandler()David Mitchell2010-11-011-14/+13
| | | | | | | | | | | | | | | | | | | 1) compress if (...) flag |= 1 ... if (flag & 1) { ... into if (...) { flag |= 1 .... 2) re-order the flag bits, since over the years some bits have become redundant.
* RT #76248: double-freed SV with nested sig-handlerDavid Mitchell2010-11-011-22/+21
| | | | | | | | | | | | | | | | | | | There was some buggy code in Perl_sighandler() related to getting an SV with the signal name to pass to the perl-level handler function. ` Basically: on threaded builds, a sig handler that died leaked PL_psig_name[sig]; on unthreaded builds, in a recursive handler that died, PL_sig_sv was prematurely freed. PL_sig_sv was originally just a file static var that was not recursion-save anyway, and got promoted to perlvars.h when it should instead have been done away with. So I've got rid of it now, and rationalised the code, which fixed the two issues listed above. Also added an assert which makes the dodgy manual popping of the save stack slightly less dodgy.
* Switch the core MRO code over to HvENAMEFather Chrysostomos2010-10-291-1/+3
| | | | | | | | | | | | | | | | | | | | | | This has the side-effect of fixing these one-liners: $ perl5.13.5 -le' my $glob = \*foo::ISA; delete $::{"foo::"}; *$glob = *a' Bus error $ perl5.13.5 -le' my $glob = \*foo::ISA; delete $::{"foo::"}; *$glob = []' Bus error $ perl5.13.6 -le'sub baz; my $glob = \*foo::bar; delete $::{"foo::"}; *$glob = *baz;' Bus error $ perl5.13.6 -le'sub foo::bar; my $glob = \*foo::bar; delete $::{"foo::"}; *$glob = *baz;' Bus error In the first two cases the crash was inadvertently fixed (isn’t it nice when that happens?) in 5.13.6 (by 6f86b615fa7), but there was still a fatal error: Can't call mro_isa_changed_in() on anonymous symbol table at -e line 1. Because sv_clear calls ->DESTROY, if an object’s stash has been detached from the symbol table, mro_get_linear_isa can be called on a hash with no HvENAME. So HvNAME is used as a fallback for those cases.
* full API for cop hint hashesZefram2010-10-211-15/+9
| | | | | | | | | | | | | Expose cop hint hashes as a type COPHH, with a cophh_* API which is a macro layer over the refcounted_he_* API. The documentation for cophh_* describes purely API-visible behaviour, whereas the refcounted_he_* documentation describes the functions mainly in terms of the implementation. Revise the cop_hints_* API, using the flags parameter consistently and reimplementing in terms of cophh_*. Use the cophh_* and cop_hints_* functions consistently where appropriate. [Modified by the committer to update two calls to Perl_refcounted_he_fetch recently added to newPMOP.]
* plugin mechanism to rewrite calls to a subroutineZefram2010-10-101-12/+53
| | | | | | | | | | | | | | | | | | | | | | | | New magic type PERL_MAGIC_checkcall attaches a function to a CV, which will be called as the second half of the op checker for an entersub op calling that CV. Default state, in the absence of this magic, is to process the CV's prototype if it has one, or apply list context to all the arguments if not. New API functions cv_get_call_checker() and cv_set_call_checker() provide a clean interface to this facility, hiding the internal use of magic. Expose in the API the new functions rv2cv_op_cv(), ck_entersub_args_list(), ck_entersub_args_proto(), and ck_entersub_args_proto_or_list(), which are meaningful segments of standard entersub op checking and are likely to be useful in plugged-in call checker functions. Expose new API function op_contextualize(), which is a public interface to the internal scalar()/list()/scalarvoid() functions. This API is likely to be required in most plugged-in call checker functions. Incidentally add new function mg_free_type(), in the API, which will remove magic of one type from an SV. (mg_free() removes all magic, and there isn't anything else more selective.)
* Add two missing break in Perl_magic_set's big switchVincent Pit2010-08-311-1/+2
| | | | | This fixes $^A being reset when $1..$2 are localized before any regexp match happened.
* Remove CALL_FPTR and CPERLscope.Ben Morrow2010-08-201-8/+8
| | | | | | | | | | | | | | | | These are left from PERL_OBJECT, which was an implementation of multiplicity using C++ objects. PERL_OBJECT was removed in 5.8, but the macros seem to have been cargo-culted all over the core (including in places where they would have been inappropriate originally). Since they now do exactly nothing, it's cleaner to remove them. I have left the definitions in perl.h, under #ifndef PERL_CORE, since some CPAN XS code uses them (also often incorrectly). I have also left STATIC alone, since it seems potentially more useful and is much more ingrained. The only appearance of these macros this patch doesn't touch is in Devel-PPPort, because that's a CPAN module.
* RT #74436: [PATCH] Add -Wwrite-stringsRobin Barker2010-08-141-1/+1
| | | | | | The perl source has for some while been clean to -Wwrite-strings. I suggest this warning be added to cflags. The patch makes the appropriate change to cflags.SH and silences a warning from mg.c
* optimise single backreferencesDavid Mitchell2010-08-011-1/+2
| | | | | | | | | | | Rather than creating an AV and pushing the backref onto it, store a single backref directly in the mg_obj or xhv_backreferences slot. If the backref is an AV, then we skip this optimisation (although I don't think at the moment, that an AV would ever be pointed to by some backref magic). So the test of whether the optimisation is is in effect is whether the thing in the slot is an AV or not.
* Restore errno if signal handler changes itLubomir Rintel2010-07-261-0/+2
| | | | | It's way too easy to forget to "local $!" in signal handlers and changing $! when signal hits between two ops is probably never useful.
* Add Perl_croak_no_modify() to implement Perl_croak("%s", PL_no_modify).Nicholas Clark2010-06-271-2/+2
| | | | | This reduces object code size, reducing CPU cache pressure on the non-exception paths.
* Revert "make 'local $tied' untied"David Mitchell2010-06-071-1/+0
| | | | | | | | | This reverts commit 191ad7eff570fc96c93993e4358f83e2033365d6. Some modules (e.g. File::chdir) relied on the current behaviour of local $tied_scalar, so lets leave things as-is for now. See http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2010-05/msg00627.html
* update Perl_magic_methcall descriptionDavid Mitchell2010-06-051-4/+3
| | | | it's now a varargs function
* rename DM_ARRAY flag to DM_ARRAY_ISADavid Mitchell2010-06-041-1/+1
| | | | | This better represents its current role as specifically delaying magic on @ISA as opposed to a general array magic delay mechanism.
* make 'local $tied' untiedDavid Mitchell2010-05-041-0/+1
| | | | When localising a tied scalar, don't make the scalar tied
* make local @tied, %tied, untiedDavid Mitchell2010-05-041-0/+1
| | | | | | | | | | | | | | | | | Fix for RT #7938, #7939: when localising an array or hash, don't make the new aggregate tied. The old behaviour of { local @tied; ... } was equivalent to: { my $saved = \@tied; *tied = []; tied(@tied) = tied(@$saved) # if tied() were an lvalue function ... *tied = $saved; } This patch simply removes the 'tied(@tied) = ...' step
* Merge remote branch 'zefram/zefram/reliable_exception' into bleadRafael Garcia-Suarez2010-05-041-1/+1
|\ | | | | | | | | Conflicts: pp_ctl.c
| * SV-based interfaces for dieing and warningZefram2010-04-231-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | New functions croak_sv(), die_sv(), mess_sv(), and warn_sv(), each act much like their _sv-less counterparts, but take a single SV argument instead of sprintf-like format and args. They will accept RVs, passing them through as such. This means there's no more need to clobber ERRSV in order to throw a structured exception. pp_warn() and pp_die() are rewritten to use the _sv interfaces. This fixes part of [perl #74538]. It also means that a structured warning object will be passed through to $SIG{__WARN__} instead of being stringified, thus bringing warn in line with die with respect to structured exception objects. The new functions and their existing counterparts are all fully documented.
* | For SAVEt_ALLOC, store the number of save stack entries used with the type.Nicholas Clark2010-05-031-7/+5
| |
* | On the save stack, store the save type as the bottom 6 bits of a UV.Nicholas Clark2010-05-011-4/+5
| | | | | | | | This makes the other 26 (or 58) bits available for save data.
* | Convert Perl_magic_methcall() to varargs.Nicholas Clark2010-04-261-13/+16
| | | | | | | | | | This means removing its macro wrapper, as there's no portable way to do varargs macros.
* | For Perl_magic_methcall() add G_UNDEF_FILL to fill the stack with &PL_sv_undef.Nicholas Clark2010-04-261-17/+13
| | | | | | | | | | | | This replaces the previous special case of using a negative argument count to signify this, allowing the argument count to become unsigned. Rename it from n to argc.
* | Change the flags argument to magic_methcall/magic_methcall1 from I32 to U32.Nicholas Clark2010-04-251-2/+2
| |
* | In S_magic_methcall1(), tweak the initialisation of arg1 to reduce code size.Nicholas Clark2010-04-251-4/+2
| |
* | add Perl_magic_methcallDavid Mitchell2010-04-251-86/+105
|/ | | | | | | | | | | | | | | Add a new function that wraps the setup needed to call a magic method like FETCH (the existing S_magic_methcall function has been renamed S_magic_methcall1). There is one functional change, done mainly to allow for a single clean wrapper function, and that is that the method calls are no longer wrapped with SAVETMPS/FREETMPS. Previously only about half of them had this, so some relied on the caller to free, some didn't. At least we're consistent now. Doing it this way is necessary because otherwise magic_methcall() can't return an SV (eg for POP) because it'll be a temp and get freed by FREETMPS before it gets returned. So you'd have to copy everything, which would slow things down.
* Set the legacy process name with prctl() on assignment to $0 on LinuxÆvar Arnfjörð Bjarmason2010-04-151-0/+11
| | | | | | | | | | | | | Ever since perl 4.000 we've only set the POSIX process name via argv[0]. Unfortunately on Linux the POSIX name isn't used by utilities like top(1), ps(1) and killall(1). Now when we set C<$0 = "hello"> both C<qx[ps h $$]> (POSIX) and C<qx[ps hc $$]> (legacy) will say "hello", instead of the latter being "perl" as was previously the case. See also the March 9 2010 thread "Why doesn't assignment to $0 on Linux also call prctl()?" on perl5-porters.
* use cBOOL for bool castsDavid Mitchell2010-04-151-2/+2
| | | | | | | | | | | | | bool b = (bool)some_int doesn't necessarily do what you think. In some builds, bool is defined as char, and that cast's behaviour is thus undefined. So this line in mg.c: const bool was_temp = (bool)SvTEMP(sv); was actually setting was_temp to false even when the SVs_TEMP flag was set. Fix this by replacing all the (bool) casts with a new cBOOL() cast macro that (hopefully) does the right thing.
* remove 'enable taint if modify gid/uid' featureDavid Mitchell2010-04-111-4/+0
| | | | | | | | | | | If at runtime you modify any of any the id variables $<, $>, $(, $), such that the id and effective id differ, perl used to enable tainting, even if -T wasn't specified at startup. This commit removes that feature. See http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2010-03/mail9.html RT #67260
* PL_defoutgv isn't always a GV.David Mitchell2010-03-301-19/+31
| | | | | | | | | | | | | | | | | | | | Nasty code like the following results in PL_defoutgv not pointing to a valid GV: my $x = *STDERR; select($x); $x = 1; This causes all sorts of SEGVs when PL_defoutgv is subsequently accessed, because most code assumes that it has a valid gv_gp pointer. It also turns out that PL_defoutgv is under-tested; for example, temporarily hacking pp_close to make an arg-less close() croak didn't cause any minitest failures. Add a new test file that does some basic testing of a bad PL_defoutgv, and fix all the obvious badness in accessing it. This also fixes #20727, which although ostensibly a tie bug, was due to PL_defoutgv pointing to a tiedelem scalar, and fun like that described above happening.
* Fix assorted bugs related to magic (such as pos) not "sticking" toDavid Mitchell2010-03-231-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | magical array and hash elements; e.g. the following looped infinitely: $h{tainted_element} =~ /..../g There are two side-effects of this fix. First, MGf_GSKIP has been extended to work on tied array elements as well as hash elements. This is the mechanism that skips all but the first tied element magic gets until after the next set. Second, rvalue hash/array element access where the element has get magic, now directly returns the element rather than a mortal copy. The root cause of the bug was code similar to the following in pp_alem, pp_aelemfast, pp_helem and pp_rv2av: if (!lval && SvGMAGICAL(sv)) /* see note in pp_helem() */ sv = sv_mortalcopy(sv); According to the note, this was added in 1998 to make this work: local $tied{foo} = $tied{foo} Since it returns a copy rather than the element, this make //g fail. My first attempt, a few years ago, to fix this, took the approach that the LHS of the bind should be made an lvalue in the presence of //g, since it now modifies its LHS; i.e. expr =~ // expr is rvalue expr =~ s/// expr is lvalue expr =~ //g expr was rvalue, I proposed to change it to lvalue Unfortunately this fix broke too much stuff (stuff that was arguably already broken, but it upset people). For example, f() ~= s//// correctly gives the error Can't modify non-lvalue subroutine call My fix extended f() =~ //g to give the same error. Which is reasonable, because the g isn't doing what you want. But plenty of people had code that only needed to match once and the g had just been cargo-culted. So it broke their working code. So lets not do this. My new approach has been to remove the sv_mortalcopy(). It turns out that this is no longer needed to fix the local $tied{foo} issue. Presumably that went away as a side-effect of my container/value magic localisation rationalisation of a few years ago, although I haven't analysed it - just noted that the tests still pass (!). However, an issue with removing it is that mg_get() no longer gets called. So a plain $tied_hash{elem}; in void context no longer calls FETCH(). Which broke some tests and might break some code. Also, there's an issue with the delayed calling of magic in @+[n] and %+{foo}; by the time the get magic is called, the original pattern may have gone out of scope. The solution is to simply replace the original sv = sv_mortalcopy(sv); with mg_get(sv); This then caused problems with tied array FETCH() getting called too much. I fixed this by extending the MGf_GSKIP mechanism to tied arrays as well as hashes. I don't understand why tied arrays have always been treated differently than tied hashes, but unifying them didn't seem to break anything (except for a Storable test, whose comment indicated that the test's author thought FETCH() was being called to often anyway).
* [perl #6758] tainted values become untainted in tied hashesDavid Mitchell2010-03-201-1/+22
|
* Fix #72850 - reading $! shouldn't SEGV if Strerror(errno) returns NULL.Nicholas Clark2010-02-161-1/+2
| | | | | | | This can happen on some OSes for out of range errno values. The bug was introduced with 0097b436152452e4, which in turn fixed #61976. Test case by Steve Peters.
* Convert Perl_sv_pos_u2b_proper() to Perl_sv_pos_u2b_flags().Nicholas Clark2010-02-141-3/+3
| | | | | | | Change from a value/return offset pointer to passing a Unicode offset, and returning a byte offset. The optional length value/return pointer remains. Add a flags argument, passed to SvPV_flags(). This allows the caller to specify whether mg_get() should be called on sv.
* Remove a vestigial STRLEN case and convert a label to lowercase.Nicholas Clark2010-02-141-1/+1
| | | | (Tweaking 777f7c561610dee6.)
* Removes 32-bit limit on substr arguments. The full range of IV and UV is ↵Eric Brine2010-02-141-10/+9
| | | | available for the pos and len arguments, with safe conversion to STRLEN where it's smaller than an IV.
* Fix for #71254: SEGV in Data::DumperFather Chrysostomos2010-01-181-1/+2
| | | | | | | | | | | This was caused by change 27323/f7877b281b4, which changes the way globs are stored in SVs. This patch teaches Perl_magic_setmglob (which resets the match position after an assignment) about globs. What was happening was that the globness was turned off (with the type still as PVGV), which essentially turned the variable into a strange empty string. Data::Dumper, seeing a PVGV, assumes the string form is at least 1 char (which should always be the case), and ends up reading past the end of the string if it is blank.
* Correct VMS-specific handling of $! in Perl_magic_get.Craig A. Berry2010-01-161-4/+4
| | | | | | | | 0097b436152452e403cc71b4f1a1cfd30ec0ba1a had introduced a test failure on VMS because it only set the POK flag in the non-VMS code path, which was an easy mistake to make because accumulated patches had over time made the #ifdef jungle way more tangled than it needed to be. There is really only one line that needs to be VMS-specific.
* fix for [perl #61976] Errno ($!) not evaluated to a error message stringDavid Mitchell2010-01-121-0/+1
| | | | | | | | | | | (5.10.0 in taint mode) Change 27176 / 2a509ed3c095f7d712013e653f68821f6bb2d6db fixed a taint bug, which as a side effect, meant that $! used within a tainted expression failed to have a string value. This quick fix just makes sure the POK flag is set (prior to it being shifted back to pPOK).
* preserve readonly flag when saving and restoring magic flagsChip Salzenberg2009-12-051-11/+20
|
* SvREFCNT_dec already checks if the SV is non-NULL (continued)Vincent Pit2009-11-081-6/+3
|
* mg.c uses a fixed NGROUPS contantperlbug-followup@perl.org2009-10-261-1/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | # New Ticket Created by casper.dik@sun.com # Please include the string: [perl #69977] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=69977 > This is a bug report for perl from casper.dik@sun.com, generated with the help of perlbug 1.36 running under perl 5.10.0. ----------------------------------------------------------------- [Please enter your report here] In mg.c NGROUPS is defined as follows: #if defined(HAS_SETGROUPS) # ifndef NGROUPS # define NGROUPS 32 # endif #endif and uses it later here: 2632 #ifdef HAS_SETGROUPS 2633 { 2634 const char *p = SvPV_const(sv, len); 2635 Groups_t *gary = NULL; 2636 2637 while (isSPACE(*p)) 2638 ++p; 2639 PL_egid = Atol(p); 2640 for (i = 0; i < NGROUPS; ++i) { 2641 while (*p && !isSPACE(*p)) 2642 ++p; 2643 while (isSPACE(*p)) 2644 ++p; 2645 if (!*p) 2646 break; 2647 if(!gary) 2648 Newx(gary, i + 1, Groups_t); 2649 else 2650 Renew(gary, i + 1, Groups_t); 2651 gary[i] = Atol(p); 2652 } 2653 if (i) 2654 (void)setgroups(i, gary); 2655 Safefree(gary); 2656 } 2657 #else /* HAS_SETGROUPS */ This should be changed as follows
* Add Perl_ck_warner(), which combines Perl_ckwarn() and Perl_warner().Nicholas Clark2009-10-121-11/+9
| | | | | | | Replace ckWARN{,2,3,4}() && Perl_warner() with it, which trades reduced code size (about 0.2%), for 1 more function call if warnings are not enabled. However, if we're now in the L1 or L2 cache when we weren't previously, that's still going to be a speed win.
* finish more implementing -DB vs. -DxChip Salzenberg2009-08-301-1/+2
|