File: newSV_with_free.c.inc

package info (click to toggle)
libxs-parse-sublike-perl 0.37-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 516 kB
  • sloc: ansic: 944; perl: 930; sh: 6; makefile: 3
file content (20 lines) | stat: -rw-r--r-- 522 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/* vi: set ft=c : */

static int magic_free(pTHX_ SV *sv, MAGIC *mg)
{
  void (*freefunc)(pTHX_ SV *sv) = (void *)mg->mg_ptr;
  (*freefunc)(aTHX_ sv);
  return 0;
}

static const MGVTBL vtbl_sv_with_free = {
  .svt_free = magic_free,
};

#define newSV_with_free(size, freefunc)  S_newSV_with_free(aTHX_ size, freefunc)
static SV *S_newSV_with_free(pTHX_ STRLEN size, void (*freefunc)(pTHX_ SV *sv))
{
  SV *sv = newSV(size);
  sv_magicext(sv, NULL, PERL_MAGIC_ext, &vtbl_sv_with_free, (void *)freefunc, 0);
  return sv;
}