Skip Menu |
Report information
Id: 129831
Status: new
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: cookbook_000 [at] <titsuki [at]>

Severity: (no value)
Tag: Bug
Platform: (no value)
Patch Status: (no value)
VM: (no value)

From: cookbook_000 [...]
Subject: [NATIVECALL][BUG] Cannot pass the role instance to the C-side function as an argument
To: "rakudobug [...]" <rakudobug [...]>
Date: Sun, 9 Oct 2016 00:07:37 +0900 (JST)
Download (untitled) / with headers
text/plain 2.3k
See the following results:

* codes *

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "03-role.h"

#ifdef _WIN32
#define DLLEXPORT __declspec(dllexport)
#define DLLEXPORT extern

struct Foo {
  int a;
  double b;
} Foo;

void c_insert(struct Foo* foo, void* item) {
  // insert operation

#if ! defined(HEADER_ROLE_H)

#ifdef __cplusplus
extern "C" {

struct Foo;
void c_insert(struct Foo*, void*);

#ifdef __cplusplus
} /* closing brace for extern "C" */

#endif /* HEADER_ROLE_H */

use v6;
use Test;
use NativeCall;
use lib <lib t>;
use CompileTestLib;


role Foo is export is repr('CPointer') {
    my sub c_insert(Foo, Pointer[void] is rw) is native("./03-callback") { * }
    method insert(Pointer[void] $item) {
        c_insert(self, $item);


* results *

$ mi6 test t/03-role.t
==> Set PERL6LIB=/home/itoyota/Programs/p6-Foo/lib
==> prove -e /home/itoyota/.rakudobrew/bin/../moar-nom/install/bin/perl6 -r t/03-role.t
t/03-role.t .. ===SORRY!=== Error while compiling /home/itoyota/Programs/p6-Foo/t/03-role.t
Too many positionals passed; expected 2 arguments but got 3
at /home/itoyota/Programs/p6-Foo/t/03-role.t:10
t/03-role.t .. Dubious, test returned 1 (wstat 256, 0x100)
No subtests run 

Test Summary Report
t/03-role.t (Wstat: 256 Tests: 0 Failed: 0)
  Non-zero exit status: 1
  Parse errors: No plan found in TAP output
Files=1, Tests=0,  1 wallclock secs ( 0.02 usr  0.00 sys +  0.40 cusr  0.02 csys =  0.44 CPU)
Result: FAIL


It seems weird to me, because roles can define with `is export is repr("CPointer")` traits and can use `self`.without any errors as the following example.

$ perl6 -MNativeCall -e 'role R is export is repr("CPointer") { method insert($item) { self!c_insert(self, $item); }; method !c_insert(R $r, $item){ say $r; } }; my $r =; $r.insert(10);' 

My Perl 6 version is:
$ perl6 --version
This is Rakudo version 2016.09-105-g4abc28c built on MoarVM version 2016.09-13-g34c375a
implementing Perl 6.c.

This service is sponsored and maintained by Best Practical Solutions and runs on infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at