Skip to content

Instantly share code, notes, and snippets.

View Xliff's full-sized avatar
🏠
Working from home

Xliff Xliff

🏠
Working from home
View GitHub Profile
@Xliff
Xliff / gist:2907106c84e9eb14d4c0
Last active March 31, 2016 21:03
Match infix:<eqv> -- Draft!
multi sub infix:<eqv>(Match:D $a, Match:D $b) {
   $a.to   eqv $b.to   &&
   $a.from eqv $b.from &&
   $a.orig eqv $b.orig &&
   $a.made eqv $b.made &&
   $a.list eqv $b.list &&
   $a.hash eqv $b.hash;
}
@Xliff
Xliff / NativeCall.md
Last active April 4, 2016 15:16
So why doesn't this bit of NativeCall work?

Here is the C code:

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

struct TestStruct_s {
        int t;
        int *tp;

In non-virtualized Ubuntu 64-bit system (6 Hyperthreaded cores):

Stage start      :   0.000
Stage parse      :  55.174
Stage syntaxcheck:   0.000
Stage ast        :   0.000
Stage optimize   :  10.591
Stage mast       :  16.263
Stage mbc : 0.179

Recently used to clean up a bad PDF-to-Word-to-ePub conversion.

#/usr/bin/perl6

use Inline::Perl5;
#use Mojo::DOM:from<Perl5>;

my $p5 = Inline::Perl5.new;
my $m;

I am working on a set of NativeCall library bindings for Perl 6. Right now I am testing one set of them. If I run the tests, sometimes they complete with no issues:

$ perl6 -Ilib t/02-ogg-test.t
ok 1 - can create ogg_sync_state
ok 2 - can call ogg_sync_init
ok 3 - can create ogg_page
ok 4 - can call ogg_sync_pageout
ok 5 - can allocate buffer with ogg_sync_buffer

In working on trying to write Perl6 library bindings for libogg, I ran into this interesting problem.

How would you represent this piece of a struct in NativeCall:

unsigned char header[282]

Turns out that this is one of the shortcomings of NativeCall.

SOLVED

Trying to get this to bind properly with Perl6, and it's being difficult!

#include <stdlib.h>
#include <stdio.h>

int floatArrayTest(float **pa) {
  *pa = malloc(sizeof(float *) * 500);

Herre is a diff against p6-MyHTML that seems to induces a seemingly infinite precompile loop in rakudo:

diff --git a/lib/HTML/MyHTML.pm6 b/lib/HTML/MyHTML.pm6
index 64c285e..00448da 100644
--- a/lib/HTML/MyHTML.pm6
+++ b/lib/HTML/MyHTML.pm6
@@ -23,22 +23,36 @@ class HTML::MyHTML is export {

   method clean { $!myhtml.clean; $!tree.clean }

Updated! See below...

Code excerpt:

class TreeStruct is repr('CStruct') {
  # ref
  has Pointer #`{myhtml_t*}                    $.myhtml;
  has Pointer #`{mchar_async_t*}               $.mchar;
 has Pointer #`{myhtml_token_t*} $.token;

So libmyhtml.so is now compiled with debugging information and I've tracked the crash here:

Starting program: /home/cbwood/.rakudobrew/moar-nom/install/bin/moar --execname=/home/cbwood/.rakudobrew/bin/../moar-nom/install/bin/perl6-gdb-m --libpath=/home/cbwood/.rakudobrew/moar-nom/install/share/nqp/lib --libpath=/home/cbwood/.rakudobrew/moar-nom/install/share/perl6/lib --libpath=/home/cbwood/.rakudobrew/moar-nom/install/share/perl6/runtime /home/cbwood/.rakudobrew/moar-nom/install/share/perl6/runtime/perl6.moarvm -Ilib eg/attributes-high.pl6
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/i386-linux-gnu/i686/cmov/libthread_db.so.1".
running now...
building now...
building native MyHTML...
[New Thread 0xb52dbb40 (LWP 15572)]