summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeil Jerram <neil@ossau.uklinux.net>2009-01-04 21:32:23 +0000
committerNeil Jerram <neil@ossau.uklinux.net>2009-01-04 22:41:51 +0000
commit53a79cd06028690074bfeb6a20ef1c8cf2adcbee (patch)
treeb5828e66152e19903dfbfa827f90ca0bde9e9027
parentd1fae96472b273efff65e4629554322a9d754e48 (diff)
downloadguile-53a79cd06028690074bfeb6a20ef1c8cf2adcbee.tar.gz
Fix implementation of %fast-slot-ref and %fast-slot-set!
* libguile/goops.c (scm_sys_fast_slot_ref, scm_sys_fast_slot_set_x): Correct incantation for getting the number of slots of the specified instance. * libguile/goops.h (SCM_NUMBER_OF_SLOTS): Removed (because wrong). * test-suite/standalone/test-fast-slot-ref.in: New standalone test. * configure.in: Generate test-suite/standalone/test-fast-slot-ref. * test-suite/standalone/Makefile.am (check_SCRIPTS): Add test-fast-slot-ref.
-rw-r--r--configure.in2
-rw-r--r--libguile/goops.c10
-rw-r--r--libguile/goops.h2
-rw-r--r--test-suite/standalone/.gitignore1
-rw-r--r--test-suite/standalone/Makefile.am4
-rw-r--r--test-suite/standalone/test-fast-slot-ref.in39
6 files changed, 54 insertions, 4 deletions
diff --git a/configure.in b/configure.in
index bffd155fa..de99f7f98 100644
--- a/configure.in
+++ b/configure.in
@@ -1567,6 +1567,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 3fc87886f..fe2dc9a1e 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 44156ec1d..356573f88 100644
--- a/test-suite/standalone/Makefile.am
+++ b/test-suite/standalone/Makefile.am
@@ -109,6 +109,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