Commit graph

1152 commits

Author SHA1 Message Date
Marius Gerbershagen
da26facffa file.d: introduce :nonblock and :close-on-exec options for open
Maps directly to flags for open syscall. Ignored on Windows. We now
let the user decide whether to open fifos in nonblocking mode or not.
Manual has been extended to document the new extensions and slightly
rearranged to put the important information first.
2021-02-10 20:06:57 +01:00
Marius Gerbershagen
3827daf4d9 file.d: clean up ecl_stream_open
Previous implementation was messy and contained several race
conditions (multiple open/close operations on the same file, first
checking whether the file exists before opening it). We now always use
a single open call and then optionally do an fdopen later
on (exception being :rename which contains an unavoidable race
condition between checking whether the file exists and then renaming
it later on). Also improve error messages.
2021-02-10 20:05:05 +01:00
Marius Gerbershagen
d4e5a96c23 config-internal.h: automatically set ECL_C_COMPATIBLE_VARIADIC_DISPATCH for apple/arm64 2021-01-29 19:46:01 +01:00
Marius Gerbershagen
da807da49a internal.h: fix ifdef for mp_get_rwlock_{read,write}_wait
rwlocks are emulated using standard locks if no OS primitive for them
exists, therefore we need the declarations in any case.
2021-01-24 18:00:17 +01:00
Marius Gerbershagen
3cec96739d bytecmp: fix evaluation order of load time forms
We need to defer initialization forms until all dependent creation
forms have been compiled (see CLHS make-load-form). Closes #562.

Co-authored-by: Marius Gerbershagen <marius.gerbershagen@gmail.com>
2020-12-27 19:12:49 +01:00
Marius Gerbershagen
b730412ebc bytecmp: preserve the identity for literal objects
When a literal appears in the file multiple times its identity should be
preserved.

CLHS 3.2.4.4:

> If two literal objects appearing in the source code for a single
> file processed with the file compiler are the identical, the
> corresponding objects in the compiled code must also be the identical.

Previously, every bytecode object created during ext::bc-compile-file
had its own vector of constants making it impossible to satisfy this
constraint. Thus, we change ext::bc-compile-file to use the same
constants vector for all bytecode objects from the same file. The
simplest way to achieve this is to use the same compiler environment
for all of the compilation process and push the read-compile loop
into the si_bc_compile_from_stream function implemented in C.
2020-12-27 19:04:00 +01:00
Daniel Kochmański
6e0124bc64 si::mangle-name: return the function name from symbols_list.h
To achieve that we store the symbol name in a separate ecl_symbol slot called
cname. It is initialized from the translation slot in the structure
cl_symbol_initializer. That makes dpp and runtime always resolve function
names to the same symbol. Fixes #534.
2020-12-23 12:08:33 +01:00
Daniel Kochmański
7908ba8003 refactor: remove the file symbols_list2.h
The file symbols_list2.h was automatically generated from the file
symbols_list.h for dpp. This commit unifies said structure definition and
removes a step for generating symbols_list2.h.

From now on at runtime the structurecl_symbol_initializer has an additional
element storing the function name. That will help solving #543.
2020-12-23 12:08:33 +01:00
Pritam Baral
a1b2909b8a s/TCP/ECL_TCP/ among preprocessor defines 2020-11-22 21:04:16 +00:00
Marius Gerbershagen
cdb602e40d fpe: prevent spurious floating point exceptions in WITH_LISP_FPE
feenableexcept may generate a SIGFPE signal if exception status flags
are not cleared beforehand. Happens for example on powerpc platforms.

Fixes #612.
2020-10-31 11:36:52 +01:00
Marius Gerbershagen
34b17a9fe0 unixint.d: remove unused argument to si::handle-signal
Argument was unused since commit c5d2408cc5
2020-08-02 10:55:25 +02:00
Marius Gerbershagen
892a34e66d fix encoding issues on windows console streams
Always use the byte sized input/output operations ReadConsoleA/WriteConsoleA
and do all the conversion to unicode by ourself.

Moreover, expand the set of known encodings for Windows codepages and print
a warning if we encounter an unsupported codepage.

Fixes #582.
2020-08-02 10:55:25 +02:00
Marius Gerbershagen
75877dd8f0 fpe: fix ECL_WITH_LISP_FPE macro
We can't use ecl_process_env_unsafe() == NULL to check if ECL has
booted because the return value of ecl_process_env_unsafe is
unpredictable before ECL has booted. The reason is that
ecl_process_env_unsafe calls pthread_getspecific with an uninitialized
key stored in cl_env_key. But another call to pthread_setspecific
might have already registered a key which happens to be the same as
the not yet initialized cl_env_key, yielding a non-NULL value.
2020-06-28 11:16:17 +02:00
Marius Gerbershagen
c1b5aee6de Merge branch 'mp-timedwait2' into 'develop'
Mp timedwait2

Closes #588

See merge request embeddable-common-lisp/ecl!217
2020-06-20 14:58:19 +00:00
Daniel Kochmański
6322e34415 mp: queue: use less cryptic names
- variable name "o" is replaced with "mp_object"
- typedef "mp_wait_test" to "cl_object(*c)(cl_env_ptr,cl_object)"
2020-06-15 12:34:10 +02:00
Daniel Kochmański
0ab85fc9d5 conditions: add an ext:timeout serious condition 2020-06-15 12:34:10 +02:00
Marius Gerbershagen
90043d205c stacks: fix default C stack size
The ifdef in config-internal.h was buggy since RLIMIT_STACK is only defined after
sys/resource.h has been included which it wasn't. This lead to the stack size always being
increased to at least the default of 1 MB. To fix this, we move the check for RLIMIT_STACK
to the configure script.
2020-06-11 15:16:10 +02:00
Marius Gerbershagen
636cb4cf60 cmp: add support for precompiled header files
Improves compilation speed for single functions by about 40-50
percent. Precompiled headers are specific to the compiler version and
options in use. Due to this, we regenerate the header whenever the
compiler configuration changes.
2020-05-16 18:53:57 +02:00
Marius Gerbershagen
e0bf0f5ac2 gc: remove unnecessary workarounds for old bdwgc versions 2020-05-10 19:47:05 +02:00
Marius Gerbershagen
73af5cdcdd gc: fix signal handlers for generational garbage collector
The boehm gc needs SIGSEGV or SIGBUS to track dirty pages (see
GC_write_fault_handler). Thus these signals need to be unblocked at
all times.
2020-05-08 20:57:56 +02:00
Marius Gerbershagen
c6b4296bb8 cosmetic: fix some compiler warnings 2020-04-29 20:35:37 +02:00
Marius Gerbershagen
bae7d696a9 numbers: remove unnecessary workarounds for single-float numeric functions
Fixes test failures from cmp.0044.inline-cos.
2020-04-25 18:01:00 +02:00
Daniel Kochmański
b9d54d6be7 internals: rename instance.sig to instance.slotds
Slot definitions are no longer a signature, but they are still needed
to update obsolete instances. Reader function name is also changed to
SI:INSTANCE-SLOTDS. SI:INSTANCE-SIG-SET name does not change, because
it sets both SLOTDS and the STAMP.
2020-04-19 17:04:42 +02:00
Daniel Kochmański
f1bc883ed6 clos: introduce class stamps for marking instances obsolete
We should call make-instances-obsolete from finalize-inheritance if we
want to be conforming, because user may have added their own auxiliary
methods.

This change while being last in a serie of commits was locally the
first change which solved problems. It will enable us to implement the
fast generic dispatch after the release.
2020-04-19 17:04:41 +02:00
Daniel Kochmański
81a85f37bd clos: introduce a new system function si:instance-obsolete-p
It helps to determine whether the instance needs to be updated for a
class after redefinition. Currently it is done by comparing the
signature with the instance's class slots.
2020-04-19 14:34:23 +02:00
Daniel Kochmański
aa34ab7119 compiler: rewrite clos::need-to-make-load-form-p
Function is rewritten in C in compiler.d to remove a dependency
between the bytecodes compiler and the clos module. It may be more
performant thanks to more precise type handing, however we use a list
instead of a hashtable, so it may be slower with lookup. To assess
that we should run some benchmarks against real code -- rewriting C
code to work with a hash table should be trivial.

clos::need-to-make-load-form-p is now si::need-to-make-load-form-p and
may be called from C code as si_need_to_make_load_form_p.
2020-04-08 22:01:16 +02:00
Marius Gerbershagen
d7529988f0 numbers: add workaround for log1p
log1pl is not present on NetBSD.
2020-03-12 21:29:12 +01:00
Marius Gerbershagen
4faac4dcb8 doc: replace legacy names by their new counterparts 2020-02-22 19:12:43 +01:00
Marius Gerbershagen
3afa3e1a42 ieee_fp: move fetestexcept checks directly after floating point calculations
The C standard allows compilers to ignore side effects of floating
point operations unless the STDC FENV_ACCESS pragma is in effect. This
could lead to spurious floating point exceptions being signaled
because the C compiler optimized a calculation that would ordinarily
not set fpe bits to one that did (observed with clang for a cast
double to cl_fixnum).

To solve this, we resurrect the ECL_MATHERR macro which was removed in
commit cb03494a6d. We handle fpe bits
only around calculations which are known to be "unsafe" in the sense
that they can produce floating point exceptions. Before the
calculation, all bits are unset and afterwards, we test for
exceptions.

The disadvantage of this method is that optimizations by the C
compiler resulting in unboxed float arithmetic might lead to
missing exceptions, because our native C compiler does not insert
ECL_MATHERR statements around these calculations.
2020-02-16 22:32:37 +01:00
Marius Gerbershagen
07c5c6b3c1 ecl_process_env_unsafe: don't mark as __attribute__((const))
This can cause the C compiler to optimize away multiple calls to this
function, which makes the ECL_WITH_LISP_FPE macro fail.
2020-01-12 18:53:50 +01:00
Marius Gerbershagen
865b9e7636 fpe: fix ECL_WITH_LISP_FPE macro after changes to floating point exception handling
Make sure that apart from turning on/off signaling for exceptions, we
also clear all exception bits. After the recent changes to how ECL
handles floating point exceptions, not doing that could lead to
spurious exceptions being signaled even when using the
ECL_WITH_LISP_FPE macro because an earlier calculation yielded
infinity/NaN.
2020-01-12 18:53:45 +01:00
Daniel Kochmański
9cf6e774a4 Merge branch 'fpe-without-sigfpe' into 'develop'
Fix floating point exceptions for systems without working feenableexcept

See merge request embeddable-common-lisp/ecl!177
2020-01-12 10:30:09 +00:00
Marius Gerbershagen
cb03494a6d ieee_fp: use explicit checks for fpe bits if feenableexcept is not declared
Using isnan and isfinite to check for floating point exceptions
doesn't work when we want floats to be able to have infinity or NaN as
values, thus this option was removed with commit
5f71f728a3. However, we can still use
fetestexcept to explicitly check if floating point exceptions occurred
even when we can't use the feenableexcept/SIGFPE signal delivery
mechanism.

Previously, we had something like this in the
ECL_MATHERR_TEST/ECL_MATHERR_CLEAR macros, but this was not used
consistently in our codebase (the ECL_MATHERR_TEST macro was missing
in many places). Instead of error-prone testing at every point of
computation, we call fetestexcept in DO_DETECT_FPE when creating a new
float/complex float. In order to avoid having to do this twice, the
DO_DETECT_FPE2 macro is introduced.

A minor disadvantage of this strategy is that floating point
exceptions may be signaled later than they occurred.
2020-01-11 15:32:52 +01:00
Marius Gerbershagen
c2a577d609 bignums: prevent bignum registers from growing too big
We had this code before, but it made non-functional in commit
20f4c8931e and got removed with commit
749b97d06c.
2020-01-04 18:07:41 +01:00
Marius Gerbershagen
c301b108a7 bignums: don't use ecl_alloc_atomic for gmp
The gmp manual (https://gmplib.org/manual/Custom-Allocation.html) states

> GMP may use allocated blocks to hold pointers to other allocated
  blocks. This will limit the assumptions a conservative garbage
  collection scheme can make.

Thus we can't use ecl_alloc_atomic. We could just use ecl_alloc
instead, however our implementation is already structured in such a
way that it is sufficient to use ecl_alloc_uncollectable. The reason
for that is that currently all bignums except those in the bignum
registers in the thread local environment are allocated as compact
objects so that we only need to call mpz_clear for the few non-compact
objects in the bignum registers.

See also commits 7b536161 and bd48b859.
Fixes #485.
2020-01-04 17:49:08 +01:00
Marius Gerbershagen
d7b2dfb722 Change handling of C stack size
Previously: unconditionally use the size from ECL_OPT_C_STACK_SIZE if
it is larger than the OS provided value and if possible resize the
stack at runtime.

Now: Use ECL_OPT_C_STACK_SIZE if provided. Otherwise, use a) the OS
provided value if we can resize the stack at runtime (for Unix) or b)
the new build option ECL_DEFAULT_C_STACK_SIZE (1 MB) if we can set the
stack size at link time (for Windows).
2019-12-26 19:13:31 +01:00
Marius Gerbershagen
b2f09b4809 ffi: generate abi list from available libffi abis
This is more robust against changes in the abi support in libffi.
We also remove unused struct and enum type definitions (left over from
our own dynamic ffi implementation?).
2019-12-09 19:49:30 +01:00
Marius Gerbershagen
e37fafb335 stacks.d: fix several problems with C stack
ecl_cs_set_org and cs_set_size had several problems:
-the size of the stack was estimated to be 1/2 of the actual value,
 which could lead to wrong stack overflow errors. In particular, we
 cannot assume that the stack pointer will always start at the stack
 origin and increase/decrease linearly (counterexamples could
 include callbacks from other threads).
