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

C++ PyBuffer_Release函数代码示例

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

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



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

示例1: 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


示例2: 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


示例3: BYTES_ADD_INCREMENTAL

NUITKA_MAY_BE_UNUSED static bool BYTES_ADD_INCREMENTAL(PyObject **operand1, PyObject *operand2) {
    assert(PyBytes_CheckExact(*operand1));
    assert(PyBytes_CheckExact(operand2));

    // Buffer
    Py_buffer wb;
    wb.len = -1;

    if (PyObject_GetBuffer(operand2, &wb, PyBUF_SIMPLE) != 0) {
        PyErr_Format(PyExc_TypeError, "can't concat %s to %s", Py_TYPE(operand2)->tp_name, Py_TYPE(*operand1)->tp_name);

        return false;
    }

    Py_ssize_t oldsize = PyBytes_GET_SIZE(*operand1);

    if (oldsize > PY_SSIZE_T_MAX - wb.len) {
        PyErr_NoMemory();
        PyBuffer_Release(&wb);
        return false;
    }
    if (_PyBytes_Resize(operand1, oldsize + wb.len) < 0) {
        PyBuffer_Release(&wb);
        return false;
    }

    memcpy(PyBytes_AS_STRING(*operand1) + oldsize, wb.buf, wb.len);
    PyBuffer_Release(&wb);
    return true;
}
开发者ID:kayhayen,项目名称:Nuitka,代码行数:30,代码来源:HelpersOperationBinaryInplaceAdd.c


示例4: PyObject_GetBuffer

static IDProperty *idp_from_PySequence(const char *name, PyObject *ob)
{
	Py_buffer buffer;
	bool use_buffer = false;

	if (PyObject_CheckBuffer(ob)) {
		PyObject_GetBuffer(ob, &buffer, PyBUF_SIMPLE | PyBUF_FORMAT);
		char format = *buffer.format;
		if (ELEM(format, 'i', 'f', 'd')) {
			use_buffer = true;
		}
		else {
			PyBuffer_Release(&buffer);
		}
	}

	if (use_buffer) {
		IDProperty *prop = idp_from_PySequence_Buffer(name, &buffer);
		PyBuffer_Release(&buffer);
		return prop;
	}
	else {
		PyObject *ob_seq_fast = PySequence_Fast(ob, "py -> idprop");
		if (ob_seq_fast != NULL) {
			IDProperty *prop = idp_from_PySequence_Fast(name, ob_seq_fast);
			Py_DECREF(ob_seq_fast);
			return prop;
		}
		else {
			return NULL;
		}
	}
}
开发者ID:wchargin,项目名称:blender,代码行数:33,代码来源:idprop_py_api.c


示例5: Stream_func_try_write

static PyObject *
Stream_func_try_write(Stream *self, PyObject *args)
{
    int err;
    uv_buf_t buf;
    Py_buffer view;

    RAISE_IF_HANDLE_NOT_INITIALIZED(self, NULL);
    RAISE_IF_HANDLE_CLOSED(self, PyExc_HandleClosedError, NULL);

    if (!PyArg_ParseTuple(args, PYUV_BYTES"*:try_write", &view)) {
        return NULL;
    }

    buf = uv_buf_init(view.buf, view.len);
    err = uv_try_write((uv_stream_t *)UV_HANDLE(self), &buf, 1);
    if (err < 0) {
        RAISE_STREAM_EXCEPTION(err, UV_HANDLE(self));
        PyBuffer_Release(&view);
        return NULL;
    }

    PyBuffer_Release(&view);
    return PyInt_FromLong((long)err);
}
开发者ID:ConchLikeSun,项目名称:pyuv,代码行数:25,代码来源:stream.c


示例6: PyBytes_FromStringAndSize

static PyObject *Sponge_decrypt(PyObject *obj, PyObject *args)
{
	SpongeObject *self = (SpongeObject *)obj;
	PyObject *res;
	PyObject *dataobj;
	void *resdata;
	Py_buffer buf;

	if (!PyArg_ParseTuple(args, "O", &dataobj))
		return NULL;
	if (!get_buffer(dataobj, &buf))
		return NULL;

	/* allocate result object */
	res = PyBytes_FromStringAndSize(NULL, buf.len);
	if (!res) {
		PyBuffer_Release(&buf);
		return NULL;
	}

	/* get internal buffer */
	resdata = PyBytes_AsString(res);
	if (!resdata) {
		PyBuffer_Release(&buf);
		Py_CLEAR(res);
		return NULL;
	}

	keccak_decrypt(&self->md, resdata, buf.buf, buf.len);

	PyBuffer_Release(&buf);

	return res;
}
开发者ID:markokr,项目名称:spongeshaker,代码行数:34,代码来源:pykeccak.c


示例7: py_avg

/* double avg(double*, int) */
static PyObject* py_avg(PyObject* self, PyObject* args)
{
    PyObject* bufobj;
    Py_buffer view;
    double result;

    if (!PyArg_ParseTuple(args, "O", &bufobj)) {
        return NULL;
    }

    if (PyObject_GetBuffer(bufobj, &view, PyBUF_ANY_CONTIGUOUS | PyBUF_FORMAT) == -1) {
        return NULL;
    }

    if (view.ndim != 1) {
        PyErr_SetString(PyExc_TypeError, "Expected a 1-dimensional array");
        PyBuffer_Release(&view);
        return NULL;
    }

    if (strcmp(view.format, "d") != 0) {
        PyErr_SetString(PyExc_TypeError, "Expected an array of doubles");
        PyBuffer_Release(&view);
        return NULL;
    }

    result = avg(view.buf, view.shape[0]);
    PyBuffer_Release(&view);
    return Py_BuildValue("d", result);
}
开发者ID:weiang,项目名称:recent,代码行数:31,代码来源:pysample.c


示例8: PyErr_SetString

/* int primes_c(int, int *) */
static PyObject *py_primes_c(PyObject *self, PyObject *args) {
  int howmany;
  PyObject *bufobj;
  Py_buffer view;
  double result;
  /* Get the howmany param and the passed Python object (int and Object) */
  if (!PyArg_ParseTuple(args, "iO", &howmany, &bufobj)) {
    return NULL;
  }

  /* Attempt to extract buffer information from it */
  if (PyObject_GetBuffer(bufobj, &view, PyBUF_ANY_CONTIGUOUS | PyBUF_FORMAT) == -1) {
    return NULL;
  }

  if (view.ndim != 1) {
    PyErr_SetString(PyExc_TypeError, "Expected a 1-dimensional array");
    PyBuffer_Release(&view);
    return NULL;
  }

  /* Check the type of items in the array */
  if (strcmp(view.format, "i") != 0) {
    PyErr_SetString(PyExc_TypeError, "Expected an array of int");
    PyBuffer_Release(&view);
    return NULL;
  }

  /* Pass the raw buffer to the C function */
  result = primes_c(howmany, view.buf);

  /* Indicate we're done working with the buffer */
  PyBuffer_Release(&view);
  return Py_BuildValue("i", result);
}
开发者ID:mwoinoski,项目名称:crs1906,代码行数:36,代码来源:primes_ext_mod.c


示例9: PyErr_Format

static PyObject *verify(RSAObject *self, PyObject *args)
{
    Py_buffer digest, signature;
    int result = 0;
    PyObject *result_obj = NULL;

#if PY_MAJOR_VERSION >= 3
    if (!PyArg_ParseTuple(args, "y*y*:verify", &digest, &signature))
        return NULL;
#else
    if (!PyArg_ParseTuple(args, "s*s*:verify", &digest, &signature))
        return NULL;
#endif

    if (digest.len != SHA_DIGEST_LENGTH)
    {
        PyErr_Format(PyExc_ValueError, "digest should be %i bytes",
                     SHA_DIGEST_LENGTH);
        goto cleanup;
    }

    result = RSA_verify(NID_sha1, digest.buf, digest.len,
                        signature.buf, signature.len, self->rsa);

    result_obj = PyBool_FromLong(result);

cleanup:
    PyBuffer_Release(&digest);
    PyBuffer_Release(&signature);

    return result_obj;
}
开发者ID:eric-wieser,项目名称:python-raven,代码行数:32,代码来源:rsa.c


示例10: PyBuffer_Release

static PyObject *convert(PyObject *self, PyObject *args) {
	Py_buffer      inBuf, outBuf;
	short          row, col, r, g, b, w, h, rd, gd, bd;
	unsigned char *rgbPtr, *yPtr, y;
	signed char   *uPtr, *vPtr, u, v;

	if(!PyArg_ParseTuple(args, "s*s*hh", &inBuf, &outBuf, &w, &h))
		return NULL;

	if(w & 31) w += 32 - (w & 31); // Round up width to multiple of 32
	if(h & 15) h += 16 - (h & 15); // Round up height to multiple of 16

	rgbPtr = outBuf.buf;
	yPtr   = inBuf.buf;
	uPtr   = (signed char *)&yPtr[w * h];
	vPtr   = &uPtr[(w * h) >> 2];
	w    >>= 1; // 2 columns processed per iteration

	for(row=0; row<h; row++) {
		for(col=0; col<w; col++) {
			// U, V (and RGB deltas) updated on even columns
			u          = uPtr[col] - 128;
			v          = vPtr[col] - 128;
			rd         =  (359 * v)             >> 8;
			gd         = ((183 * v) + (88 * u)) >> 8;
			bd         =  (454 * u)             >> 8;
			// Even column
			y          = *yPtr++;
			r          = y + rd;
			g          = y - gd;
			b          = y + bd;
			*rgbPtr++  = (r > 255) ? 255 : (r < 0) ? 0 : r;
			*rgbPtr++  = (g > 255) ? 255 : (g < 0) ? 0 : g;
			*rgbPtr++  = (b > 255) ? 255 : (b < 0) ? 0 : b;
			// Odd column
			y          = *yPtr++;
			r          = y + rd;
			g          = y - gd;
			b          = y + bd;
			*rgbPtr++  = (r > 255) ? 255 : (r < 0) ? 0 : r;
			*rgbPtr++  = (g > 255) ? 255 : (g < 0) ? 0 : g;
			*rgbPtr++  = (b > 255) ? 255 : (b < 0) ? 0 : b;
		}
		if(row & 1) {
			uPtr += w;
			vPtr += w;
		}
	}

	PyBuffer_Release(&inBuf);
	PyBuffer_Release(&outBuf);

	Py_INCREF(Py_None);
	return Py_None;
}
开发者ID:spadgenske,项目名称:GoPiGo,代码行数:55,代码来源:yuv2rgb.c


示例11: Billiard_read

static PyObject *
Billiard_read(PyObject *self, PyObject *args)
{
    int fd;
    Py_buffer view;
    Py_ssize_t buflen, recvlen = 0;

    char *buf = NULL;

    Py_ssize_t n = 0;

    if (!PyArg_ParseTuple(args, "iw*|n", &fd, &view, &recvlen))
        return NULL;
    buflen = view.len;
    buf = view.buf;

    if (recvlen < 0) {
        PyBuffer_Release(&view);
        PyErr_SetString(PyExc_ValueError, "negative len for read");
        return NULL;
    }

    if (recvlen == 0) {
        recvlen = buflen;
    }

    if (buflen < recvlen) {
        PyBuffer_Release(&view);
        PyErr_SetString(PyExc_ValueError,
            "Buffer too small for requested bytes");
        return NULL;

    }

    if (buflen < 0 || buflen == 0) {
        errno = EINVAL;
        goto bail;
    }
    // Requires Python 2.7
    //if (!_PyVerify_fd(fd)) goto bail;

    Py_BEGIN_ALLOW_THREADS
    n = read(fd, buf, recvlen);
    Py_END_ALLOW_THREADS
    if (n < 0) goto bail;
    PyBuffer_Release(&view);
    return PyInt_FromSsize_t(n);

bail:
    PyBuffer_Release(&view);
    return PyErr_SetFromErrno(PyExc_OSError);
}
开发者ID:andresriancho,项目名称:billiard,代码行数:52,代码来源:multiprocessing.c


