Skip to content

Perl_more_bodies - figure out sizing from sv_type #23360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: blead
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions embed.fnc
Original file line number Diff line number Diff line change
Expand Up @@ -2043,9 +2043,7 @@ p |int |mode_from_discipline \
|STRLEN len

: Used in sv.c and hv.c
Cop |void * |more_bodies |const svtype sv_type \
|const size_t body_size \
|const size_t arena_size
Cop |void * |more_bodies |const svtype sv_type
Cp |const char *|moreswitches \
|NN const char *s
Adp |void |mortal_destructor_sv \
Expand Down
2 changes: 1 addition & 1 deletion hv.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ S_new_he(pTHX)
void ** const root = &PL_body_roots[HE_ARENA_ROOT_IX];

if (!*root)
Perl_more_bodies(aTHX_ HE_ARENA_ROOT_IX, sizeof(HE), PERL_ARENA_SIZE);
Perl_more_bodies(aTHX_ HE_ARENA_ROOT_IX);
he = (HE*) *root;
assert(he);
*root = HeNEXT(he);
Expand Down
2 changes: 1 addition & 1 deletion proto.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 16 additions & 4 deletions sv.c
Original file line number Diff line number Diff line change
Expand Up @@ -856,10 +856,22 @@ available in hv.c. Similarly SVt_IV is re-used for HVAUX_ARENA_ROOT_IX.


void *
Perl_more_bodies (pTHX_ const svtype sv_type, const size_t body_size,
const size_t arena_size)
Perl_more_bodies (pTHX_ const svtype sv_type)
{
void ** const root = &PL_body_roots[sv_type];

const struct body_details *type_details =
(sv_type > SVt_IV)
? bodies_by_type + sv_type
: (sv_type == SVt_NULL)
? NULL
: &fake_hv_with_aux
;

const size_t body_size = (type_details) ? type_details->body_size
: sizeof(HE);
const size_t arena_size = (type_details) ? type_details->arena_size
: PERL_ARENA_SIZE;
struct arena_desc *adesc;
struct arena_set *aroot = (struct arena_set *) PL_body_arenas;
unsigned int curr;
Expand Down Expand Up @@ -1291,7 +1303,7 @@ Perl_hv_auxalloc(pTHX_ HV *hv) {
#ifdef PURIFY
new_body = new_NOARENAZ(&fake_hv_with_aux);
#else
new_body_from_arena(new_body, HVAUX_ARENA_ROOT_IX, fake_hv_with_aux);
new_body_from_arena(new_body, HVAUX_ARENA_ROOT_IX);
#endif

old_body = SvANY(hv);
Expand Down Expand Up @@ -14799,7 +14811,7 @@ S_sv_dup_common(pTHX_ const SV *const ssv, CLONE_PARAMS *const param)
#ifdef PURIFY
new_body = new_NOARENA(sv_type_details);
#else
new_body_from_arena(new_body, HVAUX_ARENA_ROOT_IX, fake_hv_with_aux);
new_body_from_arena(new_body, HVAUX_ARENA_ROOT_IX);
#endif
goto have_body;
}
Expand Down
25 changes: 12 additions & 13 deletions sv_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ ALIGNED_TYPE(XPVOBJ);
STRUCT_OFFSET(type, last_member) \
+ sizeof (((type*)SvANY((const SV *)0))->last_member)

static const struct body_details fake_hv_with_aux =
/* The SVt_IV arena is used for (larger) PVHV bodies. */
{ sizeof(ALIGNED_TYPE_NAME(XPVHV_WITH_AUX)),
copy_length(XPVHV, xhv_max),
0,
SVt_PVHV, TRUE, NONV, HASARENA,
FIT_ARENA(0, sizeof(ALIGNED_TYPE_NAME(XPVHV_WITH_AUX))) };

static const struct body_details bodies_by_type[] = {
/* HEs use this offset for their arena. */
{ 0, 0, 0, SVt_NULL, FALSE, NONV, NOARENA, 0 },
Expand Down Expand Up @@ -328,21 +336,19 @@ static const struct body_details bodies_by_type[] = {
#ifndef PURIFY

/* grab a new thing from the arena's free list, allocating more if necessary. */
#define new_body_from_arena(xpv, root_index, type_meta) \
#define new_body_from_arena(xpv, root_index) \
STMT_START { \
void ** const r3wt = &PL_body_roots[root_index]; \
xpv = (PTR_TBL_ENT_t*) (*((void **)(r3wt)) \
? *((void **)(r3wt)) : Perl_more_bodies(aTHX_ root_index, \
type_meta.body_size,\
type_meta.arena_size)); \
? *((void **)(r3wt)) : Perl_more_bodies(aTHX_ root_index)); \
*(r3wt) = *(void**)(xpv); \
} STMT_END

PERL_STATIC_INLINE void *
S_new_body(pTHX_ const svtype sv_type)
{
void *xpv;
new_body_from_arena(xpv, sv_type, bodies_by_type[sv_type]);
new_body_from_arena(xpv, sv_type);
return xpv;
}

Expand All @@ -351,14 +357,6 @@ S_new_body(pTHX_ const svtype sv_type)
static const struct body_details fake_rv =
{ 0, 0, 0, SVt_IV, FALSE, NONV, NOARENA, 0 };

static const struct body_details fake_hv_with_aux =
/* The SVt_IV arena is used for (larger) PVHV bodies. */
{ sizeof(ALIGNED_TYPE_NAME(XPVHV_WITH_AUX)),
copy_length(XPVHV, xhv_max),
0,
SVt_PVHV, TRUE, NONV, HASARENA,
FIT_ARENA(0, sizeof(ALIGNED_TYPE_NAME(XPVHV_WITH_AUX))) };

/*
=for apidoc newSV_type

Expand All @@ -381,6 +379,7 @@ Perl_newSV_type(pTHX_ const svtype type)

SvFLAGS(sv) &= ~SVTYPEMASK;
SvFLAGS(sv) |= type;
// SvFLAGS(sv) = type;

switch (type) {
case SVt_NULL:
Expand Down
Loading