• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ CHECK_VALID函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: mmap_gfind

static PyObject *
mmap_gfind(mmap_object *self,
           PyObject *args,
           int reverse)
{
    Py_ssize_t start = self->pos;
    Py_ssize_t end = self->size;
    Py_buffer view;

    CHECK_VALID(NULL);
    if (!PyArg_ParseTuple(args, reverse ? "y*|nn:rfind" : "y*|nn:find",
                          &view, &start, &end)) {
        return NULL;
    } else {
        const char *p, *start_p, *end_p;
        int sign = reverse ? -1 : 1;
        const char *needle = view.buf;
        Py_ssize_t len = view.len;

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

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

        start_p = self->data + start;
        end_p = self->data + end;

        for (p = (reverse ? end_p - len : start_p);
             (p >= start_p) && (p + len <= end_p); p += sign) {
            Py_ssize_t i;
            for (i = 0; i < len && needle[i] == p[i]; ++i)
                /* nothing */;
            if (i == len) {
                PyBuffer_Release(&view);
                return PyLong_FromSsize_t(p - self->data);
            }
        }
        PyBuffer_Release(&view);
        return PyLong_FromLong(-1);
    }
}
开发者ID:1st1,项目名称:cpython,代码行数:50,代码来源:mmapmodule.c


示例17: pthread_kill

int pthread_kill(pthread_t thread, int signal)
{
	if ((unsigned) signal <= RTL_MAX_SIGNAL) 
	{
		CHECK_VALID(thread);
		if (signal == 0) 
		{
			return 0;
		}
		set_bit(signal, &thread->pending);
		return 0;
	}
	return 0;
}
开发者ID:akshar100,项目名称:SPaRK_x86,代码行数:14,代码来源:rtl_sched.c


示例18: mmap_write_byte_method

static PyObject *
mmap_write_byte_method(mmap_object *self,
		       PyObject *args)
{
	char value;

	CHECK_VALID(NULL);
	if (!PyArg_ParseTuple(args, "c:write_byte", &value))
		return(NULL);

	if (!is_writeable(self))
		return NULL;
	*(self->data+self->pos) = value;
	self->pos += 1;
	Py_INCREF(Py_None);
	return Py_None;
}
开发者ID:BIT66COM,项目名称:python-multiprocessing,代码行数:17,代码来源:mmapmodule.c


示例19: mmap_read_method

static PyObject *
mmap_read_method(mmap_object *self,
		 PyObject *args)
{
	Py_ssize_t num_bytes;
	PyObject *result;

	CHECK_VALID(NULL);
	if (!PyArg_ParseTuple(args, "n:read", &num_bytes))
		return(NULL);

	/* silently 'adjust' out-of-range requests */
	if (num_bytes > self->size - self->pos) {
		num_bytes -= (self->pos+num_bytes) - self->size;
	}
	result = Py_BuildValue("s#", self->data+self->pos, num_bytes);
	self->pos += num_bytes;
	return result;
}
开发者ID:BIT66COM,项目名称:python-multiprocessing,代码行数:19,代码来源:mmapmodule.c


示例20: mmap_read_method

static PyObject *
mmap_read_method(mmap_object *self,
                 PyObject *args)
{
    Py_ssize_t num_bytes = PY_SSIZE_T_MAX, remaining;
    PyObject *result;

    CHECK_VALID(NULL);
    if (!PyArg_ParseTuple(args, "|O&:read", _Py_convert_optional_to_ssize_t, &num_bytes))
        return(NULL);

    /* silently 'adjust' out-of-range requests */
    remaining = (self->pos < self->size) ? self->size - self->pos : 0;
    if (num_bytes < 0 || num_bytes > remaining)
        num_bytes = remaining;
    result = PyBytes_FromStringAndSize(&self->data[self->pos], num_bytes);
    self->pos += num_bytes;
    return result;
}
开发者ID:1st1,项目名称:cpython,代码行数:19,代码来源:mmapmodule.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ CHECK_VALUE函数代码示例发布时间:2022-05-30
下一篇:
C++ CHECK_UNITID函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap