summaryrefslogtreecommitdiff
path: root/sv.c
Commit message (Collapse)AuthorAgeFilesLines
* add PL_signalhook to hook into signal dispatchDavid Mitchell2010-06-041-0/+1
| | | | | This is initially intended for threads::shared and shouldn't (yet) be considered part of the public API.
* Fix CLONE/weakref bug revealed by adf8f095c5881bce.Nicholas Clark2010-05-251-7/+36
| | | | | | | | The AV unreferenced in the clone_params needs to be reference counted, rather than not referenced counted, because the fixup to ensure that all otherwise 0-reference count scalars have a reference (on the temps stack) happens after CLONE is run, and CLONE can run Perl code that causes their reference counts to increase from then return to zero, which prematurely triggers sv_free().
* Convert PAD_DUP to a function Perl_padlist_dup().Nicholas Clark2010-05-241-1/+1
| | | | assert() that pads are never AvREAL().
* When deleting CLONE_PARAMS, push any unreferenced SVs onto the temps stack.Nicholas Clark2010-05-241-32/+29
| | | | | | | | | | | | Effectively this leaves the cloned-into interpreter in a consistent state. In the cloned-from interpreter, the SV targets of non-reference owning pointers *are* referenced and managed by other pointers. SvREFCNT() == 0 SVs in the cloned-into interpreter result from the non-reference owning pointers being found and followed, but the reference owning and managing pointers not being part of the subsection of interpreter state cloned over. Hence, this change creates reference owning pointers to this SVs on the temps stack, which ensures that they are correctly cleaned up, and don't "leak" until interpreter destruction. (Which might be some time away, in a persistent process.)
* Better ithreads cloning - add all SVs with a 0 refcnt to the temps stack.Nicholas Clark2010-05-241-24/+61
| | | | | | | | | | Track all SVs created by sv_dup() that have a 0 reference count. If they still have a 0 reference count at the end of cloning, assign a reference to each to the temps stack. As the temps stack is cleared at thread exit, SVs book keeping will be correct and consistent before perl_destruct() makes its check for leaked scalars. Remove special case code for checking each @_ and the parent's temp stack.
* Cleaner implementations for Perl_clone_params_{new,del}Nicholas Clark2010-05-241-33/+10
| | | | Not source or binary compatible with maint-5.12.
* Abstract *correct* initialisation of CLONE_PARAMS into Perl_clone_params_new().Nicholas Clark2010-05-241-0/+81
| | | | | | | | | | | | | As it allocates memory dynamically, add Perl_clone_params_del(). This will allow CLONE_PARAMS to be expand in future in a source and binary compatible fashion. These implementations of Perl_clone_params_new()/Perl_clone_params_del() jump through hoops to remain source and binary compatible, in particular, by not assuming that the structure member is present and correctly initialised. Hence they should be suitable for inclusion into Devel::PPPort. Convert threads.xs to use them, resolving RT #73046.
* Convert Perl_sv_dup_inc() from a macro to a real function.Nicholas Clark2010-05-241-7/+13
|
* In perl_clone_using(), turn off AvREAL() on param->stashes.Nicholas Clark2010-05-241-0/+7
| | | | This is an optimisation, not a bug fix.
* Change the API documentation from sv_2nv to sv_2nv_flags.Nicholas Clark2010-05-231-1/+1
| | | | Addendum to 39d5de13bc6d138b.
* Eliminate xhv_fill from struct xpvhv.Nicholas Clark2010-05-211-1/+1
|
* Make HvFILL() count the allocated buckets, instead of reading a stored value.Nicholas Clark2010-05-211-7/+0
| | | | | Add a function Perl_hv_fill to perform the count. This will save 1 IV per hash, and on some systems cause struct xpvhv to become cache aligned.
* make overload respect get magicDavid Mitchell2010-05-211-4/+39
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In most places, ops checked their args for overload *before* doing mg_get(). This meant that, among other issues, tied vars that returned overloaded objects wouldn't trigger calling the overloaded method. (Actually, for tied and arrays and hashes, it still often would since mg_get gets called beforehand in rvalue context). This patch does the following: Makes sure get magic is called first. Moves most of the overload code formerly included by macros at the start of each pp function into the separate helper functions Perl_try_amagic_bin, Perl_try_amagic_un, S_try_amagic_ftest, with 3 new wrapper macros: tryAMAGICbin_MG, tryAMAGICun_MG, tryAMAGICftest_MG. This made the code 3800 bytes smaller. Makes sure that FETCH is not called multiple times. Much of this bit was helped by some earlier work from Father Chrysostomos. Added new functions and macros sv_inc_nomg(), sv_dec_nomg(), dPOPnv_nomg, dPOPXiirl_ul_nomg, dPOPTOPnnrl_nomg, dPOPTOPiirl_ul_nomg dPOPTOPiirl_nomg, SvIV_please_nomg, SvNV_nomg (again, some of these were based on Father Chrysostomos's work). Fixed the list version of the repeat operator (x): it now only calls overloaded methods for the scalar version: (1,2,$overloaded) x 10 no longer erroneously calls x_method($overloaded,10)) The only thing I haven't checked/fixed yet is overloading the iterator operator, <>.
* Remove union _xivu from struct xpvhv - replace it with a non-union xav_keys.Nicholas Clark2010-05-211-1/+1
|
* Remove union _xivu from struct xpvav - replace it with a non-union xav_alloc.Nicholas Clark2010-05-211-1/+1
| | | | This was the only user of xivu_p1 in union _xivu, so remove that too.
* Reinstate space optimisations to SV body structures.Nicholas Clark2010-05-211-4/+22
|
* In the SV body, exchange the positions of the NV and stash/magic.Nicholas Clark2010-05-211-6/+7
|
* Remove all space optimisations from SV body structures.Nicholas Clark2010-05-211-31/+31
|
* In sv.c, _all_ {new,del}_X* macros can be *_body_allocated.Nicholas Clark2010-05-201-15/+8
| | | | | | | Previously those where bodies_by_type[sv_type].offset was zero were using {new,del}_body_typed. However, the optimiser can spot this, and generates the same object code. This allows simplification of the C code, and more flexibility to rearrange the structures without generating bugs.
* Return 0 (with a warning) for sprintf("%.0g") and sprintf("%.0f")Nicholas Clark2010-05-131-9/+2
| | | | | | | | | | | | | | | | | | | | | | | | There is special case code in the sprintf implementation, for simple %f and %g formats, conditionally compiled in only when NVs are doubles. Under long doubles, these are handled by the general purpose code, which always returns 0 if the argument is missing. Note that sprintf(" %.0g"), ie a leading space, sufficient to bypass the special case code, would return the string " 0". The special case code used to return an empty string, meaning that the behaviour of sprintf("%.0g") and sprintf("%.0f") was inconsistent between a perl built with doubles, and a perl with long doubles, and the behaviour of sprintf("%.0g") and sprintf(" %.0g") was inconsistent. 5b98cd54dff3b163 fixed #62874 - the special case code did not warn, but changed behaviour to return 0. d347ad18ecf3da70 undid the behaviour change, viewing it as a regression. However, the tests added in 5b98cd54dff3b163 expose the inconsistency in behaviour between doubles and long doubles. There should be no inconsistency, hence the only logically consistent conclusion is that the special case implementation was wrong - it cannot give results inconsistent with the general code. Hence this commit changes it to return 0 (with a warning). This is achieved by simply skipping the special case code, if there are insufficient arguments.
* add SV_SKIP_OVERLOAD flag to sv_2*v_flags fnsDavid Mitchell2010-05-081-4/+16
| | | | | | While trying to coerce an SV into a string or whatever, stop if you suddenly discover it's overloaded (this may not happen until after you've called it's get magic)
* add flags arg to sv_2nv (as sv_2nv_flags)David Mitchell2010-05-081-4/+5
|
* Stop returning 0 for sprintf("%.0g")Vincent Pit2010-05-061-1/+3
| | | | | | And also from throwing two "Missing argument" warnings for this construct. This was a regression introduced by 5b98cd54dff3b16344eab33ce6b09fb6fb1b89c2.
* Make sv_vcatpvfn() complain when special formats "%s" and "%.0f" can't find ↵Vincent Pit2010-05-061-1/+3
| | | | | | their argument This fixes [RT #62874] : printf does not print a warning when a lone %s conversion is used
* When saving ints, if the value is small enough save it with the type.Nicholas Clark2010-05-051-0/+1
| | | | This uses a new type, SAVEt_INT_SMALL.
* When saving I32s, if the value is small enough save it with the type.Nicholas Clark2010-05-051-0/+1
| | | | This uses a new type, SAVEt_I32_SMALL.
* For SAVEt_I16, save the value with the type.Nicholas Clark2010-05-041-1/+1
|
* For SAVEt_I8, save the value with the type.Nicholas Clark2010-05-041-1/+1
|
* For SAVEt_BOOL, save the value with the type.Nicholas Clark2010-05-031-6/+2
|
* For SAVEt_ALLOC, store the number of save stack entries used with the type.Nicholas Clark2010-05-031-5/+1
|
* For SAVEt_REGCONTEXT, store the number of save stack entries used with the type.Nicholas Clark2010-05-021-0/+2
|
* Better fix for RT #2140 (list assignment with duplicated temporaries)Nicholas Clark2010-05-021-3/+1
| | | | | | | | | 4c8f17b905f2 (change 7867) took the approach of a special case in sv_setsv() when PL_op indicated that the current OP was OP_AASSIGN. The problem is in one part of pp_aassign, where it was using sv_mortalcopy() on values that were correctly marked as temporaries, but also still needed later. Hence a more targetted solution is to avoid that call, and to instead use API calls that will not steal temporaries.
* For SVt_CLEAR, store the pad offset with the type.Nicholas Clark2010-05-021-2/+2
| | | | This saves 1 slot on the save stack for each lexical encountered at run time.
* On the save stack, store the save type as the bottom 6 bits of a UV.Nicholas Clark2010-05-011-2/+6
| | | | This makes the other 26 (or 58) bits available for save data.
* Deprecate Perl_ptr_table_clear(). Nothing outside sv.c uses it.Nicholas Clark2010-04-291-1/+13
| | | | | Inline the necessary parts of Perl_ptr_table_clear() into Perl_ptr_table_free(). No need to reset memory to zero that is about to be freed anyway.
* Fix possible undefined behaviour introduced by ↵Vincent Pit2010-04-261-1/+2
| | | | b9e00b79e4947c49d5520633f9efd2a8e39ec14f
* Globs that are in symbol table can be un-globbedLubomir Rintel (GoodData)2010-04-261-3/+4
| | | | | | | | | | | If a symbol table entry is undefined when a glob is assigned into it, it gets a FAKE flag which makes it possible to be downgraded when non-glob is subsequently assigned into it. It doesn't really matter, until we decide to localize it -- it wouldn't be possible to restore its GP upon context return if it changed type, therefore we must not do that. This patch turns off FAKE flag when localizing a GV and restores it when the context is left. A test case is included.
* unwinding target nominated by separate globalZefram2010-04-251-0/+1
| | | | | | | | When unwinding due to die, the new global PL_restartjmpenv points to the JMP_ENV at which longjmping should stop and control should be transferred to PL_restartop. This replaces the previous use of cxstack[cxstack_ix+1].blk_eval.cur_top_env, located in a nominally-discarded context frame.
* Don't allocate pointer table entries from arenas.Nicholas Clark2010-04-251-54/+46
| | | | | Instead, allocate a private arena chain per pointer table, and free that chain when its pointer table is freed. Patch from RT #72598.
* Consistently use OP_DESC instead of OP_NAME in error messagesRafael Garcia-Suarez2010-04-221-6/+6
| | | | | | | This solves bug: [perl #74572] chop dies with error about schop This is not backwards-compatible, as some error messages can change, as seen by the required change to t/op/sprintf2.t.
* use cBOOL for bool castsDavid Mitchell2010-04-151-3/+3
| | | | | | | | | | | | | 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.
* [perl #45167] Taint removal by sprintfDavid Mitchell2010-03-211-0/+1
| | | | | | | | | | | | | | | | Under some circumstances the value returned by sprintf wasn't tainted, even though its args were. While trying to fix this, I also came across a second bug (which made fixing the first bug very confusing!) where the TARG of the sprintf op, after getting tainted once, permanently retained taint magic, which depending on circumstances, wasn't always set to untainted (mg_len =0) The original bug basically boiled down to parts of Perl_sv_vcatpvfn() directly manipulating the target with SvGROW() / Copy(), which failed to taint the target. Other parts used sv_catsv(), which did. So for example: "%s%s" failed, (only SvGROW) "%s %s" worked (the space char was appended using sv_catsv).
* Clarify sv.c API wording.Karl Williamson2010-02-281-1/+2
|
* fix for [perl #72604] @DB::args and win32 forkDavid Mitchell2010-02-281-3/+2
| | | | | | | | | | | | | A previous fix for [perl #66108] (7fa38291524c327a3cb23bfe94979e1537743cac) stopped cloning PL_dbargs, on the grounds that it was usually filled with garbage (it contains an un-refcounted copy of @_'s elements; once the function has returned, these may have been freed or reassigned). However, the fix instead recreated PL_dbargs as a new empty AV that *wasn't* then associated with the DB::args glob; so modifications to PL_dbargs weren't seen via @DB::args. The fix is to simply set it to null when cloning; pp_caller() will recreate it again if necessary when it is needed.
* rt #72866 - add magic to arrayrefs assigned to *Foo::ISATony Cook2010-02-181-4/+4
| | | | | | | The fix for rt #60220 (26d68d86) updated the isa cache when an arrayref was assigned to some *ISA, but didn't add the magic to the new @ISA to catch any further updates to it. Add the magic, and tests.
* Avoid a panic from the UTF-8 length cache if the length overflows 32 bits.Nicholas Clark2010-02-181-0/+4
| | | | | | Rather than storing a value, and having it wrap to a wrong value, treat such lengths as "still unknown". This is a work around until a proper solution is designed an implemented.
* Remove unused variableH.Merijn Brand2010-02-161-2/+0
|
* Convert Perl_sv_pos_u2b_proper() to Perl_sv_pos_u2b_flags().Nicholas Clark2010-02-141-25/+27
| | | | | | | 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.
* Removes 32-bit limit on substr arguments. The full range of IV and UV is ↵Eric Brine2010-02-141-6/+41
| | | | available for the pos and len arguments, with safe conversion to STRLEN where it's smaller than an IV.
* Fix for non-regexps being upgraded to SVt_REGEXPNicholas Clark2010-02-091-1/+43
| | | | | | | | | | | | | | $ ./perl -lwe '$a = ${qr//}; $a = 2; print re::is_regexp(\$a)' 1 It is possible for arbitrary SVs (eg PAD entries) to be upgraded to SVt_REGEXP. (This is new with first class regexps) Whilst the example above does not SEGV, it will be possible to write code that will cause SEGVs (or worse) at the point when the scalar is freed, because the code in sv_clear() assumes that all scalars of type SVt_REGEXP *are* regexps, and passes them to pregfree2(), which assumes that pointers within are valid.