[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
dlopen try / catch failure
From: |
Brian Hunt |
Subject: |
dlopen try / catch failure |
Date: |
Tue, 01 Oct 2002 14:09:06 GMT |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.0.1) Gecko/20020826 |
Hi everyone,
I cannot seem to catch errors either within or about objects opened with
dlopen. See the code below for an example. I am using gcc 3.0.2 et al.,
as follows (this problem occurs with gcc 3.2, as well, I believe):
address@hidden ~/tmp/dlopen]$ g++ -o y.o y.cc -c
address@hidden ~/tmp/dlopen]$ ld -E -shared y.o -o y.so
address@hidden ~/tmp/dlopen]$ g++ x.cc -Wl,-E -ldl -rdynamic
address@hidden ~/tmp/dlopen]$ ./a.out
Registered rae
Aborted (core dumped)
In the example below, I am autoregistering components into a factory map
(alpha) using the _init() symbol for on linkage execution.
x.h has the (abstract) interface class "doe", and the extern definition
for the factory "alpha". x.cc allocates space for the factory, and has
a main function which iterates through the registered objects. y.cc
extends "doe", into the class "rae", and defines extern "C" symbols
_init() which autoregisters the rae class and doe*Rae() which returns a
new rae object.
The simple explicit try / throw / catch block within the "rae::hello()"
function elucidates the issue I am having. I have tried a number of
linking and compiling options, but have yet to find a combination that
solves this problem.
It is not even that there is failure passing a throw in a dlopen'ed
symbol up to the main, although that fails too; the try/catch block is
localized, yet still fails.
Any help would be greatly appreciated.
Cheers,
Brian
//---- x.h
#include #include
#ifndef __DOE_
#define __DOE_
class doe {
public:
virtual string hello() = 0;
};
typedef doe* doe_t();
typedef map fact;
extern fact alpha;
#endif
//----/ x.h
//---- x.cc
#include
#include
#include
using namespace std;
#include "x.h"
extern "C"{
fact alpha;
}
int main(int argc, char**argv) {
void * handle = dlopen("./y.so", RTLD_GLOBAL|RTLD_NOW);
if (handle == NULL) {
cerr << "Error opening y.so: " << dlerror() <::iterator sit =
alpha.begin();
for (; sit != alpha.end(); sit++) {
doe * Y = alpha[sit->first]();
std::cerr << " Registered " << sit->first << std::endl;
std::cerr << " Hello: " << Y->hello() << std::endl;
}
dlclose(handle);
}
//----/ x.cc
//---- y.cc
#include
#include
#include using namespace std;
#include "x.h"
class rae : public doe {
public:
virtual string hello() {
try {
// remove this throw, and everything works.
throw runtime_error("Why does this throw abort?");
return "I am the lizard queen!";
} catch (runtime_error &e) {
cerr <<" Caught exception: " <<e.what() <<endl;
return "exception caught";
}
}
};
extern "C" {
doe * Rae() { return new rae(); }
void _init() { alpha["rae"] = Rae; }
}
//----/ y.cc
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- dlopen try / catch failure,
Brian Hunt <=