From 2217ed7fae729d833169a7e44d53ef7e9ca660d8 Mon Sep 17 00:00:00 2001 From: Peter Bex Date: Fri, 4 Jul 2025 14:03:05 +0200 Subject: [PATCH 1/2] Fix define-pyfun macro in compiled mode The macro would expand to a direct reference to the hash-table-ref/default and hash-table-set! procedures rather than the identifiers for those procedures. This works in the interpreter because it is a bit lax when intermixing expansion code with evaluated code, but when compiling code that uses the macro, it breaks with this error: Syntax error: illegal atomic form # Fixes issue #12 --- pyffi.scm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyffi.scm b/pyffi.scm index dcbe98f..b2c5b1a 100644 --- a/pyffi.scm +++ b/pyffi.scm @@ -570,8 +570,8 @@ EOF (%begin (r 'begin)) (%set! (r 'set!)) (not (r 'not)) - (alist-ref (r 'alist-ref)) - (alist-update! (r 'alist-update!)) + (hash-table-ref/default (r 'hash-table-ref/default)) + (hash-table-set! (r 'hash-table-set!)) (py-eval (r 'py-eval)) (py-apply (r 'py-apply)) (raise-python-exception (r 'raise-python-exception)) From 4a97c4823c2cebc7c861352ecc26f527b58029fc Mon Sep 17 00:00:00 2001 From: Peter Bex Date: Fri, 4 Jul 2025 14:41:13 +0200 Subject: [PATCH 2/2] Fix some potential issues in define-pymethod The names "args" and "kwargs" were left as bare symbols, which meant the expansion could unhygienically take these identifiers from the surrounding code. Similarly, the core macro "receive" was not renamed. --- pyffi.scm | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pyffi.scm b/pyffi.scm index b2c5b1a..2a79447 100644 --- a/pyffi.scm +++ b/pyffi.scm @@ -646,6 +646,7 @@ EOF (let ((scheme-name (member 'scheme-name: rest)) (kw (member 'kw: rest))) (let ((%define (r 'define)) + (%receive (r 'receive)) (%quote (r 'quote)) (%cons (r 'cons)) (%list (r 'list)) @@ -658,6 +659,8 @@ EOF (%if (r 'if)) (%list->vector (r 'list->vector)) (%->string (r '->string)) + (args (r 'args)) + (kwargs (r 'kwargs)) (parse-argument-list (r 'parse-argument-list)) (PyObject_GetAttrString (r 'PyObject_GetAttrString)) (PyObject_CallObject (r 'PyObject_CallObject)) @@ -671,15 +674,15 @@ EOF (,PyObject_CallObject (,PyObject_GetAttrString ,obj ,(->string name) ) (,%list->vector ,rest))) - (let ((kwargs (map (compose string->keyword symbol->string) (cadr kw)))) + (let ((the-kwargs (map (compose string->keyword symbol->string) (cadr kw)))) `(,%define (,proc-name ,obj #!rest ,rest) - (receive - (args kwargs) - (,parse-argument-list ,rest ',kwargs) + (,%receive + (,args ,kwargs) + (,parse-argument-list ,rest ',the-kwargs) (,PyObject_Call (,PyObject_GetAttrString ,obj ,(->string name) ) - (list->vector args) - (,%if (,%null? kwargs) #f kwargs)) + (list->vector ,args) + (,%if (,%null? ,kwargs) #f ,kwargs)) )) )) ))