Better handling of archive open/close and begin/end.

This commit is contained in:
Chris Johns 2012-11-18 07:37:02 +11:00
parent 065ac15a40
commit f1cf3a9dd3

View File

@ -546,26 +546,31 @@ namespace rld
archive::~archive () archive::~archive ()
{ {
end ();
close (); close ();
} }
void void
archive::begin () archive::begin ()
{ {
elf ().begin (name ().full (), fd ()); if (references () == 1)
{
elf ().begin (name ().full (), fd ());
/* /*
* Make sure it is an archive. * Make sure it is an archive.
*/ */
if (!elf ().is_archive ()) if (!elf ().is_archive ())
throw rld::error ("Not an archive.", throw rld::error ("Not an archive.",
"archive-begin:" + name ().full ()); "archive-begin:" + name ().full ());
}
} }
void void
archive::end () archive::end ()
{ {
elf ().end (); if (references () == 1)
elf ().end ();
} }
bool bool
@ -875,9 +880,6 @@ namespace rld
void void
object::open () object::open ()
{ {
if (rld::verbose () >= RLD_VERBOSE_TRACE)
std::cout << "object::open: " << name ().full () << std::endl;
if (archive_) if (archive_)
archive_->open (); archive_->open ();
else else
@ -887,13 +889,16 @@ namespace rld
void void
object::close () object::close ()
{ {
if (rld::verbose () >= RLD_VERBOSE_TRACE)
std::cout << "object::close: " << name ().full () << std::endl;
if (archive_) if (archive_)
{
archive_->end ();
archive_->close (); archive_->close ();
}
else else
{
end ();
image::close (); image::close ();
}
} }
void void
@ -1215,17 +1220,36 @@ namespace rld
void void
cache::load_symbols (rld::symbols::table& symbols, bool local) cache::load_symbols (rld::symbols::table& symbols, bool local)
{ {
for (objects::iterator oi = objects_.begin (); if (rld::verbose () >= RLD_VERBOSE_INFO)
oi != objects_.end (); std::cout << "cache:load-sym: object files: " << objects_.size ()
++oi) << std::endl;
try
{ {
object* obj = (*oi).second; archives_begin ();
obj->open (); for (objects::iterator oi = objects_.begin ();
obj->begin (); oi != objects_.end ();
obj->load_symbols (symbols, local); ++oi)
obj->end (); {
obj->close (); object* obj = (*oi).second;
obj->open ();
obj->begin ();
obj->load_symbols (symbols, local);
obj->end ();
obj->close ();
}
} }
catch (...)
{
archives_end ();
throw;
}
archives_end ();
if (rld::verbose () >= RLD_VERBOSE_INFO)
std::cout << "cache:load-sym: symbols: " << symbols.size ()
<< std::endl;
} }
void void