diff options
author | Ludovic Courtès <ludo@gnu.org> | 2010-04-09 00:30:10 +0200 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2010-04-09 00:32:15 +0200 |
commit | 01ad5a7ba9edb5d8c96567ed80ea1a34019c5338 (patch) | |
tree | 0e99da198557e8718718377432f0771c45f7025a /libguile/foreign.c | |
parent | 4551e860f02244ffb3858c941319f1613bac40e4 (diff) | |
download | guile-01ad5a7ba9edb5d8c96567ed80ea1a34019c5338.tar.gz |
Raise an error when attempting to modify the value of `%null-pointer'.
* libguile/foreign.c (sym_null_pointer_error): New variable.
(null_pointer_error): New function.
(scm_foreign_set_x): Raise an error if attempting to modify
NULL_POINTER.
(scm_foreign_to_bytevector): Use `null_pointer_error ()' instead of
`scm_misc_error ()'.
* test-suite/tests/foreign.test: New file.
* test-suite/Makefile.am (SCM_TESTS): Add tests/foreign.test.
* test-suite/lib.scm (exception:null-pointer-error): New variable.
Diffstat (limited to 'libguile/foreign.c')
-rw-r--r-- | libguile/foreign.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/libguile/foreign.c b/libguile/foreign.c index 0d6b67000..eaeea6c90 100644 --- a/libguile/foreign.c +++ b/libguile/foreign.c @@ -52,6 +52,7 @@ SCM_SYMBOL (sym_size_t, "size_t"); SCM_SYMBOL (sym_asterisk, "*"); SCM_SYMBOL (sym_null, "%null-pointer"); +SCM_SYMBOL (sym_null_pointer_error, "null-pointer-error"); /* The cell representing the null pointer. */ static const scm_t_bits null_pointer[2] = @@ -60,6 +61,15 @@ static const scm_t_bits null_pointer[2] = 0 }; +/* Raise a null pointer dereference error. */ +static void +null_pointer_error (const char *func_name) +{ + scm_error (sym_null_pointer_error, func_name, + "null pointer dereference", SCM_EOL, SCM_EOL); +} + + static SCM cif_to_procedure (SCM cif, SCM func_ptr); @@ -161,6 +171,12 @@ SCM_DEFINE (scm_foreign_set_x, "foreign-set!", 2, 0, 0, scm_t_uint8 *ptr; SCM_VALIDATE_FOREIGN (1, foreign); + + if (SCM_UNLIKELY (scm_is_eq (foreign, PTR2SCM (&null_pointer)))) + /* Attempting to modify the pointer value of NULL_POINTER (which is + read-only anyway), so raise an error. */ + null_pointer_error (FUNC_NAME); + ptr = SCM_FOREIGN_POINTER (foreign, scm_t_uint8); ftype = SCM_FOREIGN_TYPE (foreign); @@ -237,7 +253,7 @@ SCM_DEFINE (scm_foreign_to_bytevector, "foreign->bytevector", 1, 3, 0, ptr = SCM_FOREIGN_POINTER (foreign, scm_t_int8); if (SCM_UNLIKELY (ptr == NULL)) - scm_misc_error (FUNC_NAME, "null pointer dereference", SCM_EOL); + null_pointer_error (FUNC_NAME); if (SCM_UNBNDP (uvec_type)) btype = SCM_ARRAY_ELEMENT_TYPE_VU8; |