本文整理汇总了C++中Py_InitModule3函数的典型用法代码示例。如果您正苦于以下问题:C++ Py_InitModule3函数的具体用法?C++ Py_InitModule3怎么用?C++ Py_InitModule3使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Py_InitModule3函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: inittradesocket
PyMODINIT_FUNC inittradesocket(void)
{
Py_InitModule3("tradesocket", tradesocket_methods, tradesocket__doc__);
}
示例2: initwave2d_cfunc
PyMODINIT_FUNC initwave2d_cfunc() {
Py_InitModule3("wave2d_cfunc", wave2d_cfunc_methods, module_doc);
import_array();
}
示例3: initRadialVelocity
//initialise the module
PyMODINIT_FUNC
initRadialVelocity(void)
{
(void) Py_InitModule3("RadialVelocity", RadialVelocityMethods, "Radial vel docstring...");
import_array(); //must be present for numpy stuff
}
示例4: initguiQt
PyMODINIT_FUNC
initguiQt(void) {
PyEval_InitThreads(); /* Start the interpreter's thread-awareness */
if(PyType_Ready(&QtGuiObject_Type) < 0) {
Py_FatalError("Can't initialize QtGuiObject type");
return;
}
PyObject* m = Py_InitModule3("guiQt", module_methods, module_doc);
if(!m) {
Py_FatalError("Can't initialize guiQt module");
return;
}
bool fail = false;
if(PyModule_AddObject(m, "QtGuiObject", (PyObject*) &QtGuiObject_Type) != 0)
fail = true;
iterControlTypes([&](const std::string& controlType, ControlBuilderFunc builderFunc) {
struct PythonWrapper {
std::string controlType;
ControlBuilderFunc builderFunc;
PyObject* operator()(PyObject* args, PyObject* kw) {
PyObject* control = NULL;
if(!PyArg_ParseTuple(args, ("O:buildControl" + controlType).c_str(), &control))
return NULL;
if(!PyType_IsSubtype(Py_TYPE(control), &QtGuiObject_Type)) {
PyErr_Format(PyExc_ValueError, "guiQt.buildControl%s: we expect a QtGuiObject", controlType.c_str());
return NULL;
}
PyQtGuiObject* guiObject = (PyQtGuiObject*) control;
bool res = builderFunc(guiObject);
if(!res)
// XXX: handle somehow? ...
printf("guiQt.buildControl%s: warning, returned error\n", controlType.c_str());
Py_INCREF(control);
return control;
}
};
PythonWrapper wrapper;
wrapper.controlType = controlType;
wrapper.builderFunc = builderFunc;
PyObject* funcObj = (PyObject*) newFunctionWrapper(wrapper);
if(!funcObj) {
fail = true;
return;
}
if(PyModule_AddObject(m, ("builControl" + controlType).c_str(), funcObj) != 0)
fail = true;
});
if(fail) {
if(PyErr_Occurred())
PyErr_Print();
Py_FatalError("guiQt module init error");
}
}
示例5: init_svgview
PyMODINIT_FUNC init_svgview() {
Py_InitModule3("_svgview", _viewer_methods, "");
rsvg_init();
g_thread_init(NULL);
gdk_threads_init();
}
示例6: init_phono4py
PyMODINIT_FUNC init_phono4py(void)
{
Py_InitModule3("_phono4py", functions, "C-extension for phono4py\n\n...\n");
return;
}
示例7: initEfiCompressor
PyMODINIT_FUNC
initEfiCompressor(VOID) {
Py_InitModule3("EfiCompressor", EfiCompressor_Funcs, "EFI Compression Algorithm Extension Module");
}
示例8: initangie_c
/* Init module function */
void initangie_c(void)
{
//printf("ANGIE [optimized, c] module was initialized!\n");
Py_InitModule3("angie_c", angie_c_funcs,
"ANGIE");
}
示例9: init_laplacian
PyMODINIT_FUNC init_laplacian(void)
{
Py_InitModule3("_laplacian", _functions, "Second degree Laplacian edge detection accelerator module.");
}
示例10: init_ExtensionClass
PyMODINIT_FUNC
init_ExtensionClass(void)
{
PyObject *m, *s;
if (pickle_setup() < 0)
return;
#define DEFINE_STRING(S) \
if(! (str ## S = PyString_FromString(# S))) return
DEFINE_STRING(__of__);
DEFINE_STRING(__get__);
DEFINE_STRING(__class_init__);
DEFINE_STRING(__init__);
DEFINE_STRING(__bases__);
DEFINE_STRING(__mro__);
DEFINE_STRING(__new__);
#undef DEFINE_STRING
PyExtensionClassCAPI = &TrueExtensionClassCAPI;
ExtensionClassType.ob_type = &PyType_Type;
ExtensionClassType.tp_base = &PyType_Type;
ExtensionClassType.tp_basicsize = PyType_Type.tp_basicsize;
ExtensionClassType.tp_traverse = PyType_Type.tp_traverse;
ExtensionClassType.tp_clear = PyType_Type.tp_clear;
/* Initialize types: */
if (PyType_Ready(&ExtensionClassType) < 0)
return;
BaseType.ob_type = &ExtensionClassType;
BaseType.tp_base = &PyBaseObject_Type;
BaseType.tp_basicsize = PyBaseObject_Type.tp_basicsize;
BaseType.tp_new = PyType_GenericNew;
if (PyType_Ready(&BaseType) < 0)
return;
NoInstanceDictionaryBaseType.ob_type = &ExtensionClassType;
NoInstanceDictionaryBaseType.tp_base = &BaseType;
NoInstanceDictionaryBaseType.tp_basicsize = BaseType.tp_basicsize;
NoInstanceDictionaryBaseType.tp_new = PyType_GenericNew;
if (PyType_Ready(&NoInstanceDictionaryBaseType) < 0)
return;
/* Create the module and add the functions */
m = Py_InitModule3("_ExtensionClass", ec_methods,
_extensionclass_module_documentation);
if (m == NULL)
return;
s = PyCObject_FromVoidPtr(PyExtensionClassCAPI, NULL);
if (PyModule_AddObject(m, "CAPI2", s) < 0)
return;
/* Add types: */
if (PyModule_AddObject(m, "ExtensionClass",
(PyObject *)&ExtensionClassType) < 0)
return;
if (PyModule_AddObject(m, "Base", (PyObject *)&BaseType) < 0)
return;
if (PyModule_AddObject(m, "NoInstanceDictionaryBase",
(PyObject *)&NoInstanceDictionaryBaseType) < 0)
return;
}
示例11: initedit_distance
void initedit_distance(void) {
PyObject *m = Py_InitModule3(module_name, module_methods,
module_docstring);
if (m == NULL)
return;
}
示例12: main
int main(int argc, char *argv[]) {
std::cout << "C++: This is process: " << getpid() << std::endl;
PyObject *pName, *pModule, *pFunc; //, *pDict, ;
PyObject *pValue; // *pArgs,
// int i;
std::string module("python6");
std::string function("run_now");
// Initilize Python
Py_Initialize();
/* NameObjectType.tp_new = PyType_GenericNew;
if (PyType_Ready(&NameObjectType) < 0) {
PyErr_Print();
fprintf(stderr, "Type not ready - PyType_Ready\n");
return 1;
} */
PyTypeObject* type_object = create_type_object();
if (PyType_Ready(type_object) < 0) {
PyErr_Print();
fprintf(stderr, "Type not ready - PyType_Ready\n");
free_type_object(type_object);
return 1;
}
PyObject* m = Py_InitModule3("name", NULL, "XXX");
if (!m) {
PyErr_Print();
fprintf(stderr, "Failed to load initilize module - Py_InitModule3\n");
free_type_object(type_object);
return 1;
}
/*Py_INCREF(&NameObjectType);
PyModule_AddObject(m, "Name", (PyObject *)&NameObjectType);*/
Py_INCREF(type_object);
PyModule_AddObject(m, "Name", (PyObject*)type_object);
// Load module python2.py
pName = PyString_FromString(module.c_str()); // Error checking of pName left out
pModule = PyImport_Import(pName);
Py_DECREF(pName);
if (!pModule) {
PyErr_Print();
fprintf(stderr, "Failed to load \"%s\"\n", argv[1]);
free_type_object(type_object);
return 1;
}
// Get the python fuction to call
pFunc = PyObject_GetAttrString(pModule, function.c_str()); // pFunc is a new reference
if (!pFunc || !PyCallable_Check(pFunc)) {
if (PyErr_Occurred())
PyErr_Print();
fprintf(stderr, "Cannot find function \"%s\"\n", argv[2]);
Py_XDECREF(pFunc);
Py_DECREF(pModule);
free_type_object(type_object);
return 1;
}
// Make the call to the python function
pValue = PyObject_CallObject(pFunc, NULL);
if (!pValue) {
PyErr_Print();
fprintf(stderr,"Call failed\n");
Py_DECREF(pFunc);
Py_DECREF(pModule);
free_type_object(type_object);
return 1;
}
// Show the result of the python call
printf("Result of call: %ld\n", PyInt_AsLong(pValue));
// Decrease counters for python garbage collection
Py_DECREF(pValue);
Py_XDECREF(pFunc);
Py_DECREF(pModule);
std::cout << "Before Py_Finalize()" << std::endl;
// Clean up python
Py_Finalize();
free_type_object(type_object);
std::cout << "Freeing the allocated memory" << std::endl;
return 0;
}
示例13: initmpatch
PyMODINIT_FUNC
initmpatch(void)
{
Py_InitModule3("mpatch", methods, mpatch_doc);
mpatch_Error = PyErr_NewException("mpatch.mpatchError", NULL, NULL);
}
示例14: init_spglib
PyMODINIT_FUNC init_spglib(void)
{
Py_InitModule3("_spglib", functions, "C-extension for spglib\n\n...\n");
return;
}
示例15: initdefault_encoding_utf8
PyMODINIT_FUNC
initdefault_encoding_utf8(void)
{
PyUnicode_SetDefaultEncoding("utf-8");
Py_InitModule3("default_encoding_utf8", methods, "Forces the default encoding to utf-8");
}