Beispiel #1
0
PyObject *v3_write(PyObject *_, PyObject *args)
{
  Vj1b* dut = ((v3*)_)->dut;
  const char *s;
  Py_ssize_t n;
  if (!PyArg_ParseTuple(args, "s#", &s, &n))
    return NULL;

  for (Py_ssize_t i = 0; i < n; i++) {
    dut->uart0_data = s[i];
    dut->uart0_valid = 1;
    do {
      if (PyErr_CheckSignals())
        return NULL;
      CYCLE();
    } while (dut->uart0_rd == 0);
    do {
      if (PyErr_CheckSignals())
        return NULL;
      CYCLE();
    } while (dut->uart0_rd == 1);
  }

  dut->uart0_valid = 0;
  Py_RETURN_NONE;
}
static gboolean
pyg_signal_watch_check(GSource *source)
{
    PyGILState_STATE state;
    GMainLoop *main_loop;

#ifdef HAVE_PYSIGNAL_SETWAKEUPFD
    PySignalWatchSource *real_source = (PySignalWatchSource *)source;
    GPollFD *poll_fd = &real_source->fd;
    unsigned char dummy;
    if (poll_fd->revents & G_IO_IN)
	read(poll_fd->fd, &dummy, 1);
#endif

    state = pyglib_gil_state_ensure();

    main_loop = pyg_get_current_main_loop();

    if (PyErr_CheckSignals() == -1 && main_loop != NULL) {
	PyErr_SetNone(PyExc_KeyboardInterrupt);
	g_main_loop_quit(main_loop);
    }

    pyglib_gil_state_release(state);

    return FALSE;
}
Beispiel #3
0
int riscos_sleep(double delay)
{
	os_t starttime, endtime, time; /* monotonic times (centiseconds) */
	int *pollword, ret;
	osbool claimed;

        /* calculate end time */
	starttime = os_read_monotonic_time();
	if (starttime + 100.0*delay >INT_MAX)
		endtime = INT_MAX;
	else
		endtime = (os_t)(starttime + 100.0*delay);

	/* allocate (in RMA) and set pollword for xupcall_sleep */
	pollword = osmodule_alloc(4);
	*pollword = 1;

	time = starttime;
	ret = 0;
	while ( time<endtime && time>=starttime ) {
		xupcall_sleep (pollword, &claimed);
		if (PyErr_CheckSignals()) {
			ret = 1;
			break;
		}
		time = os_read_monotonic_time();
	}

	/* deallocate pollword */
	osmodule_free(pollword);
	return ret;
}
Beispiel #4
0
static PyObject *p_sendfd(PyObject *self, PyObject *args)
{
    int sock, fd, ret;
    PyObject *data;
    
    if(!PyArg_ParseTuple(args, "iiO", &sock, &fd, &data))
	return(NULL);
    if(!PyString_Check(data)) {
	PyErr_SetString(PyExc_TypeError, "datagram must be a string");
	return(NULL);
    }
    while(1) {
	Py_BEGIN_ALLOW_THREADS;
	ret = sendfd(sock, fd, PyString_AsString(data), PyString_Size(data));
	Py_END_ALLOW_THREADS;
	if(ret < 0) {
	    if(errno == EINTR) {
		if(PyErr_CheckSignals())
		    return(NULL);
		continue;
	    }
	    PyErr_SetFromErrno(PyExc_OSError);
	    return(NULL);
	}
	Py_RETURN_NONE;
    }
}
Beispiel #5
0
static PyObject *
Simulator_run(Simulator *self, PyObject *args)
{
    PyObject *ret = NULL;
    int status, not_done;
    uint64_t chunk = 8192; 
    double max_time = DBL_MAX;
    if (Simulator_check_sim(self) != 0) {
        goto out;
    }
    if (!PyArg_ParseTuple(args, "|d", &max_time)) {
        goto out;
    }
    not_done = 1; 
    self->sim->max_time = max_time;
    while (not_done) {
        status = sim_simulate(self->sim, chunk);
        if (status < 0) {
            handle_library_error(status);
            goto out;
        }
        not_done = status != 0; 
        if (PyErr_CheckSignals() < 0) {
            goto out;
        }
    }
    /* return True if complete coalescence has occured */
    ret = self->sim->time < max_time ? Py_True : Py_False;
    Py_INCREF(ret);
out:
    return ret;
}
Beispiel #6
0
static int
_posixshmem_shm_open_impl(PyObject *module, PyObject *path, int flags,
                          int mode)
/*[clinic end generated code: output=8d110171a4fa20df input=e83b58fa802fac25]*/
{
    int fd;
    int async_err = 0;
    const char *name = PyUnicode_AsUTF8(path);
    if (name == NULL) {
        return -1;
    }
    do {
        Py_BEGIN_ALLOW_THREADS
        fd = shm_open(name, flags, mode);
        Py_END_ALLOW_THREADS
    } while (fd < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));

    if (fd < 0) {
        if (!async_err)
            PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError, path);
        return -1;
    }

    return fd;
}
Beispiel #7
0
static int color_setr(PyColor *self, PyObject *value, void *closure)
{
    int v;

    if (PyErr_CheckSignals())
       return -1;

    if (!value)
    {
       PyErr_SetString(PyExc_TypeError, "Cannot delete red component");
       return -1;
    }

    if (!PyInt_Check(value))
    {
       PyErr_SetString(PyExc_TypeError, "Red component must be an integer.");
       return -1;
    }

    v = PyInt_AsLong(value);

    if ((v < 0) || (v > 255))
    {
       PyErr_SetString(PyExc_ValueError, "Red component must be between 0 and 255");
       return -1;
    }

    self->color = (self->color & 0xFFFFFF00U) | (u32)v;

    return 0;
}
Beispiel #8
0
static PyObject *p_recvfd(PyObject *self, PyObject *args)
{
    int fd, ret;
    char *data;
    size_t dlen;
    PyObject *ro;
    
    fd = 0;
    if(!PyArg_ParseTuple(args, "|i", &fd))
	return(NULL);
    while(1) {
	Py_BEGIN_ALLOW_THREADS;
	ret = recvfd(fd, &data, &dlen);
	Py_END_ALLOW_THREADS;
	if(ret < 0) {
	    if(errno == 0)
		return(Py_BuildValue("OO", Py_None, Py_None));
	    if(errno == EINTR) {
		if(PyErr_CheckSignals())
		    return(NULL);
		continue;
	    }
	    PyErr_SetFromErrno(PyExc_OSError);
	    return(NULL);
	}
	ro = Py_BuildValue("Ni", PyString_FromStringAndSize(data, dlen), ret);
	free(data);
	return(ro);
    }
}
Beispiel #9
0
static int
_Py_open_impl(const char *pathname, int flags, int gil_held)
{
    int fd;
    int async_err = 0;
#ifndef MS_WINDOWS
    int *atomic_flag_works;
#endif

#ifdef MS_WINDOWS
    flags |= O_NOINHERIT;
#elif defined(O_CLOEXEC)
    atomic_flag_works = &_Py_open_cloexec_works;
    flags |= O_CLOEXEC;
#else
    atomic_flag_works = NULL;
#endif

    if (gil_held) {
        do {
            Py_BEGIN_ALLOW_THREADS
            fd = open(pathname, flags);
            Py_END_ALLOW_THREADS
        } while (fd < 0
                 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
        if (async_err)
            return -1;
        if (fd < 0) {
            PyErr_SetFromErrnoWithFilename(PyExc_OSError, pathname);
            return -1;
        }
    }
    else {
Beispiel #10
0
static PyObject* image_getsizeY(PyImage *self, void *closure)
{
    if (PyErr_CheckSignals())
       return NULL;

    return Py_BuildValue("i", self->pImg->sizeY);
}
Beispiel #11
0
static int
tb_printinternal(tracebackobject *tb, PyObject *f, int limit)
{
	int err = 0;
	int depth = 0;
	tracebackobject *tb1 = tb;
	while (tb1 != NULL) {
		depth++;
		tb1 = tb1->tb_next;
	}
	while (tb != NULL && err == 0) {
		if (depth <= limit) {
			err = tb_displayline(f,
			    PyString_AsString(
				    tb->tb_frame->f_code->co_filename),
			    tb->tb_lineno,
			    PyString_AsString(tb->tb_frame->f_code->co_name));
		}
		depth--;
		tb = tb->tb_next;
		if (err == 0)
			err = PyErr_CheckSignals();
	}
	return err;
}
Beispiel #12
0
static PyObject* pspsnd_setSndFxVolume(PyObject *self,
                                       PyObject *args,
                                       PyObject *kwargs)
{
    int volume;

    if (!PyArg_ParseTuple(args, "i:setSndFxVolume", &volume))
       return NULL;

    if (PyErr_CheckSignals())
       return NULL;

#ifdef CHECKTYPE
    if ((volume < 0) || (volume > 255))
    {
       PyErr_SetString(PyExc_ValueError, "Bad volume value");
       return NULL;
    }
#endif

    PSPSND::Sound::setVolume((unsigned char)volume);

    Py_INCREF(Py_None);
    return Py_None;
}
Beispiel #13
0
static PyObject* image_getangle(PyImage *self, void *closure)
{
    if (PyErr_CheckSignals())
       return NULL;

    return Py_BuildValue("f", self->pImg->angle);
}
Beispiel #14
0
static void
pyuv__check_signals(uv_poll_t *handle, int status, int events)
{
    PyGILState_STATE gstate = PyGILState_Ensure();
    SignalChecker *self;

    ASSERT(handle);

    self = PYUV_CONTAINER_OF(handle, SignalChecker, poll_h);

    if (status == 0) {
        ASSERT(events == UV_READABLE);
    }

    /* Drain the fd */
    if (pyuv__drain_poll_fd(self->fd) != 0) {
        uv_poll_stop(handle);
    }

    /* Check for signals */
    PyErr_CheckSignals();
    if (PyErr_Occurred()) {
        handle_uncaught_exception(HANDLE(self)->loop);
    }

    Py_DECREF(self);

    PyGILState_Release(gstate);
}
Beispiel #15
0
static PyObject* color_getg(PyColor *self, void *closure)
{
    if (PyErr_CheckSignals())
       return NULL;

    return Py_BuildValue("i", (self->color >> 8) & 0xFF);
}
Beispiel #16
0
static char *
readline_until_enter_or_signal(const char *prompt, int *signal)
{
    char * not_done_reading = "";
    fd_set selectset;

    *signal = 0;
#ifdef HAVE_RL_CATCH_SIGNAL
    rl_catch_signals = 0;
#endif

    rl_callback_handler_install (prompt, rlhandler);
    FD_ZERO(&selectset);

    completed_input_string = not_done_reading;

    while (completed_input_string == not_done_reading) {
        int has_input = 0, err = 0;

        while (!has_input)
        {               struct timeval timeout = {0, 100000}; /* 0.1 seconds */

            /* [Bug #1552726] Only limit the pause if an input hook has been
               defined.  */
            struct timeval *timeoutp = NULL;
            if (PyOS_InputHook)
                timeoutp = &timeout;
            FD_SET(fileno(rl_instream), &selectset);
            /* select resets selectset if no input was available */
            has_input = select(fileno(rl_instream) + 1, &selectset,
                               NULL, NULL, timeoutp);
            err = errno;
            if(PyOS_InputHook) PyOS_InputHook();
        }

        if (has_input > 0) {
            rl_callback_read_char();
        }
        else if (err == EINTR) {
            int s;
#ifdef WITH_THREAD
            PyEval_RestoreThread(_PyOS_ReadlineTState);
#endif
            s = PyErr_CheckSignals();
#ifdef WITH_THREAD
            PyEval_SaveThread();
#endif
            if (s < 0) {
                rl_free_line_state();
                rl_cleanup_after_signal();
                rl_callback_handler_remove();
                *signal = 1;
                completed_input_string = NULL;
            }
        }
    }

    return completed_input_string;
}
Beispiel #17
0
static CYTHON_INLINE void gevent_check_signals(struct PyGeventLoopObject* loop) {
    if (!ev_is_default_loop(loop->_ptr)) {
        /* only reporting signals on the default loop */
        return;
    }
    PyErr_CheckSignals();
    if (PyErr_Occurred()) gevent_handle_error(loop, Py_None);
}
Beispiel #18
0
static int
sem_timedwait_save(sem_t *sem, struct timespec *deadline, PyThreadState *_save)
{
    int res;
    unsigned long delay, difference;
    struct timeval now, tvdeadline, tvdelay;

    errno = 0;
    tvdeadline.tv_sec = deadline->tv_sec;
    tvdeadline.tv_usec = deadline->tv_nsec / 1000;

    for (delay = 0 ; ; delay += 1000) {
        /* poll */
        if (sem_trywait(sem) == 0)
            return 0;
        else if (errno != EAGAIN)
            return MP_STANDARD_ERROR;

        /* get current time */
        if (gettimeofday(&now, NULL) < 0)
            return MP_STANDARD_ERROR;

        /* check for timeout */
        if (tvdeadline.tv_sec < now.tv_sec ||
            (tvdeadline.tv_sec == now.tv_sec &&
             tvdeadline.tv_usec <= now.tv_usec)) {
            errno = ETIMEDOUT;
            return MP_STANDARD_ERROR;
        }

        /* calculate how much time is left */
        difference = (tvdeadline.tv_sec - now.tv_sec) * 1000000 +
            (tvdeadline.tv_usec - now.tv_usec);

        /* check delay not too long -- maximum is 20 msecs */
        if (delay > 20000)
            delay = 20000;
        if (delay > difference)
            delay = difference;

        /* sleep */
        tvdelay.tv_sec = delay / 1000000;
        tvdelay.tv_usec = delay % 1000000;
        if (select(0, NULL, NULL, NULL, &tvdelay) < 0)
            return MP_STANDARD_ERROR;

        /* check for signals */
        Py_BLOCK_THREADS
        res = PyErr_CheckSignals();
        Py_UNBLOCK_THREADS

        if (res) {
            errno = EINTR;
            return MP_EXCEPTION_HAS_BEEN_SET;
        }
    }
}
Beispiel #19
0
PyObject *
py_download_url(G_GNUC_UNUSED PyObject *self, PyObject *args)
{
    gboolean ret;
    PyObject *py_handle;
    LrHandle *handle = NULL;
    char *url;
    int fd;
    GError *tmp_err = NULL;
    PyThreadState *state = NULL;

    if (!PyArg_ParseTuple(args, "Osi:download_url",
                          &py_handle, &url, &fd))
        return NULL;

    Py_XINCREF(py_handle);

    if (HandleObject_Check(py_handle)) {
        handle = Handle_FromPyObject(py_handle);
    } else if (py_handle != Py_None) {
        PyErr_SetString(PyExc_TypeError, "Only Handle or None is supported");
        return NULL;
    }

    // XXX: GIL Hack
    int hack_rc = gil_logger_hack_begin(&state);
    if (hack_rc == GIL_HACK_ERROR)
        return NULL;

    BeginAllowThreads(&state);
    ret = lr_download_url(handle, url, fd, &tmp_err);
    EndAllowThreads(&state);

    // XXX: GIL Hack
    if (!gil_logger_hack_end(hack_rc))
        return NULL;

    assert((ret && !tmp_err) || (!ret && tmp_err));

    if (ret)
        Py_RETURN_NONE; // All fine - Return None

    // Error occurred
    if (PyErr_Occurred()) {
        // Python exception occurred (in a python callback probably)
        return NULL;
    } else if(tmp_err->code == LRE_INTERRUPTED) {
        // Interrupted by Ctr+C
        g_error_free(tmp_err);
        PyErr_SetInterrupt();
        PyErr_CheckSignals();
        return NULL;
    } else {
        // Return exception created from GError
        RETURN_ERROR(&tmp_err, -1, NULL);
    }
}
Beispiel #20
0
/* Check whether we received an interrupt before sig_on().
 * Return 0 if there was an interrupt, 1 otherwise. */
int _sig_on_interrupt_received()
{
    _signals.interrupt_received = 0;
    if (PyErr_CheckSignals())
    {
        _signals.sig_on_count = 0;
        return 0;
    }
    return 1;
}
Beispiel #21
0
static PyObject *PySSL_SSLwrite(PySSLObject *self, PyObject *args)
{
	char *data;
	int len;
	int count;
	int sockstate;
	int err;

	if (!PyArg_ParseTuple(args, "s#:write", &data, &count))
		return NULL;

	sockstate = check_socket_and_wait_for_timeout(self->Socket, 1);
	if (sockstate == SOCKET_HAS_TIMED_OUT) {
		PyErr_SetString(PySSLErrorObject, "The write operation timed out");
		return NULL;
	} else if (sockstate == SOCKET_HAS_BEEN_CLOSED) {
		PyErr_SetString(PySSLErrorObject, "Underlying socket has been closed.");
		return NULL;
	} else if (sockstate == SOCKET_TOO_LARGE_FOR_SELECT) {
		PyErr_SetString(PySSLErrorObject, "Underlying socket too large for select().");
		return NULL;
	}
	do {
		err = 0;
		Py_BEGIN_ALLOW_THREADS
		len = SSL_write(self->ssl, data, count);
		err = SSL_get_error(self->ssl, len);
		Py_END_ALLOW_THREADS
		if(PyErr_CheckSignals()) {
			return NULL;
		}
		if (err == SSL_ERROR_WANT_READ) {
			sockstate = check_socket_and_wait_for_timeout(self->Socket, 0);
		} else if (err == SSL_ERROR_WANT_WRITE) {
			sockstate = check_socket_and_wait_for_timeout(self->Socket, 1);
		} else {
			sockstate = SOCKET_OPERATION_OK;
		}
	        if (sockstate == SOCKET_HAS_TIMED_OUT) {
			PyErr_SetString(PySSLErrorObject, "The write operation timed out");
			return NULL;
		} else if (sockstate == SOCKET_HAS_BEEN_CLOSED) {
			PyErr_SetString(PySSLErrorObject, "Underlying socket has been closed.");
			return NULL;
		} else if (sockstate == SOCKET_IS_NONBLOCKING) {
			break;
		}
	} while (err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE);
	if (len > 0)
		return PyInt_FromLong(len);
	else
		return PySSL_SetError(self, len);
}
Beispiel #22
0
/* Implementation of PyObject_Print with recursion checking */
static int
internal_print(PyObject *op, FILE *fp, int flags, int nesting)
{
	int ret = 0;
	if (nesting > 10) {
		PyErr_SetString(PyExc_RuntimeError, "print recursion");
		return -1;
	}
	if (PyErr_CheckSignals())
		return -1;
#ifdef USE_STACKCHECK
	if (PyOS_CheckStack()) {
		PyErr_SetString(PyExc_MemoryError, "stack overflow");
		return -1;
	}
#endif
	clearerr(fp); /* Clear any previous error condition */
	if (op == NULL) {
		fprintf(fp, "<nil>");
	}
	else {
		if (op->ob_refcnt <= 0)
			/* XXX(twouters) cast refcount to long until %zd is
			   universally available */
			fprintf(fp, "<refcnt %ld at %p>",
				(long)op->ob_refcnt, op);
		else if (op->ob_type->tp_print == NULL) {
			PyObject *s;
			if (flags & Py_PRINT_RAW)
				s = PyObject_Str(op);
			else
				s = PyObject_Repr(op);
			if (s == NULL)
				ret = -1;
			else {
				ret = internal_print(s, fp, Py_PRINT_RAW,
						     nesting+1);
			}
			Py_XDECREF(s);
		}
		else
			ret = (*op->ob_type->tp_print)(op, fp, flags);
	}
	if (ret == 0) {
		if (ferror(fp)) {
			PyErr_SetFromErrno(PyExc_IOError);
			clearerr(fp);
			ret = -1;
		}
	}
	return ret;
}
Beispiel #23
0
void
EventIterator::wait_internal(int timeout_ms)
{
    if (m_done == 0) {return;}
    off_t prev_done = m_done;
    if (timeout_ms == 0)
    {
        reset_to(prev_done);
        return;
    }
    int time_remaining = timeout_ms;
    int step = m_step;
    fflush(m_source);
    clearerr(m_source);
    int fd = fileno(m_source);
    struct stat result;
    while ((-1 != fstat(fd, &result)) && (result.st_size == m_done))
    {
        struct pollfd fd;
        fd.fd = watch();
        fd.events = POLLIN;
        Py_BEGIN_ALLOW_THREADS
        if (time_remaining != -1 && time_remaining < 1000) {step = time_remaining;}
        if (fd.fd == -1)
        {
            struct timeval tv;
            tv.tv_sec = step / 1000;
            tv.tv_usec = 1000*(step % 1000);
            select(1,NULL,NULL,NULL,&tv);
        }
        else
        {
            ::poll(&fd, 1, step);
        }
        Py_END_ALLOW_THREADS
        if (PyErr_CheckSignals() == -1)
        {
            boost::python::throw_error_already_set();
        }
        time_remaining -= step;
        if (time_remaining <= 0)
        {
            errno = 0;
            break;
        }
    }
    if (errno)
    {
        THROW_EX(IOError, "Failure when checking file size of event log.");
    }
    reset_to(prev_done);
}
Beispiel #24
0
static int
tb_printinternal(PyTracebackObject *tb, PyObject *f, long limit)
{
    int err = 0;
    Py_ssize_t depth = 0;
    PyObject *last_file = NULL;
    int last_line = -1;
    PyObject *last_name = NULL;
    long cnt = 0;
    PyTracebackObject *tb1 = tb;
    while (tb1 != NULL) {
        depth++;
        tb1 = tb1->tb_next;
    }
    while (tb != NULL && depth > limit) {
        depth--;
        tb = tb->tb_next;
    }
    while (tb != NULL && err == 0) {
        if (last_file != NULL &&
            tb->tb_frame->f_code->co_filename == last_file &&
            last_line != -1 && tb->tb_lineno == last_line &&
            last_name != NULL && tb->tb_frame->f_code->co_name == last_name)
        {
            cnt++;
        }
        else {
            if (cnt > 3) {
                err = tb_print_line_repeated(f, cnt);
            }
            last_file = tb->tb_frame->f_code->co_filename;
            last_line = tb->tb_lineno;
            last_name = tb->tb_frame->f_code->co_name;
            cnt = 0;
        }
        if (err == 0 && cnt < 3) {
            err = tb_displayline(f,
                                 tb->tb_frame->f_code->co_filename,
                                 tb->tb_lineno,
                                 tb->tb_frame->f_code->co_name);
            if (err == 0) {
                err = PyErr_CheckSignals();
            }
        }
        tb = tb->tb_next;
    }
    if (err == 0 && cnt > 3) {
        err = tb_print_line_repeated(f, cnt);
    }
    return err;
}
Beispiel #25
0
static int
conn_poll(ConnectionObject *conn, double timeout, PyThreadState *_save)
{
	DWORD bytes, deadline, delay;
	int difference, res;
	BOOL block = FALSE;

	if (!PeekNamedPipe(conn->handle, NULL, 0, NULL, &bytes, NULL))
		return MP_STANDARD_ERROR;

	if (timeout == 0.0)
		return bytes > 0;

	if (timeout < 0.0)
		block = TRUE;
	else
		/* XXX does not check for overflow */
		deadline = GetTickCount() + (DWORD)(1000 * timeout + 0.5);

	Sleep(0);

	for (delay = 1 ; ; delay += 1) {
		if (!PeekNamedPipe(conn->handle, NULL, 0, NULL, &bytes, NULL))
			return MP_STANDARD_ERROR;
		else if (bytes > 0)
			return TRUE;

		if (!block) {
			difference = deadline - GetTickCount();
			if (difference < 0)
				return FALSE;
			if ((int)delay > difference)
				delay = difference;
		}

		if (delay > 20)
			delay = 20;

		Sleep(delay);

		/* check for signals */
		Py_BLOCK_THREADS 
		res = PyErr_CheckSignals();
		Py_UNBLOCK_THREADS

		if (res)
			return MP_EXCEPTION_HAS_BEEN_SET;
	}
}
Beispiel #26
0
static PyObject* color_new(PyTypeObject *type,
                           PyObject *args,
                           PyObject *kwargs)
{
    PyColor *self;

    if (PyErr_CheckSignals())
       return NULL;

    self = (PyColor*)type->tp_alloc(type, 0);
    if (self)
       self->color = 0;

    return (PyObject*)self;
}
Beispiel #27
0
static PyObject *
signal_pause(PyObject *self)
{
	Py_BEGIN_ALLOW_THREADS
	(void)pause();
	Py_END_ALLOW_THREADS
	/* make sure that any exceptions that got raised are propagated
	 * back into Python
	 */
	if (PyErr_CheckSignals())
		return NULL;

	Py_INCREF(Py_None);
	return Py_None;
}
Beispiel #28
0
static PyObject* PyWeave_Sniffer_run(PyWeave_SnifferObject* self)
{
	bool capturingFromFile = (Weave::Sniffer::capture_file() != NULL);
	
	for(;;)
	{
		if(!Weave::Sniffer::next() && capturingFromFile)
			break;
		
		if(PyErr_CheckSignals() < 0 || PyErr_Occurred())
			return NULL;
	}
	
	Py_RETURN_NONE;
}
Beispiel #29
0
static int color_init(PyColor *self,
                      PyObject *args,
                      PyObject *kwargs)
{
    int r, g, b, a = 255;

    if (!PyArg_ParseTuple(args, "iii|i:__init__", &r, &g, &b, &a))
       return -1;

    if (PyErr_CheckSignals())
       return -1;

    self->color = ((u32)a << 24) | ((u32)b << 16) | ((u32)g << 8) | (u32)r;

    return 0;
}
Beispiel #30
0
int
PyObject_Print(PyObject *op, FILE *fp, int flags)
{
	int ret = 0;
	if (PyErr_CheckSignals())
		return -1;
#ifdef USE_STACKCHECK
	if (PyOS_CheckStack()) {
		PyErr_SetString(PyExc_MemoryError, "stack overflow");
		return -1;
	}
#endif
	clearerr(fp); /* Clear any previous error condition */
	if (op == NULL) {
		fprintf(fp, "<nil>");
	}
	else {
		if (op->ob_refcnt <= 0)
			fprintf(fp, "<refcnt %u at %p>",
				op->ob_refcnt, op);
		else if (op->ob_type->tp_print == NULL) {
			PyObject *s;
			if (flags & Py_PRINT_RAW)
				s = PyObject_Str(op);
			else
				s = PyObject_Repr(op);
			if (s == NULL)
				ret = -1;
			else {
				ret = PyObject_Print(s, fp, Py_PRINT_RAW);
			}
			Py_XDECREF(s);
		}
		else
			ret = (*op->ob_type->tp_print)(op, fp, flags);
	}
	if (ret == 0) {
		if (ferror(fp)) {
			PyErr_SetFromErrno(PyExc_IOError);
			clearerr(fp);
			ret = -1;
		}
	}
	return ret;
}