mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-20 11:40:18 +02:00
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.
This commit is contained in:
parent
d1fae96472
commit
53a79cd060
6 changed files with 54 additions and 4 deletions
|
@ -1567,6 +1567,8 @@ AC_CONFIG_FILES([libguile/guile-snarf-docs],
|
||||||
[chmod +x libguile/guile-snarf-docs])
|
[chmod +x libguile/guile-snarf-docs])
|
||||||
AC_CONFIG_FILES([test-suite/standalone/test-use-srfi],
|
AC_CONFIG_FILES([test-suite/standalone/test-use-srfi],
|
||||||
[chmod +x 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
|
AC_OUTPUT
|
||||||
|
|
||||||
|
|
|
@ -1218,7 +1218,10 @@ SCM_DEFINE (scm_sys_fast_slot_ref, "%fast-slot-ref", 2, 0, 0,
|
||||||
unsigned long int i;
|
unsigned long int i;
|
||||||
|
|
||||||
SCM_VALIDATE_INSTANCE (1, obj);
|
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);
|
return SCM_SLOT (obj, i);
|
||||||
}
|
}
|
||||||
#undef FUNC_NAME
|
#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;
|
unsigned long int i;
|
||||||
|
|
||||||
SCM_VALIDATE_INSTANCE (1, obj);
|
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);
|
SCM_SET_SLOT (obj, i, value);
|
||||||
|
|
||||||
|
|
|
@ -98,8 +98,6 @@ typedef struct scm_t_method {
|
||||||
/* Also defined in libguile/objects.c */
|
/* Also defined in libguile/objects.c */
|
||||||
#define SCM_CLASS_OF(x) SCM_STRUCT_VTABLE (x)
|
#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_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) \
|
#define SCM_CLASSP(x) \
|
||||||
(SCM_STRUCTP (x) && SCM_STRUCT_VTABLE_FLAGS (x) & SCM_CLASSF_METACLASS)
|
(SCM_STRUCTP (x) && SCM_STRUCT_VTABLE_FLAGS (x) & SCM_CLASSF_METACLASS)
|
||||||
|
|
1
test-suite/standalone/.gitignore
vendored
1
test-suite/standalone/.gitignore
vendored
|
@ -8,3 +8,4 @@
|
||||||
/test-use-srfi
|
/test-use-srfi
|
||||||
/test-scm-with-guile
|
/test-scm-with-guile
|
||||||
/test-scm-c-read
|
/test-scm-c-read
|
||||||
|
/test-fast-slot-ref
|
||||||
|
|
|
@ -109,6 +109,10 @@ test_conversion_LDADD = ${top_builddir}/libguile/libguile.la
|
||||||
check_PROGRAMS += test-conversion
|
check_PROGRAMS += test-conversion
|
||||||
TESTS += test-conversion
|
TESTS += test-conversion
|
||||||
|
|
||||||
|
# test-fast-slot-ref
|
||||||
|
check_SCRIPTS += test-fast-slot-ref
|
||||||
|
TESTS += test-fast-slot-ref
|
||||||
|
|
||||||
# test-use-srfi
|
# test-use-srfi
|
||||||
check_SCRIPTS += test-use-srfi
|
check_SCRIPTS += test-use-srfi
|
||||||
TESTS += test-use-srfi
|
TESTS += test-use-srfi
|
||||||
|
|
39
test-suite/standalone/test-fast-slot-ref.in
Normal file
39
test-suite/standalone/test-fast-slot-ref.in
Normal file
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue