Ejemplo n.º 1
0
PyMODINIT_FUNC
PyInit__gdbm(void) {
    PyObject *m, *d, *s;

    if (PyType_Ready(&Dbmtype) < 0)
            return NULL;
    m = PyModule_Create(&_gdbmmodule);
    if (m == NULL)
        return NULL;
    d = PyModule_GetDict(m);
    DbmError = PyErr_NewException("_gdbm.error", PyExc_IOError, NULL);
    if (DbmError != NULL) {
        PyDict_SetItemString(d, "error", DbmError);
        s = PyUnicode_FromString(dbmmodule_open_flags);
        PyDict_SetItemString(d, "open_flags", s);
        Py_DECREF(s);
    }
    return m;
}
Ejemplo n.º 2
0
PyMODINIT_FUNC
  initumemcache(void)
{
  PyObject* m;

  m = Py_InitModule3("umemcache", methods, "");
  if (m == NULL)
    return;

  ClientType.tp_new = PyType_GenericNew;
  if (PyType_Ready(&ClientType) < 0)
    return;
  Py_INCREF(&ClientType);
  PyModule_AddObject(m, "Client", (PyObject *)&ClientType);

  umemcache_MemcachedError = PyErr_NewException("umemcache.MemcachedError",
      PyExc_RuntimeError, NULL);
  PyModule_AddObject(m, "MemcachedError", (PyObject *)umemcache_MemcachedError);
}
Ejemplo n.º 3
0
PyMODINIT_FUNC
initVmMngr(void)
{
    PyObject *m;

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

    m = Py_InitModule("VmMngr", VmMngr_Methods);
    if (m == NULL)
	    return;

    Vm_Mngr_Error = PyErr_NewException("VmMngr.error", NULL, NULL);
    Py_INCREF(Vm_Mngr_Error);
    PyModule_AddObject(m, "error", Vm_Mngr_Error);

    Py_INCREF(&VmMngrType);
    PyModule_AddObject(m, "Vm", (PyObject *)&VmMngrType);
}
Ejemplo n.º 4
0
PyObject *PyInit__minpack(void)
{
    PyObject *m, *d, *s;

    m = PyModule_Create(&moduledef);
    import_array();

    d = PyModule_GetDict(m);

    s = PyUnicode_FromString(" 1.10 ");
    PyDict_SetItemString(d, "__version__", s);
    Py_DECREF(s);
    minpack_error = PyErr_NewException ("minpack.error", NULL, NULL);
    PyDict_SetItemString(d, "error", minpack_error);
    if (PyErr_Occurred())
        Py_FatalError("can't initialize module minpack");

    return m;
}
Ejemplo n.º 5
0
PyMODINIT_FUNC
initpyhook(void) {
  PyObject *m;
  
  pyhook_StreetAddressLookupType.tp_members = StreetAddressLookup_members;
  if (PyType_Ready(&pyhook_StreetAddressLookupType) < 0)
    return;
  
  m = Py_InitModule("pyhook", PyhookMethods);
  if (m == NULL)
    return;

  PyhookError = PyErr_NewException("pyhook.error", NULL, NULL);
  Py_INCREF(PyhookError);
  PyModule_AddObject(m, "error", PyhookError);

  Py_INCREF(&pyhook_StreetAddressLookupType);
  PyModule_AddObject(m, "StreetAddressLookup", StreetAddressLookup_new(&pyhook_StreetAddressLookupType, NULL, NULL));
}
Ejemplo n.º 6
0
    PyMODINIT_FUNC
    initrtaudio(void) 
    {
        PyEval_InitThreads();

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

        PyObject* module = Py_InitModule3("rtaudio", NULL, "RtAudio wrapper.");
        if (module == NULL)
            return;

        Py_INCREF(&RtAudio_type);
        PyModule_AddObject(module, "RtAudio", (PyObject *)&RtAudio_type);

        RtAudioError = PyErr_NewException("rtaudio.RtError", NULL, NULL);
        Py_INCREF(RtAudioError);
        PyModule_AddObject(module, "RtError", RtAudioError);
    }
Ejemplo n.º 7
0
/* Initialization function for the module */
void initrrdtool(
    void)
{
    PyObject *m, *d, *t;

    /* Create the module and add the functions */
    m = Py_InitModule("rrdtool", _rrdtool_methods);

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

    SET_STRCONSTANT(d, __version__);
    ErrorObject = PyErr_NewException("rrdtool.error", NULL, NULL);
    PyDict_SetItemString(d, "error", ErrorObject);

    /* Check for errors */
    if (PyErr_Occurred())
        Py_FatalError("can't initialize the rrdtool module");
}
Ejemplo n.º 8
0
PyMODINIT_FUNC
initlibmtp(void) {
    PyObject *m;

    DeviceType.tp_new = PyType_GenericNew;
    if (PyType_Ready(&DeviceType) < 0)
        return;
    
    m = Py_InitModule3("libmtp", libmtp_methods, "Interface to libmtp.");
    if (m == NULL) return;

    MTPError = PyErr_NewException("libmtp.MTPError", NULL, NULL);
    if (MTPError == NULL) return;
    PyModule_AddObject(m, "MTPError", MTPError);

    // Redirect stdout to get rid of the annoying message about mtpz. Really,
    // who designs a library without anyway to control/redirect the debugging
    // output, and hardcoded paths that cannot be changed? Compiling libmtp without the crypt use flag disables mtpz support in libmtp
    /* int bak, new; */
    /* fprintf(stdout, "\n"); // This is needed, without it, for some odd reason the code below causes stdout to buffer all output after it is restored, rather than using line buffering, and setlinebuf does not work. */
    /* fflush(stdout); */
    /* bak = dup(STDOUT_FILENO); */
    /* new = open("/dev/null", O_WRONLY); */
    /* dup2(new, STDOUT_FILENO); */
    /* close(new); */
    LIBMTP_Init();
    /* fflush(stdout); */
    /* dup2(bak, STDOUT_FILENO); */
    /* close(bak); */

    LIBMTP_Set_Debug(LIBMTP_DEBUG_NONE);

    Py_INCREF(&DeviceType);
    PyModule_AddObject(m, "Device", (PyObject *)&DeviceType);

    PyModule_AddStringMacro(m, LIBMTP_VERSION_STRING);
    PyModule_AddIntMacro(m, LIBMTP_DEBUG_NONE);
    PyModule_AddIntMacro(m, LIBMTP_DEBUG_PTP);
    PyModule_AddIntMacro(m, LIBMTP_DEBUG_PLST);
    PyModule_AddIntMacro(m, LIBMTP_DEBUG_USB);
    PyModule_AddIntMacro(m, LIBMTP_DEBUG_DATA);
    PyModule_AddIntMacro(m, LIBMTP_DEBUG_ALL);
}
Ejemplo n.º 9
0
PyMODINIT_FUNC
init_sophia(void)

#endif
{
    static char *sophia_constant_names[] = {"SPGT", "SPGTE", "SPLT", "SPLTE",
        "SPCMP", "SPPAGE", "SPMERGEWM", "SPGC", "SPMERGE", "SPGCF", "SPGROW", NULL};
    
    static int sophia_constant_values[] = {SPGT, SPGTE, SPLT, SPLTE,
        SPCMP, SPPAGE, SPMERGEWM, SPGC, SPMERGE, SPGCF, SPGROW, 0};
    
    if (PyType_Ready(&SophiaDBType) == -1)
        return PSP_NOTHING;
    SophiaError = PyErr_NewException("sophia.Error", NULL, NULL);
    if (!SophiaError)
        return PSP_NOTHING;

#if PY_MAJOR_VERSION >= 3
    PyObject *module = PyModule_Create(&_sophiamodule);
#else
    PyObject *module = Py_InitModule("_sophia", NULL);
#endif
    if (!module)
        return PSP_NOTHING;
    
    char **names = sophia_constant_names;
    int *values = sophia_constant_values;
    while (*names) {
        if (PyModule_AddIntConstant(module, *names++, *values++) == -1)
            return PSP_NOTHING;
    }
    
    Py_INCREF(&SophiaDBType);
    Py_INCREF(SophiaError);
    
    if (PyModule_AddObject(module, "Database", (PyObject *)&SophiaDBType) == -1 ||
        PyModule_AddObject(module, "Error", SophiaError) == -1)
        return PSP_NOTHING;

#if PY_MAJOR_VERSION >= 3
    return module;
#endif
}
Ejemplo n.º 10
0
static int
psyco_errors_init(void)
{
    /* the names of the exceptions here reflect the organization of the
       psycopg2 module and not the fact the the original error objects
       live in _psycopg */

    int i;
    PyObject *dict = NULL;
    PyObject *str = NULL;
    int rv = -1;

    /* 'Error' has been defined elsewhere: only init the other classes */
    Error = (PyObject *)&errorType;

    for (i = 1; exctable[i].name; i++) {
        if (!(dict = PyDict_New())) { goto exit; }

        if (exctable[i].docstr) {
            if (!(str = Text_FromUTF8(exctable[i].docstr))) { goto exit; }
            if (0 != PyDict_SetItemString(dict, "__doc__", str)) { goto exit; }
            Py_CLEAR(str);
        }

        /* can't put PyExc_StandardError in the static exctable:
         * windows build will fail */
        if (!(*exctable[i].exc = PyErr_NewException(
                exctable[i].name,
                exctable[i].base ? *exctable[i].base : PyExc_StandardError,
                dict))) {
            goto exit;
        }
        Py_CLEAR(dict);
    }

    rv = 0;

exit:
    Py_XDECREF(str);
    Py_XDECREF(dict);
    return rv;
}
Ejemplo n.º 11
0
initsound(void)
{
	Py_Initialize();
	PyObject *m= Py_InitModule(MODULE_NAME, pysound_methods);

	// Initialize tables
	PyModule_AddStringConstant(m, "__doc__", PYMODULEDOC );
	PyModule_AddStringConstant(m, "version", PYSNDVERSION );
	PyModule_AddIntConstant(m, "build", PYSNDBUILD );
  _EXPORT_INT(m, AFMT_MU_LAW);
  _EXPORT_INT(m, AFMT_A_LAW);
  _EXPORT_INT(m, AFMT_IMA_ADPCM);
  _EXPORT_INT(m, AFMT_U8);
  _EXPORT_INT(m, AFMT_S16_LE);
  _EXPORT_INT(m, AFMT_S16_BE);
  _EXPORT_INT(m, AFMT_S8);
  _EXPORT_INT(m, AFMT_U16_LE);
  _EXPORT_INT(m, AFMT_U16_BE);
  _EXPORT_INT(m, AFMT_MPEG);
  _EXPORT_INT(m, AFMT_AC3);
  _EXPORT_INT(m, AFMT_S16_NE);

	g_cErr = PyErr_NewException(MODULE_NAME".SoundError", NULL, NULL);
	if( g_cErr != NULL)
	  PyModule_AddObject(m, "SoundError", g_cErr );

	PyISoundType.ob_type = &PyType_Type;
	Py_INCREF((PyObject *)&PyISoundType);
	PyModule_AddObject(m, INPUT_NAME, (PyObject *)&PyISoundType);
	PySoundType.ob_type = &PyType_Type;
	Py_INCREF((PyObject *)&PySoundType);
	PyModule_AddObject(m, OUTPUT_NAME, (PyObject *)&PySoundType);
	ResamplerType.ob_type = &PyType_Type;
	Py_INCREF((PyObject *)&ResamplerType);
	PyModule_AddObject(m, RESAMPLER_NAME, (PyObject *)&ResamplerType);
	AnalyzerType.ob_type = &PyType_Type;
	Py_INCREF((PyObject *)&AnalyzerType);
	PyModule_AddObject(m, ANALYZER_NAME, (PyObject *)&AnalyzerType);
	MixerType.ob_type = &PyType_Type;
	Py_INCREF((PyObject *)&MixerType);
	PyModule_AddObject(m, MIXER_NAME, (PyObject *)&MixerType);
}
Ejemplo n.º 12
0
PyMODINIT_FUNC
PyInit_zlib(void)
{
    PyObject *m, *ver;
    Comptype.ob_type = &PyType_Type;
    Decomptype.ob_type = &PyType_Type;
    m = Py_InitModule4("zlib", zlib_methods,
		       zlib_module_documentation,
		       (PyObject*)NULL,PYTHON_API_VERSION);
    if (m == NULL)
	return;

    ZlibError = PyErr_NewException("zlib.error", NULL, NULL);
    if (ZlibError != NULL) {
        Py_INCREF(ZlibError);
	PyModule_AddObject(m, "error", ZlibError);
    }
    PyModule_AddIntConstant(m, "MAX_WBITS", MAX_WBITS);
    PyModule_AddIntConstant(m, "DEFLATED", DEFLATED);
    PyModule_AddIntConstant(m, "DEF_MEM_LEVEL", DEF_MEM_LEVEL);
    PyModule_AddIntConstant(m, "Z_BEST_SPEED", Z_BEST_SPEED);
    PyModule_AddIntConstant(m, "Z_BEST_COMPRESSION", Z_BEST_COMPRESSION);
    PyModule_AddIntConstant(m, "Z_DEFAULT_COMPRESSION", Z_DEFAULT_COMPRESSION);
    PyModule_AddIntConstant(m, "Z_FILTERED", Z_FILTERED);
    PyModule_AddIntConstant(m, "Z_HUFFMAN_ONLY", Z_HUFFMAN_ONLY);
    PyModule_AddIntConstant(m, "Z_DEFAULT_STRATEGY", Z_DEFAULT_STRATEGY);

    PyModule_AddIntConstant(m, "Z_FINISH", Z_FINISH);
    PyModule_AddIntConstant(m, "Z_NO_FLUSH", Z_NO_FLUSH);
    PyModule_AddIntConstant(m, "Z_SYNC_FLUSH", Z_SYNC_FLUSH);
    PyModule_AddIntConstant(m, "Z_FULL_FLUSH", Z_FULL_FLUSH);

    ver = PyString_FromString(ZLIB_VERSION);
    if (ver != NULL)
	PyModule_AddObject(m, "ZLIB_VERSION", ver);

    PyModule_AddStringConstant(m, "__version__", "1.0");

#ifdef WITH_THREAD
    zlib_lock = PyThread_allocate_lock();
#endif /* WITH_THREAD */
}
Ejemplo n.º 13
0
PyMODINIT_FUNC PyInit_cstuff(void) {
	PyObject *module;
	module = PyModule_Create(&cstuff_module);
	if (module == NULL) {
		return NULL;
	}

	if (PyType_Ready(&cstuff_DirectionMapType) < 0) {
		return NULL;
	}

	CStuffError = PyErr_NewException("cstuff.CStuffError", NULL, NULL);
	Py_INCREF(CStuffError);
	PyModule_AddObject(module, "CStuffError", CStuffError);

	Py_INCREF(&cstuff_DirectionMapType);
	PyModule_AddObject(module, "DirectionMap", (PyObject *)&cstuff_DirectionMapType);

	return module;
}
Ejemplo n.º 14
0
PyMODINIT_FUNC
PyInit__simpleaudio(void)
{
    PyObject *m;

    m = PyModule_Create(&_simpleaudio_module);
    if (m == NULL)
        return NULL;

    sa_python_error = PyErr_NewException("_simpleaudio.SimpleaudioError", NULL, NULL);
    Py_INCREF(sa_python_error);
    PyModule_AddObject(m, "SimpleaudioError", sa_python_error);

    /* initialize the list head mutex */
    play_list_head.mutex = create_mutex();

    dbg1("init'd list head at %p\n", &play_list_head);

    return m;
}
Ejemplo n.º 15
0
initcd(void)
{
	Py_Initialize();
	g_iMaxCDROMIndex= -1;
	PyObject *m = Py_InitModule("cd", pycd_methods);
	PyModule_AddStringConstant( m, "__doc__", (char*)PYDOC );
	PyModule_AddStringConstant( m, "version", (char*)PYCDVERSION );
	PyModule_AddIntConstant( m, "build", PYCDBUILD );

	INT_CONSTANT( SEEK_SET );
	INT_CONSTANT( SEEK_END );
	INT_CONSTANT( SEEK_CUR );
	g_cErr = PyErr_NewException(MODULE_NAME".CDError", NULL, NULL);
	if( g_cErr != NULL)
	  PyModule_AddObject(m, "CDError", g_cErr );

	PyCDType.ob_type = &PyType_Type;
	Py_INCREF((PyObject *)&PyCDType);
	PyModule_AddObject(m, "CD", (PyObject *)&PyCDType);
}
Ejemplo n.º 16
0
CALIBRE_MODINIT_FUNC
inithunspell(void) {
    PyObject *mod;

    // Create the module
    mod = Py_InitModule3("hunspell", NULL,
                "A wrapper for the hunspell spell checking library");
    if (mod == NULL) return;

    HunspellError = PyErr_NewException((char*)"hunspell.HunspellError", NULL, NULL);
    if (HunspellError == NULL) return;
    PyModule_AddObject(mod, "HunspellError", HunspellError);

    // Fill in some slots in the type, and make it ready
    DictionaryType.tp_new = PyType_GenericNew;
    if (PyType_Ready(&DictionaryType) < 0) return;
    // Add the type to the module.
    Py_INCREF(&DictionaryType);
    PyModule_AddObject(mod, "Dictionary", (PyObject *)&DictionaryType);
}
Ejemplo n.º 17
0
PyMODINIT_FUNC initketama(void) {
    PyObject *m;

    if (PyType_Ready(&pyketama_ContinuumType) < 0) {
        return;
    }

    if (!(m = Py_InitModule3("ketama", ketamaMethods,
        "Python extension for calling libketama functions."))) {
        return;
    }

    pyketama_error = PyErr_NewException("ketama.KetamaError", NULL, NULL);

    Py_INCREF(pyketama_error);
    PyModule_AddObject(m, "KetamaError", pyketama_error);

    Py_INCREF(&pyketama_ContinuumType);
    PyModule_AddObject(m, "Continuum", (PyObject *)&pyketama_ContinuumType);
}
Ejemplo n.º 18
0
PyMODINIT_FUNC initscheme(void){
    PyObject *m;

    m = Py_InitModule("scheme", SchemeMethods);
    if (m == NULL)
        return;

    SchemeError = PyErr_NewException("scheme.error", NULL, NULL);
    Py_INCREF(SchemeError);
    PyModule_AddObject(m, "error", SchemeError);
    
    VM_Type.tp_new = PyType_GenericNew;
    if (PyType_Ready(VM_Type) < 0)
        return;

    Py_INCREF(&VM_Type);
    PyModule_AddObject(m, "VM", (PyObject *)&VM_Type);
    
    
}
Ejemplo n.º 19
0
PyMODINIT_FUNC
initJitCore_x86(void)
{
    PyObject *m;

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

    m = Py_InitModule("JitCore_x86", JitCore_x86_Methods);
    if (m == NULL)
	    return;

    JitCore_x86_Error = PyErr_NewException("JitCore_x86.error", NULL, NULL);
    Py_INCREF(JitCore_x86_Error);
    PyModule_AddObject(m, "error", JitCore_x86_Error);

    Py_INCREF(&JitCpuType);
    PyModule_AddObject(m, "JitCpu", (PyObject *)&JitCpuType);

}
Ejemplo n.º 20
0
PyMODINIT_FUNC initfftpack_lite(void)
{
    PyObject *m, *d;

    /* Create the module and add the functions */
    m = Py_InitModule4("fftpack_lite", fftpack_methods,
            fftpack_module_documentation,
            (PyObject*)NULL,PYTHON_API_VERSION);

    /* Import the array object */
    import_array();

    /* Add some symbolic constants to the module */
    d = PyModule_GetDict(m);
    ErrorObject = PyErr_NewException("fftpack.error", NULL, NULL);
    PyDict_SetItemString(d, "error", ErrorObject);

    /* XXXX Add constants here */

}
Ejemplo n.º 21
0
void
init_cpg(void)
{
    int i;
    PyObject *Pmodule, *Pdict;

    Pmodule = Py_InitModule("_cpg", py_cpg_methods);
    Pdict = PyModule_GetDict(Pmodule);

    py_cpg_init_callbacks();

    py_cpg_error = PyErr_NewException("corosync._cpg.Error", NULL, NULL);
    PyDict_SetItemString(Pdict, "Error", py_cpg_error);

    for (i=0; py_cpg_constants[i].name != NULL; i++)
    {
	PyDict_SetItemString(Pdict, py_cpg_constants[i].name,
			     PyInt_FromLong(py_cpg_constants[i].value));
    }
}
Ejemplo n.º 22
0
PyMODINIT_FUNC
initstruct(void)
{
	PyObject *m;

	/* Create the module and add the functions */
	m = Py_InitModule4("struct", struct_methods, struct__doc__,
			   (PyObject*)NULL, PYTHON_API_VERSION);
	if (m == NULL)
		return;

	/* Add some symbolic constants to the module */
	if (StructError == NULL) {
		StructError = PyErr_NewException("struct.error", NULL, NULL);
		if (StructError == NULL)
			return;
	}
	Py_INCREF(StructError);
	PyModule_AddObject(m, "error", StructError);
}
Ejemplo n.º 23
0
PyMODINIT_FUNC
PyInit_termios(void)
{
	PyObject *m;
	struct constant *constant = termios_constants;

	m = Py_InitModule4("termios", termios_methods, termios__doc__,
                           (PyObject *)NULL, PYTHON_API_VERSION);

	if (TermiosError == NULL) {
		TermiosError = PyErr_NewException("termios.error", NULL, NULL);
	}
	Py_INCREF(TermiosError);
	PyModule_AddObject(m, "error", TermiosError);

	while (constant->name != NULL) {
		PyModule_AddIntConstant(m, constant->name, constant->value);
		++constant;
	}
}
Ejemplo n.º 24
0
initcdb() {
  PyObject *m, *d, *v;

  CdbType.ob_type = &PyType_Type;
  CdbMakeType.ob_type = &PyType_Type;

  m = Py_InitModule3("cdb", module_functions, module_doc);

  d = PyModule_GetDict(m);

  CDBError = PyErr_NewException("cdb.error", NULL, NULL);
  PyDict_SetItemString(d, "error", CDBError);

  PyDict_SetItemString(d, "__version__", 
                       v = PyString_FromString(VERSION));
  PyDict_SetItemString(d, "__cdb_version__",
                       v = PyString_FromString(CDBVERSION));
  Py_XDECREF(v);

}
Ejemplo n.º 25
0
PyMODINIT_FUNC inithdhomerun(void) {
    PyObject *m;

    m = Py_InitModule3("hdhomerun", hdhomerun_methods, hdhomerun_module_doc);
    if(!m)
        return;

    /* Finalize the Device type object */
    if (PyType_Ready(&hdhomerun_Device_type) < 0)
        return;
    Py_INCREF(&hdhomerun_Device_type);
    if(PyModule_AddObject(m, "Device", (PyObject *)&hdhomerun_Device_type) < 0)
        return;

    /* Initialize the DeviceError exception class */
    hdhomerun_device_error = PyErr_NewException("hdhomerun.DeviceError", PyExc_Exception, NULL);
    Py_INCREF(hdhomerun_device_error);
    if(PyModule_AddObject(m, "DeviceError", hdhomerun_device_error) < 0)
        return;
}
Ejemplo n.º 26
0
init_yappi(void)
#endif
{
    PyObject *m, *d;

#ifdef IS_PY3K
    m = PyModule_Create(&_yappi_module);
    if (m == NULL)
        return NULL;
#else
    m = Py_InitModule("_yappi",  yappi_methods);
    if (m == NULL)
        return;
#endif

    d = PyModule_GetDict(m);
    YappiProfileError = PyErr_NewException("_yappi.error", NULL, NULL);
    PyDict_SetItemString(d, "error", YappiProfileError);

    // init the profiler memory and internal constants
    yappinitialized = 0;
    yapphavestats = 0;
    yapprunning = 0;
    paused = 0;
    flags.builtins = 0;
    flags.multithreaded = 0;
    test_timings = NULL;
    
    if (!_init_profiler()) {
        PyErr_SetString(YappiProfileError, "profiler cannot be initialized.");
#ifdef IS_PY3K
        return NULL;
#else
        return;
#endif
    }

#ifdef IS_PY3K
    return m;
#endif
}
Ejemplo n.º 27
0
  void initlinux_sgio(void)

#endif
  /* ------------------------------------------------------------------------ **
   * Module initialization.
   * ------------------------------------------------------------------------ **
   */
  {
#if PY_MAJOR_VERSION >= 3
    PyObject *module = PyModule_Create(&moduledef);
#else
    PyObject *module = Py_InitModule("linux_sgio", SGIOMethods);
#endif
      if( module == NULL)
        INITERROR;

      SGIOError = PyErr_NewException( "linux_sgio.SGIOError", NULL, NULL );
      Py_INCREF(SGIOError);
      if ( PyModule_AddObject(module, "SGIOError", SGIOError) == -1 )
	INITERROR;

      /* Define some of the SGIO constants for use in the Python code. */
      if ( PyModule_AddIntConstant(module, "DXFER_NONE", SG_DXFER_NONE) < 0 )
	INITERROR;
      if ( PyModule_AddIntConstant(module, "DXFER_TO_DEV", SG_DXFER_TO_DEV) < 0 )
	INITERROR;
      if ( PyModule_AddIntConstant(module, "DXFER_FROM_DEV", SG_DXFER_FROM_DEV) < 0 )
	INITERROR;
      if ( PyModule_AddIntConstant(module, "DXFER_TO_FROM_DEV", SG_DXFER_TO_FROM_DEV) < 0 )
	INITERROR;

    if (SGIOError == NULL)
    {
        Py_DECREF(module);
        INITERROR;
    }
#if PY_MAJOR_VERSION >= 3
    return module;
#endif

  } /* initsgio */
