Displaying 2 results from an estimated 2 matches for "pybytearray_asstr".
2019 Nov 23
1
[PATCH] python: Support buffer protocol for pread() result
...ize (r) < count) {
- nbdkit_error ("%s: byte array returned from pread is too small", script);
- Py_DECREF (r);
- return -1;
+ if (view.len < count) {
+ nbdkit_error ("%s: buffer returned from pread is too small", script);
+ goto out;
}
- memcpy (buf, PyByteArray_AsString (r), count);
+ memcpy (buf, view.buf, count);
+ ret = 0;
+
+out:
+ if (view.obj)
+ PyBuffer_Release (&view);
+
Py_DECREF (r);
- return 0;
+ return ret;
}
static int
--
2.21.0
2010 Sep 09
2
[PATCH]: add libxl python binding
...PyObject *xl_error_obj;
+
+static int fixed_bytearray_set(PyObject *v, uint8_t *ptr, size_t len)
+{
+ char *tmp;
+ size_t sz;
+
+ if ( NULL == v ) {
+ memset(ptr, 0, len);
+ return 0;
+ }
+ if ( PyByteArray_Check(v) ) {
+ sz = PyByteArray_Size(v);
+ tmp = PyByteArray_AsString(v);
+ }else{
+ Py_ssize_t ssz;
+ if ( PyString_AsStringAndSize(v, &tmp, &ssz) )
+ return -1;
+ if ( ssz < 0 )
+ tmp = NULL;
+ sz = ssz;
+ }
+ if ( NULL == tmp ) {
+ memset(ptr, 0, len);
+ return 0;
+ }
+ if...