mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-24 12:20:20 +02:00
Reimplement scm_is_mutable_pair using gc_heap_contains
* libguile/pairs.c (scm_to_ref): Copy this stub around again; we should fix this... (scm_is_mutable_pair): Use gc_heap_contains.
This commit is contained in:
parent
fd921be76c
commit
fcf8fa3d10
2 changed files with 22 additions and 25 deletions
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright 1995-1996,2000-2001,2004-2006,2008-2013,2017-2019
|
/* Copyright 1995-1996,2000-2001,2004-2006,2008-2013,2017-2019,2025
|
||||||
Free Software Foundation, Inc.
|
Free Software Foundation, Inc.
|
||||||
|
|
||||||
This file is part of Guile.
|
This file is part of Guile.
|
||||||
|
@ -26,6 +26,7 @@
|
||||||
#include <verify.h>
|
#include <verify.h>
|
||||||
|
|
||||||
#include "boolean.h"
|
#include "boolean.h"
|
||||||
|
#include "gc-internal.h"
|
||||||
#include "gsubr.h"
|
#include "gsubr.h"
|
||||||
|
|
||||||
#include "pairs.h"
|
#include "pairs.h"
|
||||||
|
@ -74,6 +75,24 @@ scm_cons2 (SCM w, SCM x, SCM y)
|
||||||
return scm_cons (w, scm_cons (x, y));
|
return scm_cons (w, scm_cons (x, y));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline struct gc_ref scm_to_ref (SCM scm)
|
||||||
|
{
|
||||||
|
return gc_ref (SCM_UNPACK (scm));
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
scm_is_mutable_pair (SCM x)
|
||||||
|
{
|
||||||
|
/* Guile embeds literal pairs into compiled object files. It's not
|
||||||
|
valid Scheme to mutate literal values. Two practical reasons to
|
||||||
|
enforce this restriction are to allow literals to share share
|
||||||
|
structure (pairs) with other literals in the compilation unit, and
|
||||||
|
to allow literals containing immediates to be allocated in the
|
||||||
|
read-only, shareable section of the file. Attempting to mutate a
|
||||||
|
pair in the read-only section would cause a segmentation fault, so
|
||||||
|
to avoid that, we really do need to enforce the restriction. */
|
||||||
|
return scm_is_pair (x) && gc_heap_contains (the_gc_heap, scm_to_ref (x));
|
||||||
|
}
|
||||||
|
|
||||||
SCM_DEFINE (scm_pair_p, "pair?", 1, 0, 0,
|
SCM_DEFINE (scm_pair_p, "pair?", 1, 0, 0,
|
||||||
(SCM x),
|
(SCM x),
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef SCM_PAIRS_H
|
#ifndef SCM_PAIRS_H
|
||||||
#define SCM_PAIRS_H
|
#define SCM_PAIRS_H
|
||||||
|
|
||||||
/* Copyright 1995-1996,2000-2001,2004,2006,2008-2010,2012,2018
|
/* Copyright 1995-1996,2000-2001,2004,2006,2008-2010,2012,2018,2025
|
||||||
Free Software Foundation, Inc.
|
Free Software Foundation, Inc.
|
||||||
|
|
||||||
This file is part of Guile.
|
This file is part of Guile.
|
||||||
|
@ -199,29 +199,7 @@ scm_cdr (SCM x)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef BUILDING_LIBGUILE
|
SCM_INTERNAL int scm_is_mutable_pair (SCM x);
|
||||||
#ifndef HAVE_GC_IS_HEAP_PTR
|
|
||||||
static int
|
|
||||||
GC_is_heap_ptr (void *ptr)
|
|
||||||
{
|
|
||||||
return GC_base (ptr) != NULL;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static inline int
|
|
||||||
scm_is_mutable_pair (SCM x)
|
|
||||||
{
|
|
||||||
/* Guile embeds literal pairs into compiled object files. It's not
|
|
||||||
valid Scheme to mutate literal values. Two practical reasons to
|
|
||||||
enforce this restriction are to allow literals to share share
|
|
||||||
structure (pairs) with other literals in the compilation unit, and
|
|
||||||
to allow literals containing immediates to be allocated in the
|
|
||||||
read-only, shareable section of the file. Attempting to mutate a
|
|
||||||
pair in the read-only section would cause a segmentation fault, so
|
|
||||||
to avoid that, we really do need to enforce the restriction. */
|
|
||||||
return scm_is_pair (x) && GC_is_heap_ptr (SCM2PTR (x));
|
|
||||||
}
|
|
||||||
#endif /* BUILDING_LIBGUILE */
|
|
||||||
|
|
||||||
SCM_API SCM scm_cons2 (SCM w, SCM x, SCM y);
|
SCM_API SCM scm_cons2 (SCM w, SCM x, SCM y);
|
||||||
SCM_API SCM scm_pair_p (SCM x);
|
SCM_API SCM scm_pair_p (SCM x);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue