[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Calling back scheme from C
From: |
divoplade |
Subject: |
Calling back scheme from C |
Date: |
Tue, 22 Sep 2020 08:25:25 +0200 |
User-agent: |
Evolution 3.34.2 |
Hello guile,
I am having a hard time understanding what I do wrong when trying to
pass a guile function as a C callback (from C).
You should be able to trigger the bug by saving the 3 attached files
and running:
guix build -L . pkg-with-the-bug
The bug disappears when ignoring the scheme callback, so I suspect it
has something to do with the callback and not further functions:
guix build -L . pkg-without-the-bug
Does anyone see an error?
You will find the C code under libguile-nettle.c. guile-nettle.c is
just an ad-hoc interpreter with the primitives built in, to run the
test. The test is example-rsa-sign.in: it defines a callback that will
return a bytevector of length its argument, and that bytevector will be
processed to generate an RSA key pair with nettle. The function with-
rsa-generated-key-pair takes the callback plus other arguments and a
function, and it will call that function with the public key and the
private key.
(define (random-with-guile length)
(use-modules (srfi srfi-1))
(use-modules (rnrs bytevectors))
(u8-list->bytevector
(unfold (lambda (i) (>= i length))
(lambda (i) (random 256))
1+
0)))
(define (generate-rsa-keypair nbits random progress)
(with-rsa-generated-key-pair random progress nbits 16
(lambda (public private)
(rsa-public-key-n public))))
(define keypair
(generate-rsa-keypair 2048 random-with-guile #f))
(if keypair
(format #t "The key pair has been generated.\n")
(begin
(format (current-error-port)
"The key pair could not be generated.\n")
(exit 1)))
Best regards,
divoplade
bugs.scm
Description: Text Data
disable-function-call.patch
Description: Text Data
guile-nettle-0.3.0.8-c2e5.tar.gz
Description: application/compressed-tar
- Calling back scheme from C,
divoplade <=