Skip to content

Instantly share code, notes, and snippets.

@Xliff
Last active November 27, 2020 10:40
Show Gist options
  • Save Xliff/3290a3f31a3f7937f22421bb1d4e0480 to your computer and use it in GitHub Desktop.
Save Xliff/3290a3f31a3f7937f22421bb1d4e0480 to your computer and use it in GitHub Desktop.
Dealing with BOOTInt in Raku code

Recently, I've encountered the following error in some of my Raku code:

B: Clutter::Raw::Structs::ClutterColor.new(0, 0, 0, -1)
Cannot resolve caller new(Clutter::Raw::Structs::ClutterColor:U: BOOTInt, BOOTInt, BOOTInt, BOOTInt); none of these signatures match:
    (Mu: *%attrinit)
    (Mu: $, *@, *%_)
    (Clutter::Raw::Structs::ClutterColor: $red, $green, $blue, $alpha, *%_)
  in method throw at SETTING::src/core.c/Exception.pm6 line 62
  in block  at SETTING::src/core.c/Exception.pm6 line 3014
  in any  at gen/moar/BOOTSTRAP/v6c.nqp line 2628
  in method new_from_color at /home/cbwood/Projects/p6-Clutter/lib/Clutter/Color.pm6 (Clutter::Color) line 98
  in sub draw_clock at t/05-clock.t line 47
  in block  at t/05-clock.t line 118
  in block  at SETTING::src/core.c/Supply-factories.pm6 line 153
  in block  at SETTING::src/core.c/Supply-factories.pm6 line 117
  in method run-with-updated-recursion-list at SETTING::src/core.c/Lock/Async.pm6 line 176
  in method protect-or-queue-on-recursion at SETTING::src/core.c/Lock/Async.pm6 line 142
  in block  at SETTING::src/core.c/Supply-factories.pm6 line 117
  in method emit at SETTING::src/core.c/Supplier.pm6 line 55
  in method emit at SETTING::src/core.c/Supplier.pm6 line 105
  in block  at /home/cbwood/Projects/p6-Clutter/lib/Clutter/Roles/Signals/Canvas.pm6 (Clutter::Roles::Signals::Canvas) line 31
  in block clutter_content_invalidate at /home/cbwood/Projects/rakudobrew/versions/moar-blead/install/share/perl6/core/sources/947BDAB9F96E0E5FCCB383124F923A6BF6F8D76B (NativeCall) line 592
  in method invalidate at /home/cbwood/Projects/p6-Clutter/lib/Clutter/Roles/Content.pm6 (Clutter::Roles::Content) line 66
  in sub MAIN at t/05-clock.t line 121
  in block  at SETTING::src/core.c/Main.pm6 line 357
  in sub RUN-MAIN at SETTING::src/core.c/Main.pm6 line 349

This stems from the following code:

  method new_from_color (
  Clutter::Color:U:
  ClutterColor()    $c
)
  is also<new-from-color>
{
  my $color = ClutterColor.new($c.red, $c.green, $c.blue, $c.alpha);

  X::ClutterColor::Memory.new.throw unless $color;

  self.bless(:$color);
}

Which itself comes from this:

my $color = Clutter::Color.new_from_color($CLUTTER_COLOR_White);

And $CLUTTER_COLOR_White is built at INIT time from this:

$CLUTTER_COLOR_White            = Clutter::Color.get_static(CLUTTER_COLOR_WHITE);

Where get_static pulls the CStruct definition from a C-library.

I don't know how to deal with this error, so I am asking for help from the experts.

@Xliff
Copy link
Author

Xliff commented Nov 27, 2020

So it turns out that if you get this message, values from nqp-land have leaked into your Raku code. The best solution for this is to use nqp to HLLize the value into something Raku can use. This can be done like so:

use nqp;
my $a = nqp::hllize( nqp::decont($nqp-bootint-value) )

With this fix applied, my errors went away. The clock image attached to this gist is the proof that this fix works!

Thanks to lizmat++ for the solution.

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