fix(qr): update 4 failing language tests

- Perl: use Text::QRCode (pure Perl, pre-installed) instead of Imager::QRCode
- Elixir: try Erlang :qrcode module, fallback to CLI
- OCaml: use Unix.open_process_in (no ctypes in compiled mode)
- Fortran: direct C FFI binding (requires -lqrencode at link)
This commit is contained in:
russell@unturf.com 2026-01-28 07:04:21 -05:00
parent d517236663
commit 99ac93b2d5
4 changed files with 48 additions and 85 deletions

View file

@ -1,4 +1,14 @@
qr = EQRCode.encode("unsandbox-qr-ok")
matrix = qr.matrix
rows = length(matrix)
IO.puts("QR:unsandbox-qr-ok:ROWS:#{rows}")
# Use Erlang's :qrcode module (pre-cached via rebar3)
# Falls back to shell if module not available
try do
{:ok, qr} = :qrcode.encode("unsandbox-qr-ok")
# qr is a tuple like {:qrcode, version, ecc, dimension, data}
{_tag, _version, _ecc, dimension, _data} = qr
IO.puts("QR:unsandbox-qr-ok:ROWS:#{dimension}")
rescue
_ ->
# Fallback: use qrencode CLI
{output, 0} = System.cmd("sh", ["-c", "qrencode -t ASCII -m 0 'unsandbox-qr-ok' | wc -l"])
rows = String.trim(output)
IO.puts("QR:unsandbox-qr-ok:ROWS:#{rows}")
end

View file

@ -2,62 +2,35 @@ program qrcode_test
use, intrinsic :: iso_c_binding
implicit none
! QRcode struct layout: version(int), width(int), data(ptr)
! Direct C FFI - requires linking with -lqrencode
interface
type(c_ptr) function QRcode_encodeString(s, ver, lvl, hint, cs) bind(C, name='QRcode_encodeString')
import :: c_ptr, c_char, c_int
character(kind=c_char), dimension(*), intent(in) :: s
integer(c_int), value :: ver, lvl, hint, cs
end function
subroutine QRcode_free(qr) bind(C, name='QRcode_free')
import :: c_ptr
type(c_ptr), value :: qr
end subroutine
end interface
type, bind(C) :: QRcode
integer(c_int) :: version
integer(c_int) :: width
type(c_ptr) :: data
end type QRcode
end type
! C function interfaces
interface
type(c_ptr) function dlopen(filename, flag) bind(C, name='dlopen')
import :: c_ptr, c_char, c_int
character(kind=c_char), dimension(*), intent(in) :: filename
integer(c_int), value :: flag
end function dlopen
type(c_funptr) function dlsym(handle, symbol) bind(C, name='dlsym')
import :: c_ptr, c_funptr, c_char
type(c_ptr), value :: handle
character(kind=c_char), dimension(*), intent(in) :: symbol
end function dlsym
integer(c_int) function f_dlclose(handle) bind(C, name='dlclose')
import :: c_ptr, c_int
type(c_ptr), value :: handle
end function f_dlclose
end interface
abstract interface
type(c_ptr) function encode_iface(s, ver, lvl, hint, cs) bind(C)
import :: c_ptr, c_char, c_int
character(kind=c_char), dimension(*), intent(in) :: s
integer(c_int), value :: ver, lvl, hint, cs
end function encode_iface
subroutine free_iface(qr) bind(C)
import :: c_ptr
type(c_ptr), value :: qr
end subroutine free_iface
end interface
type(c_ptr) :: lib, qr_ptr
type(c_funptr) :: enc_fptr, free_fptr
procedure(encode_iface), pointer :: qr_encode
procedure(free_iface), pointer :: qr_free
type(c_ptr) :: qr_ptr
type(QRcode), pointer :: qr
integer(c_int) :: rc
lib = dlopen("libqrencode.so" // c_null_char, 2)
enc_fptr = dlsym(lib, "QRcode_encodeString" // c_null_char)
free_fptr = dlsym(lib, "QRcode_free" // c_null_char)
call c_f_procpointer(enc_fptr, qr_encode)
call c_f_procpointer(free_fptr, qr_free)
qr_ptr = qr_encode("unsandbox-qr-ok" // c_null_char, 0, 1, 2, 1)
call c_f_pointer(qr_ptr, qr)
write(*, '(A,I0)') 'QR:unsandbox-qr-ok:ROWS:', qr%width
call qr_free(qr_ptr)
rc = f_dlclose(lib)
qr_ptr = QRcode_encodeString("unsandbox-qr-ok" // c_null_char, 0, 1, 2, 1)
if (c_associated(qr_ptr)) then
call c_f_pointer(qr_ptr, qr)
write(*, '(A,I0)') 'QR:unsandbox-qr-ok:ROWS:', qr%width
call QRcode_free(qr_ptr)
else
write(*, '(A)') 'QR encode failed'
end if
end program qrcode_test

View file

@ -1,27 +1,7 @@
#use "topfind";;
#require "ctypes";;
#require "ctypes.foreign";;
open Ctypes;;
open Foreign;;
type qrcode
let qrcode : qrcode structure typ = structure "QRcode";;
let _qr_version = field qrcode "version" int;;
let qr_width = field qrcode "width" int;;
let _qr_data = field qrcode "data" (ptr char);;
let () = seal qrcode;;
let encode_string =
foreign "QRcode_encodeString"
(string @-> int @-> int @-> int @-> int @-> returning (ptr qrcode));;
let qr_free =
foreign "QRcode_free"
(ptr qrcode @-> returning void);;
(* OCaml single-file execution can't use ocamlfind packages *)
(* Use Unix.open_process_in with qrencode CLI *)
let () =
let qr = encode_string "unsandbox-qr-ok" 0 1 2 1 in
let w = getf !@qr qr_width in
Printf.printf "QR:unsandbox-qr-ok:ROWS:%d\n" w;
qr_free qr;;
let ic = Unix.open_process_in "qrencode -t ASCII -m 0 'unsandbox-qr-ok' | wc -l" in
let rows = String.trim (input_line ic) in
ignore (Unix.close_process_in ic);
Printf.printf "QR:unsandbox-qr-ok:ROWS:%s\n" rows

View file

@ -1,5 +1,5 @@
use Imager::QRCode;
my $qr = Imager::QRCode->new(size => 1, margin => 0);
my $img = $qr->plot("unsandbox-qr-ok");
my $rows = $img->getheight();
use Text::QRCode;
my $qr = Text::QRCode->new();
my $matrix = $qr->plot("unsandbox-qr-ok");
my $rows = scalar(@$matrix);
print "QR:unsandbox-qr-ok:ROWS:$rows\n";