Skip to content

Commit 8d99295

Browse files
authored
Merge pull request #1119 from titsuki/fix-cpointer
Fix the example of "Basic use of Pointers" so that it doesn't store a…
2 parents 9d98a02 + 8974606 commit 8d99295

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

doc/Language/nativecall.pod6

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -138,27 +138,28 @@ can serve this role. This means you can expose libraries that work on handles
138138
by writing a class like this:
139139
140140
class FooHandle is repr('CPointer') {
141-
has $!initialized;
142-
143141
# Here are the actual NativeCall functions.
144142
sub Foo_init() returns FooHandle is native("foo") { * }
145143
sub Foo_free(FooHandle) is native("foo") { * }
144+
sub Foo_query(FooHandle, Str) returns int8 is native("foo") { * }
145+
sub Foo_close(FooHandle) returns int8 is native("foo") { * }
146146
147147
# Here are the methods we use to expose it to the outside world.
148-
method new() {
148+
method new {
149149
Foo_init();
150-
$!initialized = True;
151150
}
152-
method free() {
153-
if $!initialized {
154-
Foo_free(self);
155-
$!initialized = False; # prevent double frees
156-
}
151+
152+
method query(Str $stmt) {
153+
Foo_query(self, $stmt);
154+
}
155+
156+
method close {
157+
Foo_close(self);
157158
}
158159
159160
# Free data when the object is garbage collected.
160-
method DESTROY() {
161-
self.free;
161+
submethod DESTROY {
162+
Foo_free(self);
162163
}
163164
}
164165

0 commit comments

Comments
 (0)