[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Chicken-users] 'f_125' undeclared with (declare (block))
From: |
.alyn.post. |
Subject: |
[Chicken-users] 'f_125' undeclared with (declare (block)) |
Date: |
Sun, 8 Dec 2013 11:01:13 -0700 |
I'm getting an error message when I use |(declare (block))|.
Using the same code in my previous email about invalid forwarded
object (repeated here), I declare it as an egg like so (the only
change is wrapping it around a module):
<++> csc -s -j pwent pwent.so pwent-egg.scm
(module pwent
(getpwent)
(import scheme)
(import chicken)
(import foreign)
(declare (block))
; a circular list (where we track the
; head and tail) with a dummy head.
;
(define (make-clist)
(let ((head (list #f)))
(cons head head)))
; O(1) list append.
;
(define (clist-append! d v)
(let ((l (list v)))
(set-cdr! (cdr d) l)
(set-cdr! d l)))
; return proper list
;
(define (clist->list d)
(cdr (car d)))
; allocate a scheme string available in C.
;
(define-external
(_make_string (size_t n)) scheme-object
(make-string n))
(declare (foreign-declare #<<EOF
#include <sys/types.h>
#include <string.h>
#include <pwd.h>
EOF
))
(define (getpwent)
; append! each pwent record to our record list.
;
(define-external
(_getpwent_cb (scheme-object clist)
(scheme-object user)
(scheme-object passwd)
(scheme-object uid)
(scheme-object gid)
(scheme-object home)
(scheme-object shell)) void
(let ((pwent `((user . ,user)
(passwd . ,passwd)
(uid . ,uid)
(gid . ,gid)
(home . ,home)
(shell . ,shell))))
(clist-append! clist pwent)))
; retrieve the next pwent record and marshall it
; in to scheme.
;
(define _getpwent
(foreign-safe-lambda* bool ((scheme-object clist)) #<<EOF
struct passwd *pw;
C_word shell, dir, passwd, name;
size_t n;
pw = getpwent();
if(!pw) {
endpwent();
C_return(0);
}
n = strlen(pw->pw_name);
name = _make_string(n);
C_memcpy(C_c_string(name), pw->pw_name, n);
n = strlen(pw->pw_passwd);
passwd = _make_string(n);
C_memcpy(C_c_string(passwd), pw->pw_passwd, n);
n = strlen(pw->pw_dir);
dir = _make_string(n);
C_memcpy(C_c_string(dir), pw->pw_dir, n);
n = strlen(pw->pw_shell);
shell = _make_string(n);
C_memcpy(C_c_string(shell), pw->pw_shell, n);
_getpwent_cb(clist,
name,
passwd,
C_fix(pw->pw_uid),
C_fix(pw->pw_gid),
dir,
shell);
C_return(1);
EOF
))
; loop ever every entry in pwent and append
; it to our list.
;
(let loop ((clist (make-clist)))
(if (_getpwent clist)
(loop clist)
(clist->list clist)))))
<-->
With that |(declare (block))|, I get the following error message:
pwent.c: In function '_getpwent_cb':
pwent.c:107: error: 'f_125' undeclared (first use in this function)
pwent.c:107: error: (Each undeclared identifier is reported only once
pwent.c:107: error: for each function it appears in.)
Error: shell command terminated with non-zero exit status 256: gcc pwent.c -o
pwent.o -c -fno-strict-aliasing -DHAVE_CHICKEN_CONFIG_H -DC_ENABLE_PTABLES -Os
-fomit-frame-pointer -fPIC -DPIC -DC_SHARED -I/usr/X11R6/include
-I/usr/local/include
Removing |(declare (block))| allows compilation as normal.
Usefully, the egg version of this code does not exhibit the
invalid forward object error and completes successfully:
$ csi -n
#;1> (use pwent)
; loading ./pwent.import.scm ...
; loading /usr/local/lib/chicken/6/chicken.import.scm ...
; loading /usr/local/lib/chicken/6/foreign.import.scm ...
; loading ./pwent.so ...
#;2> (getpwent)
(((user . "root") ...))
While it's certainly a blessing that my above code works when
compiled as an egg (though why it does so is a mystery to me),
what's going on with |(declare (block))| here? I don't understand
the documentation on this declare option to know whether I'm doing
something wrong or whether this code cannot be compiled with that
declaration.
Thank you,
-a
$ csc -V
(c) 2008-2013, The Chicken Team
(c) 2000-2007, Felix L. Winkelmann
Version 4.8.0.5 (stability/4.8.0) (rev 5bd53ac)
openbsd-unix-gnu-x86 [ manyargs dload ptables ]
compiled 2013-10-03 on aeryn.xorinia.dim (Darwin)
--
my personal website: http://c0redump.org/
- [Chicken-users] 'f_125' undeclared with (declare (block)),
.alyn.post. <=