Skip to content

Instantly share code, notes, and snippets.

@bpetering
Created January 2, 2016 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bpetering/031934a05ca1242a7def to your computer and use it in GitHub Desktop.
Save bpetering/031934a05ca1242a7def to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
struct foo {
int x;
};
void foo_init(struct foo **f) {
*f = malloc(sizeof(struct foo));
printf("malloc'd, pointer = %p\n", (void *) *f);
}
void foo_shutdown(struct foo *f) {
printf("freeing, pointer = %p\n", (void *) f);
free(f);
}
void foo_test() { printf("foo\n"); }
use NativeCall;
class foo is repr('CPointer') { }
sub foo_init(Pointer[foo])
is native('test')
{ * }
sub foo_shutdown(foo)
is native('test')
{ * }
sub foo_test()
is native('test')
{ * }
# foo_test(); # works
my Pointer[foo] $p = Pointer[foo].new;
foo_init($p);
say $p.deref(); # how do I get my pointer back to pass to foo_shutdown?
#foo_shutdown($p.deref());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment