示例#1
0
const char* session::get(const char* name)
{
	const session_string* bf = get_buf(name);
	if (bf == NULL)
		return "";
	return bf->c_str();
}
static PyObject *
buffer_repeat(PyBufferObject *self, Py_ssize_t count)
{
    PyObject *ob;
    register char *p;
    void *ptr;
    Py_ssize_t size;

    if ( count < 0 )
        count = 0;
    if (!get_buf(self, &ptr, &size, ANY_BUFFER))
        return NULL;
    if (count > PY_SSIZE_T_MAX / size) {
        PyErr_SetString(PyExc_MemoryError, "result too large");
        return NULL;
    }
    ob = PyString_FromStringAndSize(NULL, size * count);
    if ( ob == NULL )
        return NULL;

    p = PyString_AS_STRING(ob);
    while ( count-- )
    {
        memcpy(p, ptr, size);
        p += size;
    }

    /* there is an extra byte in the string object, so this is safe */
    *p = '\0';

    return ob;
}
示例#3
0
static PyObject *
buffer_repeat(PyBufferObject *self, int count)
{
	PyObject *ob;
	register char *p;
	void *ptr;
	int size;

	if ( count < 0 )
		count = 0;
	if (!get_buf(self, &ptr, &size))
		return NULL;
	ob = PyString_FromStringAndSize(NULL, size * count);
	if ( ob == NULL )
		return NULL;

	p = PyString_AS_STRING(ob);
	while ( count-- )
	{
	    memcpy(p, ptr, size);
	    p += size;
	}

	/* there is an extra byte in the string object, so this is safe */
	*p = '\0';

	return ob;
}
示例#4
0
static void mouse_push_event_thread(void *arg)
{
    (void) arg;

    t_current_set_name("MouEvents");
    t_current_set_priority(PHANTOM_SYS_THREAD_PRIO);

    while(1)
    {
        hal_sem_acquire( &mouse_sem );

        if(video_drv->mouse_redraw_cursor != NULL)
            video_drv->mouse_redraw_cursor();

        //hal_mutex_lock( &mouse_mutex );

        struct ui_event e, e1;
        while( get_buf(&e) )
        {
            if( peek_buf( &e1 ) )
            {
                // We already have one more event and buttons state is the same?
                // Throw away current event, use next one.
                if( e1.m.buttons == e.m.buttons )
                    continue;
            }

            ev_q_put_any( &e );
        }

        //hal_mutex_unlock( &mouse_mutex );
    }
}
示例#5
0
int				get_next_line(int const fd, char **line)
{
	size_t			i;
	static t_list	*fds = NULL;
	char			*tmp;
	t_fd			*current;

	if (line == NULL || BUFF_SIZE <= 0)
		return (-1);
	*line = NULL;
	current = get_current_fd(fd, &fds);
	if (current->res && current->res[0])
	{
		i = 0;
		while (current->res[i] && current->res[i] != '\n')
			*line = ft_strfjoin(*line, ft_chartostar(current->res[i++]), 3);
		if (i == 0)
			*line = ft_strnew(0);
		if ((tmp = ft_strchr(&current->res[i], '\n')))
		{
			current->res = ft_strcpy(current->res, &tmp[1]);
			return (1);
		}
		current->res = NULL;
	}
	return (get_buf(fd, line, current));
}
示例#6
0
int					get_next_line(int const fd, char **line)
{
	static t_list	*list;
	static int		pos;
	static int		start;
	char			*str;
	static int		ilk;

	if (start == -2)
	{
		*line = ft_strnew(0);
		return (0);
	}
	if (fd < 0)
		return (-1);
	ilk = 0;
	pos = get_buf(&list, start, fd, &ilk);
	str = get_copy(&list, pos, &start);
	*line = str;
	if (ilk == -1)
	{
		start = -2;
		ft_putstr(*line);
		return (0);
	}
	return (1);
}
示例#7
0
CAMLprim value bin_prot_blit_buf_string_stub(
  value v_src_pos, value v_buf, value v_dst_pos, value v_str, value v_len)
{
  char *buf = get_buf(v_buf, v_src_pos);
  char *str = String_val(v_str) + Long_val(v_dst_pos);
  memcpy(str, buf, (size_t) Long_val(v_len));
  return Val_unit;
}
示例#8
0
CAMLprim value bin_prot_blit_buf_float_array_stub(
  value v_src_pos, value v_buf, value v_dst_pos, value v_arr, value v_len)
{
  char *buf = get_buf(v_buf, v_src_pos);
  char *arr = (char*)v_arr + Long_val(v_dst_pos) * sizeof(double);
  memcpy(arr, buf, (size_t) (Long_val(v_len) * sizeof(double)));
  return Val_unit;
}
示例#9
0
int mpx_test (int argc, const char **argv)
{
  int *p;

  rd (get_buf (), 100);

  return 0;
}
示例#10
0
static int
buffer_length(PyBufferObject *self)
{
	void *ptr;
	int size;
	if (!get_buf(self, &ptr, &size))
		return -1;
	return size;
}
示例#11
0
static PyObject *
buffer_str(PyBufferObject *self)
{
	void *ptr;
	int size;
	if (!get_buf(self, &ptr, &size))
		return NULL;
	return PyString_FromStringAndSize(ptr, size);
}
示例#12
0
static int
buffer_compare(PyBufferObject *self, PyBufferObject *other)
{
	void *p1, *p2;
	int len_self, len_other, min_len, cmp;

	if (!get_buf(self, &p1, &len_self))
		return -1;
	if (!get_buf(other, &p2, &len_other))
		return -1;
	min_len = (len_self < len_other) ? len_self : len_other;
	if (min_len > 0) {
		cmp = memcmp(p1, p2, min_len);
		if (cmp != 0)
			return cmp < 0 ? -1 : 1;
	}
	return (len_self < len_other) ? -1 : (len_self > len_other) ? 1 : 0;
}
示例#13
0
 //!Constructor.
 //!Does not throw.
 basic_obufferstream(std::ios_base::openmode mode = std::ios_base::out)
    :  //basic_ios_t() is called first (lefting it uninitialized) as it's a
       //virtual base of basic_istream. The class will be initialized when
       //basic_istream is constructed calling basic_ios_t::init().
       //As bufferbuf_t's constructor does not throw there is no risk of
       //calling the basic_ios_t's destructor without calling basic_ios_t::init()
       bufferbuf_t(mode | std::ios_base::out)
    ,  base_t(&get_buf())
    {}
示例#14
0
static PyObject *
buffer_str(PyBufferObject *self)
{
    void *ptr;
    Py_ssize_t size;
    if (!get_buf(self, &ptr, &size, ANY_BUFFER))
        return NULL;
    return PyString_FromStringAndSize((const char *)ptr, size);
}
示例#15
0
static int
buffer_ass_slice(PyBufferObject *self, Py_ssize_t left, Py_ssize_t right, PyObject *other)
{
    PyBufferProcs *pb;
    void *ptr1, *ptr2;
    Py_ssize_t size;
    Py_ssize_t slice_len;
    Py_ssize_t count;

    if ( self->b_readonly ) {
        PyErr_SetString(PyExc_TypeError,
                        "buffer is read-only");
        return -1;
    }

    pb = other ? other->ob_type->tp_as_buffer : NULL;
    if ( pb == NULL ||
         pb->bf_getreadbuffer == NULL ||
         pb->bf_getsegcount == NULL )
    {
        PyErr_BadArgument();
        return -1;
    }
    if ( (*pb->bf_getsegcount)(other, NULL) != 1 )
    {
        /* ### use a different exception type/message? */
        PyErr_SetString(PyExc_TypeError,
                        "single-segment buffer object expected");
        return -1;
    }
    if (!get_buf(self, &ptr1, &size, ANY_BUFFER))
        return -1;
    if ( (count = (*pb->bf_getreadbuffer)(other, 0, &ptr2)) < 0 )
        return -1;

    if ( left < 0 )
        left = 0;
    else if ( left > size )
        left = size;
    if ( right < left )
        right = left;
    else if ( right > size )
        right = size;
    slice_len = right - left;

    if ( count != slice_len ) {
        PyErr_SetString(
            PyExc_TypeError,
            "right operand length must match slice length");
        return -1;
    }

    if ( slice_len )
        memcpy((char *)ptr1 + left, ptr2, slice_len);

    return 0;
}
示例#16
0
static int buffer_getbuffer(PyBufferObject *self, Py_buffer *buf, int flags)
{
    void *ptr;
    Py_ssize_t size;
    if (!get_buf(self, &ptr, &size, ANY_BUFFER))
        return -1;
    return PyBuffer_FillInfo(buf, (PyObject*)self, ptr, size,
                             self->b_readonly, flags);
}
示例#17
0
static Py_ssize_t
buffer_length(PyBufferObject *self)
{
    void *ptr;
    Py_ssize_t size;
    if (!get_buf(self, &ptr, &size, ANY_BUFFER))
        return -1;
    return size;
}
示例#18
0
char *
clnt_spcreateerror(char *s)
{
	char *str = get_buf();
	char *strend;

	if (str == 0)
		return(0);
	strend = str+BUFSIZ;
	(void) snprintf(str, strend-str, "%s: ", s);
	str[BUFSIZ - 1] = '\0';
	(void) strncat(str, clnt_sperrno(rpc_createerr.cf_stat), BUFSIZ - 1);
	switch (rpc_createerr.cf_stat) {
	case RPC_PMAPFAILURE:
		(void) strncat(str, " - ", BUFSIZ - 1 - strlen(str));
		(void) strncat(str,
		    clnt_sperrno(rpc_createerr.cf_error.re_status),
		    BUFSIZ - 1 - strlen(str));
		break;

	case RPC_SYSTEMERROR:
		(void) strncat(str, " - ", BUFSIZ - 1 - strlen(str));
		{
		    const char *m = strerror(rpc_createerr.cf_error.re_errno);
		    if (m)
			(void) strncat(str, m, BUFSIZ - 1 - strlen(str));
		    else
			(void) snprintf(&str[strlen(str)], BUFSIZ - strlen(str),
					"Error %d",
					rpc_createerr.cf_error.re_errno);
		}
		break;

	case RPC_CANTSEND:
	case RPC_CANTDECODERES:
	case RPC_CANTENCODEARGS:
	case RPC_SUCCESS:
	case RPC_UNKNOWNPROTO:
	case RPC_PROGNOTREGISTERED:
	case RPC_FAILED:
	case RPC_UNKNOWNHOST:
	case RPC_CANTDECODEARGS:
	case RPC_PROCUNAVAIL:
	case RPC_PROGVERSMISMATCH:
	case RPC_PROGUNAVAIL:
	case RPC_AUTHERROR:
	case RPC_VERSMISMATCH:
	case RPC_TIMEDOUT:
	case RPC_CANTRECV:
	default:
	    break;
	}
	(void) strncat(str, "\n", BUFSIZ - 1 - strlen(str));
	return (str);
}
示例#19
0
SANE_Status
sane_read(SANE_Handle handle, SANE_Byte * buf,
	  SANE_Int max_len, SANE_Int * len)
{
	struct scanner *s = (struct scanner *) handle;
	int duplex = s->val[DUPLEX].w;
	struct buf *b = s->side == SIDE_FRONT ? &s->buf[0] : &s->buf[1];
	SANE_Status err = buf_get_err(b);
	SANE_Int inbuf = 0;
	*len = 0;

	if (!s->scanning)
		return SANE_STATUS_EOF;
	if (err)
		goto out;

	if (s->read) {
		*len =
		    max_len <
		    (SANE_Int) s->read ? max_len : (SANE_Int) s->read;
		memcpy(buf, s->data + BUF_SIZE - s->read, *len);
		s->read -= *len;

		if (!s->read)
			pop_buf(b);
		goto out;
	}

	s->data = get_buf(b, &inbuf);
	if (!s->data)
		goto out;

	*len = max_len < inbuf ? max_len : inbuf;
	if (*len > BUF_SIZE)
		*len = BUF_SIZE;
	memcpy(buf, s->data, *len);
	s->read = inbuf > BUF_SIZE ? BUF_SIZE - *len : inbuf - *len;

	if (!s->read)
		pop_buf(b);
      out:
	err = *len ? SANE_STATUS_GOOD : buf_get_err(b);
	if (err == SANE_STATUS_EOF) {
		if (strcmp(s->val[FEEDER_MODE].s, SANE_I18N("continuous"))) {
			if (!duplex || s->side == SIDE_BACK)
				s->scanning = 0;
		}
		buf_deinit(b);
	} else if (err) {
		unsigned i;
		for (i = 0; i < sizeof(s->buf) / sizeof(s->buf[0]); i++)
			buf_deinit(&s->buf[i]);
	}
	return err;
}
示例#20
0
static int
buffer_getsegcount(PyBufferObject *self, int *lenp)
{
	void *ptr;
	int size;
	if (!get_buf(self, &ptr, &size))
		return -1;
	if (lenp)
		*lenp = size;
	return 1;
}
示例#21
0
static Py_ssize_t
buffer_getsegcount(PyBufferObject *self, Py_ssize_t *lenp)
{
    void *ptr;
    Py_ssize_t size;
    if (!get_buf(self, &ptr, &size, ANY_BUFFER))
        return -1;
    if (lenp)
        *lenp = size;
    return 1;
}
示例#22
0
static PyObject *
buffer_subscript(PyBufferObject *self, PyObject *item)
{
    void *p;
    Py_ssize_t size;

    if (!get_buf(self, &p, &size, ANY_BUFFER))
        return NULL;
    if (PyIndex_Check(item)) {
        Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError);
        if (i == -1 && PyErr_Occurred())
            return NULL;
        if (i < 0)
            i += size;
        return buffer_item(self, i);
    }
    else if (PySlice_Check(item)) {
        Py_ssize_t start, stop, step, slicelength, cur, i;

        if (PySlice_GetIndicesEx((PySliceObject*)item, size,
                         &start, &stop, &step, &slicelength) < 0) {
            return NULL;
        }

        if (slicelength <= 0)
            return PyString_FromStringAndSize("", 0);
        else if (step == 1)
            return PyString_FromStringAndSize((char *)p + start,
                                              stop - start);
        else {
            PyObject *result;
            char *source_buf = (char *)p;
            char *result_buf = (char *)PyMem_Malloc(slicelength);

            if (result_buf == NULL)
                return PyErr_NoMemory();

            for (cur = start, i = 0; i < slicelength;
                 cur += step, i++) {
                result_buf[i] = source_buf[cur];
            }

            result = PyString_FromStringAndSize(result_buf,
                                                slicelength);
            PyMem_Free(result_buf);
            return result;
        }
    }
    else {
        PyErr_SetString(PyExc_TypeError,
                        "sequence index must be integer");
        return NULL;
    }
}
示例#23
0
/*当接收中断来时调用此函数*/
static void get_recv_irg(void)
{
	int i;
	for(i = 0; i < MAX_PORT; i++)
	{
		if(UART_GET_RST(i) & (i%8))
		{
			get_buf(&serial_devp[i]);
		}
	}
}
示例#24
0
odp_buffer_t buffer_alloc(void *pool, size_t size)
{
	struct pool_entry_s *pool_s = &((pool_entry_t *)pool)->s;
	uintmax_t totsize = size + pool_s->room_size;
	odp_buffer_hdr_t *buf;

	/* Reject oversized allocation requests */
	if (odp_unlikely(size > pool_s->max_size))
		return ODP_BUFFER_INVALID;

	/* Try to satisfy request from the local cache */
	buf = get_local_buf(&pool_s->local_cache[local_id], pool_s, totsize);

	/* If cache is empty, satisfy request from the pool */
	if (odp_unlikely(buf == NULL)) {
		buf = get_buf(pool_s);

		if (odp_unlikely(buf == NULL))
			return ODP_BUFFER_INVALID;

		/* Get blocks for this buffer, if pool uses application data */
		if (buf->size < totsize) {
			intmax_t needed = totsize - buf->size;

			do {
				uint8_t *blk = get_blk(pool_s);

				if (blk == NULL) {
					ret_buf(pool_s, buf);
					return ODP_BUFFER_INVALID;
				}
				buf->addr[buf->segcount++] = blk;
				needed -= pool_s->seg_size;
			} while (needed > 0);
			buf->size = buf->segcount * pool_s->seg_size;

			/* Record the hdr before the buffer head */
			*(unsigned long *)(buf->addr[0] -
			      ODP_HDR_BACK_PTR_SIZE) = (unsigned long)buf;
		}
	}

	/* Mark buffer as allocated */
	buf->allocator = local_id;

	/* By default, buffers inherit their pool's zeroization setting */
	buf->flags.zeroized = pool_s->flags.zeroized;

	/* By default, buffers are not associated with an ordered queue */
	buf->origin_qe = NULL;

	return (odp_buffer_t)buf;
}
示例#25
0
/*
 * read_message -- read message sent over file descriptor fd
 *	The message has the format outlined in vp_hdr.h
 *	The caller specifies which message types she wants
 *	by placing the relevant ids in msg_ids (e.g. "HDO"
 *	means that we are interested in HELLO, DECISION and
 *	OFFER messages only.
 *	If the message being received is not of the ids
 *	specidied, reception is aborted and read_message
 *	returns an error.
 *
 *	If the message is read in its entirety, pbuf
 *	contains the payload, plen the length, and the
 *	return value is the actuall message if received.
 *
 *	Since pbuf is allocated here, it must be freed by
 *	the caller.
 */
int
read_message(FILE *fd, char *msg_ids, char **pbuf_p, int *plen_p)
{
	char c;
	char cmd;
	int rval;
	char *pbuf;
	int plen;

	printf("reading message\n");
	
	if ((cmd=getc(fd)) < 0) {
		perror("read_message: getc");
		return(MSG_CMD_ERROR);
	}
	
	// here we only look at messages that have their ids in msg_ids
	if (strchr(msg_ids, cmd) == NULL) {
		int i;

		fprintf(stderr, "process_message: invalid message id '%c'\n", cmd);

		for (i=1; i < 20; i++) {
			if ((cmd=getc(fd)) < 0) {
				perror("read_message: getc");
				return(MSG_CMD_ERROR);
			}
			putchar(cmd);
		}
		putchar('\n');

		return(MSG_CMD_ERROR);
	}
	// read message length
	for (plen = 0; isdigit((c=getc(fd))); )
		plen = plen *10 + (c - '0');
	if (c != ':') {
		fprintf(stderr, "process_message: sync error, expected ':', got '%c'\n", c);
		return;
	}

	// get message
	if ((pbuf = malloc(plen+1)) == NULL) // need one extra byte for the EOS
		perror("calloc failed");
	if ((rval = get_buf(fd, pbuf, plen)) < 0)
		perror("reading stream message");

	pbuf[plen] = '\0';
	*pbuf_p = pbuf;
	*plen_p = plen;
	return(cmd);
}
示例#26
0
static PyObject *
buffer_concat(PyBufferObject *self, PyObject *other)
{
    PyBufferProcs *pb = other->ob_type->tp_as_buffer;
    void *ptr1, *ptr2;
    char *p;
    PyObject *ob;
    Py_ssize_t size, count;

    if ( pb == NULL ||
         pb->bf_getreadbuffer == NULL ||
         pb->bf_getsegcount == NULL )
    {
        PyErr_BadArgument();
        return NULL;
    }
    if ( (*pb->bf_getsegcount)(other, NULL) != 1 )
    {
        /* ### use a different exception type/message? */
        PyErr_SetString(PyExc_TypeError,
                        "single-segment buffer object expected");
        return NULL;
    }

    if (!get_buf(self, &ptr1, &size, ANY_BUFFER))
        return NULL;

    /* optimize special case */
    if ( size == 0 )
    {
        Py_INCREF(other);
        return other;
    }

    if ( (count = (*pb->bf_getreadbuffer)(other, 0, &ptr2)) < 0 )
        return NULL;

    // Pyston change: no PY_SIZE_MAX
    // assert(count <= PY_SIZE_MAX - size);

    ob = PyString_FromStringAndSize(NULL, size + count);
    if ( ob == NULL )
        return NULL;
    p = PyString_AS_STRING(ob);
    memcpy(p, ptr1, size);
    memcpy(p + size, ptr2, count);

    /* there is an extra byte in the string object, so this is safe */
    p[size + count] = '\0';

    return ob;
}
示例#27
0
static Py_ssize_t
buffer_getreadbuf(PyBufferObject *self, Py_ssize_t idx, void **pp)
{
    Py_ssize_t size;
    if ( idx != 0 ) {
        PyErr_SetString(PyExc_SystemError,
                        "accessing non-existent buffer segment");
        return -1;
    }
    if (!get_buf(self, pp, &size, READ_BUFFER))
        return -1;
    return size;
}
示例#28
0
static PyObject *
buffer_item(PyBufferObject *self, Py_ssize_t idx)
{
    void *ptr;
    Py_ssize_t size;
    if (!get_buf(self, &ptr, &size, ANY_BUFFER))
        return NULL;
    if ( idx < 0 || idx >= size ) {
        PyErr_SetString(PyExc_IndexError, "buffer index out of range");
        return NULL;
    }
    return PyString_FromStringAndSize((char *)ptr + idx, 1);
}
示例#29
0
static int
buffer_ass_item(PyBufferObject *self, Py_ssize_t idx, PyObject *other)
{
    PyBufferProcs *pb;
    void *ptr1, *ptr2;
    Py_ssize_t size;
    Py_ssize_t count;

    if ( self->b_readonly ) {
        PyErr_SetString(PyExc_TypeError,
                        "buffer is read-only");
        return -1;
    }

    if (!get_buf(self, &ptr1, &size, ANY_BUFFER))
        return -1;

    if (idx < 0 || idx >= size) {
        PyErr_SetString(PyExc_IndexError,
                        "buffer assignment index out of range");
        return -1;
    }

    pb = other ? other->ob_type->tp_as_buffer : NULL;
    if ( pb == NULL ||
         pb->bf_getreadbuffer == NULL ||
         pb->bf_getsegcount == NULL )
    {
        PyErr_BadArgument();
        return -1;
    }
    if ( (*pb->bf_getsegcount)(other, NULL) != 1 )
    {
        /* ### use a different exception type/message? */
        PyErr_SetString(PyExc_TypeError,
                        "single-segment buffer object expected");
        return -1;
    }

    if ( (count = (*pb->bf_getreadbuffer)(other, 0, &ptr2)) < 0 )
        return -1;
    if ( count != 1 ) {
        PyErr_SetString(PyExc_TypeError,
                        "right operand must be a single byte");
        return -1;
    }

    ((char *)ptr1)[idx] = *(char *)ptr2;
    return 0;
}
示例#30
0
static long
buffer_hash(PyBufferObject *self)
{
    void *ptr;
    Py_ssize_t size;
    register Py_ssize_t len;
    register unsigned char *p;
    register long x;

    if ( self->b_hash != -1 )
        return self->b_hash;

    /* XXX potential bugs here, a readonly buffer does not imply that the
     * underlying memory is immutable.  b_readonly is a necessary but not
     * sufficient condition for a buffer to be hashable.  Perhaps it would
     * be better to only allow hashing if the underlying object is known to
     * be immutable (e.g. PyString_Check() is true).  Another idea would
     * be to call tp_hash on the underlying object and see if it raises
     * an error. */
    if ( !self->b_readonly )
    {
        PyErr_SetString(PyExc_TypeError,
                        "writable buffers are not hashable");
        return -1;
    }

    if (!get_buf(self, &ptr, &size, ANY_BUFFER))
        return -1;
    p = (unsigned char *) ptr;
    len = size;
    /*
      We make the hash of the empty buffer be 0, rather than using
      (prefix ^ suffix), since this slightly obfuscates the hash secret
    */
    if (len == 0) {
        self->b_hash = 0;
        return 0;
    }
    x = _Py_HashSecret.prefix;
    x ^= *p << 7;
    while (--len >= 0)
        x = (1000003*x) ^ *p++;
    x ^= size;
    x ^= _Py_HashSecret.suffix;
    if (x == -1)
        x = -2;
    self->b_hash = x;
    return x;
}