Skip to content

Instantly share code, notes, and snippets.

@arnsholt
Created September 3, 2013 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arnsholt/6428396 to your computer and use it in GitHub Desktop.
Save arnsholt/6428396 to your computer and use it in GitHub Desktop.
NativeCall weirdness
plan(1);
my $arg_hash;
my $return_hash;
class Call is repr('NativeCall') { }
class CPointer is repr('CPointer') { }
my $printf := nqp::create(Call);
$arg_hash := nqp::hash();
$arg_hash<type> := 'utf8str';
$arg_hash<free_str> := 1;
$return_hash := nqp::hash();
$return_hash<type> := 'void';
nqp::buildnativecall($printf, '', 'printf', '', [$arg_hash], $return_hash);
nqp::nativecall(nqp::null(), $printf, ["ok 1 - printf\n"]);
my $strdup := nqp::create(Call);
$arg_hash := nqp::hash();
$arg_hash<type> := 'utf8str';
$arg_hash<free_str> := 1;
$return_hash := nqp::hash();
$return_hash<type> := 'cpointer';
nqp::buildnativecall($strdup, '', 'strdup', '', [$arg_hash], $return_hash);
my $dupped := nqp::nativecall(CPointer, $strdup, ["ok 3 - passing cpointer"]);
ok(1, "function returning cpointer");
my $ptrprint := nqp::create(Call);
$arg_hash := nqp::hash();
$arg_hash<type> := 'cpointer';
$return_hash := nqp::hash();
$return_hash<type> := 'void';
nqp::buildnativecall($printf, '', 'printf', '', [$arg_hash], $return_hash);
nqp::nativecall(nqp::null(), $printf, [$dupped]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment