99 Commits

Author SHA1 Message Date
Karl Williamson
9b79602764 perlapi: newAV() fix typo 2025-09-18 22:49:10 -06:00
Karl Williamson
4f5164ad13 Convert all core uses of _ASSERT__() to assert()
The former symbol is undefined behavior in C and C++.
2025-09-03 19:46:22 -06:00
Karl Williamson
fd80f10181 Convert union _xmgu to legal name 2025-09-01 08:12:36 -06:00
Karl Williamson
d7e5a09366 AvFILL: Evaluate argument exactly once
Macros should not evaluate their arguments more than once due to the
possibility of the argument being an expression with side effects.

This commit creates an inlined helper function to do the main
processing.
2025-07-30 09:50:04 -06:00
Karl Williamson
316d8ea841 Revert "Move Perl_newAV() from mathoms to av.h"
This reverts commit 6a3ea4b452fdfc6bab52ec7179d25af3c115f8ee.
2025-04-20 12:13:58 -06:00
Karl Williamson
0ac9cc0234 av.h Remove obsolete comment
See https://github.com/Perl/perl5/pull/22714#pullrequestreview-2422048615
2024-11-17 13:57:21 -07:00
Karl Williamson
6a3ea4b452 Move Perl_newAV() from mathoms to av.h 2024-11-17 13:57:21 -07:00
Paul "LeoNerd" Evans
de762f9311 Define and use macro families for typed refcount increment
Create specific macros for incrementing the refcount of an AV, CV, GV or
HV, returning a typed pointer to avoid the caller needing to cast the
result. This yields neater easier-to-read code.

While not implemented here, this gives an opportunity to add an
`assert()` check on the SvTYPE of the structure being adjusted, for
extra debug checking during debugging builds.
2024-07-22 16:51:49 +01:00
Karl Williamson
5f29d4af0d perlapi: Combine all av_len synonyms into one entry 2024-06-16 18:46:36 -06:00
Karl Williamson
ebb7a94b17 perlapi, av.h: Need "apidoc_item"
Commit 0d564a3d013287cf0880fdc3264f30c20fe6188d added docs for
newAV_mortal, but it needed to use "apidoc_item", not plain "apidoc".

Not doing so resulted in this build time warning:

Empty pod for newAV (from av.h) at autodoc.pl line 1265.

and the resulting pod/perlapi.pod was incorrect.

Plain "apidoc" is used to begin a new entry.  "apidoc_item" is for
related subsidiary functions to the main entry.

Suggestions welcome as to how to make this relationship more obvious.
Perhaps it should be renamed "apidoc_sub_item"
2024-02-07 06:30:58 -07:00
Richard Leach
0d564a3d01 av.h - document new newAV_mortal macro 2024-02-05 23:48:57 +00:00
Richard Leach
b8f7169e69 av.h - add newAV_mortal macro 2024-01-28 21:43:11 +00:00
Karl Williamson
e8c6e1955e perlapi: Further clean up AV docs 2022-05-20 14:56:15 -06:00
Karl Williamson
e815fc9e52 perlapi: Clean up some AV documentation
The consolidation of newAV with newAV_alloc_xz? included nonsensical
juxtapositions.  This cleans that up, adds a bit of markup, moves the
function implementing the newAV_alloc ones to internal, as there are no
CPAN uses, and we prefer the macro interface.
2022-05-20 14:32:29 -06:00
Richard Leach
013a76a28a av.h: more apidoc tweaks 2021-08-27 07:12:53 -06:00
Richard Leach
7fc83db1d1 av.h: apidoc updates for khw comments 2021-08-27 07:12:53 -06:00
Richard Leach
37018d9541 av.h - addressing comments 2021-08-27 07:12:53 -06:00
Richard Leach
48d21358f7 av.h - better document newAV_alloc_x/newAV_alloc_xz 2021-08-27 07:12:53 -06:00
Richard Leach
7073dfe33a av.h: document that backrefs lists are fake AVs 2021-08-27 07:11:48 -06:00
Richard Leach
4762e1f88c av.h: additional comments regarding real/fake AVs 2021-08-27 07:11:48 -06:00
Richard Leach
6e7a7813c3 av.h - document newAV_alloc_xz 2021-07-29 08:53:12 -07:00
Richard Leach
0b1c19ab1c Add Perl_av_new_alloc() function and newAV_alloc_x/z() macros 2021-05-26 13:37:12 +01:00
Michael G. Schwern
1604cfb027 style: Detabify indentation of the C code maintained by the core.
This just detabifies to get rid of the mixed tab/space indentation.

Applying consistent indentation and dealing with other tabs are another issue.

Done with `expand -i`.

