Debian Codegraph @

xs/typemap

raw
1 TYPEMAP
2 PerlCryptDHGMP * T_DH_GMP
3 PerlCryptDHGMP_value T_DH_GMP_VALUE
4
5 INPUT
6 T_DH_GMP
7 {
8 MAGIC *mg;
9 mg = PerlCryptDHGMP_mg_find(aTHX_ SvRV($arg), &PerlCryptDHGMP_vtbl);
10 if (mg) {
11 $var = (PerlCryptDHGMP *) mg->mg_ptr;
12 }
13 }
14
15 T_DH_GMP_VALUE
16 if (! SvPOK($arg)) {
17 croak(\"$var is not a string!\");
18 }
19 mpz_init_set_str($var, SvPV_nolen($arg), 10);
20
21 OUTPUT
22 T_DH_GMP
23 if (!$var) /* if null */
24 SvOK_off($arg); /* then return as undef instead of reaf to undef */
25 else {
26 /* setup $arg as a ref to a blessed hash hv */
27 MAGIC *mg;
28 HV *hv = newHV();
29 const char *classname = \"Crypt::DH::GMP\";
30 /* take (sub)class name to use from class_sv if appropriate */
31 if (class_sv && SvOK(class_sv) && sv_derived_from(class_sv, classname))
32 classname = (SvROK(class_sv)) ? sv_reftype(class_sv, 0) : SvPV_nolen(class_sv);
33 sv_setsv($arg, sv_2mortal(newRV_noinc((SV*)hv)));
34 (void)sv_bless($arg, gv_stashpv(classname, TRUE));
35
36 /* now attach $var to the HV */
37 /* done as two steps to avoid sv_magic SvREFCNT_inc and MGf_REFCOUNTED */
38 mg = sv_magicext((SV*)hv, NULL, PERL_MAGIC_ext, &PerlCryptDHGMP_vtbl, (char*) $var, 0); /* sizeof($var)); */
39 mg->mg_flags |= MGf_DUP;
40 }
41
42
43 T_DH_GMP_VALUE
44 {
45 char *buf;
46 char *buf_end;
47 int len;
48
49 mpz_t *tmp = $arg; /* Set aside for temporary use */
50
51 /* len is always >= 1, and might be off (greater) by one than real len */
52 len = mpz_sizeinbase(*tmp, 10);
53 $arg = newSV(len); /* alloc len + 1 bytes */
54 SvPOK_on($arg);
55 buf = SvPVX($arg); /* get ptr to storage */
56 buf_end = buf + len - 1; /* end of storage (-1) */
57 mpz_get_str(buf, 10, *tmp);
58 if (*buf_end == 0) {
59 len--; /* got one shorter than expected */
60 }
61
62 SvCUR_set($arg, len);
63 }
64
65