at great pains, the stubber can generate (ugly) code for getcwd

This commit is contained in:
Alex Shinn 2009-12-22 22:33:53 +09:00
parent e93c1b1483
commit 6da435d21c
5 changed files with 731 additions and 483 deletions

View file

@ -823,11 +823,9 @@ SEXP_API sexp sexp_register_simple_type (sexp ctx, sexp name, sexp slots);
SEXP_API sexp sexp_register_c_type (sexp ctx, sexp name); SEXP_API sexp sexp_register_c_type (sexp ctx, sexp name);
SEXP_API sexp sexp_finalize_c_type (sexp ctx, sexp obj); SEXP_API sexp sexp_finalize_c_type (sexp ctx, sexp obj);
#define sexp_register_c_type(ctx, name, finalizer) \ #define sexp_register_c_type(ctx, name, finalizer) \
sexp_register_type(ctx, name, sexp_make_fixnum(0), sexp_make_fixnum(0), \ sexp_register_type(ctx, name, SEXP_ZERO, SEXP_ZERO, SEXP_ZERO, SEXP_ZERO, \
sexp_make_fixnum(0), sexp_make_fixnum(0), \ SEXP_ZERO, sexp_make_fixnum(sexp_sizeof(cpointer)), \
sexp_make_fixnum(0), \ SEXP_ZERO, SEXP_ZERO, finalizer)
sexp_make_fixnum(sexp_sizeof(cpointer)), \
sexp_make_fixnum(0), sexp_make_fixnum(0), finalizer)
#endif #endif
#define sexp_current_error_port(ctx) sexp_env_global_ref(sexp_context_env(ctx),sexp_global(ctx,SEXP_G_CUR_ERR_SYMBOL),SEXP_FALSE) #define sexp_current_error_port(ctx) sexp_env_global_ref(sexp_context_env(ctx),sexp_global(ctx,SEXP_G_CUR_ERR_SYMBOL),SEXP_FALSE)

View file

@ -4,7 +4,7 @@
delete-file link-file symbolic-link-file rename-file delete-file link-file symbolic-link-file rename-file
directory-files create-directory delete-directory directory-files create-directory delete-directory
current-seconds current-seconds
exit waitpid exit
) )
(import-immutable (scheme)) (import-immutable (scheme))
(include-shared "posix") (include-shared "posix")

View file

@ -1,5 +1,6 @@
(c-system-include "sys/types.h") (c-system-include "sys/types.h")
(c-system-include "sys/wait.h")
(c-system-include "time.h") (c-system-include "time.h")
(c-system-include "unistd.h") (c-system-include "unistd.h")
(c-system-include "dirent.h") (c-system-include "dirent.h")
@ -18,7 +19,8 @@
(define-c errno (symbolic-link-file "symlink") (string string)) (define-c errno (symbolic-link-file "symlink") (string string))
(define-c errno (rename-file "rename") (string string)) (define-c errno (rename-file "rename") (string string))
;;(define-c string (current-directory "getcwd") ((value (array char)) int)) (define-c non-null-string (current-directory "getcwd")
((result (array char (auto-expand arg1))) (value 256 int)))
(define-c errno (create-directory "mkdir") (string int)) (define-c errno (create-directory "mkdir") (string int))
(define-c errno (delete-directory "rmdir") (string)) (define-c errno (delete-directory "rmdir") (string))
@ -28,9 +30,9 @@
(define-c int (duplicate-fd "dup") (int)) (define-c int (duplicate-fd "dup") (int))
(define-c pid_t fork ()) (define-c pid_t fork ())
;; (define-c pid_t wait ((result pointer int))) (define-c pid_t waitpid (int (result int) int))
(define-c void exit (int)) (define-c void exit (int))
(define-c int (execute execvp) (string (array string null))) (define-c int (execute execvp) (string (array string)))
(define-c errno pipe ((result (array int 2)))) (define-c errno pipe ((result (array int 2))))

13
sexp.c
View file

@ -837,8 +837,12 @@ sexp sexp_get_output_string (sexp ctx, sexp port) {
#else #else
sexp sexp_make_input_string_port (sexp ctx, sexp str) { sexp sexp_make_input_string_port (sexp ctx, sexp str) {
FILE *in = fmemopen(sexp_string_data(str), sexp_string_length(str), "r"); FILE *in;
sexp res = sexp_make_input_port(ctx, in, SEXP_FALSE); sexp res;
if (! sexp_stringp(str))
return sexp_type_exception(ctx, "open-input-string: not a string", str);
in = fmemopen(sexp_string_data(str), sexp_string_length(str), "r");
res = sexp_make_input_port(ctx, in, SEXP_FALSE);
sexp_port_cookie(res) = str; /* for gc preservation */ sexp_port_cookie(res) = str; /* for gc preservation */
return res; return res;
} }
@ -916,7 +920,10 @@ sexp sexp_buffered_flush (sexp ctx, sexp p) {
} }
sexp sexp_make_input_string_port (sexp ctx, sexp str) { sexp sexp_make_input_string_port (sexp ctx, sexp str) {
sexp res = sexp_make_input_port(ctx, NULL, SEXP_FALSE); sexp res;
if (! sexp_stringp(str))
return sexp_type_exception(ctx, "open-input-string: not a string", str);
res = sexp_make_input_port(ctx, NULL, SEXP_FALSE);
if (sexp_exceptionp(res)) return res; if (sexp_exceptionp(res)) return res;
sexp_port_cookie(res) = str; sexp_port_cookie(res) = str;
sexp_port_buf(res) = sexp_string_data(str); sexp_port_buf(res) = sexp_string_data(str);

File diff suppressed because it is too large Load diff