MCPcopy Create free account
hub / github.com/ceph/ceph / construct_with_capsule

Function construct_with_capsule

src/mgr/ActivePyModules.cc:1337–1380  ·  view source on GitHub ↗

* Helper for our wrapped types that take a capsule in their constructor. */

Source from the content-addressed store, hash-verified

1335 * Helper for our wrapped types that take a capsule in their constructor.
1336 */
1337PyObject *construct_with_capsule(
1338 const std::string &module_name,
1339 const std::string &clsname,
1340 void *wrapped)
1341{
1342 // Look up the OSDMap type which we will construct
1343 PyObject *module = PyImport_ImportModule(module_name.c_str());
1344 if (!module) {
1345 derr << "Failed to import python module:" << dendl;
1346 derr << handle_pyerror(true, module_name,
1347 "construct_with_capsule "s + module_name + " " + clsname) << dendl;
1348 }
1349 ceph_assert(module);
1350
1351 PyObject *wrapper_type = PyObject_GetAttrString(
1352 module, (const char*)clsname.c_str());
1353 if (!wrapper_type) {
1354 derr << "Failed to get python type:" << dendl;
1355 derr << handle_pyerror(true, module_name,
1356 "construct_with_capsule "s + module_name + " " + clsname) << dendl;
1357 }
1358 ceph_assert(wrapper_type);
1359
1360 // Construct a capsule containing an OSDMap.
1361 auto wrapped_capsule = PyCapsule_New(wrapped, nullptr, nullptr);
1362 ceph_assert(wrapped_capsule);
1363
1364 // Construct the python OSDMap
1365 auto pArgs = PyTuple_Pack(1, wrapped_capsule);
1366 auto wrapper_instance = PyObject_CallObject(wrapper_type, pArgs);
1367 if (wrapper_instance == nullptr) {
1368 derr << "Failed to construct python OSDMap:" << dendl;
1369 derr << handle_pyerror(true, module_name,
1370 "construct_with_capsule "s + module_name + " " + clsname) << dendl;
1371 }
1372 ceph_assert(wrapper_instance != nullptr);
1373 Py_DECREF(pArgs);
1374 Py_DECREF(wrapped_capsule);
1375
1376 Py_DECREF(wrapper_type);
1377 Py_DECREF(module);
1378
1379 return wrapper_instance;
1380}
1381
1382PyObject *ActivePyModules::get_osdmap()
1383{

Callers 5

get_osdmapMethod · 0.85
osdmap_new_incrementalFunction · 0.85
osdmap_apply_incrementalFunction · 0.85
osdmap_get_crushFunction · 0.85
osdmap_build_simpleFunction · 0.85

Calls 2

handle_pyerrorFunction · 0.85
c_strMethod · 0.45

Tested by

no test coverage detected