Replies: 2 comments
-
Latest implementation now defines a new SV type, |
Beta Was this translation helpful? Give feedback.
-
Current Implementation (2022-08-17)An object instance is an SV of a new type, if(SvROK(sv) && SvOBJECT(SvRV(sv))) ... will still work as it does with classical objects. Most code that operates opaquely on an object instance should not need to be aware of the difference. Internally, the XPVOBJ structure stores the following fields: /* Required to align with XPVMG and other structures */
HV* xmg_stash;
union _xmgu xmg_u;
/* Fields for an object instance */
SSize_t xobject_maxfield;
SSize_t xobject_iter_sv_at; /* this is only used by Perl_sv_clear() */
SV** xobject_fields; These additional fields:
Since the size of an instance is fixed at the compiletime of its class, we do not need to store the usual pair of MAX+FILL and implement some sort of reällocation logic. A single Further, since naked object storage is never directly visible by pureperl code, there is no need to guard array or hash-shaped fields by wrapping them in an SVt_RV. Therefore, the fields array will store pointers to AVs and HVs directly for these types of fields. APICode outside of Other code can distinguish an object instance by the usual kind of if(SvTYPE(sv) == SVt_PVOBJ) ... If this is found to be true, the fields can be accessed by macros: SSize_t ObjectMAXFIELD(sv);
SV **ObjectFIELDS(sv); There is currently no helper API to make field access safer (e.g. by checking the requested fieldix is within the bounds that are valid on the object instance), but some sort of API would likely be useful to add. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
What should an actual object instance be?
The
Object::Pad
implementation has no choice but to use something existing, so its native representation is a blessed arrayref, where the elements of the array store the fields directly.I suspect for a real core implementation we'd want a new kind of SV itself, complete with its own body type and
reftype
nameBeta Was this translation helpful? Give feedback.
All reactions