当前位置: 首页>>代码示例>>C++>>正文


C++ CHECK_VALID函数代码示例

本文整理汇总了C++中CHECK_VALID函数的典型用法代码示例。如果您正苦于以下问题:C++ CHECK_VALID函数的具体用法?C++ CHECK_VALID怎么用?C++ CHECK_VALID使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了CHECK_VALID函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: mmap_resize_method

static PyObject *
mmap_resize_method(mmap_object *self,
		   PyObject *args)
{
	Py_ssize_t new_size;
	CHECK_VALID(NULL);
	if (!PyArg_ParseTuple(args, "n:resize", &new_size) ||
	    !is_resizeable(self)) {
		return NULL;
#ifdef MS_WINDOWS
	} else {
		DWORD dwErrCode = 0;
		DWORD newSizeLow, newSizeHigh;
		/* First, unmap the file view */
		UnmapViewOfFile(self->data);
		/* Close the mapping object */
		CloseHandle(self->map_handle);
		/* Move to the desired EOF position */
#if SIZEOF_SIZE_T > 4
		newSizeHigh = (DWORD)(new_size >> 32);
		newSizeLow = (DWORD)(new_size & 0xFFFFFFFF);
#else
		newSizeHigh = 0;
		newSizeLow = (DWORD)new_size;
#endif
		SetFilePointer(self->file_handle,
			       newSizeLow, &newSizeHigh, FILE_BEGIN);
		/* Change the size of the file */
		SetEndOfFile(self->file_handle);
		/* Create another mapping object and remap the file view */
		self->map_handle = CreateFileMapping(
			self->file_handle,
			NULL,
			PAGE_READWRITE,
			newSizeHigh,
			newSizeLow,
			self->tagname);
		if (self->map_handle != NULL) {
			self->data = (char *) MapViewOfFile(self->map_handle,
							    FILE_MAP_WRITE,
							    0,
							    0,
							    0);
			if (self->data != NULL) {
				self->size = new_size;
				Py_INCREF(Py_None);
				return Py_None;
			} else {
				dwErrCode = GetLastError();
			}
		} else {
			dwErrCode = GetLastError();
		}
		PyErr_SetFromWindowsErr(dwErrCode);
		return NULL;
#endif /* MS_WINDOWS */

#ifdef UNIX
#ifndef HAVE_MREMAP
	} else {
开发者ID:BIT66COM,项目名称:python-multiprocessing,代码行数:60,代码来源:mmapmodule.c

示例2: mmap_ass_item

static int
mmap_ass_item(mmap_object *self, Py_ssize_t i, PyObject *v)
{
    const char *buf;

    CHECK_VALID(-1);
    if (i < 0 || i >= self->size) {
        PyErr_SetString(PyExc_IndexError, "mmap index out of range");
        return -1;
    }
    if (v == NULL) {
        PyErr_SetString(PyExc_TypeError,
                        "mmap object doesn't support item deletion");
        return -1;
    }
    if (! (PyBytes_Check(v) && PyBytes_Size(v)==1) ) {
        PyErr_SetString(PyExc_IndexError,
                        "mmap assignment must be length-1 bytes()");
        return -1;
    }
    if (!is_writable(self))
        return -1;
    buf = PyBytes_AsString(v);
    self->data[i] = buf[0];
    return 0;
}
开发者ID:1st1,项目名称:cpython,代码行数:26,代码来源:mmapmodule.c

示例3: mmap_write_method

static PyObject *
mmap_write_method(mmap_object *self,
                  PyObject *args)
{
    Py_buffer data;

    CHECK_VALID(NULL);
    if (!PyArg_ParseTuple(args, "y*:write", &data))
        return(NULL);

    if (!is_writable(self)) {
        PyBuffer_Release(&data);
        return NULL;
    }

    if ((self->pos + data.len) > self->size) {
        PyErr_SetString(PyExc_ValueError, "data out of range");
        PyBuffer_Release(&data);
        return NULL;
    }
    memcpy(self->data + self->pos, data.buf, data.len);
    self->pos = self->pos + data.len;
    PyBuffer_Release(&data);
    Py_INCREF(Py_None);
    return Py_None;
}
开发者ID:KellyChan,项目名称:python,代码行数:26,代码来源:mmapmodule.c

示例4: mmap_flush_method

static PyObject *
mmap_flush_method(mmap_object *self, PyObject *args)
{
    Py_ssize_t offset = 0;
    Py_ssize_t size = self->size;
    CHECK_VALID(NULL);
    if (!PyArg_ParseTuple(args, "|nn:flush", &offset, &size))
        return NULL;
    if (size < 0 || offset < 0 || self->size - offset < size) {
        PyErr_SetString(PyExc_ValueError, "flush values out of range");
        return NULL;
    }

    if (self->access == ACCESS_READ || self->access == ACCESS_COPY)
        return PyLong_FromLong(0);

#ifdef MS_WINDOWS
    return PyLong_FromLong((long) FlushViewOfFile(self->data+offset, size));
#elif defined(UNIX)
    /* XXX semantics of return value? */
    /* XXX flags for msync? */
    if (-1 == msync(self->data + offset, size, MS_SYNC)) {
        PyErr_SetFromErrno(PyExc_OSError);
        return NULL;
    }
    return PyLong_FromLong(0);
#else
    PyErr_SetString(PyExc_ValueError, "flush not supported on this system");
    return NULL;
#endif
}
开发者ID:1st1,项目名称:cpython,代码行数:31,代码来源:mmapmodule.c

示例5: mmap_find_method

static PyObject *
mmap_find_method(mmap_object *self,
		 PyObject *args)
{
	Py_ssize_t start = self->pos;
	char *needle;
	Py_ssize_t len;

	CHECK_VALID(NULL);
	if (!PyArg_ParseTuple(args, "s#|n:find", &needle, &len, &start)) {
		return NULL;
	} else {
		char *p;
		char *e = self->data + self->size;

                if (start < 0)
			start += self->size;
                if (start < 0)
			start = 0;
                else if ((size_t)start > self->size)
			start = self->size;

		for (p = self->data + start; p + len <= e; ++p) {
			Py_ssize_t i;
			for (i = 0; i < len && needle[i] == p[i]; ++i)
				/* nothing */;
			if (i == len) {
				return PyInt_FromSsize_t(p - self->data);
			}
		}
		return PyInt_FromLong(-1);
	}
}
开发者ID:BIT66COM,项目名称:python-multiprocessing,代码行数:33,代码来源:mmapmodule.c

示例6: mmap_write_method

static PyObject *
mmap_write_method(mmap_object *self,
                  PyObject *args)
{
    Py_buffer data;

    CHECK_VALID(NULL);
    if (!PyArg_ParseTuple(args, "y*:write", &data))
        return(NULL);

    if (!is_writable(self)) {
        PyBuffer_Release(&data);
        return NULL;
    }

    if (self->pos > self->size || self->size - self->pos < data.len) {
        PyBuffer_Release(&data);
        PyErr_SetString(PyExc_ValueError, "data out of range");
        return NULL;
    }

    memcpy(&self->data[self->pos], data.buf, data.len);
    self->pos += data.len;
    PyBuffer_Release(&data);
    return PyLong_FromSsize_t(data.len);
}
开发者ID:1st1,项目名称:cpython,代码行数:26,代码来源:mmapmodule.c

示例7: mmap_move_method

static PyObject *
mmap_move_method(mmap_object *self, PyObject *args)
{
    Py_ssize_t dest, src, cnt;
    CHECK_VALID(NULL);
    if (!PyArg_ParseTuple(args, "nnn:move", &dest, &src, &cnt) ||
        !is_writable(self)) {
        return NULL;
    } else {
        /* bounds check the values */
        if (dest < 0 || src < 0 || cnt < 0)
            goto bounds;
        if (self->size - dest < cnt || self->size - src < cnt)
            goto bounds;

        memmove(&self->data[dest], &self->data[src], cnt);

        Py_RETURN_NONE;

      bounds:
        PyErr_SetString(PyExc_ValueError,
                        "source, destination, or count out of range");
        return NULL;
    }
}
开发者ID:1st1,项目名称:cpython,代码行数:25,代码来源:mmapmodule.c

示例8: mmap__enter__method

static PyObject *
mmap__enter__method(mmap_object *self, PyObject *args)
{
    CHECK_VALID(NULL);

    Py_INCREF(self);
    return (PyObject *)self;
}
开发者ID:1st1,项目名称:cpython,代码行数:8,代码来源:mmapmodule.c

示例9: mmap_concat

static PyObject *
mmap_concat(mmap_object *self, PyObject *bb)
{
    CHECK_VALID(NULL);
    PyErr_SetString(PyExc_SystemError,
                    "mmaps don't support concatenation");
    return NULL;
}
开发者ID:1st1,项目名称:cpython,代码行数:8,代码来源:mmapmodule.c

示例10: mmap_repeat

static PyObject *
mmap_repeat(mmap_object *self, Py_ssize_t n)
{
    CHECK_VALID(NULL);
    PyErr_SetString(PyExc_SystemError,
                    "mmaps don't support repeat operation");
    return NULL;
}
开发者ID:1st1,项目名称:cpython,代码行数:8,代码来源:mmapmodule.c

示例11: mmap_buffer_getbuf

static int
mmap_buffer_getbuf(mmap_object *self, Py_buffer *view, int flags)
{
    CHECK_VALID(-1);
    if (PyBuffer_FillInfo(view, (PyObject*)self, self->data, self->size,
                          (self->access == ACCESS_READ), flags) < 0)
        return -1;
    self->exports++;
    return 0;
}
开发者ID:1st1,项目名称:cpython,代码行数:10,代码来源:mmapmodule.c

示例12: mmap_item

static PyObject *
mmap_item(mmap_object *self, Py_ssize_t i)
{
    CHECK_VALID(NULL);
    if (i < 0 || i >= self->size) {
        PyErr_SetString(PyExc_IndexError, "mmap index out of range");
        return NULL;
    }
    return PyBytes_FromStringAndSize(self->data + i, 1);
}
开发者ID:1st1,项目名称:cpython,代码行数:10,代码来源:mmapmodule.c

示例13: mmap_read_byte_method

static PyObject *
mmap_read_byte_method(mmap_object *self,
                      PyObject *unused)
{
    CHECK_VALID(NULL);
    if (self->pos >= self->size) {
        PyErr_SetString(PyExc_ValueError, "read byte out of range");
        return NULL;
    }
    return PyLong_FromLong((unsigned char)self->data[self->pos++]);
}
开发者ID:1st1,项目名称:cpython,代码行数:11,代码来源:mmapmodule.c

示例14: mmap_subscript

static PyObject *
mmap_subscript(mmap_object *self, PyObject *item)
{
    CHECK_VALID(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 += self->size;
        if (i < 0 || i >= self->size) {
            PyErr_SetString(PyExc_IndexError,
                "mmap index out of range");
            return NULL;
        }
        return PyLong_FromLong(Py_CHARMASK(self->data[i]));
    }
    else if (PySlice_Check(item)) {
        Py_ssize_t start, stop, step, slicelen;

        if (PySlice_Unpack(item, &start, &stop, &step) < 0) {
            return NULL;
        }
        slicelen = PySlice_AdjustIndices(self->size, &start, &stop, step);

        if (slicelen <= 0)
            return PyBytes_FromStringAndSize("", 0);
        else if (step == 1)
            return PyBytes_FromStringAndSize(self->data + start,
                                              slicelen);
        else {
            char *result_buf = (char *)PyMem_Malloc(slicelen);
            Py_ssize_t cur, i;
            PyObject *result;

            if (result_buf == NULL)
                return PyErr_NoMemory();
            for (cur = start, i = 0; i < slicelen;
                 cur += step, i++) {
                result_buf[i] = self->data[cur];
            }
            result = PyBytes_FromStringAndSize(result_buf,
                                                slicelen);
            PyMem_Free(result_buf);
            return result;
        }
    }
    else {
        PyErr_SetString(PyExc_TypeError,
                        "mmap indices must be integers");
        return NULL;
    }
}
开发者ID:1st1,项目名称:cpython,代码行数:53,代码来源:mmapmodule.c

示例15: QAngle___div

static int QAngle___div (lua_State *L) {
  QAngle a = *(QAngle *)luaL_checkangle(L, 1);
  float b = luaL_checknumber(L, 2);
  QAngle c;
  CHECK_VALID(a);
  Assert( b != 0.0f );
  vec_t oob = 1.0f / b;
  c.x = a.x * oob;
  c.y = a.y * oob;
  c.z = a.z * oob;
  lua_pushangle(L, &c);
  return 1;
}
开发者ID:AluminumKen,项目名称:hl2sb-src,代码行数:13,代码来源:lvector.cpp


注:本文中的CHECK_VALID函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。