Ejemplo n.º 1
0
static int do_append( struct chronos_handle * handle, int argc, char** argv ){
	int key_parsed = 0;
	struct index_key key;

	if( argc > 4 && strncmp("-t", argv[3], 2) == 0 ){
		int rc = parse_key( argv[4], strlen( argv[4] ), & key );
		if( rc == 0 ){
			key_parsed = 1;
		} else {
			bad_key(rc, argv[4]);
			return rc;
		}
	}

	int rc = 0;
	if( key_parsed ){
		rc = chronos_append( handle, & key, 0 );
	} else {
		rc = chronos_append( handle, NULL, 0 );
	}
	if( rc != 0 ){
		if( rc == C_PROVIDED_KEY_NOT_LATEST ){
			fprintf( stderr, "can't insert keys before the last entry.\n");
        } else if ( rc == C_IO_NEEDS_A_PIPE ) {
			fprintf( stderr, "error reading stdin, it must be a pipe!\n");
		} else {
			perror("chronos_append");
		}
		return rc;
	}

	return 0;
}
Ejemplo n.º 2
0
static int do_get( struct chronos_handle * handle, int argc, char** argv ){
	struct index_key key;
	int rc = parse_key( argv[3], strlen( argv[3] ), & key );
	if( rc != 0 ){
		bad_key(rc, argv[3]);
		return rc;
	}

	struct index_entry entry;

	rc = chronos_find( handle, & key, & entry );
	if( rc != 0 ){
		if( rc != C_NOT_FOUND ){
			perror("chronos_find");
		}
		return rc;
	}

	// output to stdout
	chronos_output( handle, & entry, 1 );
	if( rc != 0 ){
		perror("chronos_output");
		return rc;
	}

	return 0;
}
Ejemplo n.º 3
0
/*
 * Implement mapping assignment sub-script for the type.
 */
static int sipArray_ass_subscript(PyObject *self, PyObject *key,
        PyObject *value)
{
    sipArrayObject *array = (sipArrayObject *)self;
    SIP_SSIZE_T start, len;
    void *value_data;

    if (check_writable(array) < 0)
        return -1;

    if (PyIndex_Check(key))
    {
        start = PyNumber_AsSsize_t(key, PyExc_IndexError);

        if (start == -1 && PyErr_Occurred())
            return -1;

        if (start < 0)
            start += array->len;

        if (check_index(array, start) < 0)
            return -1;

        if ((value_data = get_value(array, value)) == NULL)
            return -1;

        len = 1;
    }
    else if (PySlice_Check(key))
    {
        Py_ssize_t stop, step;

        if (sipConvertFromSliceObject(key, array->len, &start, &stop, &step, &len) < 0)
            return -1;

        if (step != 1)
        {
            PyErr_SetNone(PyExc_NotImplementedError);
            return -1;
        }

        if ((value_data = get_slice(array, value, len)) == NULL)
            return -1;
    }
    else
    {
        bad_key(key);

        return -1;
    }

    memmove(element(array, start), value_data, len * array->stride);

    return 0;
}
Ejemplo n.º 4
0
Archivo: voidptr.c Proyecto: Werkov/SIP
/*
 * Implement mapping sub-script for the type.
 */
static PyObject *sipVoidPtr_subscript(PyObject *self, PyObject *key)
{
    sipVoidPtrObject *v;

    if (check_size(self) < 0)
        return NULL;

    v = (sipVoidPtrObject *)self;

    if (PyIndex_Check(key))
    {
        Py_ssize_t idx = PyNumber_AsSsize_t(key, PyExc_IndexError);

        if (idx == -1 && PyErr_Occurred())
            return NULL;

        if (idx < 0)
            idx += v->size;

        return sipVoidPtr_item(self, idx);
    }

    if (PySlice_Check(key))
    {
        Py_ssize_t start, stop, step, slicelength;

        if (sipConvertFromSliceObject(key, v->size, &start, &stop, &step, &slicelength) < 0)
            return NULL;

        if (step != 1)
        {
            PyErr_SetNone(PyExc_NotImplementedError);
            return NULL;
        }

        return make_voidptr((char *)v->voidptr + start, slicelength, v->rw);
    }

    bad_key(key);

    return NULL;
}
Ejemplo n.º 5
0
/*
 * Implement mapping sub-script for the type.
 */
static PyObject *sipArray_subscript(PyObject *self, PyObject *key)
{
    sipArrayObject *array = (sipArrayObject *)self;

    if (PyIndex_Check(key))
    {
        Py_ssize_t idx = PyNumber_AsSsize_t(key, PyExc_IndexError);

        if (idx == -1 && PyErr_Occurred())
            return NULL;

        if (idx < 0)
            idx += array->len;

        return sipArray_item(self, idx);
    }

    if (PySlice_Check(key))
    {
        Py_ssize_t start, stop, step, slicelength;

        if (sipConvertFromSliceObject(key, array->len, &start, &stop, &step, &slicelength) < 0)
            return NULL;

        if (step != 1)
        {
            PyErr_SetNone(PyExc_NotImplementedError);
            return NULL;
        }

        return make_array(element(array->data, start), array->td,
                array->format, array->stride, slicelength,
                (array->flags & ~SIP_OWNS_MEMORY), array->owner);
    }

    bad_key(key);

    return NULL;
}
Ejemplo n.º 6
0
Archivo: voidptr.c Proyecto: Werkov/SIP
/*
 * Implement mapping assignment sub-script for the type.
 */
static int sipVoidPtr_ass_subscript(PyObject *self, PyObject *key,
        PyObject *value)
{
    sipVoidPtrObject *v;
    Py_ssize_t start, size;
#if PY_VERSION_HEX >= 0x02060000
    Py_buffer value_view;
#else
    Py_ssize_t value_size;
    void *value_ptr;
#endif

    if (check_rw(self) < 0 || check_size(self) < 0)
        return -1;

    v = (sipVoidPtrObject *)self;

    if (PyIndex_Check(key))
    {
        start = PyNumber_AsSsize_t(key, PyExc_IndexError);

        if (start == -1 && PyErr_Occurred())
            return -1;

        if (start < 0)
            start += v->size;

        if (check_index(self, start) < 0)
            return -1;

        size = 1;
    }
    else if (PySlice_Check(key))
    {
        Py_ssize_t stop, step;

        if (sipConvertFromSliceObject(key, v->size, &start, &stop, &step, &size) < 0)
            return -1;

        if (step != 1)
        {
            PyErr_SetNone(PyExc_NotImplementedError);
            return -1;
        }
    }
    else
    {
        bad_key(key);

        return -1;
    }

#if PY_VERSION_HEX >= 0x02060000
    if (PyObject_GetBuffer(value, &value_view, PyBUF_CONTIG_RO) < 0)
        return -1;

    /* We could allow any item size... */
    if (value_view.itemsize != 1)
    {
        PyErr_Format(PyExc_TypeError, "'%s' must have an item size of 1",
                Py_TYPE(value_view.obj)->tp_name);

        PyBuffer_Release(&value_view);
        return -1;
    }

    if (check_slice_size(size, value_view.len) < 0)
    {
        PyBuffer_Release(&value_view);
        return -1;
    }

    memmove((char *)v->voidptr + start, value_view.buf, size);

    PyBuffer_Release(&value_view);
#else
    if ((value_size = get_value_data(value, &value_ptr)) < 0)
        return -1;

    if (check_slice_size(size, value_size) < 0)
        return -1;

    memmove((char *)v->voidptr + start, value_ptr, size);
#endif

    return 0;
}