Skip to content

Commit 1601312

Browse files
committed
Update nativecall.pod
Describe how to pass allocated pointers to native types in native calls
1 parent c08878c commit 1601312

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

doc/Language/nativecall.pod

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,21 @@ For string arguments that are specified as C<const char *> it is necessary
9797
to tell Perl not to free the memory allocated to the C string after the
9898
function returns using C<explicitly-manage> :
9999
100-
# C prototype is set_foo(const char * foo)
100+
# C prototype is void set_foo(const char * foo)
101101
sub set_foo(Str) is native('foo') { * }
102102
my $string = "FOO";
103103
explicitly-manage($string);
104104
set_foo($string);
105105
106106
=head1 Basic use of Pointers
107107
108+
When the signature of your native function needs a pointer to some native type
109+
(int, uint, etc.) all you need to do is declare the argument C<is rw> :
110+
111+
# C prototype is void my_version(int *mayor, int *minor)
112+
sub my_version(int32 is rw, int32 is rw) is native('foo') { * }
113+
my_version(my int32 $mayor, my int32 $minor); # Pass a pointer to
114+
108115
Sometimes you need to get a pointer (for example, a library handle) back from a
109116
C library. You don't care about what it points to - you just need to keep hold
110117
of it. The Pointer type provides for this.

0 commit comments

Comments
 (0)