aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-06-27 15:27:14 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-06-27 15:27:14 +0200
commit34cc74df52ed129bffeb7b6fcf11f05c222550ba (patch)
treec4e3a48a03cf507ee4a4219a8b3d57c4dce17a8c
parent5f924ea1926fe17acf699a43713b7f5881e9d30d (diff)
Get rid of extern "C" in module boot()/init()
We will have a separate (extern "C") register() function that will return the pointers to these two. This way we can still throw exceptions from boot() and init().
-rw-r--r--build2/b.cxx22
-rw-r--r--build2/bin/module16
-rw-r--r--build2/bin/module.cxx16
-rw-r--r--build2/cli/module16
-rw-r--r--build2/cli/module.cxx16
-rw-r--r--build2/config/module22
-rw-r--r--build2/config/module.cxx20
-rw-r--r--build2/cxx/module16
-rw-r--r--build2/cxx/module.cxx16
-rw-r--r--build2/dist/module20
-rw-r--r--build2/dist/module.cxx20
-rw-r--r--build2/install/module20
-rw-r--r--build2/install/module.cxx20
-rw-r--r--build2/module22
-rw-r--r--build2/test/module20
-rw-r--r--build2/test/module.cxx20
16 files changed, 153 insertions, 149 deletions
diff --git a/build2/b.cxx b/build2/b.cxx
index 633d583..e7c8721 100644
--- a/build2/b.cxx
+++ b/build2/b.cxx
@@ -185,18 +185,16 @@ main (int argc, char* argv[])
// Register builtin modules.
//
- builtin_modules["config"] = module_functions {&config::config_boot,
- &config::config_init};
- builtin_modules["dist"] = module_functions {&dist::dist_boot,
- &dist::dist_init};
- builtin_modules["test"] = module_functions {&test::test_boot,
- &test::test_init};
- builtin_modules["install"] = module_functions {&install::install_boot,
- &install::install_init};
-
- builtin_modules["bin"] = module_functions {nullptr, &bin::bin_init};
- builtin_modules["cxx"] = module_functions {nullptr, &cxx::cxx_init};
- builtin_modules["cli"] = module_functions {nullptr, &cli::cli_init};
+ builtin_modules["config"] = module_functions {&config::boot,
+ &config::init};
+ builtin_modules["dist"] = module_functions {&dist::boot, &dist::init};
+ builtin_modules["test"] = module_functions {&test::boot, &test::init};
+ builtin_modules["install"] = module_functions {&install::boot,
+ &install::init};
+
+ builtin_modules["bin"] = module_functions {nullptr, &bin::init};
+ builtin_modules["cxx"] = module_functions {nullptr, &cxx::init};
+ builtin_modules["cli"] = module_functions {nullptr, &cli::init};
// Figure out work and home directories.
//
diff --git a/build2/bin/module b/build2/bin/module
index 0b9d44e..e74cbe2 100644
--- a/build2/bin/module
+++ b/build2/bin/module
@@ -14,14 +14,14 @@ namespace build2
{
namespace bin
{
- extern "C" bool
- bin_init (scope&,
- scope&,
- const location&,
- unique_ptr<module_base>&,
- bool,
- bool,
- const variable_map&);
+ bool
+ init (scope&,
+ scope&,
+ const location&,
+ unique_ptr<module_base>&,
+ bool,
+ bool,
+ const variable_map&);
}
}
diff --git a/build2/bin/module.cxx b/build2/bin/module.cxx
index d5df054..70a2b98 100644
--- a/build2/bin/module.cxx
+++ b/build2/bin/module.cxx
@@ -30,14 +30,14 @@ namespace build2
static const strings liba_lib {"static"};
static const strings libso_lib {"shared"};
- extern "C" bool
- bin_init (scope& r,
- scope& b,
- const location&,
- unique_ptr<module_base>&,
- bool first,
- bool,
- const variable_map& config_hints)
+ bool
+ init (scope& r,
+ scope& b,
+ const location&,
+ unique_ptr<module_base>&,
+ bool first,
+ bool,
+ const variable_map& config_hints)
{
tracer trace ("bin::init");
l5 ([&]{trace << "for " << b.out_path ();});
diff --git a/build2/cli/module b/build2/cli/module
index f55e03c..50d07ef 100644
--- a/build2/cli/module
+++ b/build2/cli/module
@@ -14,14 +14,14 @@ namespace build2
{
namespace cli
{
- extern "C" bool
- cli_init (scope&,
- scope&,
- const location&,
- unique_ptr<module_base>&,
- bool,
- bool,
- const variable_map&);
+ bool
+ init (scope&,
+ scope&,
+ const location&,
+ unique_ptr<module_base>&,
+ bool,
+ bool,
+ const variable_map&);
}
}
diff --git a/build2/cli/module.cxx b/build2/cli/module.cxx
index 13325d9..01d606f 100644
--- a/build2/cli/module.cxx
+++ b/build2/cli/module.cxx
@@ -25,14 +25,14 @@ namespace build2
{
static compile compile_;
- extern "C" bool
- cli_init (scope& root,
- scope& base,
- const location& loc,
- unique_ptr<module_base>&,
- bool first,
- bool optional,
- const variable_map& config_hints)
+ bool
+ init (scope& root,
+ scope& base,
+ const location& loc,
+ unique_ptr<module_base>&,
+ bool first,
+ bool optional,
+ const variable_map& config_hints)
{
tracer trace ("cli::init");
l5 ([&]{trace << "for " << base.out_path ();});
diff --git a/build2/config/module b/build2/config/module
index 912ab57..adc9b05 100644
--- a/build2/config/module
+++ b/build2/config/module
@@ -28,17 +28,17 @@ namespace build2
static const string name;
};
- extern "C" void
- config_boot (scope&, const location&, unique_ptr<module_base>&);
-
- extern "C" bool
- config_init (scope&,
- scope&,
- const location&,
- unique_ptr<module_base>&,
- bool,
- bool,
- const variable_map&);
+ void
+ boot (scope&, const location&, unique_ptr<module_base>&);
+
+ bool
+ init (scope&,
+ scope&,
+ const location&,
+ unique_ptr<module_base>&,
+ bool,
+ bool,
+ const variable_map&);
}
}
diff --git a/build2/config/module.cxx b/build2/config/module.cxx
index 70301c5..4f4064f 100644
--- a/build2/config/module.cxx
+++ b/build2/config/module.cxx
@@ -27,8 +27,8 @@ namespace build2
//
static const path config_file ("build/config.build");
- extern "C" void
- config_boot (scope& root, const location&, unique_ptr<module_base>&)
+ void
+ boot (scope& root, const location&, unique_ptr<module_base>&)
{
tracer trace ("config::boot");
@@ -53,14 +53,14 @@ namespace build2
source (f, root, root);
}
- extern "C" bool
- config_init (scope& root,
- scope&,
- const location& l,
- unique_ptr<module_base>& mod,
- bool first,
- bool,
- const variable_map& config_hints)
+ bool
+ init (scope& root,
+ scope&,
+ const location& l,
+ unique_ptr<module_base>& mod,
+ bool first,
+ bool,
+ const variable_map& config_hints)
{
tracer trace ("config::init");
diff --git a/build2/cxx/module b/build2/cxx/module
index 254eb44..37466ef 100644
--- a/build2/cxx/module
+++ b/build2/cxx/module
@@ -14,14 +14,14 @@ namespace build2
{
namespace cxx
{
- extern "C" bool
- cxx_init (scope&,
- scope&,
- const location&,
- unique_ptr<module_base>&,
- bool,
- bool,
- const variable_map&);
+ bool
+ init (scope&,
+ scope&,
+ const location&,
+ unique_ptr<module_base>&,
+ bool,
+ bool,
+ const variable_map&);
}
}
diff --git a/build2/cxx/module.cxx b/build2/cxx/module.cxx
index 7e9b5e2..71304c8 100644
--- a/build2/cxx/module.cxx
+++ b/build2/cxx/module.cxx
@@ -29,14 +29,14 @@ namespace build2
{
namespace cxx
{
- extern "C" bool
- cxx_init (scope& r,
- scope& b,
- const location& loc,
- unique_ptr<module_base>&,
- bool first,
- bool,
- const variable_map& config_hints)
+ bool
+ init (scope& r,
+ scope& b,
+ const location& loc,
+ unique_ptr<module_base>&,
+ bool first,
+ bool,
+ const variable_map& config_hints)
{
tracer trace ("cxx::init");
l5 ([&]{trace << "for " << b.out_path ();});
diff --git a/build2/dist/module b/build2/dist/module
index 984a969..3c43c1f 100644
--- a/build2/dist/module
+++ b/build2/dist/module
@@ -14,17 +14,17 @@ namespace build2
{
namespace dist
{
- extern "C" void
- dist_boot (scope&, const location&, unique_ptr<module_base>&);
+ void
+ boot (scope&, const location&, unique_ptr<module_base>&);
- extern "C" bool
- dist_init (scope&,
- scope&,
- const location&,
- unique_ptr<module_base>&,
- bool,
- bool,
- const variable_map&);
+ bool
+ init (scope&,
+ scope&,
+ const location&,
+ unique_ptr<module_base>&,
+ bool,
+ bool,
+ const variable_map&);
}
}
diff --git a/build2/dist/module.cxx b/build2/dist/module.cxx
index 58bfc6f..eed9562 100644
--- a/build2/dist/module.cxx
+++ b/build2/dist/module.cxx
@@ -22,8 +22,8 @@ namespace build2
{
static rule rule_;
- extern "C" void
- dist_boot (scope& r, const location&, unique_ptr<module_base>&)
+ void
+ boot (scope& r, const location&, unique_ptr<module_base>&)
{
tracer trace ("dist::boot");
@@ -54,14 +54,14 @@ namespace build2
}
}
- extern "C" bool
- dist_init (scope& r,
- scope&,
- const location& l,
- unique_ptr<module_base>&,
- bool first,
- bool,
- const variable_map& config_hints)
+ bool
+ init (scope& r,
+ scope&,
+ const location& l,
+ unique_ptr<module_base>&,
+ bool first,
+ bool,
+ const variable_map& config_hints)
{
tracer trace ("dist::init");
diff --git a/build2/install/module b/build2/install/module
index b2a3301..3f59fee 100644
--- a/build2/install/module
+++ b/build2/install/module
@@ -14,17 +14,17 @@ namespace build2
{
namespace install
{
- extern "C" void
- install_boot (scope&, const location&, unique_ptr<module_base>&);
+ void
+ boot (scope&, const location&, unique_ptr<module_base>&);
- extern "C" bool
- install_init (scope&,
- scope&,
- const location&,
- unique_ptr<module_base>&,
- bool,
- bool,
- const variable_map&);
+ bool
+ init (scope&,
+ scope&,
+ const location&,
+ unique_ptr<module_base>&,
+ bool,
+ bool,
+ const variable_map&);
}
}
diff --git a/build2/install/module.cxx b/build2/install/module.cxx
index 6a7e500..5a18899 100644
--- a/build2/install/module.cxx
+++ b/build2/install/module.cxx
@@ -100,8 +100,8 @@ namespace build2
static alias_rule alias_;
static file_rule file_;
- extern "C" void
- install_boot (scope& r, const location&, unique_ptr<module_base>&)
+ void
+ boot (scope& r, const location&, unique_ptr<module_base>&)
{
tracer trace ("install::boot");
@@ -112,14 +112,14 @@ namespace build2
r.operations.insert (install_id, install);
}
- extern "C" bool
- install_init (scope& r,
- scope& b,
- const location& l,
- unique_ptr<module_base>&,
- bool first,
- bool,
- const variable_map& config_hints)
+ bool
+ init (scope& r,
+ scope& b,
+ const location& l,
+ unique_ptr<module_base>&,
+ bool first,
+ bool,
+ const variable_map& config_hints)
{
tracer trace ("install::init");
diff --git a/build2/module b/build2/module
index 314f5a6..c19f31d 100644
--- a/build2/module
+++ b/build2/module
@@ -25,7 +25,6 @@ namespace build2
~module_base () = default;
};
- extern "C"
using module_boot_function =
void (scope& root, const location&, unique_ptr<module_base>&);
@@ -35,7 +34,6 @@ namespace build2
// unconfigured for as long as it is actually not used (e.g., install,
// dist). The return value is used to set the <module>.configured variable.
//
- extern "C"
using module_init_function =
bool (scope& root,
scope& base,
@@ -45,7 +43,21 @@ namespace build2
bool optional, // Loaded with using? (optional module).
const variable_map& hints); // Configuration hints (see below).
+ struct module_functions
+ {
+ module_boot_function* boot;
+ module_init_function* init;
+ };
+ // The register() function will be written in C++ and will be called from
+ // C++ but we need to suppress name mangling to be able to use dlsym() and
+ // equivalent.
+ //
+ extern "C"
+ using module_register_function = module_functions ();
+
+ // Loaded modules state.
+ //
struct module_state
{
bool boot; // True if the module boot'ed but not yet init'ed.
@@ -93,12 +105,6 @@ namespace build2
// Builtin modules.
//
- struct module_functions
- {
- module_boot_function* boot;
- module_init_function* init;
- };
-
using available_module_map = std::map<string, module_functions>;
extern available_module_map builtin_modules;
}
diff --git a/build2/test/module b/build2/test/module
index b9c3ea5..dacb364 100644
--- a/build2/test/module
+++ b/build2/test/module
@@ -14,17 +14,17 @@ namespace build2
{
namespace test
{
- extern "C" void
- test_boot (scope&, const location&, unique_ptr<module_base>&);
+ void
+ boot (scope&, const location&, unique_ptr<module_base>&);
- extern "C" bool
- test_init (scope&,
- scope&,
- const location&,
- unique_ptr<module_base>&,
- bool,
- bool,
- const variable_map&);
+ bool
+ init (scope&,
+ scope&,
+ const location&,
+ unique_ptr<module_base>&,
+ bool,
+ bool,
+ const variable_map&);
}
}
diff --git a/build2/test/module.cxx b/build2/test/module.cxx
index c20e274..3b5cf7b 100644
--- a/build2/test/module.cxx
+++ b/build2/test/module.cxx
@@ -21,8 +21,8 @@ namespace build2
{
static rule rule_;
- extern "C" void
- test_boot (scope& root, const location&, unique_ptr<module_base>&)
+ void
+ boot (scope& root, const location&, unique_ptr<module_base>&)
{
tracer trace ("test::boot");
@@ -49,14 +49,14 @@ namespace build2
}
}
- extern "C" bool
- test_init (scope& root,
- scope&,
- const location& l,
- unique_ptr<module_base>&,
- bool first,
- bool,
- const variable_map& config_hints)
+ bool
+ init (scope& root,
+ scope&,
+ const location& l,
+ unique_ptr<module_base>&,
+ bool first,
+ bool,
+ const variable_map& config_hints)
{
tracer trace ("test::init");