Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@ab5tract 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