3

There is a C function which returns some string to a provided pointer:

void    snmp_error(netsnmp_session *sess, int *clib_errorno,
                       int *snmp_errorno, char **errstring);

The Perl6 version is:

sub snmp_error(Snmp-session, int32 is rw, int32 is rw, Str is rw) is native("netsnmp") { * };

snmp_error($sess, my int32 $errno, my int32 $liberr, my Str $errstr);
say $errno, " ", $liberr, " ", $errstr;

It returns correct ints but not a string:

0 -3 (Str)

Is it a just a bug or something is wrong here?

perl6 -v
This is Rakudo version 2016.12 built on MoarVM version 2016.12
implementing Perl 6.c.

The same is on

This is Rakudo version 2017.09 built on MoarVM version 2017.09.1
implementing Perl 6.c.
Christopher Bottoms
  • 11,218
  • 8
  • 50
  • 99
Yuriy Zhilovets
  • 400
  • 2
  • 10

3 Answers3

2

When I wrestled with the same problem I translated this:

gboolean notify_get_server_info (char **ret_name,
                                 char **ret_vendor,
                                 char **ret_version,
                                 char **ret_spec_version);

into this:

sub notify_get_server_info(Pointer[Str] $name is rw,
                           Pointer[Str] $vendor is rw,
                           Pointer[Str] $version is rw,
                           Pointer[Str] $spec_version is rw --> int32)
                           is native(LIB) { * }

which works for me.

Fernando Santagata
  • 1,487
  • 1
  • 8
  • 15
0

I think it is a bug (or rather more likely just not fully implemented yet).

See the answers here for some work-arounds: Passing pointer to pointer in Perl 6 Nativecall

Curt Tilmes
  • 3,035
  • 1
  • 12
  • 24
0

The method of Fernando Santagata works as intended:

sub snmp_error(Snmp-session, int32 is rw, int32 is rw, Pointer[Str] is rw) is native("netsnmp") { * };

my $e = Pointer[Str].new;
snmp_error($sess, my int32 $errno, my int32 $liberr, $e);
say "syserr=$errno liberr=$liberr error=", $e.deref;
Yuriy Zhilovets
  • 400
  • 2
  • 10