OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-atomspace commits / 2278341

Perform atomspace install correctly.
The previous commit was ... almost correct. But the install happened much too early, leading to bad inheritance. This one gets it right.
22783413dbcd545549b7cf6dc69cdf2bdfccb4d0
by Linas Vepštas <linasvepstas@gmail.com> · 2026-01-21T04:41:01.000Z

Changed files (3) +18 -26

opencog/atomspace/AtomSpace.cc +5 -7
……@@ -120,7 +120,7 @@ AtomSpace::~AtomSpace()
120120}
121121
122122/// Set up a vector of pointers to the parent AtomSpaces.
123void AtomSpace::do_install(void)
123void AtomSpace::install(void)
124124{
125125 if (0 == _environ.size())
126126 {
……@@ -144,7 +144,7 @@ void AtomSpace::do_install(void)
144144 {
145145 Handle bh(base);
146146 if (nullptr == base->getAtomSpace())
147 bh = this->add_atom(base);
147 bh = _atom_space->add_atom(base);
148148
149149 ValuePtr vp(bh->execute(this));
150150 AtomSpacePtr as(AtomSpaceCast(vp));
……@@ -162,12 +162,10 @@ void AtomSpace::do_install(void)
162162 }
163163 }
164164
165 // XXX FIXME. I think this is installing into the wrong AtomSpace.
166 // Maybe. I'm confused. But no unit test seems to fail as a result
167 // of this, so I dunno. Go figure.
168 setAtomSpace(this);
165 // XXX FIXME: Frame::install loops over _outgoing but maybe it
166 // should be looping over _environ, instead? Maybe we should copy
167 // _environ to _outgoing?
169168 Frame::install();
170 setAtomSpace(nullptr);
171169}
172170
173171// ====================================================================
opencog/atomspace/AtomSpace.h +1 -5
……@@ -80,7 +80,7 @@ class AtomSpace : public Frame
8080 // result of this execution is stored in _environ; the original
8181 // Atoms are in _outgoing.
8282 std::vector<AtomSpacePtr> _environ;
83 void do_install();
83 virtual void install(void) override;
8484
8585 void init();
8686 void clear_all_atoms();
……@@ -539,10 +539,6 @@ template< class... Args >
539539AtomSpacePtr createAtomSpace( Args&&... args )
540540{
541541 AtomSpacePtr asp(std::make_shared<AtomSpace>(std::forward<Args>(args) ...));
542 // Unfortunately, Frame::install() cannot be called in the ctor
543 // because shared_from_this() cannot be called in the ctor.
544 // So we do this after the ctor has finished.
545 asp->do_install();
546542 return asp;
547543}
548544
opencog/guile/SchemeSmobAS.cc +12 -14
……@@ -76,28 +76,26 @@ SCM SchemeSmob::ss_new_as (SCM space_list)
7676 }
7777
7878 // Create new AtomSpace with the indicated parents.
79 // This can throw an exception if the parents don't have
80 // a valid form. Catch that exception and rethrow.
81 AtomSpacePtr asp;
79 AtomSpacePtr asp(createAtomSpace(spaces));
80
81 // If a name was provided, set that name.
82 if (0 < name.size())
83 asp->set_name(name);
84
85 Handle hasp(HandleCast(asp));
8286 try
8387 {
84 asp = createAtomSpace(spaces);
88 // Insert it into the current AtomSpace
89 // This can throw an exception if the parents don't have
90 // a valid form. Catch that exception and rethrow.
91 const AtomSpacePtr& env = ss_get_env_as("cog-new-atomspace");
92 if (env) hasp = env->add_atom(hasp);
8593 }
8694 catch (const std::exception& ex)
8795 {
8896 throw_exception(ex, "cog-new-atomspace", space_list);
8997 }
9098
91 // If a name was provided, set that name.
92 if (0 < name.size())
93 asp->set_name(name);
94
95 Handle hasp(HandleCast(asp));
96
97 // Insert it nto the current AtomSpace
98 const AtomSpacePtr& env = ss_get_env_as("cog-new-atomspace");
99 if (env) hasp = env->add_atom(hasp);
100
10199 return protom_to_scm(hasp);
102100}
103101