示例12: PyErr_SetString

/*
 * TODO: note the definition of the py_calc_z_ser() function.
 * (no code change required) 
 */
static PyObject *py_calc_z_ser(PyObject *self, PyObject *args) {
  PyObject *q, *output;
  int len_q, maxiter, result = 0;
  Py_buffer q_buffer, output_buffer;

  /* Get the arguments: two arrays (two Objects) and two int  */
  if (!PyArg_ParseTuple(args, "OOii", &q, &output, &len_q, &maxiter)) {
    return NULL;
  }

  /* Attempt to extract buffer information from q */
  if (PyObject_GetBuffer(q, &q_buffer,
                         PyBUF_ANY_CONTIGUOUS | PyBUF_FORMAT) == -1) {
    return NULL;
  }

  if (q_buffer.ndim != 1) {
    PyErr_SetString(PyExc_TypeError,
                    "First arg must be a 1-dimensional array of complex");
    PyBuffer_Release(&q_buffer);
    return NULL;
  }

  /* Attempt to extract buffer information from output_buffer */
  if (PyObject_GetBuffer(output, &output_buffer,
                         PyBUF_ANY_CONTIGUOUS | PyBUF_FORMAT) == -1) {
    return NULL;
  }

  if (output_buffer.ndim != 1) {
    PyErr_SetString(PyExc_TypeError,
                    "Second arg must be a 1-dimensional array of int");
    PyBuffer_Release(&output_buffer);
    return NULL;
  }

  /* Check the type of items in the array */
  if (strcmp(output_buffer.format, "i") != 0) {
    PyErr_SetString(PyExc_TypeError, "Second arg must be an array of int");
    PyBuffer_Release(&output_buffer);
    return NULL;
  }

  /* Pass the raw buffers to the C function */
  result = calc_z_ser(q_buffer.buf, output_buffer.buf, len_q, maxiter);

  /* Indicate we're done working with the buffers */
  PyBuffer_Release(&q_buffer);
  PyBuffer_Release(&output_buffer);
  return Py_BuildValue("i", result);
}
开发者ID:mwoinoski,项目名称:crs1906,代码行数:55,代码来源:calc_z_ser_ext_mod.c


示例13: 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


示例14: DCStaticTriangleMeshShapeInit

static int DCStaticTriangleMeshShapeInit(DCStaticTriangleMeshShape *self, PyObject *args, PyObject *kwds)
{
	DKObject<DKStaticTriangleMeshShape> shape = NULL;
	if (self->shape == NULL)
	{
		Py_buffer vertexBuffer, indexBuffer;
		int use16bit = 0;
		int rebuildIndex = 1;
		float welding = 0.0f;
		char* kwlist[] = { "vertexBuffer", "indexBuffer", "use16bitIndex", "rebuildIndex", "weldingThreshold", NULL };
		if (!PyArg_ParseTupleAndKeywords(args, kwds, "y*y*|ppf", kwlist,
			&vertexBuffer, &indexBuffer, &use16bit, &rebuildIndex, &welding))
			return -1;

		DKVector3* vertices = reinterpret_cast<DKVector3*>(vertexBuffer.buf);
		size_t numVerts = vertexBuffer.len / sizeof(DKVector3);

		if (use16bit)
		{
			unsigned int* indices = reinterpret_cast<unsigned int*>(indexBuffer.buf);
			size_t numIndices = indexBuffer.len / sizeof(unsigned int);
			if (numVerts > 0 && numIndices > 0)
			{
				shape = DKOBJECT_NEW DKStaticTriangleMeshShape(vertices, numVerts, indices, numIndices, DKAABox(), rebuildIndex != 0, welding);
			}
		}
		else
		{
			unsigned int* indices = reinterpret_cast<unsigned int*>(indexBuffer.buf);
			size_t numIndices = indexBuffer.len / sizeof(unsigned int);
			if (numVerts > 0 && numIndices > 0)
			{
				shape = DKOBJECT_NEW DKStaticTriangleMeshShape(vertices, numVerts, indices, numIndices, DKAABox(), rebuildIndex != 0, welding);
			}
		}
		PyBuffer_Release(&vertexBuffer);
		PyBuffer_Release(&indexBuffer);

		if (shape == NULL)
		{
			PyErr_SetString(PyExc_ValueError, "invalid argument.");
			return -1;
		}
		self->shape = shape;
	}

	self->base.shape = self->shape;
	return DCConcaveShapeTypeObject()->tp_init((PyObject*)self, args, kwds);
}
开发者ID:hhg128,项目名称:DKGL,代码行数:49,代码来源:DCStaticTriangleMeshShape.cpp


