diff options
-rw-r--r-- | configure.in | 2 | ||||
-rw-r--r-- | libguile/goops.c | 10 | ||||
-rw-r--r-- | libguile/goops.h | 2 | ||||
-rw-r--r-- | test-suite/standalone/.gitignore | 1 | ||||
-rw-r--r-- | test-suite/standalone/Makefile.am | 4 | ||||
-rw-r--r-- | test-suite/standalone/test-fast-slot-ref.in | 39 |
6 files changed, 54 insertions, 4 deletions
diff --git a/configure.in b/configure.in index a7fd9c914..fce493a19 100644 --- a/configure.in +++ b/configure.in @@ -1570,6 +1570,8 @@ AC_CONFIG_FILES([libguile/guile-snarf-docs], [chmod +x libguile/guile-snarf-docs]) AC_CONFIG_FILES([test-suite/standalone/test-use-srfi], [chmod +x test-suite/standalone/test-use-srfi]) +AC_CONFIG_FILES([test-suite/standalone/test-fast-slot-ref], + [chmod +x test-suite/standalone/test-fast-slot-ref]) AC_OUTPUT diff --git a/libguile/goops.c b/libguile/goops.c index 840ddd694..b3dfe0d69 100644 --- a/libguile/goops.c +++ b/libguile/goops.c @@ -1218,7 +1218,10 @@ SCM_DEFINE (scm_sys_fast_slot_ref, "%fast-slot-ref", 2, 0, 0, unsigned long int i; SCM_VALIDATE_INSTANCE (1, obj); - i = scm_to_unsigned_integer (index, 0, SCM_NUMBER_OF_SLOTS(obj)-1); + i = scm_to_unsigned_integer (index, 0, + SCM_I_INUM (SCM_SLOT (SCM_CLASS_OF (obj), + scm_si_nfields)) + - 1); return SCM_SLOT (obj, i); } #undef FUNC_NAME @@ -1232,7 +1235,10 @@ SCM_DEFINE (scm_sys_fast_slot_set_x, "%fast-slot-set!", 3, 0, 0, unsigned long int i; SCM_VALIDATE_INSTANCE (1, obj); - i = scm_to_unsigned_integer (index, 0, SCM_NUMBER_OF_SLOTS(obj)-1); + i = scm_to_unsigned_integer (index, 0, + SCM_I_INUM (SCM_SLOT (SCM_CLASS_OF (obj), + scm_si_nfields)) + - 1); SCM_SET_SLOT (obj, i, value); diff --git a/libguile/goops.h b/libguile/goops.h index 80ba98549..6b88ae267 100644 --- a/libguile/goops.h +++ b/libguile/goops.h @@ -98,8 +98,6 @@ typedef struct scm_t_method { /* Also defined in libguile/objects.c */ #define SCM_CLASS_OF(x) SCM_STRUCT_VTABLE (x) #define SCM_ACCESSORS_OF(x) (SCM_PACK (SCM_STRUCT_VTABLE_DATA (x)[scm_si_getters_n_setters])) -#define SCM_NUMBER_OF_SLOTS(x) \ - ((SCM_STRUCT_DATA (x)[scm_struct_i_n_words]) - scm_struct_n_extra_words) #define SCM_CLASSP(x) \ (SCM_STRUCTP (x) && SCM_STRUCT_VTABLE_FLAGS (x) & SCM_CLASSF_METACLASS) diff --git a/test-suite/standalone/.gitignore b/test-suite/standalone/.gitignore index b1f40882e..df1ad7028 100644 --- a/test-suite/standalone/.gitignore +++ b/test-suite/standalone/.gitignore @@ -8,3 +8,4 @@ /test-use-srfi /test-scm-with-guile /test-scm-c-read +/test-fast-slot-ref diff --git a/test-suite/standalone/Makefile.am b/test-suite/standalone/Makefile.am index 3afd7e586..cc8b58871 100644 --- a/test-suite/standalone/Makefile.am +++ b/test-suite/standalone/Makefile.am @@ -103,6 +103,10 @@ test_conversion_LDADD = ${top_builddir}/libguile/libguile.la check_PROGRAMS += test-conversion TESTS += test-conversion +# test-fast-slot-ref +check_SCRIPTS += test-fast-slot-ref +TESTS += test-fast-slot-ref + # test-use-srfi check_SCRIPTS += test-use-srfi TESTS += test-use-srfi diff --git a/test-suite/standalone/test-fast-slot-ref.in b/test-suite/standalone/test-fast-slot-ref.in new file mode 100644 index 000000000..5bd063876 --- /dev/null +++ b/test-suite/standalone/test-fast-slot-ref.in @@ -0,0 +1,39 @@ +#!/bin/sh + +# Copyright (C) 2006 Free Software Foundation, Inc. +# +# This library is free software; you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation; either version 2.1 of the License, or (at +# your option) any later version. +# +# This library is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +# License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this library; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +# Test for %fast-slot-ref, which was previously implemented such that +# an out-of-range slot index could escape being properly detected, and +# could then cause a segmentation fault. +# +# Prior to the change in this commit to goops.c, the following +# sequence reliably causes a segmentation fault on my GNU/Linux when +# executing the (%fast-slot-ref i 3) line. For reasons as yet +# unknown, it does not cause a segmentation fault if the same code is +# loaded as a script; that is why we run it here using "guile -q <<EOF". +exec guile -q -l @top_builddir_absolute@/libguile/stack-limit-calibration.scm >/dev/null 2>&1 <<EOF +(use-modules (oop goops)) +(define-module (oop goops)) +(define-class <c> () (a #:init-value 1) (b #:init-value 2) (c #:init-value 3)) +(define i (make <c>)) +(%fast-slot-ref i 1) +(%fast-slot-ref i 0) +(%fast-slot-ref i 3) +(%fast-slot-ref i -1) +(%fast-slot-ref i 2) +(exit 0) +EOF |