Skip to content

Commit 03418d6

Browse files
committed
Changes to enable independence from interrogatedb runtime lib
interrogate_request_database is a rather obscure mechanism, which is (probably) currently already broken; let's handle this via Dtool_PyModuleInitHelper instead in the future
1 parent 15bd969 commit 03418d6

File tree

5 files changed

+46
-13
lines changed

5 files changed

+46
-13
lines changed

src/interrogate/interfaceMakerPythonNative.cxx

+27-3
Original file line numberDiff line numberDiff line change
@@ -1760,14 +1760,38 @@ write_module_support(ostream &out, ostream *out_h, InterrogateModuleDef *def) {
17601760

17611761
out << " {nullptr, nullptr, 0, nullptr}\n" << "};\n\n";
17621762

1763+
if (!no_database) {
1764+
out << "static const InterrogateModuleDef _in_module_def = {\n"
1765+
<< " " << def->file_identifier << ", /* file_identifier */\n"
1766+
<< " \"" << def->library_name << "\", /* library_name */\n"
1767+
<< " \"" << def->library_hash_name << "\", /* library_hash_name */\n"
1768+
<< " \"" << def->module_name << "\", /* module_name */\n";
1769+
if (def->database_filename != nullptr) {
1770+
out << " \"" << def->database_filename
1771+
<< "\", /* database_filename */\n";
1772+
} else {
1773+
out << " (const char *)0, /* database_filename */\n";
1774+
}
1775+
1776+
out << " nullptr, /* unique_names */\n"
1777+
<< " 0, /* num_unique_names */\n";
1778+
out << " nullptr, /* fptrs */\n"
1779+
<< " 0, /* num_fptrs */\n";
1780+
out << " 1, /* first_index */\n"
1781+
<< " " << InterrogateDatabase::get_ptr()->get_next_index()
1782+
<< " /* next_index */\n"
1783+
<< "};\n\n";
1784+
}
1785+
1786+
const char *def_ptr = no_database ? "nullptr" : "&_in_module_def";
17631787
if (_external_imports.empty()) {
1764-
out << "extern const struct LibraryDef " << def->library_name << "_moddef = {python_simple_funcs, exports, nullptr};\n";
1788+
out << "extern const struct LibraryDef " << def->library_name << "_moddef = {python_simple_funcs, exports, nullptr, " << def_ptr << "};\n";
17651789
} else {
17661790
out <<
17671791
"#ifdef LINK_ALL_STATIC\n"
1768-
"extern const struct LibraryDef " << def->library_name << "_moddef = {python_simple_funcs, exports, nullptr};\n"
1792+
"extern const struct LibraryDef " << def->library_name << "_moddef = {python_simple_funcs, exports, nullptr, " << def_ptr << "};\n"
17691793
"#else\n"
1770-
"extern const struct LibraryDef " << def->library_name << "_moddef = {python_simple_funcs, exports, imports};\n"
1794+
"extern const struct LibraryDef " << def->library_name << "_moddef = {python_simple_funcs, exports, imports, " << def_ptr << "};\n"
17711795
"#endif\n";
17721796
}
17731797
if (out_h != nullptr) {

src/interrogate/interrogateBuilder.cxx

+2
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ write_code(ostream &out_code,ostream * out_include, InterrogateModuleDef *def) {
508508
out_code << "};\n\n";
509509
}
510510

511+
#if 0
511512
if (!no_database) {
512513
// Now build the module definition structure to add ourselves to the
513514
// global interrogate database.
@@ -551,6 +552,7 @@ write_code(ostream &out_code,ostream * out_include, InterrogateModuleDef *def) {
551552
<< " interrogate_request_module(&_in_module_def);\n"
552553
<< "}\n\n";
553554
}
555+
#endif
554556
}
555557

556558
/**

src/interrogate/interrogate_module.cxx

+11-5
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,7 @@ static bool print_dependent_types(const string &lib1, const string &lib2) {
158158
}
159159

160160
int write_python_table_native(std::ostream &out) {
161-
out << "\n#include \"dtoolbase.h\"\n"
162-
<< "#include \"interrogate_request.h\"\n\n"
163-
<< "#include \"py_panda.h\"\n\n";
161+
out << "#include \"py_panda.h\"\n\n";
164162

165163
int count = 0;
166164

@@ -298,10 +296,18 @@ int write_python_table_native(std::ostream &out) {
298296

299297
out.put('\n');
300298

299+
out << "#if defined(_WIN32) && !defined(CPPPARSER) && !defined(LINK_ALL_STATIC)\n"
300+
<< "#define EXPORT_INIT_FUNC __declspec(dllexport)\n"
301+
<< "#elif __GNUC__ >= 4 && !defined(CPPPARSER) && !defined(LINK_ALL_STATIC)\n"
302+
<< "#define EXPORT_INIT_FUNC __attribute__((visibility(\"default\")))\n"
303+
<< "#else\n"
304+
<< "#define EXPORT_INIT_FUNC\n"
305+
<< "#endif\n\n";
306+
301307
out << "#if PY_MAJOR_VERSION >= 3\n"
302-
<< "extern \"C\" EXPORT_CLASS PyObject *PyInit_" << library_name << "();\n"
308+
<< "extern \"C\" EXPORT_INIT_FUNC PyObject *PyInit_" << library_name << "();\n"
303309
<< "#else\n"
304-
<< "extern \"C\" EXPORT_CLASS void init" << library_name << "();\n"
310+
<< "extern \"C\" EXPORT_INIT_FUNC void init" << library_name << "();\n"
305311
<< "#endif\n";
306312

307313
out << "\n"

src/interrogatedb/py_panda.cxx

+4-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66

77
#include "py_panda.h"
8-
#include "config_interrogatedb.h"
98
#include "executionEnvironment.h"
109

1110
#ifdef HAVE_PYTHON
@@ -701,17 +700,17 @@ PyObject *Dtool_PyModuleInitHelper(const LibraryDef *defs[], const char *modulen
701700
// to do that. Perhaps we'll find a better place for this in the future.
702701
static bool initialized_main_dir = false;
703702
if (!initialized_main_dir) {
704-
if (interrogatedb_cat.is_debug()) {
703+
/*if (interrogatedb_cat.is_debug()) {
705704
// Good opportunity to print this out once, at startup.
706705
interrogatedb_cat.debug()
707706
<< "Python " << version << "\n";
708-
}
707+
}*/
709708

710709
if (!ExecutionEnvironment::has_environment_variable("MAIN_DIR")) {
711710
// Grab the __main__ module.
712711
PyObject *main_module = PyImport_ImportModule("__main__");
713712
if (main_module == NULL) {
714-
interrogatedb_cat.warning() << "Unable to import __main__\n";
713+
std::cerr << "Warning: unable to import __main__\n";
715714
}
716715

717716
// Extract the __file__ attribute, if present.
@@ -743,7 +742,7 @@ PyObject *Dtool_PyModuleInitHelper(const LibraryDef *defs[], const char *modulen
743742
}
744743
#endif
745744
else {
746-
interrogatedb_cat.warning() << "Invalid string for __main__.__file__\n";
745+
std::cerr << "Invalid string for __main__.__file__\n";
747746
}
748747
}
749748
ExecutionEnvironment::shadow_environment_variable("MAIN_DIR", main_dir.to_os_specific());

src/interrogatedb/py_panda.h

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "pnotify.h"
1313
#include "vector_uchar.h"
1414
#include "register_type.h"
15+
#include "interrogate_request.h"
1516

1617
#if defined(HAVE_PYTHON) && !defined(CPPPARSER)
1718

@@ -338,6 +339,7 @@ struct LibraryDef {
338339
PyMethodDef *const _methods;
339340
const Dtool_TypeDef *const _types;
340341
Dtool_TypeDef *const _external_types;
342+
const InterrogateModuleDef *const _module_def;
341343
};
342344

343345
#if PY_MAJOR_VERSION >= 3

0 commit comments

Comments
 (0)