* vutil.* left alone, it's part of version.
* Left regen managed files alone for now.
2021-01-17 09:18:15 -07:00
Karl Williamson
8922262882 autodoc.pl: Specify scn for single-purpose files
Many of the files in perl are for one thing only, and hence their
embedded documentation will be for that one thing.  By creating a hash
here of them, those files don't have to worry about what section that
documentation goes under, and so it can be completely changed without
affecting them.
2020-11-06 07:24:38 -07:00
Felipe Gasper
941f2f3825 Add POD for AvARRAY. 2020-09-29 09:06:19 -06:00
Karl Williamson
a56541ebc9 Document AvFILLp; clarify related entries 2020-09-13 21:13:58 -06:00
Karl Williamson
51b56f5c7c Reorganize perlapi
This uses a new organization of sections that I came up with.  I asked
for comments on p5p, but there were none.
2020-09-04 16:13:25 -06:00
Karl Williamson
70b05c7cee Change some =head1 to apidoc_section lines
apidoc_section is slightly favored over head1, as it is known only to
autodoc, and can't be confused with real pod.
2020-09-04 16:13:25 -06:00
Karl Williamson
87306e0674 Add av_count()
This returns the number of elements in an array in a clearly named
function.

av_top_index(), av_tindex() are clearly named, but are less than ideal,
and came about because no one back then thought of this one, until now
Paul Evans did.
2020-08-19 16:12:19 -06:00
Karl Williamson
bb7379d723 Note that AvFILLp is not for public use 2019-09-02 21:52:11 -06:00
Karl Williamson
78342678c3 Fix apidoc macro entries
This makes various fixes to the text that is used to generate the
documentation.  The dominant change is to add the 'n' flag to indicate
that the macro takes no arguments.  A couple should have been marked
with a D (for deprecated) flag, and a couple were missing parameters,
and a couple were missing return values.

These were spotted by using Devel::PPPort on them.
2019-06-25 09:07:12 -06:00
Karl Williamson
44170c9a70 Remove redundant info on =for apidoc lines
This information is already in embed.fnc, and we know it compiles.  Some
of this information is now out-of-date.  Get rid of it.

