Example #1
0
static PyObject* PyMinqlx_InitModule(void) {
    PyObject* module = PyModule_Create(&minqlxModule);
    
    // Set minqlx version.
    PyModule_AddStringConstant(module, "__version__", MINQLX_VERSION);
    
    // Set IS_DEBUG.
    #ifdef DEBUG
    PyModule_AddObject(module, "DEBUG", Py_True);
    #else
    PyModule_AddObject(module, "DEBUG", Py_False);
    #endif
    
    // Set a bunch of constants. We set them here because if you define functions in Python that use module
    // constants as keyword defaults, we have to always make sure they're exported first, and f**k that.
    PyModule_AddIntMacro(module, RET_NONE);
    PyModule_AddIntMacro(module, RET_STOP);
    PyModule_AddIntMacro(module, RET_STOP_EVENT);
    PyModule_AddIntMacro(module, RET_STOP_ALL);
    PyModule_AddIntMacro(module, RET_USAGE);
    PyModule_AddIntMacro(module, PRI_HIGHEST);
    PyModule_AddIntMacro(module, PRI_HIGH);
    PyModule_AddIntMacro(module, PRI_NORMAL);
    PyModule_AddIntMacro(module, PRI_LOW);
    PyModule_AddIntMacro(module, PRI_LOWEST);
    
    return module;
}
Example #2
0
static void
init_macros(PyObject *mod)
{
	PyModule_AddIntMacro(mod, UCL_EMIT_JSON);
	PyModule_AddIntMacro(mod, UCL_EMIT_JSON_COMPACT);
	PyModule_AddIntMacro(mod, UCL_EMIT_CONFIG);
	PyModule_AddIntMacro(mod, UCL_EMIT_YAML);
	PyModule_AddIntMacro(mod, UCL_EMIT_MSGPACK);
}
Example #3
0
PyMODINIT_FUNC
PyInit_blosc_extension(void) {
  PyObject *m = PyModule_Create(&blosc_def);

  /* Integer macros */
  PyModule_AddIntMacro(m, BLOSC_MAX_BUFFERSIZE);
  PyModule_AddIntMacro(m, BLOSC_MAX_THREADS);
  PyModule_AddIntMacro(m, BLOSC_MAX_TYPESIZE);

  /* String macros */
  PyModule_AddStringMacro(m, BLOSC_VERSION_STRING);
  PyModule_AddStringMacro(m, BLOSC_VERSION_DATE);

  return m;
}
Example #4
0
PyMODINIT_FUNC initdl(void)
#endif
{
  PyObject *m = NULL;

#if PY_MAJOR_VERSION >= 3
  m = PyModule_Create(&dl_module);
#else
  m = Py_InitModule3((char *)"dl", dl_methods, (char *)dl_doc);
#endif
  if (!m) goto bad;

  if (PyModule_AddIntMacro(m, RTLD_LAZY   ) < 0) goto bad;
  if (PyModule_AddIntMacro(m, RTLD_NOW    ) < 0) goto bad;
  if (PyModule_AddIntMacro(m, RTLD_LOCAL  ) < 0) goto bad;
  if (PyModule_AddIntMacro(m, RTLD_GLOBAL ) < 0) goto bad;

#ifdef RTLD_NOLOAD
  if (PyModule_AddIntMacro(m, RTLD_NOLOAD   ) < 0) goto bad;
#endif
#ifdef RTLD_NODELETE
  if (PyModule_AddIntMacro(m, RTLD_NODELETE ) < 0) goto bad;
#endif
#ifdef RTLD_DEEPBIND
  if (PyModule_AddIntMacro(m, RTLD_DEEPBIND ) < 0) goto bad;
#endif
#ifdef RTLD_FIRST
  if (PyModule_AddIntMacro(m, RTLD_FIRST    ) < 0) goto bad;
#endif

#ifdef RTLD_DEFAULT
  if (PyModule_AddPtrMacro(m, RTLD_DEFAULT)   < 0) goto bad;
#endif
#ifdef RTLD_NEXT
  if (PyModule_AddPtrMacro(m, RTLD_NEXT)      < 0) goto bad;
#endif

#ifdef RTLD_SELF
  if (PyModule_AddPtrMacro(m, RTLD_SELF)      < 0) goto bad;
#endif
#ifdef RTLD_MAIN_ONLY
  if (PyModule_AddPtrMacro(m, RTLD_MAIN_ONLY) < 0) goto bad;
#endif

 finally:
#if PY_MAJOR_VERSION >= 3
  return m;
#else
  return;
#endif

 bad:
  Py_XDECREF(m);
  m = NULL;
  goto finally;
}
Example #5
0
PyMODINIT_FUNC initmouse(void)
{
	PyObject *mod;
#ifdef PYTHREE
	mod = PyModule_Create(&mousemodule);
#else
	mod = Py_InitModule3("mouse", MouseMethods,
	                               "autopy module for working with the mouse");
#endif
	if (mod == NULL) return; /* Error */

	/* Add mouse button constants for click_mouse(). */
	if (PyModule_AddIntMacro(mod, LEFT_BUTTON) < 0
			|| PyModule_AddIntMacro(mod, RIGHT_BUTTON) < 0
			|| PyModule_AddIntMacro(mod, CENTER_BUTTON) < 0
			|| PyModule_AddIntMacro(mod, SCROLL_UP_BUTTON) < 0
			|| PyModule_AddIntMacro(mod, SCROLL_DOWN_BUTTON) < 0
			|| PyModule_AddIntMacro(mod, SCROLL_LEFT_BUTTON) < 0
			|| PyModule_AddIntMacro(mod, SCROLL_RIGHT_BUTTON) < 0
			) {
		PyErr_SetString(PyExc_ValueError, "Error adding constants to mouse module");
		return;
	}

	deadbeef_srand_time();
#ifdef PYTHREE
	return mod;
#endif
}
Example #6
0
void initftpparse() {
    PyObject * m = Py_InitModule("ftpparse", _Methods);

    PyModule_AddIntMacro(m, FTPPARSE_SIZE_UNKNOWN);
    PyModule_AddIntMacro(m, FTPPARSE_SIZE_BINARY);
    PyModule_AddIntMacro(m, FTPPARSE_SIZE_ASCII);
    
    PyModule_AddIntMacro(m, FTPPARSE_MTIME_UNKNOWN);
    PyModule_AddIntMacro(m, FTPPARSE_MTIME_LOCAL);
    PyModule_AddIntMacro(m, FTPPARSE_MTIME_REMOTEMINUTE);
    PyModule_AddIntMacro(m, FTPPARSE_MTIME_REMOTEDAY);

    PyModule_AddIntMacro(m, FTPPARSE_ID_UNKNOWN);
    PyModule_AddIntMacro(m, FTPPARSE_ID_FULL);
}
Example #7
0
//-------------------------------------------------------------------------------------
void Baseapp::onInstallPyModules()
{
	// 添加globalData, globalBases支持
	pGlobalBases_ = new GlobalDataClient(DBMGR_TYPE, GlobalDataServer::GLOBAL_BASES);
	registerPyObjectToScript("globalBases", pGlobalBases_);

	if(PyModule_AddIntMacro(this->getScript().getModule(), LOG_ON_REJECT))
	{
		ERROR_MSG( "Baseapp::onInstallPyModules: Unable to set KBEngine.LOG_ON_REJECT.\n");
	}

	if(PyModule_AddIntMacro(this->getScript().getModule(), LOG_ON_ACCEPT))
	{
		ERROR_MSG( "Baseapp::onInstallPyModules: Unable to set KBEngine.LOG_ON_ACCEPT.\n");
	}

	if(PyModule_AddIntMacro(this->getScript().getModule(), LOG_ON_WAIT_FOR_DESTROY))
	{
		ERROR_MSG( "Baseapp::onInstallPyModules: Unable to set KBEngine.LOG_ON_WAIT_FOR_DESTROY.\n");
	}
}
Example #8
0
/* Python 2 module initialization */
PyMODINIT_FUNC
initblosc_extension(void)
{
  PyObject *m;
  m = Py_InitModule("blosc_extension", blosc_methods);
  if (m == NULL)
    return;

  BloscError = PyErr_NewException("blosc_extension.error", NULL, NULL);
  if (BloscError != NULL) {
    Py_INCREF(BloscError);
    PyModule_AddObject(m, "error", BloscError);
  }

  /* Integer macros */
  PyModule_AddIntMacro(m, BLOSC_MAX_BUFFERSIZE);
  PyModule_AddIntMacro(m, BLOSC_MAX_THREADS);
  PyModule_AddIntMacro(m, BLOSC_MAX_TYPESIZE);
  PyModule_AddIntMacro(m, BLOSC_NOSHUFFLE);
  PyModule_AddIntMacro(m, BLOSC_SHUFFLE);
  PyModule_AddIntMacro(m, BLOSC_BITSHUFFLE);

  /* String macros */
  PyModule_AddStringMacro(m, BLOSC_VERSION_STRING);
  PyModule_AddStringMacro(m, BLOSC_VERSION_DATE);

}
Example #9
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);
}
Example #10
0
PyMODINIT_FUNC
init_io(void)
{
    PyObject *m = Py_InitModule4("_io", module_methods,
                                 module_doc, NULL, PYTHON_API_VERSION);
    if (m == NULL)
        return;

    /* put os in the module state */
    _PyIO_os_module = PyImport_ImportModule("os");
    if (_PyIO_os_module == NULL)
        goto fail;

#define ADD_TYPE(type, name) \
    if (PyType_Ready(type) < 0) \
        goto fail; \
    Py_INCREF(type); \
    if (PyModule_AddObject(m, name, (PyObject *)type) < 0) {  \
        Py_DECREF(type); \
        goto fail; \
    }

    /* DEFAULT_BUFFER_SIZE */
    if (PyModule_AddIntMacro(m, DEFAULT_BUFFER_SIZE) < 0)
        goto fail;

    /* UnsupportedOperation inherits from ValueError and IOError */
    _PyIO_unsupported_operation = PyObject_CallFunction(
        (PyObject *)&PyType_Type, "s(OO){}",
        "UnsupportedOperation", PyExc_ValueError, PyExc_IOError);
    if (_PyIO_unsupported_operation == NULL)
        goto fail;
    Py_INCREF(_PyIO_unsupported_operation);
    if (PyModule_AddObject(m, "UnsupportedOperation",
                           _PyIO_unsupported_operation) < 0)
        goto fail;

    /* BlockingIOError */
    _PyExc_BlockingIOError.tp_base = (PyTypeObject *) PyExc_IOError;
    ADD_TYPE(&_PyExc_BlockingIOError, "BlockingIOError");

    /* Concrete base types of the IO ABCs.
       (the ABCs themselves are declared through inheritance in io.py)
    */
    ADD_TYPE(&PyIOBase_Type, "_IOBase");
    ADD_TYPE(&PyRawIOBase_Type, "_RawIOBase");
    ADD_TYPE(&PyBufferedIOBase_Type, "_BufferedIOBase");
    ADD_TYPE(&PyTextIOBase_Type, "_TextIOBase");

    /* Implementation of concrete IO objects. */
    /* FileIO */
    PyFileIO_Type.tp_base = &PyRawIOBase_Type;
    ADD_TYPE(&PyFileIO_Type, "FileIO");

    /* BytesIO */
    PyBytesIO_Type.tp_base = &PyBufferedIOBase_Type;
    ADD_TYPE(&PyBytesIO_Type, "BytesIO");

    /* StringIO */
    PyStringIO_Type.tp_base = &PyTextIOBase_Type;
    ADD_TYPE(&PyStringIO_Type, "StringIO");

    /* BufferedReader */
    PyBufferedReader_Type.tp_base = &PyBufferedIOBase_Type;
    ADD_TYPE(&PyBufferedReader_Type, "BufferedReader");

    /* BufferedWriter */
    PyBufferedWriter_Type.tp_base = &PyBufferedIOBase_Type;
    ADD_TYPE(&PyBufferedWriter_Type, "BufferedWriter");

    /* BufferedRWPair */
    PyBufferedRWPair_Type.tp_base = &PyBufferedIOBase_Type;
    ADD_TYPE(&PyBufferedRWPair_Type, "BufferedRWPair");

    /* BufferedRandom */
    PyBufferedRandom_Type.tp_base = &PyBufferedIOBase_Type;
    ADD_TYPE(&PyBufferedRandom_Type, "BufferedRandom");

    /* TextIOWrapper */
    PyTextIOWrapper_Type.tp_base = &PyTextIOBase_Type;
    ADD_TYPE(&PyTextIOWrapper_Type, "TextIOWrapper");

    /* IncrementalNewlineDecoder */
    ADD_TYPE(&PyIncrementalNewlineDecoder_Type, "IncrementalNewlineDecoder");

    /* Interned strings */
    if (!(_PyIO_str_close = PyString_InternFromString("close")))
        goto fail;
    if (!(_PyIO_str_closed = PyString_InternFromString("closed")))
        goto fail;
    if (!(_PyIO_str_decode = PyString_InternFromString("decode")))
        goto fail;
    if (!(_PyIO_str_encode = PyString_InternFromString("encode")))
        goto fail;
    if (!(_PyIO_str_fileno = PyString_InternFromString("fileno")))
        goto fail;
    if (!(_PyIO_str_flush = PyString_InternFromString("flush")))
        goto fail;
    if (!(_PyIO_str_getstate = PyString_InternFromString("getstate")))
        goto fail;
    if (!(_PyIO_str_isatty = PyString_InternFromString("isatty")))
        goto fail;
    if (!(_PyIO_str_newlines = PyString_InternFromString("newlines")))
        goto fail;
    if (!(_PyIO_str_nl = PyString_InternFromString("\n")))
        goto fail;
    if (!(_PyIO_str_read = PyString_InternFromString("read")))
        goto fail;
    if (!(_PyIO_str_read1 = PyString_InternFromString("read1")))
        goto fail;
    if (!(_PyIO_str_readable = PyString_InternFromString("readable")))
        goto fail;
    if (!(_PyIO_str_readinto = PyString_InternFromString("readinto")))
        goto fail;
    if (!(_PyIO_str_readline = PyString_InternFromString("readline")))
        goto fail;
    if (!(_PyIO_str_reset = PyString_InternFromString("reset")))
        goto fail;
    if (!(_PyIO_str_seek = PyString_InternFromString("seek")))
        goto fail;
    if (!(_PyIO_str_seekable = PyString_InternFromString("seekable")))
        goto fail;
    if (!(_PyIO_str_setstate = PyString_InternFromString("setstate")))
        goto fail;
    if (!(_PyIO_str_tell = PyString_InternFromString("tell")))
        goto fail;
    if (!(_PyIO_str_truncate = PyString_InternFromString("truncate")))
        goto fail;
    if (!(_PyIO_str_write = PyString_InternFromString("write")))
        goto fail;
    if (!(_PyIO_str_writable = PyString_InternFromString("writable")))
        goto fail;
    
    if (!(_PyIO_empty_str = PyUnicode_FromStringAndSize(NULL, 0)))
        goto fail;
    if (!(_PyIO_empty_bytes = PyBytes_FromStringAndSize(NULL, 0)))
        goto fail;
    if (!(_PyIO_zero = PyLong_FromLong(0L)))
        goto fail;

    return;

  fail:
    Py_CLEAR(_PyIO_os_module);
    Py_CLEAR(_PyIO_unsupported_operation);
    Py_DECREF(m);
}
Example #11
0
File: pyuv.c Project: benoitc/pyuv
/* Module */
PyObject*
init_pyuv(void)
{
    /* Modules */
    PyObject *pyuv;
    PyObject *errno_module;
    PyObject *error_module;
    PyObject *fs_module;
    PyObject *util_module;

    /* Initialize GIL */
    PyEval_InitThreads();

#ifdef PYUV_WINDOWS
    if (pyuv_setmaxstdio()) {
        return NULL;
    }
#endif

    /* Main module */
#ifdef PYUV_PYTHON3
    pyuv = PyModule_Create(&pyuv_module);
#else
    pyuv = Py_InitModule("pyuv", NULL);
#endif

    /* Errno module */
    errno_module = init_errno();
    if (errno_module == NULL) {
        goto fail;
    }
    PyUVModule_AddObject(pyuv, "errno", errno_module);
#ifdef PYUV_PYTHON3
    PyDict_SetItemString(PyImport_GetModuleDict(), pyuv_errno_module.m_name, errno_module);
    Py_DECREF(errno_module);
#endif

    /* Error module */
    error_module = init_error();
    if (error_module == NULL) {
        goto fail;
    }
    PyUVModule_AddObject(pyuv, "error", error_module);
#ifdef PYUV_PYTHON3
    PyDict_SetItemString(PyImport_GetModuleDict(), pyuv_error_module.m_name, error_module);
    Py_DECREF(error_module);
#endif

    /* FS module */
    fs_module = init_fs();
    if (fs_module == NULL) {
        goto fail;
    }
    PyUVModule_AddObject(pyuv, "fs", fs_module);
#ifdef PYUV_PYTHON3
    PyDict_SetItemString(PyImport_GetModuleDict(), pyuv_fs_module.m_name, fs_module);
    Py_DECREF(fs_module);
#endif

    /* Util module */
    util_module = init_util();
    if (util_module == NULL) {
        goto fail;
    }
    PyUVModule_AddObject(pyuv, "util", util_module);
#ifdef PYUV_PYTHON3
    PyDict_SetItemString(PyImport_GetModuleDict(), pyuv_util_module.m_name, util_module);
    Py_DECREF(util_module);
#endif

    /* Types */
    AsyncType.tp_base = &HandleType;
    TimerType.tp_base = &HandleType;
    PrepareType.tp_base = &HandleType;
    IdleType.tp_base = &HandleType;
    CheckType.tp_base = &HandleType;
    SignalType.tp_base = &HandleType;
    UDPType.tp_base = &HandleType;
    PollType.tp_base = &HandleType;
    ProcessType.tp_base = &HandleType;

    StreamType.tp_base = &HandleType;
    TCPType.tp_base = &StreamType;
    PipeType.tp_base = &StreamType;
    TTYType.tp_base = &StreamType;

    PyUVModule_AddType(pyuv, "Loop", &LoopType);
    PyUVModule_AddType(pyuv, "Async", &AsyncType);
    PyUVModule_AddType(pyuv, "Timer", &TimerType);
    PyUVModule_AddType(pyuv, "Prepare", &PrepareType);
    PyUVModule_AddType(pyuv, "Idle", &IdleType);
    PyUVModule_AddType(pyuv, "Check", &CheckType);
    PyUVModule_AddType(pyuv, "Signal", &SignalType);
    PyUVModule_AddType(pyuv, "TCP", &TCPType);
    PyUVModule_AddType(pyuv, "Pipe", &PipeType);
    PyUVModule_AddType(pyuv, "TTY", &TTYType);
    PyUVModule_AddType(pyuv, "UDP", &UDPType);
    PyUVModule_AddType(pyuv, "Poll", &PollType);
    PyUVModule_AddType(pyuv, "StdIO", &StdIOType);
    PyUVModule_AddType(pyuv, "Process", &ProcessType);
    PyUVModule_AddType(pyuv, "ThreadPool", &ThreadPoolType);
    PyUVModule_AddType(pyuv, "SignalChecker", &SignalCheckerType);

    /* UDP constants */
    PyModule_AddIntMacro(pyuv, UV_JOIN_GROUP);
    PyModule_AddIntMacro(pyuv, UV_LEAVE_GROUP);

    /* Process constants */
    PyModule_AddIntMacro(pyuv, UV_PROCESS_SETUID);
    PyModule_AddIntMacro(pyuv, UV_PROCESS_SETGID);
    PyModule_AddIntMacro(pyuv, UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS);
    PyModule_AddIntMacro(pyuv, UV_PROCESS_DETACHED);
    PyModule_AddIntMacro(pyuv, UV_IGNORE);
    PyModule_AddIntMacro(pyuv, UV_CREATE_PIPE);
    PyModule_AddIntMacro(pyuv, UV_READABLE_PIPE);
    PyModule_AddIntMacro(pyuv, UV_WRITABLE_PIPE);
    PyModule_AddIntMacro(pyuv, UV_INHERIT_FD);
    PyModule_AddIntMacro(pyuv, UV_INHERIT_STREAM);

    /* Poll constants */
    PyModule_AddIntMacro(pyuv, UV_READABLE);
    PyModule_AddIntMacro(pyuv, UV_WRITABLE);

    /* Handle types */
    PyModule_AddIntMacro(pyuv, UV_UNKNOWN_HANDLE);
#define XX(uc, lc) PyModule_AddIntMacro(pyuv, UV_##uc);
    UV_HANDLE_TYPE_MAP(XX)
#undef XX

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

    /* libuv version */
    PyModule_AddStringConstant(pyuv, "LIBUV_VERSION", __MSTR(LIBUV_VERSION));

    return pyuv;

fail:
#ifdef PYUV_PYTHON3
    Py_DECREF(pyuv);
#endif
    return NULL;

}
Example #12
0
File: glpk.c Project: ugonj/cvxopt
static PyObject *integer(PyObject *self, PyObject *args,
    PyObject *kwrds)
{
    matrix *c, *h, *b=NULL, *x=NULL;
    PyObject *G, *A=NULL, *IntSet=NULL, *BinSet = NULL;
    PyObject *t=NULL;
    pyiocp *iocpParm = NULL;;
    glp_iocp *options = NULL;
    glp_prob *lp;
    int m, n, p, i, j, k, nnz, nnzmax, *rn=NULL, *cn=NULL;
    double *a=NULL, val;
    char *kwlist[] = {"c", "G", "h", "A", "b", "I", "B","iocp", NULL};

    if (!PyArg_ParseTupleAndKeywords(args, kwrds, "OOO|OOOOO!", kwlist, &c,
	    &G, &h, &A, &b, &IntSet, &BinSet,iocp_t,&iocpParm)) return NULL;

    if(!iocpParm) 
    {
      iocpParm = (pyiocp*)malloc(sizeof(*iocpParm));
      glp_init_iocp(&(iocpParm->obj));
    }
    if(iocpParm) 
    {
      Py_INCREF(iocpParm);
      options = &iocpParm->obj;
      options->presolve = 1;
    }

    if ((Matrix_Check(G) && MAT_ID(G) != DOUBLE) ||
        (SpMatrix_Check(G) && SP_ID(G) != DOUBLE) ||
        (!Matrix_Check(G) && !SpMatrix_Check(G))){
        PyErr_SetString(PyExc_TypeError, "G must be a 'd' matrix");
        return NULL;
    }
    if ((m = Matrix_Check(G) ? MAT_NROWS(G) : SP_NROWS(G)) <= 0)
        err_p_int("m");
    if ((n = Matrix_Check(G) ? MAT_NCOLS(G) : SP_NCOLS(G)) <= 0)
        err_p_int("n");

    if (!Matrix_Check(h) || h->id != DOUBLE) err_dbl_mtrx("h");
    if (h->nrows != m || h->ncols != 1){
        PyErr_SetString(PyExc_ValueError, "incompatible dimensions");
        return NULL;
    }

    if (A){
        if ((Matrix_Check(A) && MAT_ID(A) != DOUBLE) ||
            (SpMatrix_Check(A) && SP_ID(A) != DOUBLE) ||
            (!Matrix_Check(A) && !SpMatrix_Check(A))){
                PyErr_SetString(PyExc_ValueError, "A must be a dense "
                    "'d' matrix or a general sparse matrix");
                return NULL;
	}
        if ((p = Matrix_Check(A) ? MAT_NROWS(A) : SP_NROWS(A)) < 0)
            err_p_int("p");
        if ((Matrix_Check(A) ? MAT_NCOLS(A) : SP_NCOLS(A)) != n){
            PyErr_SetString(PyExc_ValueError, "incompatible "
                "dimensions");
            return NULL;
	}
    }
    else p = 0;

    if (b && (!Matrix_Check(b) || b->id != DOUBLE)) err_dbl_mtrx("b");
    if ((b && (b->nrows != p || b->ncols != 1)) || (!b && p !=0 )){
        PyErr_SetString(PyExc_ValueError, "incompatible dimensions");
        return NULL;
    }

    if ((IntSet) && (!PyAnySet_Check(IntSet)))
      PY_ERR_TYPE("invalid integer index set");

    if ((BinSet) && (!PyAnySet_Check(BinSet)))
      PY_ERR_TYPE("invalid binary index set");

    lp = glp_create_prob();
    glp_add_rows(lp, m+p);
    glp_add_cols(lp, n);

    for (i=0; i<n; i++){
        glp_set_obj_coef(lp, i+1, MAT_BUFD(c)[i]);
        glp_set_col_bnds(lp, i+1, GLP_FR, 0.0, 0.0);
    }
    for (i=0; i<m; i++)
        glp_set_row_bnds(lp, i+1, GLP_UP, 0.0, MAT_BUFD(h)[i]);
    for (i=0; i<p; i++)
        glp_set_row_bnds(lp, i+m+1, GLP_FX, MAT_BUFD(b)[i],
            MAT_BUFD(b)[i]);

    nnzmax = (SpMatrix_Check(G) ? SP_NNZ(G) : m*n ) +
        ((A && SpMatrix_Check(A)) ? SP_NNZ(A) : p*n);
    a = (double *) calloc(nnzmax+1, sizeof(double));
    rn = (int *) calloc(nnzmax+1, sizeof(int));
    cn = (int *) calloc(nnzmax+1, sizeof(int));
    if (!a || !rn || !cn){
        free(a);  free(rn);  free(cn);  glp_delete_prob(lp);
        return PyErr_NoMemory();
    }

    nnz = 0;
    if (SpMatrix_Check(G)) {
        for (j=0; j<n; j++) for (k=SP_COL(G)[j]; k<SP_COL(G)[j+1]; k++)
            if ((val = SP_VALD(G)[k]) != 0.0){
                a[1+nnz] = val;
                rn[1+nnz] = SP_ROW(G)[k]+1;
                cn[1+nnz] = j+1;
                nnz++;
            }
    }
    else for (j=0; j<n; j++) for (i=0; i<m; i++)
        if ((val = MAT_BUFD(G)[i+j*m]) != 0.0){
            a[1+nnz] = val;
            rn[1+nnz] = i+1;
            cn[1+nnz] = j+1;
            nnz++;
        }

    if (A && SpMatrix_Check(A)){
        for (j=0; j<n; j++) for (k=SP_COL(A)[j]; k<SP_COL(A)[j+1]; k++)
            if ((val = SP_VALD(A)[k]) != 0.0){
                a[1+nnz] = val;
                rn[1+nnz] = m+SP_ROW(A)[k]+1;
                cn[1+nnz] = j+1;
                nnz++;
            }
    }
    else for (j=0; j<n; j++) for (i=0; i<p; i++)
        if ((val = MAT_BUFD(A)[i+j*p]) != 0.0){
            a[1+nnz] = val;
            rn[1+nnz] = m+i+1;
            cn[1+nnz] = j+1;
            nnz++;
        }

    glp_load_matrix(lp, nnz, rn, cn, a);
    free(rn);  free(cn);  free(a);

    if (!(t = PyTuple_New(2))) {
        glp_delete_prob(lp);
        return PyErr_NoMemory();
    }

    if (IntSet) {
      PyObject *iter = PySequence_Fast(IntSet, "Critical error: not sequence");

      for (i=0; i<PySet_GET_SIZE(IntSet); i++) {

	PyObject *tmp = PySequence_Fast_GET_ITEM(iter, i);
#if PY_MAJOR_VERSION >= 3
	if (!PyLong_Check(tmp)) {
#else
	if (!PyInt_Check(tmp)) {
#endif
	  glp_delete_prob(lp);
	  Py_DECREF(iter);
	  PY_ERR_TYPE("non-integer element in I");
	}
#if PY_MAJOR_VERSION >= 3
	int k = PyLong_AS_LONG(tmp);
#else
	int k = PyInt_AS_LONG(tmp);
#endif
	if ((k < 0) || (k >= n)) {
	  glp_delete_prob(lp);
	  Py_DECREF(iter);
	  PY_ERR(PyExc_IndexError, "index element out of range in I");
	}
	glp_set_col_kind(lp, k+1, GLP_IV);
      }

      Py_DECREF(iter);
    }

    if (BinSet) {
      PyObject *iter = PySequence_Fast(BinSet, "Critical error: not sequence");

      for (i=0; i<PySet_GET_SIZE(BinSet); i++) {

	PyObject *tmp = PySequence_Fast_GET_ITEM(iter, i);
#if PY_MAJOR_VERSION >= 3
	if (!PyLong_Check(tmp)) {
#else
	if (!PyInt_Check(tmp)) {
#endif
	  glp_delete_prob(lp);
	  Py_DECREF(iter);
	  PY_ERR_TYPE("non-binary element in I");
	}
#if PY_MAJOR_VERSION >= 3
	int k = PyLong_AS_LONG(tmp);
#else
	int k = PyInt_AS_LONG(tmp);
#endif
	if ((k < 0) || (k >= n)) {
	  glp_delete_prob(lp);
	  Py_DECREF(iter);
	  PY_ERR(PyExc_IndexError, "index element out of range in B");
	}
	glp_set_col_kind(lp, k+1, GLP_BV);
      }

      Py_DECREF(iter);

    }


      switch (glp_intopt(lp,options)){

          case 0:

              x = (matrix *) Matrix_New(n,1,DOUBLE);
              if (!x) {
                  Py_XDECREF(iocpParm);
                  Py_XDECREF(t);
                  glp_delete_prob(lp);
                  return PyErr_NoMemory();
              }
              set_output_string(t,"optimal");
              set_output_string(t,"optimal");

              for (i=0; i<n; i++)
                  MAT_BUFD(x)[i] = glp_mip_col_val(lp, i+1);
              PyTuple_SET_ITEM(t, 1, (PyObject *) x);

              Py_XDECREF(iocpParm);
              glp_delete_prob(lp);
              return (PyObject *) t;

          case GLP_ETMLIM:

              x = (matrix *) Matrix_New(n,1,DOUBLE);
              if (!x) {
                  Py_XDECREF(t);
                  Py_XDECREF(iocpParm);
                  glp_delete_prob(lp);
                  return PyErr_NoMemory();
              }
              set_output_string(t,"time limit exceeded");

              for (i=0; i<n; i++)
                  MAT_BUFD(x)[i] = glp_mip_col_val(lp, i+1);
              PyTuple_SET_ITEM(t, 1, (PyObject *) x);

              Py_XDECREF(iocpParm);
              glp_delete_prob(lp);
              return (PyObject *) t;


          case GLP_EBOUND:
              set_output_string(t,"incorrect bounds");
              break;
          case GLP_EFAIL:
              set_output_string(t,"invalid MIP formulation");
              break;

          case GLP_ENOPFS:
              set_output_string(t,"primal infeasible");
              break;

          case GLP_ENODFS:
              set_output_string(t,"dual infeasible");
              break;

          case GLP_EMIPGAP:
              set_output_string(t,"Relative mip gap tolerance reached");
              break;

              /*case LPX_E_ITLIM:

                set_output_string(t,"maxiters exceeded");
                break;*/

              /*case LPX_E_SING:

                set_output_string(t,"singular or ill-conditioned basis");
                break;*/


          default:

              set_output_string(t,"unknown");
      }

      Py_XDECREF(iocpParm);
    glp_delete_prob(lp);

    PyTuple_SET_ITEM(t, 1, Py_BuildValue(""));
    return (PyObject *) t;
}


static PyMethodDef glpk_functions[] = {
    {"lp", (PyCFunction) simplex, METH_VARARGS|METH_KEYWORDS,
        doc_simplex},
    {"ilp", (PyCFunction) integer, METH_VARARGS|METH_KEYWORDS,
        doc_integer},
    {NULL}  /* Sentinel */
};

#if PY_MAJOR_VERSION >= 3

static PyModuleDef glpk_module_def = {
    PyModuleDef_HEAD_INIT,
    "glpk",
    glpk__doc__,
    -1,
    glpk_functions,
    NULL, NULL, NULL, NULL
};

void addglpkConstants (void)
{
  PyModule_AddIntMacro(glpk_module, GLP_ON);
  PyModule_AddIntMacro(glpk_module,GLP_OFF);

  /* reason codes: */
  PyModule_AddIntMacro(glpk_module,GLP_IROWGEN);
  PyModule_AddIntMacro(glpk_module,GLP_IBINGO);
  PyModule_AddIntMacro(glpk_module,GLP_IHEUR);
  PyModule_AddIntMacro(glpk_module,GLP_ICUTGEN);
  PyModule_AddIntMacro(glpk_module,GLP_IBRANCH);
  PyModule_AddIntMacro(glpk_module,GLP_ISELECT);
  PyModule_AddIntMacro(glpk_module,GLP_IPREPRO);

  /* branch selection indicator: */
  PyModule_AddIntMacro(glpk_module,GLP_NO_BRNCH);
  PyModule_AddIntMacro(glpk_module,GLP_DN_BRNCH);
  PyModule_AddIntMacro(glpk_module,GLP_UP_BRNCH);

  /* return codes: */
  PyModule_AddIntMacro(glpk_module,GLP_EBADB);
  PyModule_AddIntMacro(glpk_module,GLP_ESING);
  PyModule_AddIntMacro(glpk_module,GLP_ECOND);
  PyModule_AddIntMacro(glpk_module,GLP_EBOUND);
  PyModule_AddIntMacro(glpk_module,GLP_EFAIL);
  PyModule_AddIntMacro(glpk_module,GLP_EOBJLL);
  PyModule_AddIntMacro(glpk_module,GLP_EOBJUL);
  PyModule_AddIntMacro(glpk_module,GLP_EITLIM);
  PyModule_AddIntMacro(glpk_module,GLP_ETMLIM);
  PyModule_AddIntMacro(glpk_module,GLP_ENOPFS);
  PyModule_AddIntMacro(glpk_module,GLP_ENODFS);
  PyModule_AddIntMacro(glpk_module,GLP_EROOT);
  PyModule_AddIntMacro(glpk_module,GLP_ESTOP);
  PyModule_AddIntMacro(glpk_module,GLP_EMIPGAP);
  PyModule_AddIntMacro(glpk_module,GLP_ENOFEAS);
  PyModule_AddIntMacro(glpk_module,GLP_ENOCVG);
  PyModule_AddIntMacro(glpk_module,GLP_EINSTAB);
  PyModule_AddIntMacro(glpk_module,GLP_EDATA);
  PyModule_AddIntMacro(glpk_module,GLP_ERANGE);

  /* condition indicator: */
  PyModule_AddIntMacro(glpk_module,GLP_KKT_PE);
  PyModule_AddIntMacro(glpk_module,GLP_KKT_PB);
  PyModule_AddIntMacro(glpk_module,GLP_KKT_DE);
  PyModule_AddIntMacro(glpk_module,GLP_KKT_DB);
  PyModule_AddIntMacro(glpk_module,GLP_KKT_CS);

  /* MPS file format: */
  PyModule_AddIntMacro(glpk_module,GLP_MPS_DECK);
  PyModule_AddIntMacro(glpk_module,GLP_MPS_FILE);

  /* simplex method control parameters */
  /* message level: */
  PyModule_AddIntMacro(glpk_module,GLP_MSG_OFF);
  PyModule_AddIntMacro(glpk_module,GLP_MSG_ERR);
  PyModule_AddIntMacro(glpk_module,GLP_MSG_ON);
  PyModule_AddIntMacro(glpk_module,GLP_MSG_ALL);
  PyModule_AddIntMacro(glpk_module,GLP_MSG_DBG);
  /* simplex method option: */
  PyModule_AddIntMacro(glpk_module,GLP_PRIMAL);
  PyModule_AddIntMacro(glpk_module,GLP_DUALP);
  PyModule_AddIntMacro(glpk_module,GLP_DUAL);
  /* pricing technique: */
  PyModule_AddIntMacro(glpk_module,GLP_PT_STD);
  PyModule_AddIntMacro(glpk_module,GLP_PT_PSE);
  /* ratio test technique: */
  PyModule_AddIntMacro(glpk_module,GLP_RT_STD);
  PyModule_AddIntMacro(glpk_module,GLP_RT_HAR);

  /* interior-point solver control parameters */
  /* ordering algorithm: */
  PyModule_AddIntMacro(glpk_module,GLP_ORD_NONE);
  PyModule_AddIntMacro(glpk_module,GLP_ORD_QMD);
  PyModule_AddIntMacro(glpk_module,GLP_ORD_AMD);
  PyModule_AddIntMacro(glpk_module,GLP_ORD_SYMAMD);
}

PyMODINIT_FUNC PyInit_glpk(void)
{
  if (!(glpk_module = PyModule_Create(&glpk_module_def))) return NULL;
  if (PyType_Ready(&iocp_t) < 0 || (PyType_Ready(&smcp_t) < 0)) return NULL;
  /*  Adding macros */
  addglpkConstants();
  /* Adding  option lists as objects */
  Py_INCREF(&smcp_t);
  PyModule_AddObject(glpk_module,"smcp",(PyObject*)&smcp_t);
  Py_INCREF(&iocp_t);
  PyModule_AddObject(glpk_module,"iocp",(PyObject*)&iocp_t);
  if (import_cvxopt() < 0) return NULL;
  return glpk_module;
}

#else

PyMODINIT_FUNC initglpk(void)
{
    glpk_module = Py_InitModule3("cvxopt.glpk", glpk_functions, 
            glpk__doc__);
    if (PyType_Ready(&iocp_t) < 0 || (PyType_Ready(&smcp_t) < 0)) return NULL;
    addglpkConstants();
    Py_INCREF(&smcp_t);
    PyModule_AddObject(glpk_module,"smcp",(PyObject*)&smcp_t);
    Py_INCREF(&iocp_t);
    PyModule_AddObject(glpk_module,"iocp",(PyObject*)&iocp_t);
    if (import_cvxopt() < 0) return;
}
Example #13
0
/* Code shared between 2.x and 3.x module initialization. */
static int
GeoIP_populate_module(PyObject *m)
{
    PyObject *tmp = NULL;
    PyObject *ccode = NULL;
    PyObject *cname = NULL;
    PyObject *ccont = NULL;
    size_t i;
    const size_t total_ccodes = sizeof(GeoIP_country_code) /
                                sizeof(GeoIP_country_code[0]);

#define CHECK(expr) do { if (expr) { goto fail; } } while (0)
#define CHECK_NULL(expr) do { if (!(expr)) { goto fail; } } while (0)

    GeoIP_GeoIPType.tp_new = PyType_GenericNew;
    CHECK(PyType_Ready(&GeoIP_GeoIPType));
    Py_INCREF(&GeoIP_GeoIPType);
    CHECK(PyModule_AddObject(m, "GeoIP", (PyObject *)&GeoIP_GeoIPType));

    GeoIP_GeoIPError = PyErr_NewException("GeoIP.error", PyExc_OSError, NULL);
    Py_INCREF(GeoIP_GeoIPError);
    CHECK(PyModule_AddObject(m, "error", GeoIP_GeoIPError));

    CHECK_NULL(ccode = PyTuple_New(total_ccodes));
    CHECK_NULL(cname = PyDict_New());
    CHECK_NULL(ccont = PyDict_New());

    for (i = 0; i < total_ccodes; i++) {
        CHECK_NULL(tmp = PyUnicode_FromString(GeoIP_country_code[i]));
        PyTuple_SET_ITEM(ccode, i, tmp);

#if PY_MAJOR_VERSION >= 3
        CHECK_NULL(tmp = PyUnicode_FromString(GeoIP_utf8_country_name[i]));
#else
        CHECK_NULL(tmp = PyUnicode_FromString(GeoIP_country_name[i]));
#endif
        CHECK(PyDict_SetItemString(cname, GeoIP_country_code[i], tmp));
        Py_DECREF(tmp);

        CHECK_NULL(tmp = PyUnicode_FromString(GeoIP_country_continent[i]));
        CHECK(PyDict_SetItemString(ccont, GeoIP_country_code[i], tmp));
        Py_DECREF(tmp);
    }
    tmp = NULL;

    CHECK(PyModule_AddObject(m, "country_codes", ccode));
    CHECK(PyModule_AddObject(m, "country_names", cname));
    CHECK(PyModule_AddObject(m, "country_continents", ccont));

    CHECK(PyModule_AddIntMacro(m, GEOIP_STANDARD));
    CHECK(PyModule_AddIntMacro(m, GEOIP_MEMORY_CACHE));
    CHECK(PyModule_AddIntMacro(m, GEOIP_MMAP_CACHE));
    CHECK(PyModule_AddIntMacro(m, GEOIP_CHECK_CACHE));
    CHECK(PyModule_AddIntMacro(m, GEOIP_INDEX_CACHE));
    CHECK(PyModule_AddIntMacro(m, GEOIP_CHARSET_ISO_8859_1));
    CHECK(PyModule_AddIntMacro(m, GEOIP_CHARSET_UTF8));
    CHECK(PyModule_AddIntMacro(m, GEOIP_UNKNOWN_SPEED));
    CHECK(PyModule_AddIntMacro(m, GEOIP_DIALUP_SPEED));
    CHECK(PyModule_AddIntMacro(m, GEOIP_CABLEDSL_SPEED));
    CHECK(PyModule_AddIntMacro(m, GEOIP_CORPORATE_SPEED));

    return 0;

#undef CHECK
#undef CHECK_NULL

 fail:
    Py_XDECREF(ccode);
    Py_XDECREF(cname);
    Py_XDECREF(ccont);
    Py_XDECREF(tmp);
    Py_XDECREF(m);
    Py_XDECREF(GeoIP_GeoIPError); GeoIP_GeoIPError = NULL;
    return -1;
}
Example #14
0
static int
gcc_python_init_gcc_module(struct plugin_name_args *plugin_info)
{
    int i;

    if (!gcc_python_globals.module) {
        return 0;
    }

    /* Set up int constants for each of the enum plugin_event values: */
    #define DEFEVENT(NAME) \
       PyModule_AddIntMacro(gcc_python_globals.module, NAME);
    # include "plugin.def"
    # undef DEFEVENT

    gcc_python_globals.argument_dict = PyDict_New();
    if (!gcc_python_globals.argument_dict) {
        return 0;
    }

    gcc_python_globals.argument_tuple = PyTuple_New(plugin_info->argc);
    if (!gcc_python_globals.argument_tuple) {
        return 0;
    }

    /* PySys_SetArgvEx(plugin_info->argc, plugin_info->argv, 0); */
    for (i=0; i<plugin_info->argc; i++) {
	struct plugin_argument *arg = &plugin_info->argv[i];
        PyObject *key;
        PyObject *value;
	PyObject *pair;
      
	key = gcc_python_string_from_string(arg->key);
	if (arg->value) {
            value = gcc_python_string_from_string(plugin_info->argv[i].value);
	} else {
  	    value = Py_None;
	}
        PyDict_SetItem(gcc_python_globals.argument_dict, key, value);
	// FIXME: ref counts?

	pair = Py_BuildValue("(s, s)", arg->key, arg->value);
	if (!pair) {
  	    return 1;
	}
        PyTuple_SetItem(gcc_python_globals.argument_tuple, i, pair);

    }
    PyModule_AddObject(gcc_python_globals.module, "argument_dict", gcc_python_globals.argument_dict);
    PyModule_AddObject(gcc_python_globals.module, "argument_tuple", gcc_python_globals.argument_tuple);

    /* Pass properties: */
    PyModule_AddIntMacro(gcc_python_globals.module, PROP_gimple_any);
    PyModule_AddIntMacro(gcc_python_globals.module, PROP_gimple_lcf);
    PyModule_AddIntMacro(gcc_python_globals.module, PROP_gimple_leh);
    PyModule_AddIntMacro(gcc_python_globals.module, PROP_cfg);
    PyModule_AddIntMacro(gcc_python_globals.module, PROP_referenced_vars);
    PyModule_AddIntMacro(gcc_python_globals.module, PROP_ssa);
    PyModule_AddIntMacro(gcc_python_globals.module, PROP_no_crit_edges);
    PyModule_AddIntMacro(gcc_python_globals.module, PROP_rtl);
    PyModule_AddIntMacro(gcc_python_globals.module, PROP_gimple_lomp);
    PyModule_AddIntMacro(gcc_python_globals.module, PROP_cfglayout);
    PyModule_AddIntMacro(gcc_python_globals.module, PROP_gimple_lcx);

    /* Success: */
    return 1;
}
Example #15
0
File: htpy.c Project: 0rbytal/htpy
PyMODINIT_FUNC inithtpy(void) {
	PyObject *m;

	if (PyType_Ready(&htpy_config_type) < 0 || PyType_Ready(&htpy_connp_type) < 0)
		return;

	m = Py_InitModule3("htpy", htpy_methods, "Python interface to libhtp.");
	if (!m)
		return;

	htpy_error = PyErr_NewException("htpy.error", NULL, NULL);
	Py_INCREF(htpy_error);
	PyModule_AddObject(m, "error", htpy_error);

	htpy_stop = PyErr_NewException("htpy.stop", NULL, NULL);
	Py_INCREF(htpy_stop);
	PyModule_AddObject(m, "stop", htpy_stop);

	Py_INCREF(&htpy_config_type);
	PyModule_AddObject(m, "config", (PyObject *) &htpy_config_type);
	Py_INCREF(&htpy_connp_type);
	PyModule_AddObject(m, "connp", (PyObject *) &htpy_connp_type);

	PyModule_AddStringMacro(m, HTPY_VERSION);

	PyModule_AddIntMacro(m, HTP_ERROR);
	PyModule_AddIntMacro(m, HTP_OK);
	PyModule_AddIntMacro(m, HTP_STOP);
	PyModule_AddIntMacro(m, HTP_DATA);
	PyModule_AddIntMacro(m, HTP_DATA_OTHER);
	PyModule_AddIntMacro(m, HTP_DECLINED);

	PyModule_AddIntMacro(m, HTP_PROTOCOL_UNKNOWN);
	PyModule_AddIntMacro(m, HTP_PROTOCOL_0_9);
	PyModule_AddIntMacro(m, HTP_PROTOCOL_1_0);
	PyModule_AddIntMacro(m, HTP_PROTOCOL_1_1);

	PyModule_AddIntMacro(m, HTP_COMPRESSION_NONE);
	PyModule_AddIntMacro(m, HTP_COMPRESSION_GZIP);
	PyModule_AddIntMacro(m, HTP_COMPRESSION_DEFLATE);

	PyModule_AddIntMacro(m, HTP_LOG_ERROR);
	PyModule_AddIntMacro(m, HTP_LOG_WARNING);
	PyModule_AddIntMacro(m, HTP_LOG_NOTICE);
	PyModule_AddIntMacro(m, HTP_LOG_INFO);
	PyModule_AddIntMacro(m, HTP_LOG_DEBUG);
	PyModule_AddIntMacro(m, HTP_LOG_DEBUG2);

	PyModule_AddIntMacro(m, HTP_STREAM_NEW);
	PyModule_AddIntMacro(m, HTP_STREAM_OPEN);
	PyModule_AddIntMacro(m, HTP_STREAM_CLOSED);
	PyModule_AddIntMacro(m, HTP_STREAM_ERROR);
	PyModule_AddIntMacro(m, HTP_STREAM_TUNNEL);
	PyModule_AddIntMacro(m, HTP_STREAM_DATA_OTHER);
	PyModule_AddIntMacro(m, HTP_STREAM_DATA);
	PyModule_AddIntMacro(m, HTP_STREAM_STOP);
}
Example #16
0
PyMODINIT_FUNC init_pyejdb(void) {
    PyObject *pyejdb;
    if (PyType_Ready(&EJDBType) ||
            PyType_Ready(&DBCursorType)
            ) {
        INITERROR;
    }

#if PY_MAJOR_VERSION >= 3
    pyejdb = PyModule_Create(&pyejdb_module);
#else
    pyejdb = Py_InitModule("_pyejdb", pyejdb_m_methods);
#endif

    if (!pyejdb) {
        INITERROR;
    }
    Error = PyErr_NewException("_pyejdb.Error", NULL, NULL);
    Py_XINCREF(Error);
    if (!Error || PyModule_AddObject(pyejdb, "Error", Error)) {
        Py_XDECREF(Error);
        goto fail;
    }

    /* adding types and constants */
    if (
            PyModule_AddType(pyejdb, "EJDB", &EJDBType) ||
            PyModule_AddType(pyejdb, "DBCursor", &DBCursorType) ||

            PyModule_AddIntMacro(pyejdb, JBOREADER) ||
            PyModule_AddIntMacro(pyejdb, JBOWRITER) ||
            PyModule_AddIntMacro(pyejdb, JBOCREAT) ||
            PyModule_AddIntMacro(pyejdb, JBOTRUNC) ||
            PyModule_AddIntMacro(pyejdb, JBONOLCK) ||
            PyModule_AddIntMacro(pyejdb, JBOLCKNB) ||
            PyModule_AddIntMacro(pyejdb, JBOTSYNC) ||

            PyModule_AddIntMacro(pyejdb, JBIDXDROP) ||
            PyModule_AddIntMacro(pyejdb, JBIDXDROPALL) ||
            PyModule_AddIntMacro(pyejdb, JBIDXOP) ||
            PyModule_AddIntMacro(pyejdb, JBIDXREBLD) ||
            PyModule_AddIntMacro(pyejdb, JBIDXNUM) ||
            PyModule_AddIntMacro(pyejdb, JBIDXSTR) ||
            PyModule_AddIntMacro(pyejdb, JBIDXARR) ||
            PyModule_AddIntMacro(pyejdb, JBIDXISTR) ||

            PyModule_AddIntMacro(pyejdb, PYEJDBTXBEGIN) ||
            PyModule_AddIntMacro(pyejdb, PYEJDBTXABORT) ||
            PyModule_AddIntMacro(pyejdb, PYEJDBTXCOMMIT) ||
            PyModule_AddIntMacro(pyejdb, PYEJDBTXSTATUS) ||

            PyModule_AddIntMacro(pyejdb, JBQRYCOUNT)
            ) {

        goto fail;
    }

#if PY_MAJOR_VERSION >= 3
    return pyejdb;
#else
    return;
#endif

fail:
    Py_DECREF(pyejdb);
    INITERROR;
}
Example #17
0
PyObject* init_pyejdb(void) {
    PyObject *pyejdb;
    if (PyType_Ready(&EJDBType) ||
            PyType_Ready(&DBCursorType)
            ) {
        return NULL;
    }

    pyejdb = PyModule_Create(&pyejdb_module);
    if (!pyejdb) {
        return NULL;
    }
    Error = PyErr_NewException("_pyejdb.Error", NULL, NULL);
    Py_XINCREF(Error);
    if (!Error || PyModule_AddObject(pyejdb, "Error", Error)) {
        Py_XDECREF(Error);
        goto fail;
    }

    /* adding types and constants */
    if (
            PyModule_AddType(pyejdb, "EJDB", &EJDBType) ||
            PyModule_AddType(pyejdb, "DBCursor", &DBCursorType) ||

            PyModule_AddIntMacro(pyejdb, JBOREADER) ||
            PyModule_AddIntMacro(pyejdb, JBOWRITER) ||
            PyModule_AddIntMacro(pyejdb, JBOCREAT) ||
            PyModule_AddIntMacro(pyejdb, JBOTRUNC) ||
            PyModule_AddIntMacro(pyejdb, JBONOLCK) ||
            PyModule_AddIntMacro(pyejdb, JBOLCKNB) ||
            PyModule_AddIntMacro(pyejdb, JBOTSYNC) ||

            PyModule_AddIntMacro(pyejdb, JBIDXDROP) ||
            PyModule_AddIntMacro(pyejdb, JBIDXDROPALL) ||
            PyModule_AddIntMacro(pyejdb, JBIDXOP) ||
            PyModule_AddIntMacro(pyejdb, JBIDXREBLD) ||
            PyModule_AddIntMacro(pyejdb, JBIDXNUM) ||
            PyModule_AddIntMacro(pyejdb, JBIDXSTR) ||
            PyModule_AddIntMacro(pyejdb, JBIDXARR) ||
            PyModule_AddIntMacro(pyejdb, JBIDXISTR) ||

            PyModule_AddIntMacro(pyejdb, PYEJDBTXBEGIN) ||
            PyModule_AddIntMacro(pyejdb, PYEJDBTXABORT) ||
            PyModule_AddIntMacro(pyejdb, PYEJDBTXCOMMIT) ||
            PyModule_AddIntMacro(pyejdb, PYEJDBTXSTATUS) ||

            PyModule_AddIntMacro(pyejdb, JBQRYCOUNT)
            ) {

        goto fail;
    }

    return pyejdb;

fail:
    Py_DECREF(pyejdb);
    return NULL;
}
Example #18
0
PyMODINIT_FUNC
INIT_MODULE(_psycopg)(void)
{
#if PY_VERSION_HEX < 0x03020000
    static void *PSYCOPG_API[PSYCOPG_API_pointers];
    PyObject *c_api_object;
#endif

    PyObject *module = NULL, *dict;

#ifdef PSYCOPG_DEBUG
    if (getenv("PSYCOPG_DEBUG"))
        psycopg_debug_enabled = 1;
#endif

    Dprintf("initpsycopg: initializing psycopg %s", xstr(PSYCOPG_VERSION));

    /* initialize all the new types and then the module */
    Py_TYPE(&connectionType) = &PyType_Type;
    if (PyType_Ready(&connectionType) == -1) goto exit;

    Py_TYPE(&cursorType) = &PyType_Type;
    if (PyType_Ready(&cursorType) == -1) goto exit;

    Py_TYPE(&replicationConnectionType) = &PyType_Type;
    if (PyType_Ready(&replicationConnectionType) == -1) goto exit;

    Py_TYPE(&replicationCursorType) = &PyType_Type;
    if (PyType_Ready(&replicationCursorType) == -1) goto exit;

    Py_TYPE(&replicationMessageType) = &PyType_Type;
    if (PyType_Ready(&replicationMessageType) == -1) goto exit;

    Py_TYPE(&typecastType) = &PyType_Type;
    if (PyType_Ready(&typecastType) == -1) goto exit;

    Py_TYPE(&qstringType) = &PyType_Type;
    if (PyType_Ready(&qstringType) == -1) goto exit;

    Py_TYPE(&binaryType) = &PyType_Type;
    if (PyType_Ready(&binaryType) == -1) goto exit;

    Py_TYPE(&isqlquoteType) = &PyType_Type;
    if (PyType_Ready(&isqlquoteType) == -1) goto exit;

    Py_TYPE(&pbooleanType) = &PyType_Type;
    if (PyType_Ready(&pbooleanType) == -1) goto exit;

    Py_TYPE(&pintType) = &PyType_Type;
    if (PyType_Ready(&pintType) == -1) goto exit;

    Py_TYPE(&pfloatType) = &PyType_Type;
    if (PyType_Ready(&pfloatType) == -1) goto exit;

    Py_TYPE(&pdecimalType) = &PyType_Type;
    if (PyType_Ready(&pdecimalType) == -1) goto exit;

    Py_TYPE(&asisType) = &PyType_Type;
    if (PyType_Ready(&asisType) == -1) goto exit;

    Py_TYPE(&listType) = &PyType_Type;
    if (PyType_Ready(&listType) == -1) goto exit;

    Py_TYPE(&chunkType) = &PyType_Type;
    if (PyType_Ready(&chunkType) == -1) goto exit;

    Py_TYPE(&notifyType) = &PyType_Type;
    if (PyType_Ready(&notifyType) == -1) goto exit;

    Py_TYPE(&xidType) = &PyType_Type;
    if (PyType_Ready(&xidType) == -1) goto exit;

    Py_TYPE(&errorType) = &PyType_Type;
    errorType.tp_base = (PyTypeObject *)PyExc_StandardError;
    if (PyType_Ready(&errorType) == -1) goto exit;

    Py_TYPE(&diagnosticsType) = &PyType_Type;
    if (PyType_Ready(&diagnosticsType) == -1) goto exit;

    Py_TYPE(&lobjectType) = &PyType_Type;
    if (PyType_Ready(&lobjectType) == -1) goto exit;

    /* initialize libcrypto threading callbacks */
    psyco_libcrypto_threads_init();

    /* import mx.DateTime module, if necessary */
#ifdef HAVE_MXDATETIME
    Py_TYPE(&mxdatetimeType) = &PyType_Type;
    if (PyType_Ready(&mxdatetimeType) == -1) goto exit;

    if (0 != mxDateTime_ImportModuleAndAPI()) {
        PyErr_Clear();

        /* only fail if the mx typacaster should have been the default */
#ifdef PSYCOPG_DEFAULT_MXDATETIME
        PyErr_SetString(PyExc_ImportError,
            "can't import mx.DateTime module (requested as default adapter)");
        goto exit;
#endif
    }
#endif

    /* import python builtin datetime module, if available */
    pyDateTimeModuleP = PyImport_ImportModule("datetime");
    if (pyDateTimeModuleP == NULL) {
        Dprintf("initpsycopg: can't import datetime module");
        PyErr_SetString(PyExc_ImportError, "can't import datetime module");
        goto exit;
    }

    /* Initialize the PyDateTimeAPI everywhere is used */
    PyDateTime_IMPORT;
    if (psyco_adapter_datetime_init()) { goto exit; }
    if (psyco_repl_curs_datetime_init()) { goto exit; }
    if (psyco_replmsg_datetime_init()) { goto exit; }

    Py_TYPE(&pydatetimeType) = &PyType_Type;
    if (PyType_Ready(&pydatetimeType) == -1) goto exit;

    /* initialize the module and grab module's dictionary */
#if PY_MAJOR_VERSION < 3
    module = Py_InitModule("_psycopg", psycopgMethods);
#else
    module = PyModule_Create(&psycopgmodule);
#endif
    if (!module) { goto exit; }

    dict = PyModule_GetDict(module);

    /* initialize all the module's exported functions */
    /* PyBoxer_API[PyBoxer_Fake_NUM] = (void *)PyBoxer_Fake; */

    /* Create a CObject containing the API pointer array's address */
    /* If anybody asks for a PyCapsule we'll deal with it. */
#if PY_VERSION_HEX < 0x03020000
    c_api_object = PyCObject_FromVoidPtr((void *)PSYCOPG_API, NULL);
    if (c_api_object != NULL)
        PyModule_AddObject(module, "_C_API", c_api_object);
#endif

    /* other mixed initializations of module-level variables */
    if (!(psycoEncodings = PyDict_New())) { goto exit; }
    if (0 != psyco_encodings_fill(psycoEncodings)) { goto exit; }
    psyco_null = Bytes_FromString("NULL");
    if (!(psyco_DescriptionType = psyco_make_description_type())) { goto exit; }

    /* set some module's parameters */
    PyModule_AddStringConstant(module, "__version__", xstr(PSYCOPG_VERSION));
    PyModule_AddStringConstant(module, "__doc__", "psycopg PostgreSQL driver");
    PyModule_AddIntConstant(module, "__libpq_version__", PG_VERSION_NUM);
    PyModule_AddIntMacro(module, REPLICATION_PHYSICAL);
    PyModule_AddIntMacro(module, REPLICATION_LOGICAL);
    PyModule_AddObject(module, "apilevel", Text_FromUTF8(APILEVEL));
    PyModule_AddObject(module, "threadsafety", PyInt_FromLong(THREADSAFETY));
    PyModule_AddObject(module, "paramstyle", Text_FromUTF8(PARAMSTYLE));

    /* put new types in module dictionary */
    PyModule_AddObject(module, "connection", (PyObject*)&connectionType);
    PyModule_AddObject(module, "cursor", (PyObject*)&cursorType);
    PyModule_AddObject(module, "ReplicationConnection", (PyObject*)&replicationConnectionType);
    PyModule_AddObject(module, "ReplicationCursor", (PyObject*)&replicationCursorType);
    PyModule_AddObject(module, "ReplicationMessage", (PyObject*)&replicationMessageType);
    PyModule_AddObject(module, "ISQLQuote", (PyObject*)&isqlquoteType);
    PyModule_AddObject(module, "Notify", (PyObject*)&notifyType);
    PyModule_AddObject(module, "Xid", (PyObject*)&xidType);
    PyModule_AddObject(module, "Diagnostics", (PyObject*)&diagnosticsType);
    PyModule_AddObject(module, "AsIs", (PyObject*)&asisType);
    PyModule_AddObject(module, "Binary", (PyObject*)&binaryType);
    PyModule_AddObject(module, "Boolean", (PyObject*)&pbooleanType);
    PyModule_AddObject(module, "Decimal", (PyObject*)&pdecimalType);
    PyModule_AddObject(module, "Int", (PyObject*)&pintType);
    PyModule_AddObject(module, "Float", (PyObject*)&pfloatType);
    PyModule_AddObject(module, "List", (PyObject*)&listType);
    PyModule_AddObject(module, "QuotedString", (PyObject*)&qstringType);
    PyModule_AddObject(module, "lobject", (PyObject*)&lobjectType);
    PyModule_AddObject(module, "Column", psyco_DescriptionType);

    /* encodings dictionary in module dictionary */
    PyModule_AddObject(module, "encodings", psycoEncodings);

#ifdef HAVE_MXDATETIME
    /* If we can't find mx.DateTime objects at runtime,
     * remove them from the module (and, as consequence, from the adapters). */
    if (0 != psyco_adapter_mxdatetime_init()) {
        PyDict_DelItemString(dict, "DateFromMx");
        PyDict_DelItemString(dict, "TimeFromMx");
        PyDict_DelItemString(dict, "TimestampFromMx");
        PyDict_DelItemString(dict, "IntervalFromMx");
    }
#endif
    /* initialize default set of typecasters */
    if (0 != typecast_init(dict)) { goto exit; }

    /* initialize microprotocols layer */
    microprotocols_init(dict);
    if (0 != psyco_adapters_init(dict)) { goto exit; }

    /* create a standard set of exceptions and add them to the module's dict */
    if (0 != psyco_errors_init()) { goto exit; }
    psyco_errors_fill(dict);

    replicationPhysicalConst = PyDict_GetItemString(dict, "REPLICATION_PHYSICAL");
    replicationLogicalConst  = PyDict_GetItemString(dict, "REPLICATION_LOGICAL");

    Dprintf("initpsycopg: module initialization complete");

exit:
#if PY_MAJOR_VERSION > 2
    return module;
#else
    return;
#endif
}
Example #19
0
PyMODINIT_FUNC initpepy(void) {
	PyObject *m;

	if (PyType_Ready(&pepy_parsed_type) < 0 ||
	    PyType_Ready(&pepy_section_type) < 0 ||
	    PyType_Ready(&pepy_import_type) < 0 ||
	    PyType_Ready(&pepy_export_type) < 0 ||
	    PyType_Ready(&pepy_relocation_type) < 0 ||
	    PyType_Ready(&pepy_resource_type) < 0)
		return;

	m = Py_InitModule3("pepy", pepy_methods, "Python interface to pe-parse.");
	if (!m)
		return;

	pepy_error = PyErr_NewException((char *) "pepy.error", NULL, NULL);
	Py_INCREF(pepy_error);
	PyModule_AddObject(m, "error", pepy_error);

	Py_INCREF(&pepy_parsed_type);
	PyModule_AddObject(m, "pepy_parsed", (PyObject *) &pepy_parsed_type);

	Py_INCREF(&pepy_section_type);
	PyModule_AddObject(m, "pepy_section", (PyObject *) &pepy_section_type);

	Py_INCREF(&pepy_import_type);
	PyModule_AddObject(m, "pepy_import", (PyObject *) &pepy_import_type);

	Py_INCREF(&pepy_export_type);
	PyModule_AddObject(m, "pepy_export", (PyObject *) &pepy_export_type);

	Py_INCREF(&pepy_relocation_type);
	PyModule_AddObject(m, "pepy_relocation", (PyObject *) &pepy_relocation_type);

	Py_INCREF(&pepy_resource_type);
	PyModule_AddObject(m, "pepy_resource", (PyObject *) &pepy_resource_type);

	PyModule_AddStringMacro(m, PEPY_VERSION);

	PyModule_AddIntMacro(m, MZ_MAGIC);
	PyModule_AddIntMacro(m, NT_MAGIC);
	PyModule_AddIntMacro(m, NUM_DIR_ENTRIES);
	PyModule_AddIntMacro(m, NT_OPTIONAL_32_MAGIC);
	PyModule_AddIntMacro(m, NT_SHORT_NAME_LEN);
	PyModule_AddIntMacro(m, DIR_EXPORT);
	PyModule_AddIntMacro(m, DIR_IMPORT);
	PyModule_AddIntMacro(m, DIR_RESOURCE);
	PyModule_AddIntMacro(m, DIR_EXCEPTION);
	PyModule_AddIntMacro(m, DIR_SECURITY);
	PyModule_AddIntMacro(m, DIR_BASERELOC);
	PyModule_AddIntMacro(m, DIR_DEBUG);
	PyModule_AddIntMacro(m, DIR_ARCHITECTURE);
	PyModule_AddIntMacro(m, DIR_GLOBALPTR);
	PyModule_AddIntMacro(m, DIR_TLS);
	PyModule_AddIntMacro(m, DIR_LOAD_CONFIG);
	PyModule_AddIntMacro(m, DIR_BOUND_IMPORT);
	PyModule_AddIntMacro(m, DIR_IAT);
	PyModule_AddIntMacro(m, DIR_DELAY_IMPORT);
	PyModule_AddIntMacro(m, DIR_COM_DESCRIPTOR);

	PyModule_AddIntMacro(m, IMAGE_SCN_TYPE_NO_PAD);
	PyModule_AddIntMacro(m, IMAGE_SCN_CNT_CODE);
	PyModule_AddIntMacro(m, IMAGE_SCN_CNT_INITIALIZED_DATA);
	PyModule_AddIntMacro(m, IMAGE_SCN_CNT_UNINITIALIZED_DATA);
	PyModule_AddIntMacro(m, IMAGE_SCN_LNK_OTHER);
	PyModule_AddIntMacro(m, IMAGE_SCN_LNK_INFO);
	PyModule_AddIntMacro(m, IMAGE_SCN_LNK_REMOVE);
	PyModule_AddIntMacro(m, IMAGE_SCN_LNK_COMDAT);
	PyModule_AddIntMacro(m, IMAGE_SCN_NO_DEFER_SPEC_EXC);
	PyModule_AddIntMacro(m, IMAGE_SCN_GPREL);
	PyModule_AddIntMacro(m, IMAGE_SCN_MEM_FARDATA);
	PyModule_AddIntMacro(m, IMAGE_SCN_MEM_PURGEABLE);
	PyModule_AddIntMacro(m, IMAGE_SCN_MEM_16BIT);
	PyModule_AddIntMacro(m, IMAGE_SCN_MEM_LOCKED);
	PyModule_AddIntMacro(m, IMAGE_SCN_MEM_PRELOAD);
	PyModule_AddIntMacro(m, IMAGE_SCN_ALIGN_1BYTES);
	PyModule_AddIntMacro(m, IMAGE_SCN_ALIGN_2BYTES);
	PyModule_AddIntMacro(m, IMAGE_SCN_ALIGN_4BYTES);
	PyModule_AddIntMacro(m, IMAGE_SCN_ALIGN_8BYTES);
	PyModule_AddIntMacro(m, IMAGE_SCN_ALIGN_16BYTES);
	PyModule_AddIntMacro(m, IMAGE_SCN_ALIGN_32BYTES);
	PyModule_AddIntMacro(m, IMAGE_SCN_ALIGN_64BYTES);
	PyModule_AddIntMacro(m, IMAGE_SCN_ALIGN_128BYTES);
	PyModule_AddIntMacro(m, IMAGE_SCN_ALIGN_256BYTES);
	PyModule_AddIntMacro(m, IMAGE_SCN_ALIGN_512BYTES);
	PyModule_AddIntMacro(m, IMAGE_SCN_ALIGN_1024BYTES);
	PyModule_AddIntMacro(m, IMAGE_SCN_ALIGN_2048BYTES);
	PyModule_AddIntMacro(m, IMAGE_SCN_ALIGN_4096BYTES);
	PyModule_AddIntMacro(m, IMAGE_SCN_ALIGN_8192BYTES);
	PyModule_AddIntMacro(m, IMAGE_SCN_ALIGN_MASK);
	PyModule_AddIntMacro(m, IMAGE_SCN_LNK_NRELOC_OVFL);
	PyModule_AddIntMacro(m, IMAGE_SCN_MEM_DISCARDABLE);
	PyModule_AddIntMacro(m, IMAGE_SCN_MEM_NOT_CACHED);
	PyModule_AddIntMacro(m, IMAGE_SCN_MEM_NOT_PAGED);
	PyModule_AddIntMacro(m, IMAGE_SCN_MEM_SHARED);
	PyModule_AddIntMacro(m, IMAGE_SCN_MEM_EXECUTE);
	PyModule_AddIntMacro(m, IMAGE_SCN_MEM_READ);
	PyModule_AddIntMacro(m, IMAGE_SCN_MEM_WRITE);
}
Example #20
0
File: tds.c Project: kohenchia/ctds
PyMODINIT_FUNC init_tds(void)
{
#  define FAIL_MODULE_INIT do { Py_XDECREF(module); return; } while (0)
#else /* if PY_MAJOR_VERSION < 3 */
PyMODINIT_FUNC PyInit__tds(void)
{
#  define FAIL_MODULE_INIT do { Py_XDECREF(module); return NULL; } while (0)
#endif /* else if PY_MAJOR_VERSION < 3 */

    /* Create module object. */
#if PY_MAJOR_VERSION < 3
    PyObject* module = Py_InitModule3("_tds", s_tds_methods, s_tds_doc);
    Py_XINCREF(module); /* Py_InitModule3 returns a borrowed reference */
#else /* if PY_MAJOR_VERSION < 3 */
    static struct PyModuleDef moduledef =
    {
        PyModuleDef_HEAD_INIT,
        "_tds",        /* m_name */
        s_tds_doc,     /* m_doc */
        -1,            /* m_size */
        s_tds_methods, /* m_methods */
        NULL,          /* m_slots */
        NULL,          /* m_traverse */
        NULL,          /* m_clear */
        tds_free       /* m_free */
    };
    PyObject* module = PyModule_Create(&moduledef);
#endif /* else if PY_MAJOR_VERSION < 3 */

    if (!module) FAIL_MODULE_INIT;

    /***** Define module-level constants. *****/

    /**
       https://www.python.org/dev/peps/pep-0249/#threadsafety
    */
    if (0 != PyModule_AddIntConstant(module, "threadsafety", 1)) FAIL_MODULE_INIT;

    /**
       https://www.python.org/dev/peps/pep-0249/#apilevel
    */
    if (0 != PyModule_AddStringConstant(module, "apilevel", "2.0")) FAIL_MODULE_INIT;

    /**
       https://www.python.org/dev/peps/pep-0249/#pyformat
    */
    if (0 != PyModule_AddStringConstant(module, "paramstyle", "numeric")) FAIL_MODULE_INIT;

    if (0 != PyModule_AddIntMacro(module, TDSCHAR)) FAIL_MODULE_INIT;
    if (0 != PyModule_AddIntMacro(module, TDSVARCHAR)) FAIL_MODULE_INIT;
    if (0 != PyModule_AddIntMacro(module, TDSTEXT)) FAIL_MODULE_INIT;
    if (0 != PyModule_AddIntMacro(module, TDSBIT)) FAIL_MODULE_INIT;
    if (0 != PyModule_AddIntMacro(module, TDSBITN)) FAIL_MODULE_INIT;
    if (0 != PyModule_AddIntMacro(module, TDSINTN)) FAIL_MODULE_INIT;
    if (0 != PyModule_AddIntMacro(module, TDSTINYINT)) FAIL_MODULE_INIT;
    if (0 != PyModule_AddIntMacro(module, TDSSMALLINT)) FAIL_MODULE_INIT;
    if (0 != PyModule_AddIntMacro(module, TDSINT)) FAIL_MODULE_INIT;
    if (0 != PyModule_AddIntMacro(module, TDSBIGINT)) FAIL_MODULE_INIT;
    if (0 != PyModule_AddIntMacro(module, TDSFLOAT)) FAIL_MODULE_INIT;
    if (0 != PyModule_AddIntMacro(module, TDSFLOATN)) FAIL_MODULE_INIT;
    if (0 != PyModule_AddIntMacro(module, TDSREAL)) FAIL_MODULE_INIT;
    if (0 != PyModule_AddIntMacro(module, TDSDATETIME)) FAIL_MODULE_INIT;
    if (0 != PyModule_AddIntMacro(module, TDSSMALLDATETIME)) FAIL_MODULE_INIT;
    if (0 != PyModule_AddIntMacro(module, TDSDATETIMEN)) FAIL_MODULE_INIT;
    if (0 != PyModule_AddIntMacro(module, TDSDATE)) FAIL_MODULE_INIT;
    if (0 != PyModule_AddIntMacro(module, TDSTIME)) FAIL_MODULE_INIT;
    if (0 != PyModule_AddIntMacro(module, TDSDATETIME2)) FAIL_MODULE_INIT;
    if (0 != PyModule_AddIntMacro(module, TDSIMAGE)) FAIL_MODULE_INIT;
    if (0 != PyModule_AddIntMacro(module, TDSSMALLMONEY)) FAIL_MODULE_INIT;
    if (0 != PyModule_AddIntMacro(module, TDSMONEY)) FAIL_MODULE_INIT;
    if (0 != PyModule_AddIntMacro(module, TDSMONEYN)) FAIL_MODULE_INIT;
    if (0 != PyModule_AddIntMacro(module, TDSNUMERIC)) FAIL_MODULE_INIT;
    if (0 != PyModule_AddIntMacro(module, TDSDECIMAL)) FAIL_MODULE_INIT;
    if (0 != PyModule_AddIntMacro(module, TDSBINARY)) FAIL_MODULE_INIT;
    if (0 != PyModule_AddIntMacro(module, TDSVARBINARY)) FAIL_MODULE_INIT;
    if (0 != PyModule_AddIntMacro(module, TDSGUID)) FAIL_MODULE_INIT;
    if (0 != PyModule_AddIntMacro(module, TDSVOID)) FAIL_MODULE_INIT;

    /***** Define exception types. *****/

    #define ADD_EXCEPTION_TO_MODULE(name) \
        Py_INCREF(PyExc_tds_##name); /* add ref for module to steal (global variable owns existing ref) */ \
        PyModule_AddObject(module, #name, PyExc_tds_##name);

#if PY_MAJOR_VERSION >= 3
#  define PyExc_StandardError PyExc_Exception
#endif

    /**
       https://www.python.org/dev/peps/pep-0249/#warning
    */
    static const char s_tds_Warning_doc[] =
        "Warning\n"
        "\n"
        ":pep:`0249#warning`\n"
        "\n"
        "Exception raised for important warnings like data truncations while\n"
        "inserting, etc.\n";
    if (!(PyExc_tds_Warning = PyErr_NewExceptionWithDoc_("_tds.Warning", s_tds_Warning_doc, PyExc_StandardError, NULL))) FAIL_MODULE_INIT;
    ADD_EXCEPTION_TO_MODULE(Warning);

    /**
       https://www.python.org/dev/peps/pep-0249/#error
    */
    static const char s_tds_Error_doc[] =
        "Error\n"
        "\n"
        ":pep:`0249#error`\n"
        "\n"
        "Exception that is the base class of all other error exceptions. You\n"
        "can use this to catch all errors with one single except statement.\n";
    if (!(PyExc_tds_Error = PyErr_NewExceptionWithDoc_("_tds.Error", s_tds_Error_doc, PyExc_StandardError, NULL))) FAIL_MODULE_INIT;
    ADD_EXCEPTION_TO_MODULE(Error);

    /**
       https://www.python.org/dev/peps/pep-0249/#interfaceerror
    */
    static const char s_tds_InterfaceError_doc[] =
        "InterfaceError\n"
        "\n"
        ":pep:`0249#interfaceerror`\n"
        "\n"
        "Exception raised for errors that are related to the database interface\n"
        "rather than the database itself.\n";
    if (!(PyExc_tds_InterfaceError = PyErr_NewExceptionWithDoc_("_tds.InterfaceError", s_tds_InterfaceError_doc, PyExc_tds_Error, NULL))) FAIL_MODULE_INIT;
    ADD_EXCEPTION_TO_MODULE(InterfaceError);

    /**
       https://www.python.org/dev/peps/pep-0249/#databaseerror
    */
    static const char s_tds_DatabaseError_doc[] =
        "DatabaseError\n"
        "\n"
        ":pep:`0249#databaseerror`\n"
        "\n"
        "Exception raised for errors that are related to the database.\n";
    if (!(PyExc_tds_DatabaseError = PyErr_NewExceptionWithDoc_("_tds.DatabaseError", s_tds_DatabaseError_doc, PyExc_tds_Error, NULL))) FAIL_MODULE_INIT;
    ADD_EXCEPTION_TO_MODULE(DatabaseError);

    /**
       https://www.python.org/dev/peps/pep-0249/#dataerror
    */
    static const char s_tds_DataError_doc[] =
        "DataError\n"
        "\n"
        ":pep:`0249#dataerror`\n"
        "\n"
        "Exception raised for errors that are due to problems with the\n"
        "processed data like division by zero, numeric value out of range,\n"
        "etc.\n";
    if (!(PyExc_tds_DataError = PyErr_NewExceptionWithDoc_("_tds.DataError", s_tds_DataError_doc, PyExc_tds_DatabaseError, NULL))) FAIL_MODULE_INIT;
    ADD_EXCEPTION_TO_MODULE(DataError);

    /**
       https://www.python.org/dev/peps/pep-0249/#operationalerror
    */
    static const char s_tds_OperationalError_doc[] =
        "OperationalError\n"
        "\n"
        ":pep:`0249#operationalerror`\n"
        "\n"
        "Exception raised for errors that are related to the database's\n"
        "operation and not necessarily under the control of the programmer,\n"
        "e.g. an unexpected disconnect occurs, the data source name is not\n"
        "found, a transaction could not be processed, a memory allocation\n"
        "error occurred during processing, etc.\n";
    if (!(PyExc_tds_OperationalError = PyErr_NewExceptionWithDoc_("_tds.OperationalError", s_tds_OperationalError_doc, PyExc_tds_DatabaseError, NULL))) FAIL_MODULE_INIT;
    ADD_EXCEPTION_TO_MODULE(OperationalError);

    /**
       https://www.python.org/dev/peps/pep-0249/#integrityerror
    */
    static const char s_tds_IntegrityError_doc[] =
        "IntegrityError\n"
        "\n"
        ":pep:`0249#integrityerror`\n"
        "\n"
        "Exception raised when the relational integrity of the database is\n"
        "affected, e.g. a foreign key check fails.\n";
    if (!(PyExc_tds_IntegrityError = PyErr_NewExceptionWithDoc_("_tds.IntegrityError", s_tds_IntegrityError_doc, PyExc_tds_DatabaseError, NULL))) FAIL_MODULE_INIT;
    ADD_EXCEPTION_TO_MODULE(IntegrityError);

    /**
       https://www.python.org/dev/peps/pep-0249/#internalerror
    */
    static const char s_tds_InternalError_doc[] =
        "InternalError\n"
        "\n"
        ":pep:`0249#internalerror`\n"
        "\n"
        "Exception raised when the database encounters an internal error,\n"
        "e.g. the cursor is not valid anymore, the transaction is out of\n"
        "sync, etc.\n";
    if (!(PyExc_tds_InternalError = PyErr_NewExceptionWithDoc_("_tds.InternalError", s_tds_InternalError_doc, PyExc_tds_DatabaseError, NULL))) FAIL_MODULE_INIT;
    ADD_EXCEPTION_TO_MODULE(InternalError);

    /**
       https://www.python.org/dev/peps/pep-0249/#programmingerror
    */
    static const char s_tds_ProgrammingError_doc[] =
        "ProgrammingError\n"
        "\n"
        ":pep:`0249#programmingerror`\n"
        "\n"
        "Exception raised for programming errors, e.g. table not found or\n"
        "already exists, syntax error in the SQL statement, wrong number of\n"
        "parameters specified, etc.\n";
    if (!(PyExc_tds_ProgrammingError = PyErr_NewExceptionWithDoc_("_tds.ProgrammingError", s_tds_ProgrammingError_doc, PyExc_tds_DatabaseError, NULL))) FAIL_MODULE_INIT;
    ADD_EXCEPTION_TO_MODULE(ProgrammingError);

    /**
       https://www.python.org/dev/peps/pep-0249/#notsupportederror
    */
    static const char s_tds_NotSupportedError_doc[] =
        "NotSupportedError\n"
        "\n"
        ":pep:`0249#notsupportederror`\n"
        "\n"
        "Exception raised in case a method or database API was used which is\n"
        "not supported by the database, e.g. requesting a .rollback() on a\n"
        "connection that does not support transaction or has transactions\n"
        "turned off.\n";
    if (!(PyExc_tds_NotSupportedError = PyErr_NewExceptionWithDoc_("_tds.NotSupportedError", s_tds_NotSupportedError_doc, PyExc_tds_DatabaseError, NULL))) FAIL_MODULE_INIT;
    ADD_EXCEPTION_TO_MODULE(NotSupportedError);

    /***** Define custom types. *****/

    if (0 != PyModule_AddObject(module, "Connection", (PyObject*)ConnectionType_init())) FAIL_MODULE_INIT;
    if (0 != PyModule_AddObject(module, "Cursor", (PyObject*)CursorType_init())) FAIL_MODULE_INIT;
    if (0 != PyModule_AddObject(module, "Parameter", (PyObject*)ParameterType_init())) FAIL_MODULE_INIT;

    if (0 != SqlTypes_init()) FAIL_MODULE_INIT;

    /* Add SQL type wrappers (in alphabetical order). */
#define SQL_TYPE_INIT(_type) \
        if (0 != PyModule_AddObject(module, "Sql" #_type, (PyObject*)Sql ## _type ## Type_init())) FAIL_MODULE_INIT

    /* Note: types added here must be added to __init__.py */
    SQL_TYPE_INIT(BigInt);
    SQL_TYPE_INIT(Binary);
    SQL_TYPE_INIT(Char);
    SQL_TYPE_INIT(Date);
    SQL_TYPE_INIT(Decimal);
    SQL_TYPE_INIT(Int);
    SQL_TYPE_INIT(SmallInt);
    SQL_TYPE_INIT(TinyInt);
    SQL_TYPE_INIT(VarBinary);
    SQL_TYPE_INIT(VarChar);

    /***** Import datetime module *****/
    if (!PyDateTimeType_init()) FAIL_MODULE_INIT;

    /***** Import decimal type. *****/
    if (!PyDecimalType_init()) FAIL_MODULE_INIT;

    /***** Import uuid type. *****/
    if (!PyUuidType_init()) FAIL_MODULE_INIT;

    /***** Library version *****/
    if (!(version_info = PyTuple_New(3))) FAIL_MODULE_INIT;
    PyTuple_SET_ITEM(version_info, 0, PyLong_FromLong(CTDS_MAJOR_VERSION));
    PyTuple_SET_ITEM(version_info, 1, PyLong_FromLong(CTDS_MINOR_VERSION));
    PyTuple_SET_ITEM(version_info, 2, PyLong_FromLong(CTDS_PATCH_VERSION));

    if (0 != PyModule_AddObject(module, "version_info", version_info)) FAIL_MODULE_INIT;
    Py_INCREF(version_info);

    /***** Initialize DB-lib. *****/

    /*
        FreeTDS version.

        Use the CT-library API since older versions of FreeTDS don't return
        a proper version string from dbversion()
    */
    char freetds_version[100];
    int written;
    (void)ct_config(NULL, CS_GET, CS_VERSION, freetds_version, sizeof(freetds_version), &written);
    if (0 != PyModule_AddStringConstant(module, "freetds_version", freetds_version)) FAIL_MODULE_INIT;

    if (FAIL == dbinit()) FAIL_MODULE_INIT;
    dberrhandle(Connection_dberrhandler);
    dbmsghandle(Connection_dbmsghandler);

#if PY_MAJOR_VERSION >= 3
    return module;
#endif /* if PY_MAJOR_VERSION >= 3 */
}
Example #21
0
static void
PyInit_timezone(PyObject *m) {
    /* This code moved from PyInit_time wholesale to allow calling it from
    time_tzset. In the future, some parts of it can be moved back
    (for platforms that don't HAVE_WORKING_TZSET, when we know what they
    are), and the extraneous calls to tzset(3) should be removed.
    I haven't done this yet, as I don't want to change this code as
    little as possible when introducing the time.tzset and time.tzsetwall
    methods. This should simply be a method of doing the following once,
    at the top of this function and removing the call to tzset() from
    time_tzset():

        #ifdef HAVE_TZSET
        tzset()
        #endif

    And I'm lazy and hate C so nyer.
     */
#if defined(HAVE_TZNAME) && !defined(__GLIBC__) && !defined(__CYGWIN__)
    PyObject *otz0, *otz1;
    tzset();
    PyModule_AddIntConstant(m, "timezone", timezone);
#ifdef HAVE_ALTZONE
    PyModule_AddIntConstant(m, "altzone", altzone);
#else
    PyModule_AddIntConstant(m, "altzone", timezone-3600);
#endif
    PyModule_AddIntConstant(m, "daylight", daylight);
    otz0 = PyUnicode_DecodeLocale(tzname[0], "surrogateescape");
    otz1 = PyUnicode_DecodeLocale(tzname[1], "surrogateescape");
    PyModule_AddObject(m, "tzname", Py_BuildValue("(NN)", otz0, otz1));
#else /* !HAVE_TZNAME || __GLIBC__ || __CYGWIN__*/
#ifdef HAVE_STRUCT_TM_TM_ZONE
    {
#define YEAR ((time_t)((365 * 24 + 6) * 3600))
        time_t t;
        struct tm *p;
        long janzone, julyzone;
        char janname[10], julyname[10];
        t = (time((time_t *)0) / YEAR) * YEAR;
        p = localtime(&t);
        janzone = -p->tm_gmtoff;
        strncpy(janname, p->tm_zone ? p->tm_zone : "   ", 9);
        janname[9] = '\0';
        t += YEAR/2;
        p = localtime(&t);
        julyzone = -p->tm_gmtoff;
        strncpy(julyname, p->tm_zone ? p->tm_zone : "   ", 9);
        julyname[9] = '\0';

        if( janzone < julyzone ) {
            /* DST is reversed in the southern hemisphere */
            PyModule_AddIntConstant(m, "timezone", julyzone);
            PyModule_AddIntConstant(m, "altzone", janzone);
            PyModule_AddIntConstant(m, "daylight",
                                    janzone != julyzone);
            PyModule_AddObject(m, "tzname",
                               Py_BuildValue("(zz)",
                                             julyname, janname));
        } else {
            PyModule_AddIntConstant(m, "timezone", janzone);
            PyModule_AddIntConstant(m, "altzone", julyzone);
            PyModule_AddIntConstant(m, "daylight",
                                    janzone != julyzone);
            PyModule_AddObject(m, "tzname",
                               Py_BuildValue("(zz)",
                                             janname, julyname));
        }
    }
#else
#endif /* HAVE_STRUCT_TM_TM_ZONE */
#ifdef __CYGWIN__
    tzset();
    PyModule_AddIntConstant(m, "timezone", _timezone);
    PyModule_AddIntConstant(m, "altzone", _timezone-3600);
    PyModule_AddIntConstant(m, "daylight", _daylight);
    PyModule_AddObject(m, "tzname",
                       Py_BuildValue("(zz)", _tzname[0], _tzname[1]));
#endif /* __CYGWIN__ */
#endif /* !HAVE_TZNAME || __GLIBC__ || __CYGWIN__*/

#if defined(HAVE_CLOCK_GETTIME)
    PyModule_AddIntMacro(m, CLOCK_REALTIME);
#ifdef CLOCK_MONOTONIC
    PyModule_AddIntMacro(m, CLOCK_MONOTONIC);
#endif
#ifdef CLOCK_MONOTONIC_RAW
    PyModule_AddIntMacro(m, CLOCK_MONOTONIC_RAW);
#endif
#ifdef CLOCK_HIGHRES
    PyModule_AddIntMacro(m, CLOCK_HIGHRES);
#endif
#ifdef CLOCK_PROCESS_CPUTIME_ID
    PyModule_AddIntMacro(m, CLOCK_PROCESS_CPUTIME_ID);
#endif
#ifdef CLOCK_THREAD_CPUTIME_ID
    PyModule_AddIntMacro(m, CLOCK_THREAD_CPUTIME_ID);
#endif
#endif /* HAVE_CLOCK_GETTIME */
}
Example #22
0
PyObject *
init_dns(void)
{
    PyObject *module;
#ifdef PYUV_PYTHON3
    module = PyModule_Create(&pyuv_dns_module);
#else
    module = Py_InitModule("pyuv.dns", NULL);
#endif

    if (module == NULL) {
        return NULL;
    }

    PyModule_AddIntMacro(module, ARES_NI_NOFQDN);
    PyModule_AddIntMacro(module, ARES_NI_NUMERICHOST);
    PyModule_AddIntMacro(module, ARES_NI_NAMEREQD);
    PyModule_AddIntMacro(module, ARES_NI_NUMERICSERV);
    PyModule_AddIntMacro(module, ARES_NI_DGRAM);
    PyModule_AddIntMacro(module, ARES_NI_TCP);
    PyModule_AddIntMacro(module, ARES_NI_UDP);
    PyModule_AddIntMacro(module, ARES_NI_SCTP);
    PyModule_AddIntMacro(module, ARES_NI_DCCP);
    PyModule_AddIntMacro(module, ARES_NI_NUMERICSCOPE);
    PyModule_AddIntMacro(module, ARES_NI_LOOKUPHOST);
    PyModule_AddIntMacro(module, ARES_NI_LOOKUPSERVICE);
    PyModule_AddIntMacro(module, ARES_NI_IDN);
    PyModule_AddIntMacro(module, ARES_NI_IDN_ALLOW_UNASSIGNED);
    PyModule_AddIntMacro(module, ARES_NI_IDN_USE_STD3_ASCII_RULES);

    PyUVModule_AddType(module, "DNSResolver", &DNSResolverType);

    return module;
}
Example #23
0
PyMODINIT_FUNC
PyInit_syslog(void)
{
    PyObject *m;

    /* Create the module and add the functions */
    m = PyModule_Create(&syslogmodule);
    if (m == NULL)
        return NULL;

    /* Add some symbolic constants to the module */

    /* Priorities */
    PyModule_AddIntMacro(m, LOG_EMERG);
    PyModule_AddIntMacro(m, LOG_ALERT);
    PyModule_AddIntMacro(m, LOG_CRIT);
    PyModule_AddIntMacro(m, LOG_ERR);
    PyModule_AddIntMacro(m, LOG_WARNING);
    PyModule_AddIntMacro(m, LOG_NOTICE);
    PyModule_AddIntMacro(m, LOG_INFO);
    PyModule_AddIntMacro(m, LOG_DEBUG);

    /* openlog() option flags */
    PyModule_AddIntMacro(m, LOG_PID);
    PyModule_AddIntMacro(m, LOG_CONS);
    PyModule_AddIntMacro(m, LOG_NDELAY);
#ifdef LOG_ODELAY
    PyModule_AddIntMacro(m, LOG_ODELAY);
#endif
#ifdef LOG_NOWAIT
    PyModule_AddIntMacro(m, LOG_NOWAIT);
#endif
#ifdef LOG_PERROR
    PyModule_AddIntMacro(m, LOG_PERROR);
#endif

    /* Facilities */
    PyModule_AddIntMacro(m, LOG_KERN);
    PyModule_AddIntMacro(m, LOG_USER);
    PyModule_AddIntMacro(m, LOG_MAIL);
    PyModule_AddIntMacro(m, LOG_DAEMON);
    PyModule_AddIntMacro(m, LOG_AUTH);
    PyModule_AddIntMacro(m, LOG_LPR);
    PyModule_AddIntMacro(m, LOG_LOCAL0);
    PyModule_AddIntMacro(m, LOG_LOCAL1);
    PyModule_AddIntMacro(m, LOG_LOCAL2);
    PyModule_AddIntMacro(m, LOG_LOCAL3);
    PyModule_AddIntMacro(m, LOG_LOCAL4);
    PyModule_AddIntMacro(m, LOG_LOCAL5);
    PyModule_AddIntMacro(m, LOG_LOCAL6);
    PyModule_AddIntMacro(m, LOG_LOCAL7);

#ifndef LOG_SYSLOG
#define LOG_SYSLOG              LOG_DAEMON
#endif
#ifndef LOG_NEWS
#define LOG_NEWS                LOG_MAIL
#endif
#ifndef LOG_UUCP
#define LOG_UUCP                LOG_MAIL
#endif
#ifndef LOG_CRON
#define LOG_CRON                LOG_DAEMON
#endif

    PyModule_AddIntMacro(m, LOG_SYSLOG);
    PyModule_AddIntMacro(m, LOG_CRON);
    PyModule_AddIntMacro(m, LOG_UUCP);
    PyModule_AddIntMacro(m, LOG_NEWS);

#ifdef LOG_AUTHPRIV
    PyModule_AddIntMacro(m, LOG_AUTHPRIV);
#endif

    return m;
}
Example #24
0
File: pyev.c Project: Spencerx/pyev
/* pyev_module initialization */
PyObject *
init_pyev(void)
{
    PyObject *pyev;

#ifdef MS_WINDOWS
    if (pyev_setmaxstdio() || pyev_import_socket()) {
        return NULL;
    }
#endif
    /* fill in deferred data addresses */
    WatcherType.tp_new = PyType_GenericNew;
#if EV_PERIODIC_ENABLE
    PeriodicBaseType.tp_base = &WatcherType;
#endif
#if EV_STAT_ENABLE
    /* init StatdataType */
    if (!StatdataType_initialized) {
        PyStructSequence_InitType(&StatdataType, &Statdata_desc);
        StatdataType_initialized = 1;
    }
#endif
    /* pyev */
#if PY_MAJOR_VERSION >= 3
    pyev = PyModule_Create(&pyev_module);
#else
    pyev = Py_InitModule3("pyev", pyev_m_methods, pyev_m_doc);
#endif
    if (!pyev) {
        return NULL;
    }
    /* pyev.Error */
    Error = PyErr_NewException("pyev.Error", NULL, NULL);
    if (!Error || PyModule_AddObject(pyev, "Error", Error)) {
        Py_XDECREF(Error);
        goto fail;
    }
    /* adding types and constants */
    if (
        /* Loop */
        PyModule_AddType(pyev, "Loop", &LoopType) ||
        PyModule_AddUnsignedIntMacro(pyev, EVFLAG_AUTO) ||
        PyModule_AddUnsignedIntMacro(pyev, EVFLAG_NOENV) ||
        PyModule_AddUnsignedIntMacro(pyev, EVFLAG_FORKCHECK) ||
        PyModule_AddUnsignedIntMacro(pyev, EVFLAG_NOINOTIFY) ||
        PyModule_AddUnsignedIntMacro(pyev, EVFLAG_SIGNALFD) ||
        PyModule_AddUnsignedIntMacro(pyev, EVFLAG_NOSIGMASK) ||
        PyModule_AddUnsignedIntMacro(pyev, EVBACKEND_SELECT) ||
        PyModule_AddUnsignedIntMacro(pyev, EVBACKEND_POLL) ||
        PyModule_AddUnsignedIntMacro(pyev, EVBACKEND_EPOLL) ||
        PyModule_AddUnsignedIntMacro(pyev, EVBACKEND_KQUEUE) ||
        PyModule_AddUnsignedIntMacro(pyev, EVBACKEND_DEVPOLL) ||
        PyModule_AddUnsignedIntMacro(pyev, EVBACKEND_PORT) ||
        PyModule_AddUnsignedIntMacro(pyev, EVBACKEND_ALL) ||
        PyModule_AddUnsignedIntMacro(pyev, EVBACKEND_MASK) ||
        PyModule_AddIntMacro(pyev, EVRUN_NOWAIT) ||
        PyModule_AddIntMacro(pyev, EVRUN_ONCE) ||
        PyModule_AddIntMacro(pyev, EVBREAK_ONE) ||
        PyModule_AddIntMacro(pyev, EVBREAK_ALL) ||
        /* watchers */
        PyType_Ready(&WatcherType) ||
        PyModule_AddWatcher(pyev, "Io", &IoType, NULL) ||
        PyModule_AddIntMacro(pyev, EV_IO) ||
        PyModule_AddIntMacro(pyev, EV_READ) ||
        PyModule_AddIntMacro(pyev, EV_WRITE) ||
        PyModule_AddWatcher(pyev, "Timer", &TimerType, NULL) ||
        PyModule_AddIntMacro(pyev, EV_TIMER) ||
#if EV_PERIODIC_ENABLE
        PyType_Ready(&PeriodicBaseType) ||
        PyModule_AddWatcher(pyev, "Periodic", &PeriodicType,
                            &PeriodicBaseType) ||
        PyModule_AddIntMacro(pyev, EV_PERIODIC) ||
#if EV_PREPARE_ENABLE
        PyModule_AddWatcher(pyev, "Scheduler", &SchedulerType,
                            &PeriodicBaseType) ||
#endif
#endif
#if EV_SIGNAL_ENABLE
        PyModule_AddWatcher(pyev, "Signal", &SignalType, NULL) ||
        PyModule_AddIntMacro(pyev, EV_SIGNAL) ||
#endif
#if EV_CHILD_ENABLE
        PyModule_AddWatcher(pyev, "Child", &ChildType, NULL) ||
        PyModule_AddIntMacro(pyev, EV_CHILD) ||
#endif
#if EV_STAT_ENABLE
        PyModule_AddWatcher(pyev, "Stat", &StatType, NULL) ||
        PyModule_AddIntMacro(pyev, EV_STAT) ||
#endif
#if EV_IDLE_ENABLE
        PyModule_AddWatcher(pyev, "Idle", &IdleType, NULL) ||
        PyModule_AddIntMacro(pyev, EV_IDLE) ||
#endif
#if EV_PREPARE_ENABLE
        PyModule_AddWatcher(pyev, "Prepare", &PrepareType, NULL) ||
        PyModule_AddIntMacro(pyev, EV_PREPARE) ||
#endif
#if EV_CHECK_ENABLE
        PyModule_AddWatcher(pyev, "Check", &CheckType, NULL) ||
        PyModule_AddIntMacro(pyev, EV_CHECK) ||
#endif
#if EV_EMBED_ENABLE
        PyModule_AddWatcher(pyev, "Embed", &EmbedType, NULL) ||
        PyModule_AddIntMacro(pyev, EV_EMBED) ||
#endif
#if EV_FORK_ENABLE
        PyModule_AddWatcher(pyev, "Fork", &ForkType, NULL) ||
        PyModule_AddIntMacro(pyev, EV_FORK) ||
#endif
#if EV_ASYNC_ENABLE
        PyModule_AddWatcher(pyev, "Async", &AsyncType, NULL) ||
        PyModule_AddIntMacro(pyev, EV_ASYNC) ||
#endif
        /* additional events */
        PyModule_AddIntMacro(pyev, EV_CUSTOM) ||
        PyModule_AddIntMacro(pyev, EV_ERROR) ||
        /* priorities */
        PyModule_AddIntMacro(pyev, EV_MINPRI) ||
        PyModule_AddIntMacro(pyev, EV_MAXPRI)
       ) {
        goto fail;
    }
    /* setup libev */
    ev_set_allocator(pyev_allocator);
    ev_set_syserr_cb(pyev_syserr_cb);
    return pyev;

fail:
#if PY_MAJOR_VERSION >= 3
    Py_DECREF(pyev);
#endif
    return NULL;
}
Example #25
0
PyMODINIT_FUNC
PyInit__lzma(void)
{
    PyObject *m;

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

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

    if (PyModule_AddIntMacro(m, FORMAT_AUTO) == -1 ||
        PyModule_AddIntMacro(m, FORMAT_XZ) == -1 ||
        PyModule_AddIntMacro(m, FORMAT_ALONE) == -1 ||
        PyModule_AddIntMacro(m, FORMAT_RAW) == -1 ||
        ADD_INT_PREFIX_MACRO(m, CHECK_NONE) == -1 ||
        ADD_INT_PREFIX_MACRO(m, CHECK_CRC32) == -1 ||
        ADD_INT_PREFIX_MACRO(m, CHECK_CRC64) == -1 ||
        ADD_INT_PREFIX_MACRO(m, CHECK_SHA256) == -1 ||
        ADD_INT_PREFIX_MACRO(m, CHECK_ID_MAX) == -1 ||
        ADD_INT_PREFIX_MACRO(m, CHECK_UNKNOWN) == -1 ||
        ADD_INT_PREFIX_MACRO(m, FILTER_LZMA1) == -1 ||
        ADD_INT_PREFIX_MACRO(m, FILTER_LZMA2) == -1 ||
        ADD_INT_PREFIX_MACRO(m, FILTER_DELTA) == -1 ||
        ADD_INT_PREFIX_MACRO(m, FILTER_X86) == -1 ||
        ADD_INT_PREFIX_MACRO(m, FILTER_IA64) == -1 ||
        ADD_INT_PREFIX_MACRO(m, FILTER_ARM) == -1 ||
        ADD_INT_PREFIX_MACRO(m, FILTER_ARMTHUMB) == -1 ||
        ADD_INT_PREFIX_MACRO(m, FILTER_SPARC) == -1 ||
        ADD_INT_PREFIX_MACRO(m, FILTER_POWERPC) == -1 ||
        ADD_INT_PREFIX_MACRO(m, MF_HC3) == -1 ||
        ADD_INT_PREFIX_MACRO(m, MF_HC4) == -1 ||
        ADD_INT_PREFIX_MACRO(m, MF_BT2) == -1 ||
        ADD_INT_PREFIX_MACRO(m, MF_BT3) == -1 ||
        ADD_INT_PREFIX_MACRO(m, MF_BT4) == -1 ||
        ADD_INT_PREFIX_MACRO(m, MODE_FAST) == -1 ||
        ADD_INT_PREFIX_MACRO(m, MODE_NORMAL) == -1 ||
        ADD_INT_PREFIX_MACRO(m, PRESET_DEFAULT) == -1 ||
        ADD_INT_PREFIX_MACRO(m, PRESET_EXTREME) == -1)
        return NULL;

    Error = PyErr_NewExceptionWithDoc(
            "_lzma.LZMAError", "Call to liblzma failed.", NULL, NULL);
    if (Error == NULL)
        return NULL;
    Py_INCREF(Error);
    if (PyModule_AddObject(m, "LZMAError", Error) == -1)
        return NULL;

    if (PyType_Ready(&Compressor_type) == -1)
        return NULL;
    Py_INCREF(&Compressor_type);
    if (PyModule_AddObject(m, "LZMACompressor",
                           (PyObject *)&Compressor_type) == -1)
        return NULL;

    if (PyType_Ready(&Decompressor_type) == -1)
        return NULL;
    Py_INCREF(&Decompressor_type);
    if (PyModule_AddObject(m, "LZMADecompressor",
                           (PyObject *)&Decompressor_type) == -1)
        return NULL;

    return m;
}
Example #26
0
File: main.c Project: fluggo/Canvas
EXPORT PyMODINIT_FUNC
PyInit_libav() {
    static PyModuleDef mdef = {
        .m_base = PyModuleDef_HEAD_INIT,
        .m_name = "libav",
        .m_doc = "Libav support for the Fluggo media processing library.",

        // TODO: Consider making use of this; see Python docs
        .m_size = -1,
        .m_methods = module_methods,

        // TODO: Consider supporting module cleanup
    };

    PyObject *m = PyModule_Create( &mdef );

    // Make sure process is available and initialized
    if( !PyImport_ImportModule( "fluggo.media.process" ) )
        return NULL;

    init_AVVideoDecoder( m );
    init_AVVideoEncoder( m );
    init_AVAudioDecoder( m );
    init_AVDemuxer( m );
    init_AVMuxer( m );
    init_AVContainer( m );

    // Declare Libav pixel formats
    PyModule_AddIntMacro( m, PIX_FMT_NONE );
    PyModule_AddIntMacro( m, PIX_FMT_YUV420P );
    PyModule_AddIntMacro( m, PIX_FMT_YUYV422 );
    PyModule_AddIntMacro( m, PIX_FMT_RGB24 );
    PyModule_AddIntMacro( m, PIX_FMT_BGR24 );
    PyModule_AddIntMacro( m, PIX_FMT_YUV422P );
    PyModule_AddIntMacro( m, PIX_FMT_YUV444P );
    PyModule_AddIntMacro( m, PIX_FMT_YUV410P );
    PyModule_AddIntMacro( m, PIX_FMT_YUV411P );
    PyModule_AddIntMacro( m, PIX_FMT_GRAY8 );
    PyModule_AddIntMacro( m, PIX_FMT_MONOWHITE );
    PyModule_AddIntMacro( m, PIX_FMT_MONOBLACK );
    PyModule_AddIntMacro( m, PIX_FMT_PAL8 );
    PyModule_AddIntMacro( m, PIX_FMT_YUVJ420P );
    PyModule_AddIntMacro( m, PIX_FMT_YUVJ422P );
    PyModule_AddIntMacro( m, PIX_FMT_YUVJ444P );
    PyModule_AddIntMacro( m, PIX_FMT_XVMC_MPEG2_MC );
    PyModule_AddIntMacro( m, PIX_FMT_XVMC_MPEG2_IDCT );
    PyModule_AddIntMacro( m, PIX_FMT_UYVY422 );
    PyModule_AddIntMacro( m, PIX_FMT_UYYVYY411 );
    PyModule_AddIntMacro( m, PIX_FMT_BGR8 );
    PyModule_AddIntMacro( m, PIX_FMT_BGR4 );
    PyModule_AddIntMacro( m, PIX_FMT_BGR4_BYTE );
    PyModule_AddIntMacro( m, PIX_FMT_RGB8 );
    PyModule_AddIntMacro( m, PIX_FMT_RGB4 );
    PyModule_AddIntMacro( m, PIX_FMT_RGB4_BYTE );
    PyModule_AddIntMacro( m, PIX_FMT_NV12 );
    PyModule_AddIntMacro( m, PIX_FMT_NV21 );

    PyModule_AddIntMacro( m, PIX_FMT_ARGB );
    PyModule_AddIntMacro( m, PIX_FMT_RGBA );
    PyModule_AddIntMacro( m, PIX_FMT_ABGR );
    PyModule_AddIntMacro( m, PIX_FMT_BGRA );

    PyModule_AddIntMacro( m, PIX_FMT_GRAY16BE );
    PyModule_AddIntMacro( m, PIX_FMT_GRAY16LE );
    PyModule_AddIntMacro( m, PIX_FMT_YUV440P );
    PyModule_AddIntMacro( m, PIX_FMT_YUVJ440P );
    PyModule_AddIntMacro( m, PIX_FMT_YUVA420P );
    PyModule_AddIntMacro( m, PIX_FMT_VDPAU_H264 );
    PyModule_AddIntMacro( m, PIX_FMT_VDPAU_MPEG1 );
    PyModule_AddIntMacro( m, PIX_FMT_VDPAU_MPEG2 );
    PyModule_AddIntMacro( m, PIX_FMT_VDPAU_WMV3 );
    PyModule_AddIntMacro( m, PIX_FMT_VDPAU_VC1 );
    PyModule_AddIntMacro( m, PIX_FMT_RGB48BE );
    PyModule_AddIntMacro( m, PIX_FMT_RGB48LE );

    //PyModule_AddIntMacro( m, PIX_FMT_RGB565BE );
    //PyModule_AddIntMacro( m, PIX_FMT_RGB565LE );
    //PyModule_AddIntMacro( m, PIX_FMT_RGB555BE );
    //PyModule_AddIntMacro( m, PIX_FMT_RGB555LE );

    //PyModule_AddIntMacro( m, PIX_FMT_BGR565BE );
    //PyModule_AddIntMacro( m, PIX_FMT_BGR565LE );
    //PyModule_AddIntMacro( m, PIX_FMT_BGR555BE );
    //PyModule_AddIntMacro( m, PIX_FMT_BGR555LE );

    PyModule_AddIntMacro( m, PIX_FMT_VAAPI_MOCO );
    PyModule_AddIntMacro( m, PIX_FMT_VAAPI_IDCT );
    PyModule_AddIntMacro( m, PIX_FMT_VAAPI_VLD );

    //PyModule_AddIntMacro( m, PIX_FMT_YUV420P16LE );
    //PyModule_AddIntMacro( m, PIX_FMT_YUV420P16BE );
    //PyModule_AddIntMacro( m, PIX_FMT_YUV422P16LE );
    //PyModule_AddIntMacro( m, PIX_FMT_YUV422P16BE );
    //PyModule_AddIntMacro( m, PIX_FMT_YUV444P16LE );
    //PyModule_AddIntMacro( m, PIX_FMT_YUV444P16BE );

    PyModule_AddIntMacro( m, PIX_FMT_RGB32 );
    PyModule_AddIntMacro( m, PIX_FMT_RGB32_1 );
    PyModule_AddIntMacro( m, PIX_FMT_BGR32 );
    PyModule_AddIntMacro( m, PIX_FMT_BGR32_1 );

    PyModule_AddIntMacro( m, PIX_FMT_GRAY16 );
    PyModule_AddIntMacro( m, PIX_FMT_RGB48 );
    PyModule_AddIntMacro( m, PIX_FMT_RGB565 );
    PyModule_AddIntMacro( m, PIX_FMT_RGB555 );
    PyModule_AddIntMacro( m, PIX_FMT_BGR565 );
    PyModule_AddIntMacro( m, PIX_FMT_BGR555 );

    //PyModule_AddIntMacro( m, PIX_FMT_YUV420P16 );
    //PyModule_AddIntMacro( m, PIX_FMT_YUV422P16 );
    //PyModule_AddIntMacro( m, PIX_FMT_YUV444P16 );

    // Codecs
    PyModule_AddIntMacro( m, CODEC_ID_NONE );

    PyModule_AddIntMacro( m, CODEC_ID_MPEG1VIDEO );
    PyModule_AddIntMacro( m, CODEC_ID_MPEG2VIDEO );
    PyModule_AddIntMacro( m, CODEC_ID_MPEG2VIDEO_XVMC );
    PyModule_AddIntMacro( m, CODEC_ID_H261 );
    PyModule_AddIntMacro( m, CODEC_ID_H263 );
    PyModule_AddIntMacro( m, CODEC_ID_RV10 );
    PyModule_AddIntMacro( m, CODEC_ID_RV20 );
    PyModule_AddIntMacro( m, CODEC_ID_MJPEG );
    PyModule_AddIntMacro( m, CODEC_ID_MJPEGB );
    PyModule_AddIntMacro( m, CODEC_ID_LJPEG );
    PyModule_AddIntMacro( m, CODEC_ID_SP5X );
    PyModule_AddIntMacro( m, CODEC_ID_JPEGLS );
    PyModule_AddIntMacro( m, CODEC_ID_MPEG4 );
    PyModule_AddIntMacro( m, CODEC_ID_RAWVIDEO );
    PyModule_AddIntMacro( m, CODEC_ID_MSMPEG4V1 );
    PyModule_AddIntMacro( m, CODEC_ID_MSMPEG4V2 );
    PyModule_AddIntMacro( m, CODEC_ID_MSMPEG4V3 );
    PyModule_AddIntMacro( m, CODEC_ID_WMV1 );
    PyModule_AddIntMacro( m, CODEC_ID_WMV2 );
    PyModule_AddIntMacro( m, CODEC_ID_H263P );
    PyModule_AddIntMacro( m, CODEC_ID_H263I );
    PyModule_AddIntMacro( m, CODEC_ID_FLV1 );
    PyModule_AddIntMacro( m, CODEC_ID_SVQ1 );
    PyModule_AddIntMacro( m, CODEC_ID_SVQ3 );
    PyModule_AddIntMacro( m, CODEC_ID_DVVIDEO );
    PyModule_AddIntMacro( m, CODEC_ID_HUFFYUV );
    PyModule_AddIntMacro( m, CODEC_ID_CYUV );
    PyModule_AddIntMacro( m, CODEC_ID_H264 );
    PyModule_AddIntMacro( m, CODEC_ID_INDEO3 );
    PyModule_AddIntMacro( m, CODEC_ID_VP3 );
    PyModule_AddIntMacro( m, CODEC_ID_THEORA );
    PyModule_AddIntMacro( m, CODEC_ID_ASV1 );
    PyModule_AddIntMacro( m, CODEC_ID_ASV2 );
    PyModule_AddIntMacro( m, CODEC_ID_FFV1 );
    PyModule_AddIntMacro( m, CODEC_ID_4XM );
    PyModule_AddIntMacro( m, CODEC_ID_VCR1 );
    PyModule_AddIntMacro( m, CODEC_ID_CLJR );
    PyModule_AddIntMacro( m, CODEC_ID_MDEC );
    PyModule_AddIntMacro( m, CODEC_ID_ROQ );
    PyModule_AddIntMacro( m, CODEC_ID_INTERPLAY_VIDEO );
    PyModule_AddIntMacro( m, CODEC_ID_XAN_WC3 );
    PyModule_AddIntMacro( m, CODEC_ID_XAN_WC4 );
    PyModule_AddIntMacro( m, CODEC_ID_RPZA );
    PyModule_AddIntMacro( m, CODEC_ID_CINEPAK );
    PyModule_AddIntMacro( m, CODEC_ID_WS_VQA );
    PyModule_AddIntMacro( m, CODEC_ID_MSRLE );
    PyModule_AddIntMacro( m, CODEC_ID_MSVIDEO1 );
    PyModule_AddIntMacro( m, CODEC_ID_IDCIN );
    PyModule_AddIntMacro( m, CODEC_ID_8BPS );
    PyModule_AddIntMacro( m, CODEC_ID_SMC );
    PyModule_AddIntMacro( m, CODEC_ID_FLIC );
    PyModule_AddIntMacro( m, CODEC_ID_TRUEMOTION1 );
    PyModule_AddIntMacro( m, CODEC_ID_VMDVIDEO );
    PyModule_AddIntMacro( m, CODEC_ID_MSZH );
    PyModule_AddIntMacro( m, CODEC_ID_ZLIB );
    PyModule_AddIntMacro( m, CODEC_ID_QTRLE );
    PyModule_AddIntMacro( m, CODEC_ID_SNOW );
    PyModule_AddIntMacro( m, CODEC_ID_TSCC );
    PyModule_AddIntMacro( m, CODEC_ID_ULTI );
    PyModule_AddIntMacro( m, CODEC_ID_QDRAW );
    PyModule_AddIntMacro( m, CODEC_ID_VIXL );
    PyModule_AddIntMacro( m, CODEC_ID_QPEG );
    PyModule_AddIntMacro( m, CODEC_ID_PNG );
    PyModule_AddIntMacro( m, CODEC_ID_PPM );
    PyModule_AddIntMacro( m, CODEC_ID_PBM );
    PyModule_AddIntMacro( m, CODEC_ID_PGM );
    PyModule_AddIntMacro( m, CODEC_ID_PGMYUV );
    PyModule_AddIntMacro( m, CODEC_ID_PAM );
    PyModule_AddIntMacro( m, CODEC_ID_FFVHUFF );
    PyModule_AddIntMacro( m, CODEC_ID_RV30 );
    PyModule_AddIntMacro( m, CODEC_ID_RV40 );
    PyModule_AddIntMacro( m, CODEC_ID_VC1 );
    PyModule_AddIntMacro( m, CODEC_ID_WMV3 );
    PyModule_AddIntMacro( m, CODEC_ID_LOCO );
    PyModule_AddIntMacro( m, CODEC_ID_WNV1 );
    PyModule_AddIntMacro( m, CODEC_ID_AASC );
    PyModule_AddIntMacro( m, CODEC_ID_INDEO2 );
    PyModule_AddIntMacro( m, CODEC_ID_FRAPS );
    PyModule_AddIntMacro( m, CODEC_ID_TRUEMOTION2 );
    PyModule_AddIntMacro( m, CODEC_ID_BMP );
    PyModule_AddIntMacro( m, CODEC_ID_CSCD );
    PyModule_AddIntMacro( m, CODEC_ID_MMVIDEO );
    PyModule_AddIntMacro( m, CODEC_ID_ZMBV );
    PyModule_AddIntMacro( m, CODEC_ID_AVS );
    PyModule_AddIntMacro( m, CODEC_ID_SMACKVIDEO );
    PyModule_AddIntMacro( m, CODEC_ID_NUV );
    PyModule_AddIntMacro( m, CODEC_ID_KMVC );
    PyModule_AddIntMacro( m, CODEC_ID_FLASHSV );
    PyModule_AddIntMacro( m, CODEC_ID_CAVS );
    PyModule_AddIntMacro( m, CODEC_ID_JPEG2000 );
    PyModule_AddIntMacro( m, CODEC_ID_VMNC );
    PyModule_AddIntMacro( m, CODEC_ID_VP5 );
    PyModule_AddIntMacro( m, CODEC_ID_VP6 );
    PyModule_AddIntMacro( m, CODEC_ID_VP6F );
    PyModule_AddIntMacro( m, CODEC_ID_TARGA );
    PyModule_AddIntMacro( m, CODEC_ID_DSICINVIDEO );
    PyModule_AddIntMacro( m, CODEC_ID_TIERTEXSEQVIDEO );
    PyModule_AddIntMacro( m, CODEC_ID_TIFF );
    PyModule_AddIntMacro( m, CODEC_ID_GIF );
    //PyModule_AddIntMacro( m, CODEC_ID_FFH264 );
    PyModule_AddIntMacro( m, CODEC_ID_DXA );
    PyModule_AddIntMacro( m, CODEC_ID_DNXHD );
    PyModule_AddIntMacro( m, CODEC_ID_THP );
    PyModule_AddIntMacro( m, CODEC_ID_SGI );
    PyModule_AddIntMacro( m, CODEC_ID_C93 );
    PyModule_AddIntMacro( m, CODEC_ID_BETHSOFTVID );
    PyModule_AddIntMacro( m, CODEC_ID_PTX );
    PyModule_AddIntMacro( m, CODEC_ID_TXD );
    PyModule_AddIntMacro( m, CODEC_ID_VP6A );
    PyModule_AddIntMacro( m, CODEC_ID_AMV );
    PyModule_AddIntMacro( m, CODEC_ID_VB );
    PyModule_AddIntMacro( m, CODEC_ID_PCX );
    PyModule_AddIntMacro( m, CODEC_ID_SUNRAST );
    PyModule_AddIntMacro( m, CODEC_ID_INDEO4 );
    PyModule_AddIntMacro( m, CODEC_ID_INDEO5 );
    PyModule_AddIntMacro( m, CODEC_ID_MIMIC );
    PyModule_AddIntMacro( m, CODEC_ID_RL2 );
    PyModule_AddIntMacro( m, CODEC_ID_8SVX_EXP );
    PyModule_AddIntMacro( m, CODEC_ID_8SVX_FIB );
    PyModule_AddIntMacro( m, CODEC_ID_ESCAPE124 );
    PyModule_AddIntMacro( m, CODEC_ID_DIRAC );
    PyModule_AddIntMacro( m, CODEC_ID_BFI );
    PyModule_AddIntMacro( m, CODEC_ID_CMV );
    PyModule_AddIntMacro( m, CODEC_ID_MOTIONPIXELS );
    PyModule_AddIntMacro( m, CODEC_ID_TGV );
    PyModule_AddIntMacro( m, CODEC_ID_TGQ );
    PyModule_AddIntMacro( m, CODEC_ID_TQI );
    //PyModule_AddIntMacro( m, CODEC_ID_AURA );
    //PyModule_AddIntMacro( m, CODEC_ID_AURA2 );
    //PyModule_AddIntMacro( m, CODEC_ID_V210X );
    //PyModule_AddIntMacro( m, CODEC_ID_TMV );
    //PyModule_AddIntMacro( m, CODEC_ID_V210 );
    //PyModule_AddIntMacro( m, CODEC_ID_DPX );
    //PyModule_AddIntMacro( m, CODEC_ID_MAD );

    PyModule_AddIntMacro( m, CODEC_ID_PCM_S16LE );
    PyModule_AddIntMacro( m, CODEC_ID_PCM_S16BE );
    PyModule_AddIntMacro( m, CODEC_ID_PCM_U16LE );
    PyModule_AddIntMacro( m, CODEC_ID_PCM_U16BE );
    PyModule_AddIntMacro( m, CODEC_ID_PCM_S8 );
    PyModule_AddIntMacro( m, CODEC_ID_PCM_U8 );
    PyModule_AddIntMacro( m, CODEC_ID_PCM_MULAW );
    PyModule_AddIntMacro( m, CODEC_ID_PCM_ALAW );
    PyModule_AddIntMacro( m, CODEC_ID_PCM_S32LE );
    PyModule_AddIntMacro( m, CODEC_ID_PCM_S32BE );
    PyModule_AddIntMacro( m, CODEC_ID_PCM_U32LE );
    PyModule_AddIntMacro( m, CODEC_ID_PCM_U32BE );
    PyModule_AddIntMacro( m, CODEC_ID_PCM_S24LE );
    PyModule_AddIntMacro( m, CODEC_ID_PCM_S24BE );
    PyModule_AddIntMacro( m, CODEC_ID_PCM_U24LE );
    PyModule_AddIntMacro( m, CODEC_ID_PCM_U24BE );
    PyModule_AddIntMacro( m, CODEC_ID_PCM_S24DAUD );
    PyModule_AddIntMacro( m, CODEC_ID_PCM_ZORK );
    PyModule_AddIntMacro( m, CODEC_ID_PCM_S16LE_PLANAR );
    PyModule_AddIntMacro( m, CODEC_ID_PCM_DVD );
    PyModule_AddIntMacro( m, CODEC_ID_PCM_F32BE );
    PyModule_AddIntMacro( m, CODEC_ID_PCM_F32LE );
    PyModule_AddIntMacro( m, CODEC_ID_PCM_F64BE );
    PyModule_AddIntMacro( m, CODEC_ID_PCM_F64LE );
    //PyModule_AddIntMacro( m, CODEC_ID_PCM_BLURAY );

    PyModule_AddIntMacro( m, CODEC_ID_ADPCM_IMA_QT );
    PyModule_AddIntMacro( m, CODEC_ID_ADPCM_IMA_WAV );
    PyModule_AddIntMacro( m, CODEC_ID_ADPCM_IMA_DK3 );
    PyModule_AddIntMacro( m, CODEC_ID_ADPCM_IMA_DK4 );
    PyModule_AddIntMacro( m, CODEC_ID_ADPCM_IMA_WS );
    PyModule_AddIntMacro( m, CODEC_ID_ADPCM_IMA_SMJPEG );
    PyModule_AddIntMacro( m, CODEC_ID_ADPCM_MS );
    PyModule_AddIntMacro( m, CODEC_ID_ADPCM_4XM );
    PyModule_AddIntMacro( m, CODEC_ID_ADPCM_XA );
    PyModule_AddIntMacro( m, CODEC_ID_ADPCM_ADX );
    PyModule_AddIntMacro( m, CODEC_ID_ADPCM_EA );
    PyModule_AddIntMacro( m, CODEC_ID_ADPCM_G726 );
    PyModule_AddIntMacro( m, CODEC_ID_ADPCM_CT );
    PyModule_AddIntMacro( m, CODEC_ID_ADPCM_SWF );
    PyModule_AddIntMacro( m, CODEC_ID_ADPCM_YAMAHA );
    PyModule_AddIntMacro( m, CODEC_ID_ADPCM_SBPRO_4 );
    PyModule_AddIntMacro( m, CODEC_ID_ADPCM_SBPRO_3 );
    PyModule_AddIntMacro( m, CODEC_ID_ADPCM_SBPRO_2 );
    PyModule_AddIntMacro( m, CODEC_ID_ADPCM_THP );
    PyModule_AddIntMacro( m, CODEC_ID_ADPCM_IMA_AMV );
    PyModule_AddIntMacro( m, CODEC_ID_ADPCM_EA_R1 );
    PyModule_AddIntMacro( m, CODEC_ID_ADPCM_EA_R3 );
    PyModule_AddIntMacro( m, CODEC_ID_ADPCM_EA_R2 );
    PyModule_AddIntMacro( m, CODEC_ID_ADPCM_IMA_EA_SEAD );
    PyModule_AddIntMacro( m, CODEC_ID_ADPCM_IMA_EA_EACS );
    PyModule_AddIntMacro( m, CODEC_ID_ADPCM_EA_XAS );
    PyModule_AddIntMacro( m, CODEC_ID_ADPCM_EA_MAXIS_XA );
    PyModule_AddIntMacro( m, CODEC_ID_ADPCM_IMA_ISS );

    PyModule_AddIntMacro( m, CODEC_ID_AMR_NB );
    PyModule_AddIntMacro( m, CODEC_ID_AMR_WB );

    PyModule_AddIntMacro( m, CODEC_ID_RA_144 );
    PyModule_AddIntMacro( m, CODEC_ID_RA_288 );

    PyModule_AddIntMacro( m, CODEC_ID_ROQ_DPCM );
    PyModule_AddIntMacro( m, CODEC_ID_INTERPLAY_DPCM );
    PyModule_AddIntMacro( m, CODEC_ID_XAN_DPCM );
    PyModule_AddIntMacro( m, CODEC_ID_SOL_DPCM );

    PyModule_AddIntMacro( m, CODEC_ID_MP2 );
    PyModule_AddIntMacro( m, CODEC_ID_MP3 );
    PyModule_AddIntMacro( m, CODEC_ID_AAC );
    PyModule_AddIntMacro( m, CODEC_ID_AC3 );
    PyModule_AddIntMacro( m, CODEC_ID_DTS );
    PyModule_AddIntMacro( m, CODEC_ID_VORBIS );
    PyModule_AddIntMacro( m, CODEC_ID_DVAUDIO );
    PyModule_AddIntMacro( m, CODEC_ID_WMAV1 );
    PyModule_AddIntMacro( m, CODEC_ID_WMAV2 );
    PyModule_AddIntMacro( m, CODEC_ID_MACE3 );
    PyModule_AddIntMacro( m, CODEC_ID_MACE6 );
    PyModule_AddIntMacro( m, CODEC_ID_VMDAUDIO );
    PyModule_AddIntMacro( m, CODEC_ID_SONIC );
    PyModule_AddIntMacro( m, CODEC_ID_SONIC_LS );
    PyModule_AddIntMacro( m, CODEC_ID_FLAC );
    PyModule_AddIntMacro( m, CODEC_ID_MP3ADU );
    PyModule_AddIntMacro( m, CODEC_ID_MP3ON4 );
    PyModule_AddIntMacro( m, CODEC_ID_SHORTEN );
    PyModule_AddIntMacro( m, CODEC_ID_ALAC );
    PyModule_AddIntMacro( m, CODEC_ID_WESTWOOD_SND1 );
    PyModule_AddIntMacro( m, CODEC_ID_GSM );
    PyModule_AddIntMacro( m, CODEC_ID_QDM2 );
    PyModule_AddIntMacro( m, CODEC_ID_COOK );
    PyModule_AddIntMacro( m, CODEC_ID_TRUESPEECH );
    PyModule_AddIntMacro( m, CODEC_ID_TTA );
    PyModule_AddIntMacro( m, CODEC_ID_SMACKAUDIO );
    PyModule_AddIntMacro( m, CODEC_ID_QCELP );
    PyModule_AddIntMacro( m, CODEC_ID_WAVPACK );
    PyModule_AddIntMacro( m, CODEC_ID_DSICINAUDIO );
    PyModule_AddIntMacro( m, CODEC_ID_IMC );
    PyModule_AddIntMacro( m, CODEC_ID_MUSEPACK7 );
    PyModule_AddIntMacro( m, CODEC_ID_MLP );
    PyModule_AddIntMacro( m, CODEC_ID_GSM_MS );
    PyModule_AddIntMacro( m, CODEC_ID_ATRAC3 );
    PyModule_AddIntMacro( m, CODEC_ID_VOXWARE );
    PyModule_AddIntMacro( m, CODEC_ID_APE );
    PyModule_AddIntMacro( m, CODEC_ID_NELLYMOSER );
    PyModule_AddIntMacro( m, CODEC_ID_MUSEPACK8 );
    PyModule_AddIntMacro( m, CODEC_ID_SPEEX );
    PyModule_AddIntMacro( m, CODEC_ID_WMAVOICE );
    PyModule_AddIntMacro( m, CODEC_ID_WMAPRO );
    PyModule_AddIntMacro( m, CODEC_ID_WMALOSSLESS );
    PyModule_AddIntMacro( m, CODEC_ID_ATRAC3P );
    PyModule_AddIntMacro( m, CODEC_ID_EAC3 );
    PyModule_AddIntMacro( m, CODEC_ID_SIPR );
    PyModule_AddIntMacro( m, CODEC_ID_MP1 );
    //PyModule_AddIntMacro( m, CODEC_ID_TWINVQ );
    //PyModule_AddIntMacro( m, CODEC_ID_TRUEHD );
    //PyModule_AddIntMacro( m, CODEC_ID_MP4ALS );

    PyModule_AddIntMacro( m, CODEC_ID_DVD_SUBTITLE );
    PyModule_AddIntMacro( m, CODEC_ID_DVB_SUBTITLE );
    PyModule_AddIntMacro( m, CODEC_ID_TEXT );
    PyModule_AddIntMacro( m, CODEC_ID_XSUB );
    PyModule_AddIntMacro( m, CODEC_ID_SSA );
    PyModule_AddIntMacro( m, CODEC_ID_MOV_TEXT );
    //PyModule_AddIntMacro( m, CODEC_ID_HDMV_PGS_SUBTITLE );

    PyModule_AddIntMacro( m, CODEC_ID_TTF );

    PyModule_AddIntMacro( m, CODEC_ID_PROBE );

    return m;
}