示例15: PyBlosc_decompress

static PyObject *
PyBlosc_decompress(PyObject *self, PyObject *args)
{
    Py_buffer view;
    PyObject *result_str;
    void *input, *output;
    size_t nbytes, cbytes;
    char *format;
    /* Accept some kind of input */
    #if PY_MAJOR_VERSION <= 2
        /* s* : bytes like object including unicode and anything that supports
         * the buffer interface */
        format = "s*:decompress";
    #elif PY_MAJOR_VERSION >= 3
        /* y* :bytes like object EXCLUDING unicode and anything that supports
         * the buffer interface. This is the recommended way to accept binary
         * data in Python 3. */
        format = "y*:decompress";
    #endif

    if (!PyArg_ParseTuple(args, format, &view))
      return NULL;

    cbytes = view.len;
    input = view.buf;
    /*  fetch the uncompressed size into nbytes */
    if (!get_nbytes(input, cbytes, &nbytes)){
      PyBuffer_Release(&view);
      return NULL;
    }

    /* Book memory for the result */
    if (!(result_str = PyBytes_FromStringAndSize(NULL, (Py_ssize_t)nbytes))){
      PyBuffer_Release(&view);
      return NULL;
    }

    output = PyBytes_AS_STRING(result_str);

    /*  do decompression */
    if (!decompress_helper(input, nbytes, output)){
      Py_XDECREF(result_str);
      PyBuffer_Release(&view);
      return NULL;
    }

    PyBuffer_Release(&view);
    return result_str;
}
开发者ID:ASPP,项目名称:python-blosc,代码行数:49,代码来源:blosc_extension.c


示例16: DataTransferRequest_dealloc

static void DataTransferRequest_dealloc(DataTransferRequest *self) {
   if (self->dtd) {
      if (self->ttype & SRC_ISMEM)
         PyBuffer_Release(&self->src.mem);
      if (self->ttype & DST_ISMEM)
         PyBuffer_Release(&self->dst.mem);
      
      Py_DECREF(self->py_src);
      Py_DECREF(self->py_dst);
      Py_DECREF(self->opaque);
      Py_DECREF(self->dtd);
   }
   free(self->tmpbuf);
   Py_TYPE(self)->tp_free((PyObject*)self);
}
开发者ID:sh01,项目名称:gonium,代码行数:15,代码来源:_blockfdmodule.c


示例17: _convert_argb2rgba

// Takes one argument: a contiguous buffer object.  Modifies it in place.
static PyObject *
_convert_argb2rgba(PyObject *self, PyObject *args)
{
    PyObject *ret = NULL;
    Py_buffer view;

    if (!PyArg_ParseTuple(args, "s*", &view))
        return NULL;
    if (!PyBuffer_IsContiguous(&view, 'A')) {
        PyErr_SetString(PyExc_ValueError, "Argument is not contiguous");
        goto DONE;
    }
    if (view.readonly) {
        PyErr_SetString(PyExc_ValueError, "Argument is not writable");
        goto DONE;
    }
    if (view.len % 4) {
        PyErr_SetString(PyExc_ValueError, "Argument has invalid size");
        goto DONE;
    }

    Py_BEGIN_ALLOW_THREADS
    argb2rgba(view.buf, view.len);
    Py_END_ALLOW_THREADS

    Py_INCREF(Py_None);
    ret = Py_None;

DONE:
    PyBuffer_Release(&view);
    return ret;
}
开发者ID:MeganArms,项目名称:openslide-python,代码行数:33,代码来源:_convert.c


