fix(qr): rewrite 7 failing language tests to use native C FFI
All use dlopen/dlsym to libqrencode.so (system-wide via gcc role):
- Haskell: System.Posix.DynamicLinker + foreign import ccall "dynamic"
- F#: Mono P/Invoke DllImport("libqrencode.so")
- COBOL: LINKAGE SECTION for proper struct pointer access
- Nim: dynlib module (loadLib/symAddr)
- Fortran: renamed dlclose binding to avoid symbol collision
- D: core.sys.posix.dlfcn (dlopen/dlsym)
- OCaml: Ctypes.foreign via ocamlfind #require
This commit is contained in:
parent
702b21f920
commit
bec3f8c289
7 changed files with 159 additions and 36 deletions
33
test/qr.d
33
test/qr.d
|
|
@ -1,8 +1,33 @@
|
|||
import core.sys.posix.dlfcn;
|
||||
import std.stdio;
|
||||
import qr;
|
||||
import std.string;
|
||||
|
||||
struct QRcode {
|
||||
int _version;
|
||||
int width;
|
||||
void* data;
|
||||
}
|
||||
|
||||
void main() {
|
||||
auto qrCode = QrCode("unsandbox-qr-ok");
|
||||
auto size = qrCode.size;
|
||||
writefln("QR:unsandbox-qr-ok:ROWS:%d", size);
|
||||
auto lib = dlopen("libqrencode.so", RTLD_LAZY);
|
||||
if (lib is null) {
|
||||
stderr.writeln("dlopen: ", dlerror().fromStringz);
|
||||
return;
|
||||
}
|
||||
|
||||
alias EncFunc = extern(C) QRcode* function(const char*, int, int, int, int);
|
||||
alias FreeFunc = extern(C) void function(QRcode*);
|
||||
|
||||
auto encode = cast(EncFunc) dlsym(lib, "QRcode_encodeString");
|
||||
auto qfree = cast(FreeFunc) dlsym(lib, "QRcode_free");
|
||||
|
||||
auto qr = encode("unsandbox-qr-ok", 0, 1, 2, 1);
|
||||
if (qr is null) {
|
||||
stderr.writeln("encode failed");
|
||||
return;
|
||||
}
|
||||
|
||||
writefln("QR:unsandbox-qr-ok:ROWS:%d", qr.width);
|
||||
qfree(qr);
|
||||
dlclose(lib);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue