Esempio n. 1
0
int main (int argc, char *argv[])
{
	struct version v;
	show_version(&v);
	g_log_set_default_handler(logger_stdout_log, NULL);

	struct options *opt = malloc(sizeof(struct options));
	memset(opt, 0, sizeof(struct options));

	if( options_parse(opt, argc, argv) == false )
	{
		g_error("Could not parse options!\n");
	}

	if( options_validate(opt) == false )
	{
		g_error("Invalid options");
	}

	g_log_set_default_handler(logger_stdout_log, opt->stdOUT.filter);
	// gc
	if( opt->garbage != NULL )
	{
#ifdef HAVE_LIBGC
		g_message("gc mode %s", opt->garbage);
		if( g_mem_gc_friendly != TRUE )
		{
			g_error("export G_DEBUG=gc-friendly\nexport G_SLICE=always-malloc\n for gc");
		}


		static GMemVTable memory_vtable =
		{
			.malloc = GC_malloc,
			.realloc = GC_realloc,
			.free   = GC_free,
		};

		g_mem_set_vtable(&memory_vtable);
		if( strcmp(opt->garbage, "debug") == 0 )
			GC_find_leak = 1;

		// set libev allocator
		typedef void *(*moron)(void *ptr, long size);
		ev_set_allocator((moron)GC_realloc);
#endif
	}
Esempio n. 2
0
File: pyev.c Progetto: 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;
}