X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=Op.xs;h=c5be45bd6f33b60a7fd9bec62dbb217d0a3d29be;hb=b9c3a456f75424383f35cb83000965d76e56d4ed;hp=cdcc89af7a2d45946ff78f87bf3f87190316c42e;hpb=a3c83d0adc138681da18079c268948d2fe9326d7;p=perl%2Fmodules%2FSub-Op.git diff --git a/Op.xs b/Op.xs index cdcc89a..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) {