Skip to content

Commit

Permalink
Trial of Hooks: convert ext/PerlIO-encoding/encoding.xs from Magic to…
Browse files Browse the repository at this point in the history
… Hook
  • Loading branch information
leonerd committed Feb 4, 2025
1 parent 2e9ac65 commit ac5ac36
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions ext/PerlIO-encoding/encoding.xs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ typedef struct {

#define NEEDS_LINES 1

static const MGVTBL PerlIOEncode_tag = { 0, 0, 0, 0, 0, 0, 0, 0 };
/* An empty hook structure just for the purpose of marking an SV */
static const struct HookFunctions perlencoding_hooks = {
.ver = 12345, /* TODO */
.shape = HKs_BASE,
.flags = 0,
};

static SV *
PerlIOEncode_getarg(pTHX_ PerlIO * f, CLONE_PARAMS * param, int flags)
Expand All @@ -67,9 +72,9 @@ PerlIOEncode_getarg(pTHX_ PerlIO * f, CLONE_PARAMS * param, int flags)
* that it should not call methods and wait for _dup() to actually dup the
* encoding object. */
if (param) {
sv = newSV(0);
sv_magicext(sv, NULL, PERL_MAGIC_ext, &PerlIOEncode_tag, 0, 0);
return sv;
sv = newSV(0);
sv_hook_add(sv, &perlencoding_hooks, 0, NULL, NULL);
return sv;
}
sv = &PL_sv_undef;
if (e->enc) {
Expand Down Expand Up @@ -102,7 +107,7 @@ PerlIOEncode_pushed(pTHX_ PerlIO * f, const char *mode, SV * arg, PerlIO_funcs *
SV *result = Nullsv;

if (SvTYPE(arg) >= SVt_PVMG
&& mg_findext(arg, PERL_MAGIC_ext, &PerlIOEncode_tag)) {
&& sv_hook_find_by_funcs(arg, &perlencoding_hooks)) {
e->enc = NULL;
e->chk = NULL;
e->inEncodeCall = 0;
Expand Down

0 comments on commit ac5ac36

Please sign in to comment.