本文整理汇总了C++中PyCObject_FromVoidPtr函数的典型用法代码示例。如果您正苦于以下问题:C++ PyCObject_FromVoidPtr函数的具体用法?C++ PyCObject_FromVoidPtr怎么用?C++ PyCObject_FromVoidPtr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PyCObject_FromVoidPtr函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: python_function_get_gnumeric_help
static GnmFuncHelp const *
python_function_get_gnumeric_help (PyObject *python_fn_info_dict, PyObject *python_fn,
const gchar *fn_name)
{
gchar *help_attr_name;
PyObject *cobject_help_value;
help_attr_name = g_strdup_printf ("_CGnumericHelp_%s", fn_name);
cobject_help_value = PyDict_GetItemString (python_fn_info_dict, help_attr_name);
if (cobject_help_value == NULL) {
PyObject *python_fn_help = ((PyFunctionObject *) python_fn)->func_doc;
if (python_fn_help != NULL && PyString_Check (python_fn_help)) {
GnmFuncHelp *new_help = g_new (GnmFuncHelp, 2);
int i = 0;
#if 0
new_help[i].type = GNM_FUNC_HELP_OLD;
new_help[i].text = PyString_AsString (python_fn_help);
i++;
#endif
new_help[i].type = GNM_FUNC_HELP_END;
new_help[i].text = NULL;
i++;
cobject_help_value = PyCObject_FromVoidPtr (new_help, &g_free);
PyDict_SetItemString (python_fn_info_dict, help_attr_name, cobject_help_value);
}
}
g_free (help_attr_name);
if (cobject_help_value == NULL)
return NULL;
return (GnmFuncHelp const *) PyCObject_AsVoidPtr (cobject_help_value);
}
开发者ID:bhaggerty,项目名称:gnumeric,代码行数:36,代码来源:python-loader.c
示例2: PyCObject_FromVoidPtr
PyObject *xmlsec_TransformExclC14NWithCommentsId(PyObject *self, PyObject *args) {
return PyCObject_FromVoidPtr((void *) xmlSecTransformExclC14NWithCommentsId, NULL);
}
开发者ID:badbole,项目名称:sh,代码行数:3,代码来源:transforms.c
示例3: PyDict_New
//.........这里部分代码省略.........
else if (td == sipType_QVector4D)
{
QVector4D *v = reinterpret_cast<QVector4D *>(cpp);
*ap++ = v->x();
*ap++ = v->y();
*ap++ = v->z();
*ap++ = v->w();
}
}
else
{
itm = PySequence_Fast(itm,
"attribute array elements should all be sequences");
if (itm)
{
if (PySequence_Fast_GET_SIZE(itm) != nr_dim)
{
PyErr_Format(PyExc_TypeError,
"attribute array elements should all be sequences "
#if PY_VERSION_HEX >= 0x02050000
"of length %zd",
#else
"of length %d",
#endif
nr_dim);
Py_DECREF(itm);
iserr = 1;
}
else
{
PyErr_Clear();
for (SIP_SSIZE_T j = 0; j < nr_dim; ++j)
*ap++ = PyFloat_AsDouble(
PySequence_Fast_GET_ITEM(itm, j));
if (PyErr_Occurred())
{
PyErr_SetString(PyExc_TypeError,
"attribute array elements should all be "
"sequences of floats");
Py_DECREF(itm);
iserr = 1;
}
}
}
else
{
iserr = 1;
}
}
if (iserr)
{
Py_DECREF(key);
Py_DECREF(values);
delete[] array;
*estate = sipErrorFail;
return 0;
}
}
Py_DECREF(values);
*tsize = nr_dim;
// Wrap the array in a Python object so that it won't leak.
#if defined(SIP_USE_PYCAPSULE)
PyObject *array_obj = PyCapsule_New(array, 0, array_dtor);
#else
PyObject *array_obj = PyCObject_FromVoidPtr(array, array_dtor);
#endif
if (!array_obj)
{
Py_DECREF(key);
delete[] array;
*estate = sipErrorFail;
return 0;
}
int rc = PyDict_SetItem(dict, key, array_obj);
Py_DECREF(key);
Py_DECREF(array_obj);
if (rc < 0)
{
*estate = sipErrorFail;
return 0;
}
return array;
}
开发者ID:LeonBondeLarsen,项目名称:RSDgroup6-code,代码行数:101,代码来源:qpyopengl_attribute_array.cpp
示例4: PyCObject_FromVoidPtr
/*
* Implement ascobject() for the type.
*/
static PyObject *sipVoidPtr_ascobject(sipVoidPtrObject *v, PyObject *arg)
{
return PyCObject_FromVoidPtr(v->voidptr, NULL);
}
开发者ID:Werkov,项目名称:SIP,代码行数:7,代码来源:voidptr.c
示例5: 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;
}
开发者ID:c0ns0le,项目名称:zenoss-4,代码行数:69,代码来源:_ExtensionClass.c
示例6: module_init
static PyObject*
module_init(void)
{
PyObject *module, *ts_module, *capi;
PyObject *copy_reg;
if (init_strings() < 0)
return NULL;
#ifdef PY3K
module = PyModule_Create(&moduledef);
#else
module = Py_InitModule3("cPersistence", cPersistence_methods,
cPersistence_doc_string);
#endif
#ifdef PY3K
((PyObject*)&Pertype)->ob_type = &PyType_Type;
#else
Pertype.ob_type = &PyType_Type;
#endif
Pertype.tp_new = PyType_GenericNew;
if (PyType_Ready(&Pertype) < 0)
return NULL;
if (PyModule_AddObject(module, "Persistent", (PyObject *)&Pertype) < 0)
return NULL;
cPersistenceCAPI = &truecPersistenceCAPI;
#ifdef PY3K
capi = PyCapsule_New(cPersistenceCAPI, CAPI_CAPSULE_NAME, NULL);
#else
capi = PyCObject_FromVoidPtr(cPersistenceCAPI, NULL);
#endif
if (!capi)
return NULL;
if (PyModule_AddObject(module, "CAPI", capi) < 0)
return NULL;
if (PyModule_AddIntConstant(module, "GHOST", cPersistent_GHOST_STATE) < 0)
return NULL;
if (PyModule_AddIntConstant(module, "UPTODATE",
cPersistent_UPTODATE_STATE) < 0)
return NULL;
if (PyModule_AddIntConstant(module, "CHANGED",
cPersistent_CHANGED_STATE) < 0)
return NULL;
if (PyModule_AddIntConstant(module, "STICKY",
cPersistent_STICKY_STATE) < 0)
return NULL;
py_simple_new = PyObject_GetAttrString(module, "simple_new");
if (!py_simple_new)
return NULL;
#ifdef PY3K
copy_reg = PyImport_ImportModule("copyreg");
#else
copy_reg = PyImport_ImportModule("copy_reg");
#endif
if (!copy_reg)
return NULL;
copy_reg_slotnames = PyObject_GetAttrString(copy_reg, "_slotnames");
if (!copy_reg_slotnames)
{
Py_DECREF(copy_reg);
return NULL;
}
__newobj__ = PyObject_GetAttrString(copy_reg, "__newobj__");
if (!__newobj__)
{
Py_DECREF(copy_reg);
return NULL;
}
if (!TimeStamp)
{
ts_module = PyImport_ImportModule("persistent.timestamp");
if (!ts_module)
return NULL;
TimeStamp = PyObject_GetAttrString(ts_module, "TimeStamp");
Py_DECREF(ts_module);
/* fall through to immediate return on error */
}
return module;
}
开发者ID:zopefoundation,项目名称:persistent,代码行数:90,代码来源:cPersistence.c
示例7: PyPCAP_fill_buffer
static PyObject *PyPCAP_next(PyPCAP *self) {
PyObject *result;
int len;
int packet_offset;
// Make sure our buffer is full enough:
if(self->buffer->size - self->buffer->readptr < MAX_PACKET_SIZE) {
len = PyPCAP_fill_buffer(self, self->fd);
if(len<0) return NULL;
};
packet_offset = self->buffer->readptr;
/** This is an interesting side effect of the talloc reference model:
talloc_reference(context, ptr) adds a new context to ptr so ptr is
now effectively parented by two parents. The two parents are not
equal however because a talloc free(ptr) will remove the reference
first and then the original parent.
This causes problems here because we create the packet_header with
self->buffer as a context. However other code takes references to it
- pinning it to other parents. If we did a
talloc_free(self->packet_header) here we would be removing those
references _instead_ of freeing the ptr from our own self->buffer
reference. This will cause both memory leaks (because we will not be
freeing packet_header at all, and later crashes because important
references will be removed.
When references begin to be used extensively I think we need to
start using talloc_unlink instead of talloc_free everywhere.
*/
// Free old packets:
if(self->packet_header)
talloc_unlink(self->buffer, self->packet_header);
// Make a new packet:
self->packet_header = (PcapPacketHeader)CONSTRUCT(PcapPacketHeader, Packet,
super.Con, self->buffer, NULL);
if(self->file_header->little_endian) {
self->packet_header->super.format = self->packet_header->le_format;
};
// Read the packet in:
len = self->packet_header->super.Read((Packet)self->packet_header, self->buffer);
// Did we finish?
if(len<=0) {
return PyErr_Format(PyExc_StopIteration, "Done");
};
// Make sure the new packet knows its offset and where it came from:
self->packet_header->header.offset = self->pcap_offset;
self->packet_header->header.pcap_file_id = self->pcap_file_id;
// Keep track of our own file offset:
self->pcap_offset += self->buffer->readptr - packet_offset;
// CALL(self->buffer, skip, self->buffer->readptr);
// Adjust the output endianess if needed
switch(self->output_format) {
case FORCE_BIG_ENDIAN:
// FIXME - Leaks!!!
self->packet_header->super.format = PCAP_PKTHEADER_STRUCT;
break;
case FORCE_LITTLE_ENDIAN:
self->packet_header->super.format = PCAP_PKTHEADER_STRUCT_LE;
break;
default:
// Do nothing
break;
};
// create a new pypacket object:
result = PyObject_CallMethod(g_pypacket_module, "PyPacket", "N",
PyCObject_FromVoidPtr(self->packet_header,NULL), "PcapPacketHeader");
return result;
};
开发者ID:backupManager,项目名称:pyflag,代码行数:83,代码来源:pypcap.c
示例8: Mesh_Python_New
PyObject* Mesh_Python_New( PyObject* self, PyObject* args ) {
return PyCObject_FromVoidPtr( Mesh_New(), 0 );
}
开发者ID:kelchuan,项目名称:snac_thesis,代码行数:3,代码来源:bindings.c
示例9: PyCObject_FromVoidPtr
PyObject *Node_instance(PyObject *i_s, PyObject *i_oArgs)
{
bind_node *l_oFils = bind_node::instance();
return PyCObject_FromVoidPtr(l_oFils, NULL);
}
开发者ID:alessandrostone,项目名称:semantik,代码行数:5,代码来源:sembind_py.cpp
示例10: python_process_event
static void python_process_event(int cpu, void *data,
int size __unused,
unsigned long long nsecs, char *comm)
{
PyObject *handler, *retval, *context, *t, *obj, *dict = NULL;
static char handler_name[256];
struct format_field *field;
unsigned long long val;
unsigned long s, ns;
struct event *event;
unsigned n = 0;
int type;
int pid;
t = PyTuple_New(MAX_FIELDS);
if (!t)
Py_FatalError("couldn't create Python tuple");
type = trace_parse_common_type(data);
event = find_cache_event(type);
if (!event)
die("ug! no event found for type %d", type);
pid = trace_parse_common_pid(data);
sprintf(handler_name, "%s__%s", event->system, event->name);
handler = PyDict_GetItemString(main_dict, handler_name);
if (handler && !PyCallable_Check(handler))
handler = NULL;
if (!handler) {
dict = PyDict_New();
if (!dict)
Py_FatalError("couldn't create Python dict");
}
s = nsecs / NSECS_PER_SEC;
ns = nsecs - s * NSECS_PER_SEC;
scripting_context->event_data = data;
context = PyCObject_FromVoidPtr(scripting_context, NULL);
PyTuple_SetItem(t, n++, PyString_FromString(handler_name));
PyTuple_SetItem(t, n++,
PyCObject_FromVoidPtr(scripting_context, NULL));
if (handler) {
PyTuple_SetItem(t, n++, PyInt_FromLong(cpu));
PyTuple_SetItem(t, n++, PyInt_FromLong(s));
PyTuple_SetItem(t, n++, PyInt_FromLong(ns));
PyTuple_SetItem(t, n++, PyInt_FromLong(pid));
PyTuple_SetItem(t, n++, PyString_FromString(comm));
} else {
PyDict_SetItemString(dict, "common_cpu", PyInt_FromLong(cpu));
PyDict_SetItemString(dict, "common_s", PyInt_FromLong(s));
PyDict_SetItemString(dict, "common_ns", PyInt_FromLong(ns));
PyDict_SetItemString(dict, "common_pid", PyInt_FromLong(pid));
PyDict_SetItemString(dict, "common_comm", PyString_FromString(comm));
}
for (field = event->format.fields; field; field = field->next) {
if (field->flags & FIELD_IS_STRING) {
int offset;
if (field->flags & FIELD_IS_DYNAMIC) {
offset = *(int *)(data + field->offset);
offset &= 0xffff;
} else
offset = field->offset;
obj = PyString_FromString((char *)data + offset);
} else { /* FIELD_IS_NUMERIC */
val = read_size(data + field->offset, field->size);
if (field->flags & FIELD_IS_SIGNED) {
if ((long long)val >= LONG_MIN &&
(long long)val <= LONG_MAX)
obj = PyInt_FromLong(val);
else
obj = PyLong_FromLongLong(val);
} else {
if (val <= LONG_MAX)
obj = PyInt_FromLong(val);
else
obj = PyLong_FromUnsignedLongLong(val);
}
}
if (handler)
PyTuple_SetItem(t, n++, obj);
else
PyDict_SetItemString(dict, field->name, obj);
}
if (!handler)
PyTuple_SetItem(t, n++, dict);
if (_PyTuple_Resize(&t, n) == -1)
Py_FatalError("error resizing Python tuple");
if (handler) {
retval = PyObject_CallObject(handler, t);
if (retval == NULL)
handler_call_die(handler_name);
//.........这里部分代码省略.........
开发者ID:12rafael,项目名称:jellytimekernel,代码行数:101,代码来源:trace-event-python.c
示例11: image_get_c_methods
static PyObject* image_get_c_methods( PyObject* self )
{
return PyCObject_FromVoidPtr( (void*)&c_methods, NULL );
}
开发者ID:gcross,项目名称:QC-Talks,代码行数:4,代码来源:diaimage.c
示例12: _class_add_global_event_listener
/**
* Interface for AtkUtilClass->add_global_event_listener.
*/
static guint
_class_add_global_event_listener (GSignalEmissionHook listener,
const gchar *event_type)
{
PyObject *dict = NULL;
PyObject *cb = NULL;
PyObject *key = NULL;
gchar **split = g_strsplit (event_type, ":", 3);
debug ("_class_add_global_event_listener\n");
if (!split)
return 0;
if (!_global_listeners)
{
_global_listeners = PyDict_New ();
if (!_global_listeners)
return 0;
}
if (!_global_signals)
{
_global_signals = PyDict_New ();
if (!_global_signals)
return 0;
}
#ifdef DEBUG
printf ("DEBUG: Installing handler for %s\n", event_type);
#endif
/* Create the event mappings, which are used by the AtkObject system
* and have to be implemented manually by the user.
*/
if (strcmp ("window", split[0]) == 0)
{
g_strfreev (split); /* Free string. */
/* Lookup matching dict. */
dict = PyDict_GetItemString (_global_listeners, event_type);
if (!dict)
{
dict = _add_listener_dict (event_type);
if (!dict)
return 0;
}
/* Add listener. */
cb = PyCObject_FromVoidPtr (listener, NULL);
key = PyInt_FromLong ((long) _global_listener_ids + 1);
if (PyDict_SetItem (dict, key, cb) == -1)
{
Py_DECREF (cb);
Py_DECREF (key);
return 0;
}
Py_DECREF (cb);
Py_DECREF (key);
}
else
{
/* Lookup matching dict. */
gchar *str = g_strconcat (split[1], ":", split[2], NULL);
g_strfreev (split);
dict = PyDict_GetItemString (_global_listeners, str);
if (!dict)
{
dict = _add_listener_dict (str);
if (!dict)
{
g_free (str);
return 0;
}
}
g_free (str);
/* Add listener. */
cb = PyCObject_FromVoidPtr (listener, NULL);
key = PyInt_FromLong ((long) _global_listener_ids + 1);
if (PyDict_SetItem (dict, key, cb) == -1)
{
Py_DECREF (cb);
Py_DECREF (key);
return 0;
}
Py_DECREF (cb);
Py_DECREF (key);
}
/* Increase id count upon successful addition. */
_global_listener_ids++;
return _global_listener_ids;
}
开发者ID:prim,项目名称:ocempgui,代码行数:97,代码来源:papi_atkutil.c
示例13: create_module
static PyObject* create_module (void) {
# if PY_VERSION_HEX >= 0x03000000
PyObject* module = PyModule_Create(&module_definition);
auto module_ = make_xsafe(module);
const char* ret = "O";
# else
PyObject* module = Py_InitModule3(BOB_EXT_MODULE_NAME, module_methods, module_docstr);
const char* ret = "N";
# endif
if (!module) return 0;
if (PyModule_AddStringConstant(module, "__version__", BOB_EXT_MODULE_VERSION) < 0) return 0;
if (!init_BobIpBaseGeomNorm(module)) return 0;
if (!init_BobIpBaseFaceEyesNorm(module)) return 0;
if (!init_BobIpBaseLBP(module)) return 0;
if (!init_BobIpBaseLBPTop(module)) return 0;
if (!init_BobIpBaseDCTFeatures(module)) return 0;
if (!init_BobIpBaseTanTriggs(module)) return 0;
if (!init_BobIpBaseGaussian(module)) return 0;
if (!init_BobIpBaseMultiscaleRetinex(module)) return 0;
if (!init_BobIpBaseWeightedGaussian(module)) return 0;
if (!init_BobIpBaseSelfQuotientImage(module)) return 0;
if (!init_BobIpBaseGaussianScaleSpace(module)) return 0;
if (!init_BobIpBaseSIFT(module)) return 0;
if (!init_BobIpBaseHOG(module)) return 0;
if (!init_BobIpBaseGLCM(module)) return 0;
if (!init_BobIpBaseWiener(module)) return 0;
#if HAVE_VLFEAT
if (!init_BobIpBaseVLFEAT(module)) return 0;
#endif // HAVE_VLFEAT
static void* PyBobIpBase_API[PyBobIpBase_API_pointers];
/* exhaustive list of C APIs */
/**************
* Versioning *
**************/
PyBobIpBase_API[PyBobIpBase_APIVersion_NUM] = (void *)&PyBobIpBase_APIVersion;
/********************************
* Bindings for bob.ip.base.LBP *
********************************/
PyBobIpBase_API[PyBobIpBaseLBP_Type_NUM] = (void *)&PyBobIpBaseLBP_Type;
PyBobIpBase_API[PyBobIpBaseLBP_Check_NUM] = (void *)&PyBobIpBaseLBP_Check;
PyBobIpBase_API[PyBobIpBaseLBP_Converter_NUM] = (void *)&PyBobIpBaseLBP_Converter;
#if PY_VERSION_HEX >= 0x02070000
/* defines the PyCapsule */
PyObject* c_api_object = PyCapsule_New((void *)PyBobIpBase_API,
BOB_EXT_MODULE_PREFIX "." BOB_EXT_MODULE_NAME "._C_API", 0);
#else
PyObject* c_api_object = PyCObject_FromVoidPtr((void *)PyBobIpBase_API, 0);
#endif
if (!c_api_object) return 0;
if (PyModule_AddObject(module, "_C_API", c_api_object) < 0) return 0;
/* imports bob.ip.base's C-API dependencies */
if (import_bob_blitz() < 0) return 0;
if (import_bob_core_random() < 0) return 0;
if (import_bob_core_logging() < 0) return 0;
if (import_bob_io_base() < 0) return 0;
if (import_bob_sp() < 0) return 0;
return Py_BuildValue(ret, module);
}
开发者ID:183amir,项目名称:bob.ip.base,代码行数:79,代码来源:main.cpp
示例14: initMMTK_pose
PyMODINIT_FUNC
initMMTK_pose(void)
{
PyObject *m, *d, *module;
#ifdef WITH_MPI
PyObject *mpi_module;
#endif
static void *PyFF_API[PyFF_API_pointers];
/* Create the module and add the functions */
m = Py_InitModule("MMTK_pose", pose_methods);
/* Import the array and MPI modules */
#ifdef import_array
import_array();
#endif
#ifdef WITH_MPI
import_mpi();
mpi_module = PyImport_ImportModule("Scientific.MPI");
if (mpi_module != NULL) {
PyObject *module_dict = PyModule_GetDict(mpi_module);
PyExc_MPIError = PyDict_GetItemString(module_dict, "MPIError");
}
#endif
/* Add C API pointer array */
PyFF_API[PyFFEnergyTerm_Type_NUM] = (void *)&PyFFEnergyTerm_Type;
PyFF_API[PyFFEvaluator_Type_NUM] = (void *)&PyFFEvaluator_Type;
PyFF_API[PyNonbondedList_Type_NUM] = (void *)&PyNonbondedList_Type;
PyFF_API[PySparseFC_New_NUM] = (void *)&PySparseFC_New;
PyFF_API[PySparseFC_Type_NUM] = (void *)&PySparseFC_Type;
PyFF_API[PySparseFC_Zero_NUM] = (void *)&PySparseFC_Zero;
PyFF_API[PySparseFC_Find_NUM] = (void *)&PySparseFC_Find;
PyFF_API[PySparseFC_AddTerm_NUM] = (void *)&PySparseFC_AddTerm;
PyFF_API[PySparseFC_CopyToArray_NUM] = (void *)&PySparseFC_CopyToArray;
PyFF_API[PySparseFC_AsArray_NUM] = (void *)&PySparseFC_AsArray;
PyFF_API[PySparseFC_VectorMultiply_NUM] = (void *)&PySparseFC_VectorMultiply;
PyFF_API[PySparseFC_Scale_NUM] = (void *)&PySparseFC_Scale;
PyFF_API[PyFFEnergyTerm_New_NUM] = (void *)&PyFFEnergyTerm_New;
PyFF_API[PyFFEvaluator_New_NUM] = (void *)&PyFFEvaluator_New;
PyFF_API[PyNonbondedListUpdate_NUM] = (void *)&PyNonbondedListUpdate;
PyFF_API[PyNonbondedListIterate_NUM] = (void *)&PyNonbondedListIterate;
#ifdef EXTENDED_TYPES
if (PyType_Ready(&PyFFEnergyTerm_Type) < 0)
return;
if (PyType_Ready(&PyFFEvaluator_Type) < 0)
return;
if (PyType_Ready(&PyNonbondedList_Type) < 0)
return;
if (PyType_Ready(&PySparseFC_Type) < 0)
return;
#else
PyFFEnergyTerm_Type.ob_type = &PyType_Type;
PyFFEvaluator_Type.ob_type = &PyType_Type;
PyNonbondedList_Type.ob_type = &PyType_Type;
PySparseFC_Type.ob_type = &PyType_Type;
#endif
d = PyModule_GetDict(m);
PyDict_SetItemString(d, "_C_API",
PyCObject_FromVoidPtr((void *)PyFF_API, NULL));
PyDict_SetItemString(d, "EnergyTerm", (PyObject *)&PyFFEnergyTerm_Type);
PyDict_SetItemString(d, "EnergyEvaluator",
(PyObject *)&PyFFEvaluator_Type);
/* Get the energy conversion factor from Units */
module = PyImport_ImportModule("MMTK.Units");
if (module != NULL) {
PyObject *module_dict = PyModule_GetDict(module);
PyObject *factor = PyDict_GetItemString(module_dict,
"electrostatic_energy");
electrostatic_energy_factor = PyFloat_AsDouble(factor);
}
/* Get function pointers from _universe */
module = PyImport_ImportModule("MMTK_universe");
if (module != NULL) {
PyObject *module_dict = PyModule_GetDict(module);
PyObject *c_api_object = PyDict_GetItemString(module_dict, "_C_API");
PyObject *fn;
if (PyCObject_Check(c_api_object))
PyUniverse_API = (void **)PyCObject_AsVoidPtr(c_api_object);
fn = PyDict_GetItemString(module_dict,
"infinite_universe_distance_function");
distance_vector_pointer = (distance_fn *)PyCObject_AsVoidPtr(fn);
fn = PyDict_GetItemString(module_dict,
"orthorhombic_universe_distance_function");
orthorhombic_distance_vector_pointer =
(distance_fn *)PyCObject_AsVoidPtr(fn);
fn = PyDict_GetItemString(module_dict,
"parallelepipedic_universe_distance_function");
parallelepipedic_distance_vector_pointer =
(distance_fn *)PyCObject_AsVoidPtr(fn);
}
/* Check for errors */
if (PyErr_Occurred())
Py_FatalError("can't initialize module MMTK_forcefield");
}
开发者ID:CCBatIIT,项目名称:AlGDock,代码行数:100,代码来源:MMTK_pose.c
示例15: ff_create
static PyObject *
ff_create(PyObject *self, PyObject *args)
{
PyObject *pypfo, *pycmap, *pyim, *pysite, *pyworker;
double params[N_PARAMS];
int eaa=-7, maxiter=-8, nThreads=-9;
int auto_deepen, periodicity;
int yflip;
render_type_t render_type;
pf_obj *pfo;
ColorMap *cmap;
IImage *im;
IFractalSite *site;
IFractWorker *worker;
if(!PyArg_ParseTuple(
args,
"(ddddddddddd)iiiiOOiiiOOO",
¶ms[0],¶ms[1],¶ms[2],¶ms[3],
¶ms[4],¶ms[5],¶ms[6],¶ms[7],
¶ms[8],¶ms[9],¶ms[10],
&eaa,&maxiter,&yflip,&nThreads,
&pypfo,&pycmap,
&auto_deepen,
&periodicity,
&render_type,
&pyim, &pysite,
&pyworker
))
{
return NULL;
}
cmap = (ColorMap *)PyCObject_AsVoidPtr(pycmap);
pfo = ((pfHandle *)PyCObject_AsVoidPtr(pypfo))->pfo;
im = (IImage *)PyCObject_AsVoidPtr(pyim);
site = (IFractalSite *)PyCObject_AsVoidPtr(pysite);
worker = (IFractWorker *)PyCObject_AsVoidPtr(pyworker);
if(!cmap || !pfo || !im || !site || !worker)
{
return NULL;
}
fractFunc *ff = new fractFunc(
params,
eaa,
maxiter,
nThreads,
auto_deepen,
yflip,
periodicity,
render_type,
-1, // warp_param
worker,
im,
site);
if(!ff)
{
return NULL;
}
ffHandle *ffh = new struct ffHandle;
ffh->ff = ff;
ffh->pyhandle = pyworker;
PyObject *pyret = PyCObject_FromVoidPtr(
ffh,(void (*)(void *))ff_delete);
Py_INCREF(pyworker);
return pyret;
}
开发者ID:Bookaa,项目名称:gnofract4d.simplify,代码行数:74,代码来源:fract4dmodule_gmp.cpp
示例16: addRpmTags
/*
* Add rpm tag dictionaries to the module
*/
static void addRpmTags(PyObject *module)
{
PyObject * dict = PyDict_New();
#ifdef NOTYET
PyObject *pyval, *pyname;
rpmtd names = rpmtdNew();
rpmTagGetNames(names, 1);
const char *tagname, *shortname;
rpmTag tagval;
while ((tagname = rpmtdNextString(names))) {
shortname = tagname + strlen("RPMTAG_");
tagval = rpmTagGetValue(shortname);
PyModule_AddIntConstant(module, tagname, tagval);
pyval = PyInt_FromLong(tagval);
pyname = PyString_FromString(shortname);
PyDict_SetItem(dict, pyval, pyname);
Py_XDECREF(pyval);
Py_XDECREF(pyname);
}
PyModule_AddObject(module, "tagnames", dict);
rpmtdFreeData(names);
rpmtdFree(names);
#else
PyObject * d = PyModule_GetDict(module);
PyObject * o;
{ const struct headerTagTableEntry_s * t;
PyObject * to;
for (t = rpmTagTable; t && t->name; t++) {
PyDict_SetItemString(d, (char *) t->name, to=PyInt_FromLong(t->val));
Py_XDECREF(to);
PyDict_SetItem(dict, to, o=PyString_FromString(t->name + 7));
Py_XDECREF(o);
}
}
{ headerSprintfExtension exts = rpmHeaderFormats;
headerSprintfExtension ext;
PyObject * to;
int extNum;
for (ext = exts, extNum = 0; ext != NULL && ext->type != HEADER_EXT_LAST;
ext = (ext->type == HEADER_EXT_MORE ? *ext->u.more : ext+1), extNum++)
{
if (ext->name == NULL || ext->type != HEADER_EXT_TAG)
continue;
PyDict_SetItemString(d, (char *) ext->name, to=PyCObject_FromVoidPtr((void *)ext, NULL));
Py_XDECREF(to);
PyDict_SetItem(dict, to, o=PyString_FromString(ext->name + 7));
Py_XDECREF(o);
}
}
PyDict_SetItemString(d, "tagnames", dict);
Py_XDECREF(dict);
#endif
}
开发者ID:avokhmin,项目名称:RPM5,代码行数:66,代码来源:rpmmodule.c
示例17: parse_params
static s_param *
parse_params(PyObject *pyarray, int *plen)
{
struct s_param *params;
// check and parse fractal params
if(!PySequence_Check(pyarray))
{
PyErr_SetString(PyExc_TypeError,
"parameters argument should be an array");
return NULL;
}
int len = PySequence_Size(pyarray);
if(len == 0)
{
params = (struct s_param *)malloc(sizeof(struct s_param));
params[0].t = FLOAT;
params[0].doubleval = 0.0;
}
else if(len > PF_MAXPARAMS)
{
PyErr_SetString(PyExc_ValueError,"Too many parameters");
return NULL;
}
else
{
int i = 0;
params = (struct s_param *)malloc(len * sizeof(struct s_param));
if(!params) return NULL;
for(i = 0; i < len; ++i)
{
PyObject *pyitem = PySequence_GetItem(pyarray,i);
if(NULL == pyitem)
{
return NULL;
}
if(PyFloat_Check(pyitem))
{
params[i].t = FLOAT;
params[i].doubleval = PyFloat_AsDouble(pyitem);
//printf("%d = float(%g)\n",i,params[i].doubleval);
}
else if(PyInt_Check(pyitem))
{
params[i].t = INT;
params[i].intval = PyInt_AS_LONG(pyitem);
//printf("%d = int(%d)\n",i,params[i].intval);
}
else if(
PyObject_HasAttrString(pyitem,"cobject") &&
PyObject_HasAttrString(pyitem,"segments"))
{
PyObject *pycob = PyObject_GetAttrString(pyitem,"cobject");
if(pycob == Py_None)
{
Py_DECREF(pycob);
PyObject *pysegs = PyObject_GetAttrString(
pyitem,"segments");
ColorMap *cmap = cmap_from_pyobject(pysegs);
Py_DECREF(pysegs);
if(NULL == cmap)
{
return NULL;
}
pycob = PyCObject_FromVoidPtr(
cmap, (void (*)(void *))cmap_delete);
if(NULL != pycob)
{
PyObject_SetAttrString(pyitem,"cobject",pycob);
// not quite correct, we are leaking some
// cmap objects
Py_XINCREF(pycob);
}
}
params[i].t = GRADIENT;
params[i].gradient = PyCObject_AsVoidPtr(pycob);
//printf("%d = gradient(%p)\n",i,params[i].gradient);
Py_DECREF(pycob);
}
else if(
PyObject_HasAttrString(pyitem,"_img"))
{
PyObject *pycob = PyObject_GetAttrString(pyitem,"_img");
params[i].t = PARAM_IMAGE;
params[i].image = PyCObject_AsVoidPtr(pycob);
Py_DECREF(pycob);
}
else
{
Py_XDECREF(pyitem);
PyErr_SetString(
PyExc_ValueError,
"All params must be floats, ints, or gradients");
free(params);
//.........这里部分代码省略.........
开发者ID:Bookaa,项目名称:gnofract4d.simplify,代码行数:101,代码来源:fract4dmodule_gmp.cpp
示例18: create
PyObject* create() {
brisk::BriskDescriptorExtractor* descriptor_extractor = new brisk::BriskDescriptorExtractor();
return PyCObject_FromVoidPtr(static_cast<void*>(descriptor_extractor), NULL);
}
开发者ID:gnebehay,项目名称:brisk,代码行数:4,代码来源:pybrisk.cpp
示例19: if
static PyObject *mkiir_wrap(PyObject *self, PyObject *args)
{
double lo, hi, srate;
double bwfreq, freq, h1, gain;
PyObject *o;
FILTER *handle;
IIRSPEC *filter;
if (!PyArg_ParseTuple(args, "ddd:mkiir", &lo, &hi, &srate)) {
return NULL;
}
handle = (FILTER *)malloc(sizeof(FILTER));
handle->type = FILTER_TYPE_IIR;
filter = &handle->iirspec;
filter->enable = 1;
filter->rate = srate;
if (hi > 0. && lo > 0. && lo < hi) {
filter->type = BANDPASS;
filter->order = SIG_ORDER;
filter->fl = lo;
filter->fh = hi;
} else if (hi > 0. && lo > 0. && lo > hi) {
filter->type = BANDREJECT;
filter->order = SIG_ORDER;
filter->fl = hi;
filter->fh = lo;
} else if (lo > 0. && hi == 0.) {
filter->type = HIGHPASS;
filter->order = 2 * SIG_ORDER;
filter->fl = lo;
filter->fh = srate / 2.;
} else if (lo == 0. && hi > 0.) {
filter->type = LOWPASS;
filter->order = 2 * SIG_ORDER;
filter->fl = 0;
filter->fh = hi;
}
// compute filter coefficients
if (mkiir(filter) < 0) {
PyErr_SetString(PyExc_RuntimeError, "mkiir() failed");
free(handle);
return NULL;
}
// compute effective bandwidth of data filter in steps of 1 milliHz
for (freq = bwfreq = 0.; freq < srate / 4.; freq += 0.001) {
h1 = response(filter, srate, freq);
if (h1 > M_SQRT2) {
PyErr_SetString(PyExc_RuntimeError, "mkiir() failed: IIR filter is unstable for this sample rate");
free(handle);
return NULL;
}
bwfreq += 0.001 * (h1 * h1);
}
// test filter for low gain
gain = bwfreq / (hi - lo);
if (gain < M_SQRT1_2) {
printf("nominal filter bandwidth=%f\n", bwfreq);
PyErr_SetString(PyExc_RuntimeError, "WARNING: IIR filter gain too low");
free(handle);
return NULL;
}
o = PyCObject_FromVoidPtr(handle, free_filter);
return o;
}
开发者ID:hyperbolicTom,项目名称:pyctf,代码行数:70,代码来源:samiir.c
示例20: init_cairo
//.........这里部分代码省略.........
#ifdef CAIRO_HAS_IMAGE_SURFACE
Py_INCREF(&PycairoImageSurface_Type);
PyModule_AddObject(m, "ImageSurface",
(PyObject *)&PycairoImageSurface_Type);
#endif
#ifdef CAIRO_HAS_PDF_SURFACE
Py_INCREF(&PycairoPDFSurface_Type);
PyModule_AddObject(m, "PDFSurface", (PyObject *)&PycairoPDFSurface_Type);
#endif
#ifdef CAIRO_HAS_PS_SURFACE
Py_INCREF(&PycairoPSSurface_Type);
PyModule_AddObject(m, "PSSurface", (PyObject *)&PycairoPSSurface_Type);
#endif
#ifdef CAIRO_HAS_SVG_SURFACE
Py_INCREF(&PycairoSVGSurface_Type);
PyModule_AddObject(m, "SVGSurface", (PyObject *)&PycairoSVGSurface_Type);
#endif
#ifdef CAIRO_HAS_WIN32_SURFACE
Py_INCREF(&PycairoWin32Surface_Type);
PyModule_AddObject(m, "Win32Surface",
(PyObject *)&PycairoWin32Surface_Type);
#endif
#ifdef CAIRO_HAS_XLIB_SURFACE
Py_INCREF(&PycairoXlibSurface_Type);
PyModule_AddObject(m, "XlibSurface",
(PyObject *)&PycairoXlibSurface_Type);
#endif
PyModule_AddObject(m, "CAPI", PyCObject_FromVoidPtr(&CAPI, NULL));
/* Add 'cairo.Error' to the module */
if (CairoError == NULL) {
CairoError = PyErr_NewException("cairo.Error", NULL, NULL);
if (CairoError == NULL)
return;
}
Py_INCREF(CairoError);
if (PyModule_AddObject(m, "Error", CairoError) < 0)
return;
/* constants */
#if CAIRO_HAS_ATSUI_FONT
PyModule_AddIntConstant(m, "HAS_ATSUI_FONT", 1);
#else
PyModule_AddIntConstant(m, "HAS_ATSUI_FONT", 0);
#endif
#if CAIRO_HAS_FT_FONT
PyModule_AddIntConstant(m, "HAS_FT_FONT", 1);
#else
PyModule_AddIntConstant(m, "HAS_FT_FONT", 0);
#endif
#if CAIRO_HAS_GLITZ_SURFACE
PyModule_AddIntConstant(m, "HAS_GLITZ_SURFACE", 1);
#else
PyModule_AddIntConstant(m, "HAS_GLITZ_SURFACE", 0);
#endif
#if CAIRO_HAS_IMAGE_SURFACE
PyModule_AddIntConstant(m, "HAS_IMAGE_SURFACE", 1);
#else
PyModule_AddIntConstant(m, "HAS_IMAGE_SURFACE", 0);
#endif
开发者ID:bdon,项目名称:pycairo,代码行数:67,代码来源:cairomodule.c
注:本文中的PyCObject_FromVoidPtr函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论