There was one bit of information that was (apparently) wrong in
embed.fnc.  The apidoc line asked that there be no usage example
generated for newXS.  I added that flag to the embed.fnc entry.
2019-05-30 18:13:29 -06:00
Karl Williamson
d29fa84aee perlapi: AvFILL isn't deprecated
See [perl #133278]
2018-07-16 18:40:12 -06:00
Karl Williamson
9506e94549 Change av_foo_nomg() name
These names sparked some controversy when created:

http://www.nntp.perl.org/group/perl.perl5.porters/2016/03/msg235216.html

I looked through existing code for paradigms to follow, and found some
occurrences of 'skip_foo_mg'.  So this commit changes the names to be

    av_top_index_skip_len_mg()
    av_tindex_skip_len_mg()

This is explicit about the type of magic that is ignored, and will still
be valid if another type of magic ever gets added.
2017-02-11 14:30:28 -07:00
Karl Williamson
8dbc0cc7f2 Imprison at_tindex_nomg()
This name is controversial.  Use #ifdef's to keep it from being exposed
outside of the places that already use it.  And don't publicize that it
exists.
2016-03-19 23:00:35 -06:00
Karl Williamson
6be58040b2 Add av_tindex_nomg()
This is like av_tindex, but doesn't handle magic.  I'm not documenting
it for now, in case it turns out this was not a good idea.

Inspired from an observation by Tony Cook.
2016-03-07 21:01:49 -07:00
Dagfinn Ilmari Mannsåker
abec5bedac Replace common Emacs file-local variables with dir-locals
An empty cpan/.dir-locals.el stops Emacs using the core defaults for
code imported from CPAN.

Committer's work:

To keep t/porting/cmp_version.t and t/porting/utils.t happy, $VERSION needed
to be incremented in many files, including throughout dist/PathTools.

perldelta entry for module updates.

Add two Emacs control files to MANIFEST; re-sort MANIFEST.

For: RT #124119.
2015-03-22 22:36:14 -04:00
Father Chrysostomos
9b7476d7a2 Make PADNAMELIST a separate type
This is in preparation for making PADNAME a separate type.
2014-11-30 11:48:37 -08:00
Father Chrysostomos
7db6405c07 Skip trailing constants when searching pads
Under ithreads, constants and GVs are stored in the pad.

When names are looked up up in a pad, the search begins at the end and
works its way toward the beginning, so that an $x declared later masks
one declared earlier.

If there are many constants at the end of the pad, which can happen
for generated code such as lib/unicore/TestProp.pl (which has about
100,000 lines and over 500,000 pad entries for constants at the
end of the file scope’s pad), it can take a long time to search
through them all.

Before commit 325e1816, constants used &PL_sv_undef ‘names’.  Since
that is the default value for array elements (when viewed directly
through AvARRAY, rather than av_fetch), the pad allocation code did
not even bother storing the ‘name’ for these.  So the name pad (aka
padnamelist) was not extended, leaving just 10 entries or so in the
case of lib/unicore/TestProp.pl.

Commit 325e1816 make pad constants have &PL_sv_no names, so the
name pad would be implicitly extended as a result of storing
&PL_sv_no, causing a huge slowdown in t/re/uniprops.t (which runs
lib/unicore/TestProp.pl) under threaded builds.

Now, normally the name pad *does* get extended to match the pad,
in pad_tidy, but that is skipped for string eval (and required
file scope, of course).  Hence, wrapping the contents of
lib/unicore/TestProp.pl in a sub or adding ‘my $x’ to end of it will
cause the same slowdown before 325e1816.

lib/unicore/TestProp.pl just happened to be written (ok, generated) in
such a way that it ended up with a small name pad.

This commit fixes things to make them as fast as before by recording
the index of the last named variable in the pad.  Anything following
that is disregarded in pad lookup and search begins with the last
named variable.  (This actually does make things faster before for
subs with many trailing constants in the pad.)

This is not a complete fix.  Adding ‘my $x’ to the end of a large file
like lib/unicore/TestProp.pl will make it just as slow again.

Ultimately we need another algorithm, such as a binary search.
2013-07-30 06:30:39 -07:00
Karl Williamson
1271919355 Add av_tindex() synonym for av_top_index()
The latter is a somewhat less clumsy name.  The old one is provided a a
very clear name; the new one as a somewhat slangy version
2013-02-08 14:44:24 -07:00
Karl Williamson
dab460cdc8 Change name 'av_top' to 'av_top_index'
In using the av_top() function created in a recent commit, I found
 myself being confused, and thinking it meant the top element of the
 array, whereas it really means the index of the top element of that
 array.  Since the new name has not appeared in a stable release, it can
 be changed, without remorse, to include 'index' in it.
2013-02-08 14:44:24 -07:00
Karl Williamson
36baafc9b5 Add av_top() synonym for av_len()
av_len() is misleadingly named.
2013-01-19 22:53:04 -07:00
Ricardo Signes
14d04a3346 update the editor hints for spaces, not tabs
This updates the editor hints in our files for Emacs and vim to request
that tabs be inserted as spaces.
2012-05-29 21:53:17 -04:00
Father Chrysostomos
af80dd863a [perl #97020] Carp (actually caller) leaking memory
Commit eff7e72c3 (Detect incomplete caller overrides in Carp) used
this little trick for detecting a @DB::args that an overridden
caller() failed to set:

+  @args = \$i; # A sentinal, which no-one else has the address of

But there is a bug in caller().  The first time caller tries to write
to @DB::args, it calls Perl_init_dbargs first.  That function checks
whether @DB::args is AvREAL, in case someone has assigned to it, and
takes appropriate measures.  But caller doesn’t bother calling
Perl_init_dbargs more than once.  So manually-assigned items in
@DB::args would leak, starting with the *second* call to caller.

Commit eff7e72c3 triggered that bug, resulting in a regression in
Carp, in that it started leaking.  eff7e72c3 was backported to 5.12.2
with commit 97705941a4, so in both 5.12 and 5.14 Carp is affected.

This bug (the caller bug, not Carp’s triggering thereof) also affects
any caller overrides that set @DB::args themselves, if there are
alternate calls to the overridden caller and CORE::caller.

This commit fixes that by changing the if (!PL_dbargs) condition
in pp_caller to if (!PL_dbargs || AvREAL(PL_dbargs)).  I.e., if
@args is either uninitialised or AvREAL then call Perl_init_dbargs.
Perl_init_dbargs also has a bug in it, that this fixes: The array not
only needs AvREAL turned off, but also AvREIFY turned on, so that
assignments to it that occur after its initialisation turn AvREAL back
on again.  (In fact, Larry Wall added a comment suggesting this back
in perl 5.000.)
2011-08-18 08:54:08 -07:00
Shlomi Fish
f0b90de112 perlapi.pod Enhancements
This is a patch to enhance perlapi.pod by providing Perl equivalents and
clarifying documentation where appropriate.
2011-07-18 22:09:18 -07:00
Nicholas Clark
4f7003f5e8 Remove union _xivu from struct xpvav - replace it with a non-union xav_alloc.
This was the only user of xivu_p1 in union _xivu, so remove that too.
2010-05-21 07:03:52 +01:00
Nicholas Clark
6e1287864c In the SV body, exchange the positions of the NV and stash/magic. 2010-05-21 07:03:51 +01:00
Nicholas Clark
c8e503bfe4 Eliminate *_ALLOCATED_HEAD and *_HEAD macros which are now used only once. 2009-08-22 20:49:37 +01:00
Nicholas Clark
828dad175c Eliminate the remaining definitions for *_allocated structs. 2009-08-22 20:49:37 +01:00
Nicholas Clark
a062e10d14 Add MUTABLE_AV(), and remove (AV *) casts from headers.
p4raw-id: //depot/perl@34608
2008-10-27 21:23:04 +00:00