-despite its name, cs_set_size did not actually set the stack size
 even on systems where this is possible at runtime.
-there were several magic numbers used.
2019-12-08 10:26:52 +01:00
Marius Gerbershagen
a2319d3150 unixsys: check for system() in configure
Don't let a non-available system() function (happens e.g. on iOS)
prevent us from compiling ECL.
2019-12-08 10:26:52 +01:00
Marius Gerbershagen
fbdb0a32a8 cmp: check that number of arguments matches the declaration in symbols_list.h
We also use the *in-all-symbols-functions* variable only for
determining which functions are to be exported during the build of ECL
itself. Otherwise, instead of specifying manually, which Lisp
functions are exported and in the core, we use the information from
symbols_list.h (i.e. we let all_symbols.d initialize all core
functions).
2019-12-08 10:26:52 +01:00
Marius Gerbershagen
846cf3f377 dpp: create correct signature for functions with only required arguments 2019-12-08 10:26:52 +01:00
Marius Gerbershagen
18cb1b3552 fix for calling conventions treating fixed and variadic arguments differently
Previously, we assumed that the fixed and variadic arguments of a
variadic function were passed to the function in the same way. The
arm64 calling convention used by iOS breaks this assumption by passing
fixed arguments in registers or on the stack, depending on the
position, while variadic arguments are always passed on the stack.

Solving this problem while still allowing function redefinition at
runtime requires introducing additional dispatch functions. These
dispatch functions take no fixed arguments and pass all their
arguments to the actual function. This dispatch is enabled by passing
-DECL_C_COMPATIBLE_VARIADIC_DISPATCH to the C compiler.

This problem was originally identified and a solution provided by
thewhimer@gmail.com. This commit based on his work with minor
improvements.
2019-12-08 10:26:52 +01:00
Daniel Kochmański
02038d66da complex-float: move functions to externa.h
si_complex_float_p and si_complex_float are referenced in tests, to
allow clean compilation put them in externa.h.
2019-12-04 18:03:53 +01:00
Daniel Kochmański
0a7056da5f ecl_min: symbols list: fix si::complex-float function name
Symbols must be associated with functions following an uniform naming
scheme because si:mangle-name does not return pre-existing string.
See #534 for details. This is a temporary solution.
2019-12-04 17:52:16 +01:00
Daniel Kochmański
b96d28a4f8 Merge branch 'fix-476' into 'develop'
Fix 476

Closes #476

See merge request embeddable-common-lisp/ecl!161
2019-08-26 06:15:51 +00:00
Marius Gerbershagen
693ce14130 printer: remove redundancies between pretty and ordinary printer 2019-08-18 19:31:58 +02:00
Daniel Kochmański
df339485eb Merge branch 'infinity-NaN-numeric-functions' into 'develop'
Make all numeric functions return sensible values for infinity/NaN

Closes #477

See merge request embeddable-common-lisp/ecl!160
2019-08-16 18:52:23 +00:00
Marius Gerbershagen
57db4c813c complex-float: use CMPLX for constructing complex floats
Works better for edge cases such as x + I*∞, which otherwise would
lead to a complex with NaN real part.
2019-08-14 20:51:40 +02:00
Marius Gerbershagen
046c6b9f32 number_compare.d: fix number comparison for NaN
All comparisons with NaN should return NIL for consistency with the
IEEE standard.
2019-08-14 20:51:40 +02:00
Marius Gerbershagen
0ff3e27b54 ECL_STACK_FRAME_VARARGS: Use the correct struct 2019-07-23 18:45:49 +02:00