assert (SCM_IMP (s));
}
-// For static objects, this will be called at program exit. With the
-// state of the memory system unknown, we refrain from any cleanup
-// actions outside of the object memory itself.
+SCM Protected_scm::list_ = SCM_EOL;
+SCM Protected_scm::last_ = SCM_EOL;
-Protected_scm::~Protected_scm ()
+void
+Protected_scm::protectify (SCM s)
{
- object_ = SCM_UNDEFINED;
+ s = scm_list_1 (s);
+ if (SCM_CONSP (last_))
+ SCM_SETCDR (last_, s);
+ else
+ list_ = scm_permanent_object (s);
+ last_ = object_ = s;
}
Protected_scm &
{
if (SCM_CONSP (object_))
SCM_SETCAR (object_, s);
+ else if (SCM_IMP (s))
+ object_ = s;
else
- object_ = SCM_NIMP (s) ? scm_permanent_object (scm_list_1 (s)) : s;
+ protectify (s);
return *this;
}
return *this = (SCM) s;
}
-Protected_scm::operator SCM () const
+Protected_scm::operator SCM const & () const
+{
+ if (SCM_CONSP (object_))
+ return *SCM_CARLOC (object_);
+ return object_;
+}
+
+Protected_scm::operator SCM & ()
{
- return SCM_CONSP (object_) ? SCM_CAR (object_) : object_;
+ // The reference may be used to overwrite an immediate value with a
+ // non-immediate one, so we _have_ to create full protection.
+ if (!SCM_CONSP (object_))
+ protectify (object_);
+
+ return *SCM_CARLOC (object_);
+}
+
+bool
+Protected_scm::is_bound () const
+{
+ if (SCM_CONSP (object_))
+ return !SCM_UNBNDP (SCM_CAR (object_));
+ return !SCM_UNBNDP (object_);
}