Begin working with modules

This commit is contained in:
2023-10-29 00:54:09 +02:00
parent 6ab8de5125
commit 6baa3de9a6

View File

@@ -9,6 +9,65 @@ namespace pywrap {
if (PyStatus_Exception(status)) {
throw std::runtime_error("Error initializing Python");
}
PyObject* module = PyImport_ImportModule("stree.Stree");
if (module != nullptr) {
// // dict is a borrowed reference.
// auto pdict = PyModule_GetDict(module);
// if (pdict == nullptr) {
// cout << "Fails to get the dictionary.\n";
// return;
// }
// //Py_DECREF(module);
// PyObject* pKeys = PyDict_Keys(pdict);
// PyObject* pValues = PyDict_Values(pdict);
// map<string, string> my_map;
// //cout << "size: " << PyDict_Size(pdict)<<endl;
// char* cstr_key = new char[100];
// char* cstr_value = new char[500];
// for (Py_ssize_t i = 0; i < PyDict_Size(pdict); ++i) {
// PyArg_Parse(PyList_GetItem(pKeys, i), "s", &cstr_key);
// PyArg_Parse(PyList_GetItem(pValues, i), "s", &cstr_value);
// //cout << cstr<< " "<< cstr2 <<endl;
// my_map.emplace(cstr_key, cstr_value);
// }
// for (auto x : my_map) {
// cout << x.first << " : " << x.second << endl;
// }
// system("pause");
// // Builds the name of a callable class
// auto python_class = PyDict_GetItemString(pdict, "MyClass1");
// system("pause");
// if (python_class == nullptr) {
// cout << "Fails to get the Python class.\n";
// return;
// }
// //Py_DECREF(pdict);
// cout << python_class;
// PyObject* object;
// // Creates an instance of the class
// if (PyCallable_Check(python_class)) {
// object = PyObject_CallObject(python_class, NULL);
// Py_DECREF(python_class);
// } else {
// std::cout << "Cannot instantiate the Python class" << endl;
// Py_DECREF(python_class);
// return;
// }
// auto val = PyObject_CallMethod(object, "is_jit_model_available", NULL);
// if (!val)
// cout << "error!";
// cout << val;
}
Py_RunMain();
}