Skip Menu |

This queue is for tickets about the Object-Pad CPAN distribution.

Report information
The Basics
Id: 133354
Status: resolved
Priority: 0/
Queue: Object-Pad

People
Owner: Nobody in particular
Requestors: ilmari [...] ilmari.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 0.34



Subject: [PATCH] Use named enum for repr type
Date: Thu, 17 Sep 2020 19:19:12 +0100
To: bug-Object-Pad [...] rt.cpan.org
From: ilmari [...] ilmari.org (Dagfinn Ilmari Mannsåker)
Hi Paul, I noticed a couple of places that were using U8 for the repr, and one that then switch()ed over it. The attached patch makes it a named enum, so that the compiler can warn about missed cases in more places. - ilmari -- "The surreality of the universe tends towards a maximum" -- Skud's Law "Never formulate a law or axiom that you're not prepared to live with the consequences of." -- Skud's Meta-Law
From 6861fa1f641198404dfab31850fd74f11327c278 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= <ilmari@ilmari.org> Date: Thu, 17 Sep 2020 19:11:07 +0100 Subject: [PATCH] Use named enum for repr type Then the compiler can warn about unhandled cases in more places. --- lib/Object/Pad.xs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/Object/Pad.xs b/lib/Object/Pad.xs index e65222e..beceb8c 100644 --- a/lib/Object/Pad.xs +++ b/lib/Object/Pad.xs @@ -301,17 +301,19 @@ enum MetaType { METATYPE_ROLE, }; +enum ReprType { + REPR_NATIVE, /* instances are in native format - blessed AV as slots */ + REPR_HASH, /* instances are blessed HASHes; our slots live in $self->{"Object::Pad/slots"} */ + REPR_MAGIC, /* instances store slot AV via magic; superconstructor must be foreign */ + + REPR_AUTOSELECT, /* pick one of the above depending on foreign_new and SvTYPE()==SVt_PVHV */ +}; + /* Metadata about a class or role */ struct ClassMeta { enum MetaType type : 8; + enum ReprType repr : 8; bool sealed; - enum { - REPR_NATIVE, /* instances are in native format - blessed AV as slots */ - REPR_HASH, /* instances are blessed HASHes; our slots live in $self->{"Object::Pad/slots"} */ - REPR_MAGIC, /* instances store slot AV via magic; superconstructor must be foreign */ - - REPR_AUTOSELECT, /* pick one of the above depending on foreign_new and SvTYPE()==SVt_PVHV */ - } repr : 8; SLOTOFFSET start_slotix; /* first slot index of this partial within its instance */ SLOTOFFSET next_slotix; /* 1 + final slot index of this partial within its instance; includes slots in roles */ @@ -364,7 +366,7 @@ static CV *S_embed_cv(pTHX_ CV *cv, RoleEmbedding *embedding) static MGVTBL vtbl_slotsav = {}; #define get_obj_slotsav(self, repr, create) S_obj_get_slotsav(aTHX_ self, repr, create) -static SV *S_obj_get_slotsav(pTHX_ SV *self, U8 repr, bool create) +static SV *S_obj_get_slotsav(pTHX_ SV *self, enum ReprType repr, bool create) { SV *rv = SvRV(self); @@ -648,7 +650,7 @@ static void S_generate_initslots_method(pTHX_ ClassMeta *meta) intro_my(); - U8 repr = meta->repr; + enum ReprType repr = meta->repr; ops = op_append_list(OP_LINESEQ, ops, newMETHSTARTOP(OPf_MOD | -- 2.27.0
Thanks. Now applied as -r384 -- Paul Evans
Released in 0.34 -- Paul Evans