Matt Birkholz [Mon, 18 Apr 2011 00:08:38 +0000 (17:08 -0700)]
Added FFI test.
* doc/ffi/ffi.texinfo: Punt the Makefile fragments for the example,
and the logic behind the leak-proof malloc/free procedures.
* doc/user-manual/user.texinfo: Needlessly picked some consistency nits.
* src/Clean.sh, src/Setup.sh: Link config.sub and config.guess to
microcode/*, and clean them too. These scripts are used by
src/configure.ac, which uses AC_CANONICAL_HOST to configure the
compilation and linking of FFIs.
* src/Makefile.in (FFIS, build-ffis): Added FFIS, the list of
configured foreign library interfaces (subdirs). These are built by
the new build-ffis target, which follows build-bands in most places,
and does `make build' in each ffi subdir.
* src/configure.ac: Added --enable-debugging, FFIS, CCLD, DEFS,
CFLAGS, CPPFLAGS, LDFLAGS, SHIM_CFLAGS and SHIM_LDFLAGS. Include
microcode/achost.ac. Added FFIS to the bundles list.
* src/etc/compile.scm (compile-ffi): New. This procedure arranges to
compile an FFI subdir as a LIARC bundle when LIARC is in use.
* src/ffi/Clean.sh: Punt prhello example. Clean up ffi-test-* build
products.
* src/ffi/Makefile-fragment: Punt prhello example. Build and install
an FFI test lib instead.
* src/ffi/: ffi-test.c.stay, ffi-test.cdecl, ffi-test.h: The new test
foreign library and interface.
* src/ffi/: prhello.cdecl, prhello.scm: Removed. Now in doc/;
replaced in src/ by ffi-test*.*.
* src/microcode/: achost.ac, configure.ac: Moved the host
configuration from configure.ac to the new achost.ac, to share with
src/configure.ac.
* src/runtime/ffi.scm (guarantee-alien, error:not-alien): Use the
standard arglist (object operator), not (operator object #!optional
ctype), and do not loop insisting on a qualifying object. Integrate
the test, separated from the restart code, which goes in the new,
global error:not-alien procedure.
(guarantee-alien-function, error:not-alien-function): New, like
guarantee-alien and error:not-alien. Use them in call-alien.
(make-alien-to-free): New, for interfacing to C functions like
malloc() that return something that needs to be freed with free().
Use it in the Scheme malloc procedure, and the test FFI.
* src/runtime/runtime.pkg: Added error:not-alien,
guarantee-alien-function, error:not-alien-function and
make-alien-to-free.
* tests/Clean.sh: New, for cleaning up after tests.
* tests/check.scm: Added tests/ffi/test-ffi.scm. Hacked handling of
test-flonum-casts.com so that `make check' works on portable C.
* tests/ffi/test-ffi-wrapper.scm: New. Code that needs to be
syntaxed/compiled as part of the FFI test.
* tests/ffi/test-ffi.scm: New. A test of the C/Unix FFI.
Use the closefrom system call if available to close all fds.
If not available, fall back to fcntl(F_CLOSEM); if that's not
available, fall back to closing all fds up to and including
fcntl(F_MAXFD); if that's not available, fall back to closing all
fds below UX_SC_OPEN_MAX like before.
Each case tested under NetBSD by running runtime/test-process.scm,
evaluating (RUN-SHELL-COMMAND "ls"), and ktracing Scheme during
The implementation is totally kludgey, and the tests take an
unreasonably long time to run (since we've mixed stress tests with
simple tests), but this is better than nothing, and may help to
complement firing up Edwin as the general way to test Scheme.
Advise operating system about memory access during GC.
- Expect sequential access to oldspace during gc_scan_oldspace.
- Free heap pages (newspace) before copying tospace over them.
- Free tospace pages after saving tospace.
The OS hooks are implemented only for Unix, in terms of posix_madvise
and madvise. Implementing them for Windows and/or OS/2 is left as an
exercise for the reader.
Chris Hanson [Sun, 20 Mar 2011 09:25:38 +0000 (02:25 -0700)]
For some reason, fatal_buf doesn't have a NUL under certain circumstances on my Mac. Instead of calling strlen, do a more careful scan that stops at the end of the buffer.
This returns the number of seconds, with at most nanosecond
resolution, that have elapsed since the start of 1972 in UTC.
Representation is fixed-point, stored in a pair given as input.
Thanks to Yoichi Hirai and Kazuhiko Yamamoto for analyzing the nature
of the bug and finding a good fix.
The trivial tests are enough to catch trivial errors, and one
manifestation of the balancing bug, but they should be replaced by a
more comprehensive test suite later.
Check URI record arguments more carefully in ->MUMBLE-URI.
->ABSOLUTE-URI would formerly accept URI records representing
relative references, even though it would reject their string
representations. Now it rejects both.
Matt Birkholz [Tue, 21 Dec 2010 17:28:03 +0000 (10:28 -0700)]
FFI support for 64bit architectures.
* src/ffi/generator.scm: Declare long callback IDs, large enough to
avoid truncation warnings when the toolkit type is also large. Use
%ld instead of %d for sizeof and member offsets, and cast them to
long. On x86_64, these have types ulong and long respectively.
* src/microcode/: pruxffi.c, pruxffi.h: (callback_run_kernel)
(callback_run_handler): Declare long callback_id params. Use %ld.
* src/runtime/ffi.scm (radix): Parameterize alien operations to
support 64bit or 32bit addresses.
Fix datime.scm's time formats to accept up to 61 seconds in a minute.
Minutes in any UTC-based time system, which covers every system of
which representations are parsed in datime.scm, can have 59, 60, or
61 seconds; previously we refused to parse representations of the
61st second.
Unfortunately, our notion of `universal time' is still essentially
Common Lisp's ill-specified notion of universal time, and implemented
by POSIX's mind-bogglingly brain-damaged notion of `number of seconds
since the Epoch' which actually means `number of seconds since the
Epoch, minus the number of them that were leap seconds in UTC'.
Replace `masking exceptions' by `trapping exceptions'.
Reversing the sense makes it clearer -- `trap on division by zero' is
a positive request, versus `mask division by zero traps', i.e. `don't
trap on division by zero'. This better reflects the IEEE 754 notion
of actions to take on exceptions. Also, the sense of `mask' is often
confusing (Scheme's `interrupt mask' is not the interrupts that are
masked, but the bit mask of interrupts that are *enabled*; the BSD
fpgetmask and fpsetmask library routines control the bit mask of
floating-point exceptions for which trapping is enabled; but, on the
other hand, a POSIX process's `signal mask' is the set of signals
that are disabled).
Implement a complete set of integer division operator pairs.
Given a numerator n and a denominator d, each operator pair computes
an integral quotient q and the induced remainder r = n - d q such
that |r| < |d|. There are five pairs: ceiling, euclidean, floor,
round, and truncate. Ceiling, floor, round, and truncate compute the
rounded quotient as their names suggest. Euclidean division is floor
division for positive denominators, and ceiling division for negative
denominators, so that it exhibits the stronger property 0 <= r < |d|.
Matt Birkholz [Fri, 12 Nov 2010 21:16:11 +0000 (14:16 -0700)]
Fixed src/README.txt. Portable C Installation instructions.
* doc/user-manual/user.texinfo: Added node "Portable C Installation".
Added "Type and range checking" describing the no-type-checks and
no-range-checks declarations.
* src/README.txt: Added a preface for the newbie that runs across this
file in a binary distribution. Removed "CVS". Added "portable C
distribution" and "MIT_SCHEME_EXE". Removed mention of "bin/" in
binary distributions, and "SCHEME_LARGE" and "SCHEME_COMPILER"
variables in build scripts; these are no longer used. Replaced
"system" with "program" or "build tree" or whatnot, reserving "system"
for the thing that runs the "operating system". Punted sections
"Building from source... ```The Hard Way''" and "... Tabula Rasa''",
which were mostly about re-compiling / re-linking the microcode. The
solution to such problems is now automated by the compile-microcode
step in the Unix installation instructions.
Matt Birkholz [Sun, 31 Oct 2010 00:05:05 +0000 (17:05 -0700)]
Added c-cast, struct member peeks, param syntax checking.
* src/ffi/cdecls.scm (valid-param): Check that the param name does not
contain `-', nor any other non-C identifier chars. These names go
into the generated .c files.
* src/ffi/syntax.scm (expand-peek): Allow peeks at struct members to
create or set an alien, just as peeking an array member does already.
* src/ffi/ffi.scm (c-cast): New. Basically set-%alien/ctype! with a
convenient return value.
(alien/address, copy-alien-address!, alien-null?, alien-null!, alien=?):
Declare these as integrable operators, not via define-integrable.
Their arguments are referenced multiple times.
* src/runtime/runtime.pkg (runtime ffi): Export c-cast to ().
This causes problems in the cold load, and doesn't enhance the safety
of the relevant code. It only marginally increases the debuggability
of the mistake it catches.
Make #@n always read as a quotation of the nth hashed object.
Previously, #@n sometimes read as the nth hashed object, and
sometimes read as a quotation of it. The advantage of the old
behaviour is that non-scode objects could be mentioned inside
quotations with #@n. Personally, most of the time I referred to
non-scode objects inside quotations with #@n was as '#@n to work
around the problems this fixes:
New operations on the two's-complement representation of integers.
These include the SRFI 33 operations, as well as some other useful
operations.
Although these are implemented as primitives with native definitions
for bignums, the primitives are not yet open-coded for the fixnum
case. Eventually they should be open-coded, so that you don't need
to make a choice between safe code using the integer operations and
fast code using FIX:AND, FIX:LSH, &c. Some operations are easy to
open-code for the fixnum case, such as all the bitwise operations.
Others are not so easy, such as SHIFT-LEFT, and it would be better to
open-code common aggregate operations such as EXTRACT-BIT-FIELD for
the fixnum case. In any case, at least we now have names for the
safe operations.
Simplify and fix X-DISPLAY-PROCESS-EVENTS primitive.
This primitive no longer supports options for blocking vs
non-blocking or selecting vs not selecting; these are now the
responsibility of the caller.
The cached event trick previously used the value of the
uninitialized variable `event', rather than the event that was
cached. Now it correctly uses the event that was cached.
Implement user-defined unparser methods for entities.
New DEFINE-STRUCTURE option PRINT-ENTITY-PROCEDURE is like
PRINT-PROCEDURE, except that the second argument to the procedure
is not a structure instance itself but an entity whose extra is a
structure instance.
New procedure SET-RECORD-TYPE-ENTITY-UNPARSER-METHOD! is like
SET-RECORD-TYPE-UNPARSER-METHOD! with the same difference.
New optional argument to MAKE-RECORD-TYPE specifies an entity
unparser method.
Existing code should be unaffected by the changes, including
existing compiled code that used DEFINE-STRUCTURE.
Screen coordinates are signed, and not always nonnegative; project
negative ones onto the border. Widths and heights are technically
signed too, according to my Xlib.h, but I haven't observed negative
values, and negative values can't possibly make sense, whereas I have
observed negative coordinates in the wild (button down in-window,
button up out-of-window).
Refuse to signal a subprocess that has terminated.
Once Scheme has called wait*(2) on a process that has terminated, its
pid may be recycled, so attempting to send a signal to it may cause a
signal to be sent to some random process!
New tests for subprocess support include a regression test for this.
Add hook in dynamically loaded modules for unloading actions.
Dynamically loaded modules can't use reload cleanups, because they
may be unloaded by pruxdld's reload cleanup before their reload
cleanups get to run, causing DISK-RESTORE to attempt to execute
unmapped code. Instead, pruxdld will now call dload_finalize_file
if it is defined in the file.
Use this mechanism in prx11. Fixes DISK-RESTORE after launching
and exiting Edwin. (Does not fix DISK-RESTORE of an image that was
saved while Edwin was running. That is much harder.)