X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=Op.xs;h=c5be45bd6f33b60a7fd9bec62dbb217d0a3d29be;hb=b9c3a456f75424383f35cb83000965d76e56d4ed;hp=89716e7602a4ed44c9719441ebd3e2fb3aae26fe;hpb=c4608b58e39347084b651ee4c3db26bf522378ea;p=perl%2Fmodules%2FSub-Op.git diff --git a/Op.xs b/Op.xs index 89716e7..c5be45b 100644 --- a/Op.xs +++ b/Op.xs @@ -113,16 +113,26 @@ typedef struct { #include "sub_op.h" -void sub_op_register(pTHX_ const sub_op_config_t *c) { +void sub_op_init(sub_op_config_t *c) { + c->name = NULL; + c->namelen = 0; + c->pp = 0; + c->check = 0; + c->ud = NULL; + + return; +} + +void sub_op_register(pTHX_ const sub_op_config_t *c, U32 flags) { SV *key = newSViv(PTR2IV(c->pp)); if (!PL_custom_op_names) PL_custom_op_names = newHV(); - (void) hv_store_ent(PL_custom_op_names, key, newSVpv(c->name, c->len), 0); + (void) hv_store_ent(PL_custom_op_names, key, newSVpv(c->name, c->namelen), 0); if (!PL_custom_op_descs) PL_custom_op_descs = newHV(); - (void) hv_store_ent(PL_custom_op_descs, key, newSVpv(c->name, c->len), 0); + (void) hv_store_ent(PL_custom_op_descs, key, newSVpv(c->name, c->namelen), 0); if (c->check) { SV *check = newSViv(PTR2IV(c->check)); @@ -132,10 +142,31 @@ void sub_op_register(pTHX_ const sub_op_config_t *c) { { dMY_CXT; - (void) hv_store(MY_CXT.map, c->name, c->len, key, 0); + (void) hv_store(MY_CXT.map, c->name, c->namelen, key, 0); } } +sub_op_config_t *sub_op_dup(pTHX_ const sub_op_config_t *orig) { + sub_op_config_t *dupe = PerlMemShared_malloc(sizeof *dupe); + + dupe->namelen = orig->namelen; + dupe->name = PerlMemShared_malloc(dupe->namelen); + Copy(orig->name, dupe->name, dupe->namelen, char); + + dupe->pp = orig->pp; + dupe->check = orig->check; + dupe->ud = orig->ud; + + return dupe; +} + +void sub_op_free(pTHX_ sub_op_config_t *c) { + PerlMemShared_free((char *) c->name); + PerlMemShared_free(c); + + return; +} + /* --- Private helpers ----------------------------------------------------- */ STATIC IV so_hint(pTHX) { @@ -381,3 +412,15 @@ PPCODE: XSRETURN_UNDEF; ST(0) = sv_2mortal(newSVpvn(&on->buf, on->len)); XSRETURN(1); + +void +_constant_sub(SV *sv) +PROTOTYPE: $ +PPCODE: + if (!SvROK(sv)) + XSRETURN_UNDEF; + sv = SvRV(sv); + if (SvTYPE(sv) < SVt_PVCV) + XSRETURN_UNDEF; + ST(0) = sv_2mortal(newSVuv(CvCONST(sv))); + XSRETURN(1);