Ejemplo n.º 28
0
PyMODINIT_FUNC
initxx(void)
{
    PyObject *m;

    /* Due to cross platform compiler issues the slots must be filled
     * here. It's required for portability to Windows without requiring
     * C++. */
    Null_Type.tp_base = &PyBaseObject_Type;
    Null_Type.tp_new = PyType_GenericNew;
    Str_Type.tp_base = &PyUnicode_Type;

    /* Finalize the type object including setting type of the new type
     * object; doing it here is required for portability, too. */
    if (PyType_Ready(&Xxo_Type) < 0)
        return;

    /* Create the module and add the functions */
    m = Py_InitModule3("xx", xx_methods, module_doc);
    if (m == NULL)
        return;

    /* Add some symbolic constants to the module */
    if (ErrorObject == NULL) {
        ErrorObject = PyErr_NewException("xx.error", NULL, NULL);
        if (ErrorObject == NULL)
            return;
    }
    Py_INCREF(ErrorObject);
    PyModule_AddObject(m, "error", ErrorObject);

    /* Add Str */
    if (PyType_Ready(&Str_Type) < 0)
        return;
    PyModule_AddObject(m, "Str", (PyObject *)&Str_Type);

    /* Add Null */
    if (PyType_Ready(&Null_Type) < 0)
        return;
    PyModule_AddObject(m, "Null", (PyObject *)&Null_Type);
}
Ejemplo n.º 29
0
/* Module */
PyObject *
init_fibers(void)
{
    PyObject *fibers;

    /* Main module */
#if PY_MAJOR_VERSION >= 3
    fibers = PyModule_Create(&fibers_module);
#else
    fibers = Py_InitModule("fibers", fibers_methods);
#endif

    /* keys for per-thread dictionary */
#if PY_MAJOR_VERSION >= 3
    current_fiber_key = PyUnicode_InternFromString("__fibers_current");
#else
    current_fiber_key = PyString_InternFromString("__fibers_current");
#endif
    if (current_fiber_key == NULL) {
        goto fail;
    }

    /* Exceptions */
    PyExc_FiberError = PyErr_NewException("fibers.error", NULL, NULL);
    MyPyModule_AddType(fibers, "error", (PyTypeObject *)PyExc_FiberError);

    /* Types */
    MyPyModule_AddType(fibers, "Fiber", &FiberType);

    /* Module version (the MODULE_VERSION macro is defined by setup.py) */
    PyModule_AddStringConstant(fibers, "__version__", STRINGIFY(MODULE_VERSION));

    return fibers;

fail:
#if PY_MAJOR_VERSION >= 3
    Py_DECREF(fibers);
#endif
    return NULL;

}
Ejemplo n.º 30
0
static void
psyco_errors_init(void)
{
    /* the names of the exceptions here reflect the oranization of the
       psycopg2 module and not the fact the the original error objects
       live in _psycopg */

    int i;
    PyObject *dict;
    PyObject *base;
    PyObject *str;

    for (i=0; exctable[i].name; i++) {
        dict = PyDict_New();

        if (exctable[i].docstr) {
            str = Text_FromUTF8(exctable[i].docstr);
            PyDict_SetItemString(dict, "__doc__", str);
        }

        if (exctable[i].base == 0) {
            #if PY_MAJOR_VERSION < 3
            base = PyExc_StandardError;
            #else
            /* StandardError is gone in 3.0 */
            base = NULL;
            #endif
        }
        else
            base = *exctable[i].base;

        *exctable[i].exc = PyErr_NewException(exctable[i].name, base, dict);
    }

    /* Make pgerror, pgcode and cursor default to None on psycopg
       error objects.  This simplifies error handling code that checks
       these attributes. */
    PyObject_SetAttrString(Error, "pgerror", Py_None);
    PyObject_SetAttrString(Error, "pgcode", Py_None);
    PyObject_SetAttrString(Error, "cursor", Py_None);
}