示例18: memory_bio_write

static PyObject *
memory_bio_write(PySSLMemoryBIO *self, PyObject *args)
{
    PyObject *Pret = NULL;
    Py_buffer buf;
    int nbytes;

    buf.buf = NULL;
    if (!PyArg_ParseTuple(args, BUF_FMT ":write", &buf))
        RETURN_ERROR(NULL);

    if (buf.len > INT_MAX)
        RETURN_ERROR("string longer than %d bytes", INT_MAX);
    if (self->eof_written)
        RETURN_ERROR("cannot write() after write_eof()");

    nbytes = BIO_write(self->bio, buf.buf, buf.len);
    if (nbytes < 0)
        RETURN_ERROR("BIO_write() failed");

    Pret = PyLong_FromLong(nbytes);

error:
    if (buf.buf != NULL) PyBuffer_Release(&buf);
    return Pret;
}
开发者ID:geertj,项目名称:gruvi,代码行数:26,代码来源:sslcompat.c


示例19: PyMemorySimpleView_FromObject

/*
 * Factory
 */
static PyObject *
PyMemorySimpleView_FromObject(PyObject *base)
{
	PyMemorySimpleViewObject *mview = NULL;
	Py_buffer view;

	if (Py_TYPE(base)->tp_as_buffer == NULL ||
		Py_TYPE(base)->tp_as_buffer->bf_getbuffer == NULL) {

		PyErr_SetString(PyExc_TypeError,
			"cannot make memory view because object does "
			"not have the buffer interface");
		return NULL;
	}

	memset(&view, 0, sizeof(Py_buffer));
	if (PyObject_GetBuffer(base, &view, PyBUF_FULL_RO) < 0)
		return NULL;

	mview = (PyMemorySimpleViewObject *)
		PyObject_GC_New(PyMemorySimpleViewObject, &PyMemorySimpleView_Type);
	if (mview == NULL) {
		PyBuffer_Release(&view);
		return NULL;
	}
	memcpy(&mview->view, &view, sizeof(Py_buffer));
	mview->base = base;
	Py_INCREF(base);

	PyObject_GC_Track(mview);
	return (PyObject *)mview;
}
开发者ID:Eothred,项目名称:jpype,代码行数:35,代码来源:jpype_memory_view.c


示例20: Stream_func_write

static PyObject *
Stream_func_write(Stream *self, PyObject *args)
{
    uv_buf_t buf;
    stream_write_ctx *ctx;
    Py_buffer *view;
    PyObject *callback = Py_None;

    RAISE_IF_HANDLE_NOT_INITIALIZED(self, NULL);
    RAISE_IF_HANDLE_CLOSED(self, PyExc_HandleClosedError, NULL);

    ctx = PyMem_Malloc(sizeof *ctx);
    if (!ctx) {
        PyErr_NoMemory();
        return NULL;
    }

    view = &ctx->view[0];

    if (!PyArg_ParseTuple(args, PYUV_BYTES"*|O:write", view, &callback)) {
        PyMem_Free(ctx);
        return NULL;
    }

    if (callback != Py_None && !PyCallable_Check(callback)) {
        PyBuffer_Release(view);
        PyMem_Free(ctx);
        PyErr_SetString(PyExc_TypeError, "a callable or None is required");
        return NULL;
    }

    buf = uv_buf_init(view->buf, view->len);

    return pyuv_stream_write(self, ctx, view, &buf, 1, callback, NULL);
}
开发者ID:imclab,项目名称:pyuv,代码行数:35,代码来源:stream.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ PyBytes_AS_STRING函数代码示例发布时间:2022-05-30
下一篇:
C++ PyBool_Check函数代码示例发布时间: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