Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot pass the role instance to the C-side function as an argument #5736

Open
p6rt opened this issue Oct 8, 2016 · 1 comment
Open

Cannot pass the role instance to the C-side function as an argument #5736

p6rt opened this issue Oct 8, 2016 · 1 comment

Comments

@p6rt
Copy link

p6rt commented Oct 8, 2016

Migrated from rt.perl.org#129831 (status was 'new')

Searchable as RT129831$

@p6rt
Copy link
Author

p6rt commented Oct 8, 2016

From @titsuki

See the following results​:

* codes *

t/03-role.c


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

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

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

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


t/03-role.h


#if ! defined(HEADER_ROLE_H)
#define HEADER_ROLE_H

#ifdef __cplusplus
extern "C" {
#endif

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

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

#endif /* HEADER_ROLE_H */


t/03-role.t


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

compile_test_lib('03-role');

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);
    }
}

done-testing;


* 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.new; $r.insert(10);'
R.new 

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant