Affix
view release on metacpan or search on metacpan
CodeRef[[Pointer[Int]] => Int]; # typedef Int (*function)(int * a);
CodeRef[[Str, Int] => Struct[...]]; # typedef struct Person (*function)(chat * name, int age);
```
## `InstanceOf[ ... ]`
```
InstanceOf['Some::Class']
```
A blessed object of a certain type. When used as an lvalue, the result is
properly blessed. As an rvalue, the reference is checked to be a subclass of
the given package.
Note: This "type" is in a state of development flux and might be made complete
with [issue #32](https://github.com/sanko/Affix.pm/issues/32)
## `Any`
Anything you dump here will be passed along unmodified. We hand off a pointer
to the `SV*` perl gives us without copying it.
eg/benchmark.pl view on Meta::CPAN
$ret = $ret_dispatch->{ shift @chars };
last;
}
push @funcs, $arg_dispatch->{$sigchar};
}
my $thing = sub {
dcReset($cvm);
$funcs[$_]->( $cvm, $_[$_] ) for 0 .. $#funcs;
$ret->( $cvm, $ptr );
};
bless $thing, $package;
}
sub load ( $path, $version = () ) {
dlLoadLibrary( guess_library_name( $path, $version ) );
}
sub func ( $lib, $symbol ) { dlFindSymbol( $lib, $symbol ); }
our $OS = $^O;
sub guess_library_name ( $name = (), $version = () ) {
( $name, $version ) = @$name if ref $name eq 'ARRAY';
lib/Affix.pm view on Meta::CPAN
say our function accepts two integers and returns an integer.
CodeRef[[] => Void]; # typedef void (*function)();
CodeRef[[Pointer[Int]] => Int]; # typedef Int (*function)(int * a);
CodeRef[[Str, Int] => Struct[...]]; # typedef struct Person (*function)(chat * name, int age);
=head2 C<InstanceOf[ ... ]>
InstanceOf['Some::Class']
A blessed object of a certain type. When used as an lvalue, the result is
properly blessed. As an rvalue, the reference is checked to be a subclass of
the given package.
Note: This "type" is in a state of development flux and might be made complete
with L<issue #32|https://github.com/sanko/Affix.pm/issues/32>
=head2 C<Any>
Anything you dump here will be passed along unmodified. We hand off a pointer
to the C<SV*> perl gives us without copying it.
lib/Affix.xs view on Meta::CPAN
break;
default:
croak("Invalid wchar_t size for argument!");
}
sv_2mortal(container);
packlist(RETVAL, pat, pat + 1, &container, &container + 1);
mPUSHs(RETVAL);
} break;
case DC_SIGCHAR_INSTANCEOF: {
DCpointer ptr = dcbArgPointer(args);
HV *blessed = MUTABLE_HV(SvRV(*av_fetch(cbx->args, i, 0)));
SV **package = hv_fetchs(blessed, "package", 0);
PUSHs(sv_setref_pv(newSV(1), SvPV_nolen(*package), ptr));
} break;
case DC_SIGCHAR_ENUM:
case DC_SIGCHAR_ENUM_UINT: {
PUSHs(enum2sv(aTHX_ * av_fetch(cbx->args, i, 0), dcbArgInt(args)));
} break;
case DC_SIGCHAR_ENUM_CHAR: {
PUSHs(enum2sv(aTHX_ * av_fetch(cbx->args, i, 0), dcbArgChar(args)));
} break;
case DC_SIGCHAR_ANY: {
lib/Affix.xs view on Meta::CPAN
case DC_SIGCHAR_ANY: {
break;
} break;
default:
if (items > 1)
croak("Too many arguments for subroutine '%s' (got %d; expected 0)", package, items);
break;
}
SV *self = newRV_inc(MUTABLE_SV(RETVAL_HV));
ST(0) = sv_bless(self, gv_stashpv(package, GV_ADD));
XSRETURN(1);
}
XS_INTERNAL(Types_sig) {
dXSARGS;
dXSI32;
dXSTARG;
if (PL_phase == PERL_PHASE_DESTRUCT) XSRETURN_IV(0);
XSRETURN_PV((char *)&ix);
}
lib/Affix.xs view on Meta::CPAN
//~ sv_dump(type);
SV **subtype_ptr = hv_fetchs(MUTABLE_HV(SvRV(type)), "type", 0);
if (SvOK(ST(pos_arg))) {
if (sv_derived_from(ST(pos_arg), "Affix::Pointer")) {
IV tmp = SvIV((SV *)SvRV(ST(pos_arg)));
pointer[pos_arg] = INT2PTR(DCpointer, tmp);
l_pointer[pos_arg] = false;
pointers = true;
}
else {
if (sv_isobject(ST(pos_arg))) croak("Unexpected pointer to blessed object");
pointer[pos_arg] = safemalloc(_sizeof(aTHX_ * subtype_ptr));
sv2ptr(aTHX_ * subtype_ptr, ST(pos_arg), pointer[pos_arg], false);
l_pointer[pos_arg] = true;
pointers = true;
}
}
else if (SvREADONLY(ST(pos_arg))) { // explicit undef
pointer[pos_arg] = NULL;
l_pointer[pos_arg] = false;
}
lib/Affix.xs view on Meta::CPAN
_ptr->ptr = ptr;
_ptr->type = newSVsv(type);
mg->mg_ptr = (char *)_ptr;
}
// magic_dump(mg);
XSRETURN_YES;
}
// clang-format off
SV *
affix(lib, symbol, args, ret = sv_bless(newRV_inc(MUTABLE_SV(newHV())), gv_stashpv("Affix::Type::Void", GV_ADD)))
SV * symbol
AV * args
SV * ret
ALIAS:
affix = 0
wrap = 1
PREINIT:
dMY_CXT;
CODE:
// clang-format on
lib/Affix.xs view on Meta::CPAN
*the necessary user data. name can be NULL => fully anonymous sub!
**/
CV *cv;
STMT_START {
cv = newXSproto_portable((ix == 0 ? func_name : NULL), Affix_call, file, call->perl_sig);
if (cv == NULL) croak("ARG! Something went really wrong while installing a new XSUB!");
XSANY.any_ptr = (DCpointer)call;
}
STMT_END;
RETVAL = sv_bless((ix == 1 ? newRV_noinc(MUTABLE_SV(cv)) : newRV_inc(MUTABLE_SV(cv))),
gv_stashpv("Affix", GV_ADD));
}
// clang-format off
OUTPUT:
RETVAL
void
typedef(char * name, IN_OUTLIST SV * type)
CODE:
// clang-format on
( run in 1.764 second using v1.01-cache-2.11-cpan-de7293f3b23 )