Skip to content

Instantly share code, notes, and snippets.

@ab5tract
Created August 2, 2016 07:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ab5tract/8e50bf6f38543191fdb756d259bdffde to your computer and use it in GitHub Desktop.
Save ab5tract/8e50bf6f38543191fdb756d259bdffde to your computer and use it in GitHub Desktop.
minimal-case-for-Array-of-Nums-smartmatch-bug
use v6;
my @tests = [
42.424242 => Buf.new( reverse 0b01000000, 0b01000101, 0b00110110, 0b01001101,
0b10001111, 0b11010101, 0b11001011, 0b01111001),
33.3 => Buf.new( reverse 0b01000000, 0b01000000, 0b10100110, 0b01100110,
0b01100110, 0b01100110, 0b01100110, 0b01100110),
];
my $double-c = q:to/ENDC/;
#include <stdio.h>
#include <string.h>
#include "double.h"
double peek_double(char *buf) {
double val = 0;
memcpy(&val, buf, sizeof(double));
printf("\tnum from c: %f\n", val);
return val;
};
ENDC
my $double-h = q:to/ENDH/;
extern double peek_double(char *buf);
ENDH
my $dir = $?FILE.IO.parent;
sub MAIN(:$cc = 'gcc', :$comp = 0) {
if $comp || ! "$dir/libbufeater.dylib".IO.e {
"$dir/libbufeater.dylib".IO.e;
"$dir/double.h".IO.spurt($double-h);
"$dir/double.c".IO.spurt($double-c);
qq:x{ $cc '$dir/double.c' -c -Wall -Werror -fpic };
say ">>> compiling bufeater";
qq:x{ $cc -shared -o libbufeater.dylib double.c };
}
do-buffy()
}
sub do-buffy {
use NativeCall;
sub peek_double(Buf $b is rw) returns num64 is native('bufeater') {*};
dd @tests;
say 'peeking at @tests[0].value: ' ~ peek_double(@tests[0].value);
say 'peeking at @tests[0].value: ' ~ peek_double(@tests[1].value);
my @filled = [ peek_double($_) for @tests>>.value ];
use Test;
ok @filled ~~ [ @tests>>.key ], "filled:case -- {@filled.perl}:{[ @tests>>.key ]} ";
use JSON::Fast;
my $key-array = from-json(to-json([@tests>>.key]));
ok @filled ~~ $key-array, "JSON roundtripped\nobjects: \n\t{@filled.perl}\n\t{$key-array.perl}\ntypes:\n\tfilled => \n\t\t{@filled.map({$_.^name})},\n\tkey-array => \n\t\t{$key-array.map({$_.^name})}";
}
@ab5tract
Copy link
Author

ab5tract commented Aug 2, 2016

It says minimal case to reproduce, but it doesn't actually reproduce the issue :(

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