update swig on windows

This commit is contained in:
Bassem Girgis
2019-08-04 21:38:19 -05:00
parent 8414b7136b
commit 76ad52be58
5943 changed files with 91790 additions and 71892 deletions

View File

@@ -0,0 +1,18 @@
TOP = ../..
SWIGEXE = $(TOP)/../swig
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
SRCS = example.c
TARGET = my-guile
INTERFACE = example.i
check: build
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' guile_augmented_run
build:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' guile_augmented
clean:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' guile_clean
rm -f test.out

View File

@@ -0,0 +1,2 @@
This example illustrates the translation from Scheme file ports to
temporary FILE streams. Read the source and run ./my-guile -s runme.scm

View File

@@ -0,0 +1,18 @@
#include <stdio.h>
#include <errno.h>
void print_int(FILE *f, int i)
{
if (fprintf(f, "%d\n", i)<0)
perror("print_int");
}
int read_int(FILE *f)
{
int i;
if (fscanf(f, "%d", &i)!=1) {
fprintf(stderr, "read_int: error reading from file\n");
perror("read_int");
}
return i;
}

View File

@@ -0,0 +1,15 @@
%module port
%include guilemain.i
/* Include the required FILE * typemaps */
%include ports.i
%{
#include <stdio.h>
%}
%inline %{
void print_int(FILE *f, int i);
int read_int(FILE *f);
%}

View File

@@ -0,0 +1,35 @@
;; Call with standard output
(print-int (current-output-port) 314159)
;; Redirection to a file. Note that the port is automatically flushed
;; (via force-output) before calling the C function, and that the C
;; function gets a temporary "FILE" stream, which is closed after the
;; call. So you can simply mix Scheme and C output.
(with-output-to-file "test.out"
(lambda ()
(display 4711)
(newline)
(print-int (current-output-port) 314159)
(display 815)
(newline)))
;; Redirection to a string or soft port won't work --
;; we can only handle file ports.
(catch #t
(lambda ()
(with-output-to-string
(lambda ()
(print-int (current-output-port) 314159))))
(lambda args
(display "Below shows that attempting to write to a string or soft port will result in a wrong-type-error...")
(newline)
(write args) (newline)))
;; Read from a file port. Note that it is a bad idea to mix Scheme and
;; C input because of buffering, hence the call to seek to rewind the file.
(with-input-from-file "test.out"
(lambda ()
(seek (current-input-port) 0 SEEK_SET)
(display (read-int (current-input-port)))
(newline)))