Exemple #1
0
void 
initvorbis(void)
{
  PyObject *module, *dict;

  py_dsp_type.ob_type = &PyType_Type;
  py_block_type.ob_type = &PyType_Type;
  py_vorbisfile_type.ob_type = &PyType_Type;
  py_vinfo_type.ob_type = &PyType_Type;
  py_vcomment_type.ob_type = &PyType_Type;

  module = Py_InitModule("ogg.vorbis", Vorbis_methods);
  dict = PyModule_GetDict(module);
  
  modinfo = PyCObject_Import("ogg._ogg", "_moduleinfo");
  if (modinfo == NULL) {
    PyErr_SetString(PyExc_ImportError, "Could not load ogg._ogg");
    return;
  }
  Py_VorbisError = PyErr_NewException("ogg.vorbis.VorbisError", 
				      modinfo->Py_OggError, NULL);
  PyDict_SetItemString(dict, "VorbisError", 
		       Py_VorbisError);
  
  PyDict_SetItemString(dict, "__doc__", 
		       PyString_FromString(docstring));

  PyDict_SetItemString(dict, "__version__", 
		       PyString_FromString("1.2"));

  if (PyErr_Occurred())
    PyErr_SetString(PyExc_ImportError, 
		    "ogg.vorbis: init failed");
}
Exemple #2
0
rpmpython rpmpythonNew(char ** av, uint32_t flags)
{
    static char * _av[] = { "rpmpython", NULL };
#if defined(WITH_PYTHONEMBED)
    int initialize = (!(flags & 0x80000000) || _rpmpythonI == NULL);
#endif
    rpmpython python = (flags & 0x80000000)
	? rpmpythonI() : rpmpythonGetPool(_rpmpythonPool);

if (_rpmpython_debug)
fprintf(stderr, "==> %s(%p, %d) python %p\n", __FUNCTION__, av, flags, python);

    if (av == NULL) av = _av;

#if defined(WITH_PYTHONEMBED)
    if (!Py_IsInitialized()) {
	Py_SetProgramName((char *)_av[0]);
	Py_Initialize();
    }
    if (PycStringIO == NULL)
	PycStringIO = PyCObject_Import("cStringIO", "cStringIO_CAPI");

    if (initialize) {
	int ac = argvCount((ARGV_t)av);
	(void) PySys_SetArgv(ac, (char **)av);
	(void) rpmpythonRun(python, rpmpythonInitStringIO, NULL);
    }
#endif

    return rpmpythonLink(python);
}
PyMODINIT_FUNC
init_zope_container_contained(void)
{
    PyObject *m;

    str_p_deactivate = PyString_FromString("_p_deactivate");
    if (str_p_deactivate == NULL)
        return;

    /* Try to fake out compiler nag function */
    if (0) init_zope_proxy_proxy();

    m = Py_InitModule3("_zope_container_contained",
                       module_functions, module___doc__);

    if (m == NULL)
        return;

    if (empty_tuple == NULL)
        empty_tuple = PyTuple_New(0);

    /* Initialize the PyPersist_C_API and the type objects. */
    cPersistenceCAPI = PyCObject_Import("persistent.cPersistence", "CAPI");
    if (cPersistenceCAPI == NULL)
        return;

    ProxyType.tp_name = "zope.container.contained.ContainedProxyBase";
    ProxyType.ob_type = &PyType_Type;
    ProxyType.tp_base = cPersistenceCAPI->pertype;
    ProxyType.tp_getattro = CP_getattro;
    ProxyType.tp_setattro = CP_setattro;
    ProxyType.tp_members = CP_members;
    ProxyType.tp_methods = CP_methods;
    ProxyType.tp_traverse = (traverseproc) CP_traverse;
    ProxyType.tp_clear = (inquiry) CP_clear;
    ProxyType.tp_dealloc = (destructor) CP_dealloc;
    ProxyType.tp_weaklistoffset = offsetof(ProxyObject, po_weaklist);

    if (PyType_Ready(&ProxyType) < 0)
        return;

    Py_INCREF(&ProxyType);
    PyModule_AddObject(m, "ContainedProxyBase", (PyObject *)&ProxyType);
}
static void
SWIG_Python_LookupTypePointer(swig_type_info ***type_list_handle) {
  PyObject *module, *pointer;
  void *type_pointer;

  /* first check if module already created */
  type_pointer = PyCObject_Import((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION, (char*)"type_pointer" SWIG_TYPE_TABLE_NAME);
  if (type_pointer) {
    *type_list_handle = (swig_type_info **) type_pointer;
  } else {
    PyErr_Clear();
    /* create a new module and variable */
    module = Py_InitModule((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION, swig_empty_runtime_method_table);
    pointer = PyCObject_FromVoidPtr((void *) (*type_list_handle), NULL);
    if (pointer && module) {
      PyModule_AddObject(module, (char*)"type_pointer" SWIG_TYPE_TABLE_NAME, pointer);
    }
  }
}
static PyObject*
module_init(void)
{
    PyObject *module, *mod_dict, *interfaces, *conflicterr;

#ifdef KEY_TYPE_IS_PYOBJECT
    object_ = PyTuple_GetItem(Py_TYPE(Py_None)->tp_bases, 0);
    if (object_ == NULL)
      return NULL;
#endif

    sort_str = INTERN("sort");
    if (!sort_str)
        return NULL;
    reverse_str = INTERN("reverse");
    if (!reverse_str)
        return NULL;
    __setstate___str = INTERN("__setstate__");
    if (!__setstate___str)
        return NULL;
    _bucket_type_str = INTERN("_bucket_type");
    if (!_bucket_type_str)
        return NULL;

    /* Grab the ConflictError class */
    interfaces = PyImport_ImportModule("BTrees.Interfaces");
    if (interfaces != NULL)
    {
        conflicterr = PyObject_GetAttrString(interfaces, "BTreesConflictError");
        if (conflicterr != NULL)
            ConflictError = conflicterr;
        Py_DECREF(interfaces);
    }

    if (ConflictError == NULL)
    {
        Py_INCREF(PyExc_ValueError);
        ConflictError=PyExc_ValueError;
    }

    /* Initialize the PyPersist_C_API and the type objects. */
#ifdef PY3K
    cPersistenceCAPI = (cPersistenceCAPIstruct *)PyCapsule_Import(
                "persistent.cPersistence.CAPI", 0);
#else
    cPersistenceCAPI = (cPersistenceCAPIstruct *)PyCObject_Import(
                "persistent.cPersistence", "CAPI");
#endif
    if (cPersistenceCAPI == NULL)
        return NULL;

#ifdef PY3K
#define _SET_TYPE(typ) ((PyObject*)(&typ))->ob_type = &PyType_Type
#else
#define _SET_TYPE(typ) (typ).ob_type = &PyType_Type
#endif
    _SET_TYPE(BTreeItemsType);
    _SET_TYPE(BTreeIter_Type);
    BTreeIter_Type.tp_getattro = PyObject_GenericGetAttr;
    BucketType.tp_new = PyType_GenericNew;
    SetType.tp_new = PyType_GenericNew;
    BTreeType.tp_new = PyType_GenericNew;
    TreeSetType.tp_new = PyType_GenericNew;
    if (!init_persist_type(&BucketType))
	    return NULL;
    if (!init_persist_type(&BTreeType))
	    return NULL;
    if (!init_persist_type(&SetType))
	    return NULL;
    if (!init_persist_type(&TreeSetType))
	    return NULL;

    if (PyDict_SetItem(BTreeType.tp_dict, _bucket_type_str,
		       (PyObject *)&BucketType) < 0)
    {
        fprintf(stderr, "btree failed\n");
        return NULL;
    }
    if (PyDict_SetItem(TreeSetType.tp_dict, _bucket_type_str,
		       (PyObject *)&SetType) < 0)
    {
        fprintf(stderr, "bucket failed\n");
        return NULL;
    }

    /* Create the module and add the functions */
#ifdef PY3K
    module = PyModule_Create(&moduledef);
#else
    module = Py_InitModule4("_" MOD_NAME_PREFIX "BTree",
		       module_methods, BTree_module_documentation,
		       (PyObject *)NULL, PYTHON_API_VERSION);
#endif

    /* Add some symbolic constants to the module */
    mod_dict = PyModule_GetDict(module);
    if (PyDict_SetItemString(mod_dict, MOD_NAME_PREFIX "Bucket",
			     (PyObject *)&BucketType) < 0)
        return NULL;
    if (PyDict_SetItemString(mod_dict, MOD_NAME_PREFIX "BTree",
			     (PyObject *)&BTreeType) < 0)
        return NULL;
    if (PyDict_SetItemString(mod_dict, MOD_NAME_PREFIX "Set",
			     (PyObject *)&SetType) < 0)
        return NULL;
    if (PyDict_SetItemString(mod_dict, MOD_NAME_PREFIX "TreeSet",
			     (PyObject *)&TreeSetType) < 0)
        return NULL;
    if (PyDict_SetItemString(mod_dict, MOD_NAME_PREFIX "TreeIterator",
			     (PyObject *)&BTreeIter_Type) < 0)
        return NULL;
	/* We also want to be able to access these constants without the prefix
	 * so that code can more easily exchange modules (particularly the integer
	 * and long modules, but also others).  The TreeIterator is only internal,
	 * so we don't bother to expose that.
     */
    if (PyDict_SetItemString(mod_dict, "Bucket",
			     (PyObject *)&BucketType) < 0)
        return NULL;
    if (PyDict_SetItemString(mod_dict, "BTree",
			     (PyObject *)&BTreeType) < 0)
        return NULL;
    if (PyDict_SetItemString(mod_dict, "Set",
			     (PyObject *)&SetType) < 0)
        return NULL;
    if (PyDict_SetItemString(mod_dict, "TreeSet",
			     (PyObject *)&TreeSetType) < 0)
        return NULL;
#if defined(ZODB_64BIT_INTS) && defined(NEED_LONG_LONG_SUPPORT)
    if (PyDict_SetItemString(mod_dict, "using64bits", Py_True) < 0)
        return NULL;
#else
    if (PyDict_SetItemString(mod_dict, "using64bits", Py_False) < 0)
        return NULL;
#endif
    return module;
}
void
INITMODULE (void)
{
  PyObject *m, *d, *c;

  UNLESS (sort_str=PyString_FromString("sort")) return;
  UNLESS (reverse_str=PyString_FromString("reverse")) return;
  UNLESS (items_str=PyString_FromString("items")) return;
  UNLESS (__setstate___str=PyString_FromString("__setstate__")) return;

  UNLESS (PyExtensionClassCAPI=PyCObject_Import("ExtensionClass","CAPI"))
      return;

#ifdef PERSISTENT
  if ((cPersistenceCAPI=PyCObject_Import("cPersistence","CAPI")))
    {
	BucketType.methods.link=cPersistenceCAPI->methods;
	BucketType.tp_getattro=cPersistenceCAPI->getattro;
	BucketType.tp_setattro=cPersistenceCAPI->setattro;

	SetType.methods.link=cPersistenceCAPI->methods;
	SetType.tp_getattro=cPersistenceCAPI->getattro;
	SetType.tp_setattro=cPersistenceCAPI->setattro;

	BTreeType.methods.link=cPersistenceCAPI->methods;
	BTreeType.tp_getattro=cPersistenceCAPI->getattro;
	BTreeType.tp_setattro=cPersistenceCAPI->setattro;

	TreeSetType.methods.link=cPersistenceCAPI->methods;
	TreeSetType.tp_getattro=cPersistenceCAPI->getattro;
	TreeSetType.tp_setattro=cPersistenceCAPI->setattro;
    }
  else return;

  /* Grab the ConflictError class */

  m = PyImport_ImportModule("ZODB.POSException");

  if (m != NULL) {
  	c = PyObject_GetAttrString(m, "BTreesConflictError");
  	if (c != NULL)
  		ConflictError = c;
	Py_DECREF(m);
  }

  if (ConflictError == NULL) {
  	Py_INCREF(PyExc_ValueError);
	ConflictError=PyExc_ValueError;
  }

#else
  BTreeType.tp_getattro=PyExtensionClassCAPI->getattro;
  BucketType.tp_getattro=PyExtensionClassCAPI->getattro;
  SetType.tp_getattro=PyExtensionClassCAPI->getattro;
  TreeSetType.tp_getattro=PyExtensionClassCAPI->getattro;
#endif

  BTreeItemsType.ob_type=&PyType_Type;

#ifdef INTSET_H
  UNLESS(d = PyImport_ImportModule("intSet")) return;
  UNLESS(intSetType = PyObject_GetAttrString (d, "intSet")) return;
  Py_DECREF (d);
#endif

  /* Create the module and add the functions */
  m = Py_InitModule4("_" MOD_NAME_PREFIX "BTree", module_methods,
		     BTree_module_documentation,
		     (PyObject*)NULL,PYTHON_API_VERSION);

  /* Add some symbolic constants to the module */
  d = PyModule_GetDict(m);

  PyExtensionClass_Export(d,MOD_NAME_PREFIX "Bucket", BucketType);
  PyExtensionClass_Export(d,MOD_NAME_PREFIX "BTree", BTreeType);
  PyExtensionClass_Export(d,MOD_NAME_PREFIX "Set", SetType);
  PyExtensionClass_Export(d,MOD_NAME_PREFIX "TreeSet", TreeSetType);
}