当前位置: 首页>>代码示例>>C++>>正文


C++ PyCObject_FromVoidPtr函数代码示例

本文整理汇总了C++中PyCObject_FromVoidPtr函数的典型用法代码示例。如果您正苦于以下问题:C++ PyCObject_FromVoidPtr函数的具体用法?C++ PyCObject_FromVoidPtr怎么用?C++ PyCObject_FromVoidPtr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了PyCObject_FromVoidPtr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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",
	   &params[0],&params[1],&params[2],&params[3],
	   &params[4],&params[5],&params[6],&params[7],
	   &params[8],&params[9],&params[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


注:本文中的PyCObject_FromVoidPtr函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。