| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
| |
Fix spelling on various files pertaining to core Perl.
|
|
|
|
|
|
|
| |
svtype is an enum with 18 values. SVTYPEMASK is 31. A picky compiler
(like on HPUX) will complain that casting 31 to a svtype is an error.
We have SvIS_FREED() to do this properly anyway.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Several cases that used to be simple assignment ops with lexical
variables have been optimized in some way:
- $foo = undef is now a single OP_UNDEF with special flags
- $foo = ... is now a single OP_PADSV_STORE
- $foo[0] = ... is now a single OP_AELEMFASTLEX_STORE
This is mostly transparent to users, except for "Use of uninitialized
value" warnings, which previously mentioned the name of the undefined
variable, but don't do so anymore in blead.
This commit teaches find_uninit_var() about the new ops, so error
messages for these ops can mention variable names again.
Fixes #20945.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
I misnamed some of the RCPV stuff when it was introduced. The macro
which I called SAVERCPVFREE should have been called SAVERCPV,
and there should also have been a SAVEFREERCPV macro.
Note the naming system for these functions is a bit confusing.
SAVEFREERCPV /just/ frees. SAVERCPV saves and restores (eg, its like
local). SAVEFREESV is an exception. :-( and it behaves like SAVERCPV.
See for instance SAVEPV or similar macros.
There also should have been RCPV_REFCNT_dec() and RCPV_REFCNT_inc()
macros.
There was also missing documentation. This patch should fix all of these
issues. Since this functionality has never been released in a production
perl it should be fine to do these renames, nothing out there should use
these macros yet.
I noticed these oversights while fixing Scope::Upper, see also:
https://github.com/Perl/perl5/issues/20861
https://rt.cpan.org/Ticket/Display.html?id=146897
|
|
|
|
|
|
|
|
| |
This field is used on DEBUG_LEAKING_SCALARS builds to track the file
where the SV was allocated. When freeing the SV, the string was
freed but the pointer was left pointing at the freed string.
So NULL it out.
|
|
|
|
|
|
|
|
|
|
|
| |
* Free the attrlist OP fragment when applying class or field attribute
* Free the OP_PADxV ops we only use to get the pad index out for
fieldvar declarations
* Add a refcount to the `struct padname_fieldinfo` to keep track of its
capture in inner closures so it can be freed at the right time
* Free the class-related fields out of HvAUX
* Free the actual ObjectFIELDS() array when destroying an object instance
* Dup fieldinfo->paramname at sv_dup() time / free it at free time
|
|
|
|
|
|
|
| |
It needs to:
* clone SVt_PVOBJ instances
* clone the xhv_class_* fields of an SVt_PVHV
* clone the PadnameFIELDINFO structure of a padname
|
| |
|
|
|
|
| |
helper function
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This compiler predates the addition of designated initializers to the
C++ standard, so it's not surprising its implementation isn't fully
compliant.
Omitting a field in a designated initializer list causes the following
error:
sv.c: In function ‘void Perl_sv_upgrade(SV*, svtype)’:
sv.c:1088:13: sorry, unimplemented: non-trivial designated initializers
not supported
|
|
|
|
| |
during sv_inc()
|
|
|
|
|
| |
The existing fast path for SVt_NULL/SVt_IV can also be used for bodyless
SVt_NVs.
|
|
|
|
|
|
|
| |
As per the old test, SvREFCNT_dec used to wrap sv_free, which then
calls the Perl_SvREFCNT_dec function. Nowadays, SvREFCNT_dec calls
Perl_SvREFCNT_dec directly, and the latter is a very small inline
function. Using the macro probably should be the go-to now.
|
| |
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The code in report_redefined_cv() would check whether the old
constant and the new constant were the same SV to avoid warning on
duplicate imports of the same constant. Since both gv_setref()
and report_redefined_cv() used cv_const_sv() to fetch the constant
SV, which returns NULL for an AV based constant sub, the check
for the equivalent SV would compare NULL to NULL and
report_redefined_cv() would return early.
Additional checks were required further down to prevent sv_cmp()
being called on AVs.
The check for simple SV's allow redefinition of constant subs if the
new value string compares the same as the old value. The AV check
does not try to allow that.
Fixed #20742
|
|
|
|
| |
These had gotten in the wrong section by things moving around in sv.c
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
In GH 20435 many typos in our C code were corrected. However, this pull
request was not applied to blead and developed merge conflicts. I
extracted diffs for the individual modified files and applied them with
'git apply', excepting four files where patch conflicts were reported.
Those files were:
handy.h
locale.c
regcomp.c
toke.c
We can handle these in a subsequent commit. Also, had to run these two
programs to keep 'make test_porting' happy:
$ ./perl -Ilib regen/uconfig_h.pl
$ ./perl -Ilib regen/regcomp.pl regnodes.h
|
|
|
|
|
|
|
|
| |
They are similar to SVf and SVf_QUOTEDPREFIX but take an HV * argument
and use HvNAME() and related macros to extract the string. This is
helpful as it makes constructing error messages from a stash (HV *)
easier. It is the callers responsibility to ensure that the HV is
actually a stash.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
When dealing with a tied scalar with get magic, and the FETCH method
returned a blessed reference with overloading magic (with "a" magic),
the tied scalar returned from the fetch was not copied prior to calling
the magic function as an argument, this would then cause the get magic
to be called again if the overloaded method happened to copy or
otherwise use the tied scalar. The solution is to copy the reference
prior to dispatching the overload call.
It looks like we have been testing for the double FETCH for some time,
without any good rationale, so this test merely changes things to expect
the desired count.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
In a nutshell, for a long time the minimum PV length (hardcoded
in Perl_sv_grow) has been 10 bytes and the minimum AV array size
(hardcoded in av_extend_guts) has been 4 elements.
These numbers have been used elsewhere for consistency (e.g.
Perl_sv_grow_fresh) in the past couple of development cycles.
Having a standard definition, rather than hardcoding in multiple
places, is more maintainable. This commit therefore introduces
into perl.h:
PERL_ARRAY_NEW_MIN_KEY
PERL_STRLEN_NEW_MIN
(Note: Subsequent commit(s) will actually change the values.)
|
|
|
|
|
|
|
|
|
| |
gcc 12 was complaining that evaluating (somehekptr)->hek_key
was always true in many places where HvNAME() or HvENAME() was
being called in boolean context.
Add new macros to check whether the names should be available and
use those instead.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
We can't put PL_compiling or PL_curcop on the save stack as we don't
have a way to ensure they cross threads properly. This showed up as a
win32 t/op/fork.t failure in the thread based fork emulation layer.
This adds a new save type SAVEt_CURCOP_WARNINGS and macro
SAVECURCOPWARNINGS() to complement SAVEt_COMPILER_WARNINGS and
SAVECOMPILEWARNINGS(). By simply hard coding where the pointers should
be restored to we side step the issue of which thread we are in.
Thanks to Graham Knop for help identifying that one of my commits was
responsible.
|
|
|
|
|
| |
With RCPV strings we can use the RCPV_LEN() macro, and
make this logic a little less weird.
|
|
|
|
|
|
|
|
| |
I also fixed const correctness for PL_splitstr, it was initialized
to " " which required it to be const, but the value is only looked
at when PL_minus_F is true, so it wasn't necessary.
So initialize it to NULL, and duplicate the value in threads.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
We have a weird bifurcation of the cop logic around threads. With
threads we use a char * cop_file member, without it we use a GV * and
replace cop_file with cop_filegv.
The GV * code refcounts filenames and more or less efficiently shares
the filename amongst many opcodes. However under threads we were
simplify copying the filenames into each opcode. This is because in
theory opcodes created in one thread can be destroyed in another. I say
in theory because as far as I know the core code does not actually do
this. But we have tests that you can construct a perl, clone it, and
then destroy the original, and have the copy work just fine, this means
that opcodes constructed in the main thread will be destroyed in the
cloned thread. This in turn means that you can't put SV derived
structures into the op-tree under threads. Which is why we can not use
the GV * stategy under threads.
As such this code adds a new struct/type RCPV, which is a refcounted
string using shared memory. This is implemented in such a way that code
that previously used a char * can continue to do so, as the refcounting
data is located a specific offset before the char * pointer itself.
This also allows the len data to embedded "into" the PV, which allows
us to expose macros to acces the length of what is in theory a null
terminated string.
struct rcpv {
UV refcount;
STRLEN len;
char pv[1];
};
typedef struct rcpv RCPV;
The struct is sized appropriately on creation in rcpv_new() so that the
pv member contains the full string plus a null byte. It then returns a
pointer to the pv member of the struct. Thus the refcount and length and
embedded at a predictable offset in front of the char *, which means we
do not have to change any types for members using this.
We provide three operations: rcpv_new(), rcpv_copy() and rcpv_free(),
which roughly correspond with newSVpv(), SvREFCNT_inc(), SvREFCNT_dec(),
and a handful of macros as well. We also expose SAVERCPVFREE which is
similar to SAVEGENERICSV but operates on pv's constructed with
rcpv_new().
Currently I have not restricted use of this logic to threaded perls. We
simply do not use it in unthreaded perls, but I see no reason we
couldn't normalize the code to use this in both cases, except possibly
that actually the GV case is more efficient.
Note that rcpv_new() does NOT use a hash table to dedup strings. Two
calls to rcpv_new() with the same arguments will produce two distinct
pointers with their own refcount data.
Refcounting the cop_file data was Tony Cook's idea.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
For "BODYLESS" IVs and NVs, type up/downgrades can be easily done
without having to call sv_upgrade. (Which will also not convert a
BODYLESS NV back down to an IV, even when it is harmless to do so.)
This commit adds "BODYLESS" handling to sv_setiv and sv_setnv, which
previously lacked it, and "BODYLESS_NV" handling to sv_setsv_flags,
which previously only special-cased "BODYLESS_IV"s.
The BODYLESS_IV code in sv_setsv_flags previously did not preserve
flags such as SVs_TEMP or SVs_PADTMP, which seemed like a potential
latent bug. (The new BODYLESS_NV code *has* to preserve SVs_TEMP in
order for all tests in t/lib/warnings to continue to pass.) Rather
than clearing all flags, this commit instead does a SvOK_off(dsv)
for both BODYLESS_IV and BODYLESS_NV cases.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This is a step in solving #20155
The POSIX 2008 locale API introduces per-thread locales. But the
previous global locale system is retained, probably for backward
compatibility.
The POSIX 2008 interface causes memory to be malloc'd that needs to be
freed. In order to do this, the caller must first stop using that
memory, by switching to another locale. perl accomplishes this during
termination by switching to the global locale, which is always available
and doesn't need to be freed.
Perl has long assumed that all that was needed to switch threads was to
change out tTHX. That's because that structure was intended to hold all
the information for a given thread. But it turns out that this doesn't
work when some library independently holds information about the
thread's state. And there are now some libraries that do that.
What was happening in this case was that perl thought that it was
sufficient to switch tTHX to change to a different thread in order to do
the freeing of memory, and then used the POSIX 2008 function to change
to the global locale so that the memory could be safely freed. But the
POSIX 2008 function doesn't care about tTHX, and actually was typically
operating on a different thread, and so changed that thread to the global
locale instead of the intended thread. Often that was the top-level
thread, thread 0. That caused whatever thread it was to no longer be in
the expected locale, and to no longer be thread-safe with regards to
localess,
This commit causes locale_term(), which has always been called from the
actual terminating thread that POSIX 2008 knows about, to change to the
global thread and free the memory.
It also creates a new per-interpreter variable that effectively maps the
tTHX thread to the associated POSIX 2008 memory. During
perl_destruct(), it frees the memory this variable points to, instead of
blindly assuming the memory to free is the current tTHX thread's.
This fixes the symptoms associtated with #20155, but doesn't solve the
whole problem. In general, a library that has independent thread status
needs to be updated to the new thread when Perl changes threads using
tTHX. Future commits will do this.
|
|
|
|
|
|
|
|
|
|
|
|
| |
Some configurations require us to store the current locale for each
category. Prior to this commit, this was done in the array
PL_curlocales, with the entry for LC_ALL being in the highest element.
Future commits will need just the value for LC_ALL in some other
configurations, without needing the rest of the array. This commit
splits off the LC_ALL element into its own per-interpreter variable to
accommodate those. It always had to have special handling anyway beyond
the rest of the array elements,
|
|
|
|
| |
So far this hadn't been an issue, but it will be for a future commit.
|
|
|
|
|
|
| |
A thread is supposed to start with the locale set to the C locale. We
were duping the parent values, and later overriding. Better to set to C
from the beginning.
|
|
|
|
|
|
| |
This moves the code for cloning the locale variables to a single place,
consolidating some that had the same cpp directives. It showed that one
variable was cloned twice; the redundant one is now removed.
|
|
|
|
|
|
|
|
|
|
| |
sv_vsetpvfn does just two things:
* SvPVCLEAR on the sv passed in
* calls sv_vcatpvfn_flags
Since the SV passed into sv_vsetpvfn by vnewSVpvf is a brand new SV,
it is more efficient to inline sv_vsetpvfn and change the SvPVCLEAR
to SvPVCLEAR_FRESH.
|
|
|
|
|
| |
It's more efficient to directly create the desired SV type than create
a SVt_NULL and then call sv_upgrade to get the desired type.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
In the "first_ switch" statement in Perl_sv_setsv_flags, there's this case:
case SVt_INVLIST:
invlist_clone(ssv, dsv);
break;
When the INVLIST code was added, it was unclear whether the logic following
that switch needed to apply to INVLISTs or not. Early returns were also seen
as risky from a future maintenance perspective. As a precaution, this case
was written to `break` rather than `return`.
With later analysis though, it seems like the code below this switch does
not apply to INVLISTs, apart from one unintended interaction.
* invlist_clone() - in regcomp.c - copies the PV buffer of ssv to dsv.
* However, whenever an invlist is initialized, SvPOK_on is called on its SV;
according to the nearby comment "/* This allows B to extract the PV */".
* Because the switch case does not return, the later `if (sflags & SVp_POK)`
branch will try to swipe/cow/copy the PV buffer of ssv to dsv. This is an
unnecessary double copy.
On that analysis, this commit changes the break into a return.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This commit removes the separate mutex for locking locale-related
numeric operations on threaded perls; instead using the general locale
one. The previous commit made that a general semaphore, so now suitable
for use for this purpose as well.
This means that the locale can be locked for the duration of some
sprintf operations, longer than before this commit. But on most modern
platforms, thread-safe locales cause this lock to expand just to a
no-op; so there is no effect on these. And on the impacted platforms,
one is not supposed to be using locales and threads in combination, as
races can occur. This lock is used on those perls to keep Perl's
manipulation of LC_NUMERIC thread-safe. And for those there is also no
effect, as they already lock around those sprintf's.
|
|
|
|
|
| |
Future commits will use this new capability, and in Configurations where
no locale locking is currently necessary.
|
|
|
|
|
| |
Rather than recalculate this combined conditional, do it once in
perl.h.
|
|
|
|
|
|
| |
This conditional dates from when the rest of the conditions used
'HAS_foo' (from config.h) instead of USE_foo, which takes more things
into account.
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
What these functions do has been subsumed by code introduced in previous
commits, and in a more straight forward manner.
Also removed in this commit is the cache of the knowing what locales are
UTF-8 or not. This data is now cheaper to calculate when needed, and
there is now a single entry cache, so I don't think the complexity
warrants keeping it.
It could be added back if necessary, split off from the remainder of
this commit.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Nested BEGIN blocks can cause us to segfault by exhausting
the C stack. Eg:
perl -le'sub f { eval "BEGIN { f() }" } f()'
will segfault. This adds a new interpreter var PL_eval_begin_nest_depth
to keep track of how many layer of eval/BEGIN we have seen, and a new
reserved variable called ${^MAX_NESTED_EVAL_BEGIN_BLOCKS} which can be
used to raise or lower the limit. When set to 0 it blocks BEGIN entirely,
which might be useful from time to time.
This fixes https://github.com/Perl/perl5/issues/20176
|
|
|
|
|
| |
This is in preparation for working on it; the new name, mem_collxfrm_ is
in compliance with the C Standard; the old was not.
|
|
|
|
|
|
|
|
|
|
|
| |
When changing locales the new decimal point needs to be calculated.
This commit creates a new per-interpreter variable to save that
calculation, so it only has to be done when a new locale is set; prior
to this commit it was recalculated each time it was needed.
The calculation is still performed twice when the new locale is switched
into. But the redundant calculation will be removed in a couple of
commits hence.
|
|
|
|
|
|
|
|
| |
This is now used as a cache of length 1 to avoid having to lookup up the
UTF-8ness as often.
This commit also skips doing S_newctype() if the new boss is the same as
the old
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
messages.
These new formats are intended to be used in error messages where
we want to show the contents of a string without any possible
hidden characters not rendering in the error message, and where
it would be unreasonable to show every character of the string
if it is very long.
A good example would be when we want to say that a class name is
illegal. Consider:
"Foo\0"->thing()
should not throw an error message about "Foo" being missing, the fact
there is a null in there should be visible to the developer.
Similarly if we had
("x" x 1000_000)->thing()
we also do not want to throw a 1MB error message as it is generally
just unhelpful, a class name that long is almost certainly a mistake.
Currently this patch restricts it to showing 256 characters, the first
128 followed by an ellipses followed by the last 128 characters, but the
docs are such that we can change that if we wish, I suspect something
like 100 would be more reasonable. You can override the define
PERL_QUOTEDPREFIX_LEN to a longer value in Configure if you wish.
Example usage:
other= newSVpvs("Some\0::Thing\n");
sv_catpvf(msg_sv,"%" SVf_QUOTEDPREFIX, SVfARG(other));
Should append
"Some\0::Thing\n"
to the msg_sv. If it were very long it would have ellipses infixed. The
class name "x" x 1_000_000 would show
Can't locate object method "non_existent_method" via \
package "x[repeated 128 times]"..."x[repeated 128 times]" \
(perhaps you forgot to load \
"x[repeated 128 times]"..."x[repeated 128 times]"?) at -e line 1.
(but obviously as one line with the literal text of the class instead of
"[repeated 128 times]")
This patch changes a variety of error messages that used to output the
full string always. I haven't changed every place that this could happen
yet, just the main ones related to method calls, subroutine names and
the like.
|
|
|
|
|
|
|
|
| |
If this flag is set, then the CvXSUBANY(cv).any_sv pointer will have its
reference count decremented when the CV itself is freed. This is useful
for XS extensions that wish to store extra data in here. Without this
flag, such extensions have to resort to using magic with a 'free'
function to perform this work.
|