Revision: 76746
http://sourceforge.net/p/brlcad/code/76746
Author: starseeker
Date: 2020-08-14 12:11:13 +0000 (Fri, 14 Aug 2020)
Log Message:
-----------
The same thing that made OpenBSD such a pain for bu_dir works against the GED
plugins - we need bu_setprogname for the initialization to work reliably, but
at library load we don't have the program name. Handle it by having the two
accessor commands - ged_cmd_valid and ged_exec - check to make sure the command
map is populated before trying anything, and if it is not re-attempt the
initialization. By the time we're calling those functions bu_setprogname
should be set and the initialization should now succeed. The regression test
that checks for bu_setprogname should ensure this will work across all BRL-CAD
commands - any program that does NOT call bu_setprogname and attempts to use a
GED command will now fail on OpenBSD. In some sense knowing the BRL-CAD root
path has always been integral to BRL-CAD's design, but the conversion of GED
commands to plugins elevates not knowing the path from an obscure source of
occasional problems to immediate breakage.
Modified Paths:
--------------
brlcad/branches/RELEASE/src/libged/exec.cpp
brlcad/branches/RELEASE/src/libged/ged_init.cpp
Modified: brlcad/branches/RELEASE/src/libged/exec.cpp
===================================================================
--- brlcad/branches/RELEASE/src/libged/exec.cpp 2020-08-13 19:39:21 UTC (rev
76745)
+++ brlcad/branches/RELEASE/src/libged/exec.cpp 2020-08-14 12:11:13 UTC (rev
76746)
@@ -32,6 +32,8 @@
#include "ged.h"
#include "./include/plugin.h"
+extern "C" void libged_init(void);
+
extern "C" int
ged_exec(struct ged *gedp, int argc, const char *argv[]) {
if (!gedp || !argc || !argv) {
@@ -52,6 +54,17 @@
// libged's command set so we have a clean fallback available if we ever
// need it to fall back on/recover with.
std::map<std::string, const struct ged_cmd *> *cmap =
(std::map<std::string, const struct ged_cmd *> *)ged_cmds;
+
+ // On OpenBSD, if the executable was launched in a way that requires
+ // bu_setprogname to find the BRL-CAD root directory the iniital libged
+ // initialization would have failed. If we have no ged_cmds at all this is
+ // probably what happened, so call libged_init again here. By the time we
+ // are calling ged_exec bu_setprogname should be set and we should be ready
+ // to actually find the commands.
+ if (!cmap->size()) {
+ libged_init();
+ }
+
std::string key(argv[0]);
std::map<std::string, const struct ged_cmd *>::iterator c_it =
cmap->find(key);
if (c_it == cmap->end()) {
Modified: brlcad/branches/RELEASE/src/libged/ged_init.cpp
===================================================================
--- brlcad/branches/RELEASE/src/libged/ged_init.cpp 2020-08-13 19:39:21 UTC
(rev 76745)
+++ brlcad/branches/RELEASE/src/libged/ged_init.cpp 2020-08-14 12:11:13 UTC
(rev 76746)
@@ -48,6 +48,8 @@
static char **cmd_list = NULL;
void *ged_cmds;
+extern "C" void libged_init(void);
+
static std::set<void *> ged_handles;
struct bu_vls *ged_init_msg_str;
@@ -67,6 +69,17 @@
return 1;
}
int cmd_invalid = 1;
+
+ // On OpenBSD, if the executable was launched in a way that requires
+ // bu_setprogname to find the BRL-CAD root directory the iniital libged
+ // initialization would have failed. If we have no ged_cmds at all this is
+ // probably what happened, so call libged_init again here. By the time we
+ // are calling ged_cmd_valid bu_setprogname should be set and we should be
+ // ready to actually find the commands.
+ if (!ged_cmd_map.size()) {
+ libged_init();
+ }
+
std::string scmd(cmd);
std::map<std::string, const struct ged_cmd *>::iterator cmd_it =
ged_cmd_map.find(scmd);
if (cmd_it != ged_cmd_map.end()) {
@@ -107,7 +120,7 @@
return cmd_list_len;
}
-static void
+extern "C" void
libged_init(void)
{
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits