Displaying 20 results from an estimated 24 matches for "pyerr_nomemory".
2017 May 11
1
[PATCH] python: improve few exceptions thrown on error
Make use of functions and types that fit more, and that do the same job:
- use PyErr_NoMemory() on malloc failure
- use PyErr_SetFromErrno when setting an exception from an errno
- throw TypeError if not getting a list when required
---
python/handle.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/python/handle.c b/python/handle.c
index 88024e1..9746dca 100644...
2014 Aug 08
2
[PATCH 1/2] Add type checking, support integers as value
...uint64_t *words;
} py_set_values;
static int
@@ -2905,13 +2951,21 @@ get_values (PyObject *v, py_set_values *ret)
ret->nr_values = len;
ret->values = malloc (len * sizeof (hive_set_value));
if (!ret->values) {
- PyErr_SetString (PyExc_RuntimeError, strerror (errno));
+ PyErr_NoMemory ();
+ return -1;
+ }
+ /* if the value is a dword/qword, it will be stored here */
+ ret->words = malloc (len * sizeof (uint64_t));
+ if (!ret->words) {
+ free (ret->values);
+ PyErr_NoMemory ();
return -1;
}
for (i = 0; i < len; ++i) {
- if (get_value (PyLi...
2020 Sep 10
1
[libnbd PATCH] python: Fix more memory leaks
...uot; %s_u32 = %s;\n" n n
+ ) optargs;
List.iter (
function
| Bool _ -> ()
| BytesIn _ -> ()
| BytesOut (n, count) ->
- pr " %s = malloc (%s);\n" n count
+ pr " %s = malloc (%s);\n" n count;
+ pr " if (%s == NULL) { PyErr_NoMemory (); goto out; }\n" n
| BytesPersistIn (n, _) | BytesPersistOut (n, _) ->
- pr " %s_buf = nbd_internal_py_get_aio_buffer (%s);\n" n n
+ pr " %s_buf = nbd_internal_py_get_aio_buffer (%s);\n" n n;
+ pr " if (!%s_buf) goto out;\n" n;
+...
2019 Aug 12
0
[PATCH libnbd 6/7] python: Use free callback to free closure root.
...eter %s is not callable\");\n" cbname;
pr " return NULL;\n";
+ pr " }\n";
+ pr " if (nbd_add_free_callback (h, %s_user_data,\n" cbname;
+ pr " decref, NULL) == -1) {\n";
+ pr " PyErr_NoMemory ();\n";
+ pr " return NULL;\n";
pr " }\n"
| Enum _ -> ()
| Flags (n, _) -> pr " %s_u32 = %s;\n" n n
@@ -4600,6 +4602,12 @@ let generate_python_methods_c () =
pr "\n";
pr "#include <methods.h>\n";...
2020 Sep 08
0
[libnbd PATCH] hack for testing python closure leaks: NOT FOR COMMIT
...t) {\n";
+ pr " init = true;\n";
+ pr " atexit (dump_alloc_count);\n";
+ pr " }\n";
+ pr " alloc_count++;\n";
pr " struct user_data *data = calloc (1, sizeof *data);\n";
pr " if (data == NULL) {\n";
pr " PyErr_NoMemory ();\n";
@@ -594,6 +612,7 @@ let generate_python_methods_c () =
pr "{\n";
pr " struct user_data *data = user_data;\n";
pr "\n";
+ pr " alloc_count--;\n";
pr " if (data->fn != NULL)\n";
pr " Py_DECREF (data->fn);\...
2019 Jul 16
1
Re: [PATCH libnbd v2] generator: Define new Closure type instead of callbacks.
...; n n;
> - pr " if (%s_data == NULL) {\n" n;
> + | Closure (false, _) -> ()
> + | Closure (true, cls) ->
> + pr " user_data = malloc (sizeof *user_data);\n";
> + pr " if (user_data == NULL) {\n";
> pr " PyErr_NoMemory ();\n";
> pr " return NULL;\n";
> pr " }\n"
Memory leak. If Closure contains two callbacks, and the first malloc()
succeeds while the second fails, we are not reclaiming the first.
Should our generated python code take advantage of
__attribute__((...
2019 Aug 10
0
[PATCH libnbd 1/5] python: Change aio_buffer into nbd.Buffer class.
...y_alloc_aio_buffer (PyObject *self, PyObject *args)
{
@@ -115,7 +113,7 @@ nbd_internal_py_alloc_aio_buffer (PyObject *self, PyObject *args)
free (buf);
return NULL;
}
- buf->data = calloc (1, buf->len);
+ buf->data = malloc (buf->len);
if (buf->data == NULL) {
PyErr_NoMemory ();
free (buf);
@@ -193,3 +191,21 @@ nbd_internal_py_aio_buffer_to_bytearray (PyObject *self, PyObject *args)
return PyByteArray_FromStringAndSize (buf->data, buf->len);
}
+
+PyObject *
+nbd_internal_py_aio_buffer_size (PyObject *self, PyObject *args)
+{
+ PyObject *obj;
+ struct...
2017 Apr 25
1
[Bug #1406906] [PATCH] python: fix segmentation fault when setting non UTF-8 strings
When constructing the returned objects, check the return value of
Python APIs.
A RuntimeError will be raised on failure pointing to the problematic
entry and the field name.
Signed-off-by: Matteo Cafasso <noxdafox@gmail.com>
---
generator/python.ml | 143 +++++++++++++++++++++++++++++++++++-----------------
1 file changed, 97 insertions(+), 46 deletions(-)
diff --git
2019 Aug 10
7
[PATCH libnbd 0/5] WIP: python: Add test for doing asynch copy.
This doesn't yet work. However it does make me more convinced than
ever that we really need to sort out persistent buffer lifetimes in
the library (similar to what we did for closures).
Rich.
2019 Jul 16
0
[libnbd PATCH 2/2] RFC: generator: Handle shared callbacks in Python
...inding name { args; ret } =
| BytesPersistIn _
| BytesOut _
| BytesPersistOut _
- | Callback _ -> ()
- | CallbackPersist (n, _) ->
- pr " %s_data = malloc (sizeof *%s_data);\n" n n;
- pr " if (%s_data == NULL) {\n" n;
- pr " PyErr_NoMemory ();\n";
- pr " return NULL;\n";
- pr " }\n"
| Flags _
| Int _
| Int64 _
- | Opaque _
+ | OpaqueAndCallbacks _ -> ()
+ | OpaqueAndCallbacksPersist (n, _) ->
+ pr " %s = malloc (sizeof *%s);\n" n n;
+ pr &qu...
2019 Jul 24
2
Re: [PATCH libnbd 1/3] generator: Change Closure so it describes single callbacks.
...ent closure user_data. *)
> - List.iter (
> - function
> - | Closure (false, _) -> ()
> - | Closure (true, cls) ->
> - pr " user_data = malloc (sizeof *user_data);\n";
> - pr " if (user_data == NULL) {\n";
> - pr " PyErr_NoMemory ();\n";
> - pr " return NULL;\n";
> - pr " }\n"
> - | _ -> ()
> - ) args;
Nice that we get rid of this.
Overall, the patch makes sense; I assume you can fix any problems I
pointed out above without needing to send v2 (especially since th...
2019 Jul 16
3
[RFC libnbd PATCH 0/2] Start fixing python nbd.pread_structured_callback
Posting now that I got something to compile (at the expense of
breaking OCaml bindings), but I'm open to ideas on how to improve it.
Eric Blake (2):
generator: Tweak print_c_arg_list to take alternate first arg
RFC: generator: Handle shared callbacks in Python
generator/generator | 556 ++++++++++++++++++++++----------------------
1 file changed, 280 insertions(+), 276 deletions(-)
--
2014 Aug 04
6
[hivex] Segfault for an integer value to node_set_value
Hi,
When an integer argument is passed as value, node_set_value
segfaults. Reproducer is at the end of this message
The backtrace points at hivex-py.c, function get_value. While obj
is non-NULL, `bytes = PyUnicode_AsUTF8String (obj);` returns NULL.
Kind regards,
Peter
https://lekensteyn.nl
#!/usr/bin/env python3
import hivex, sys
h = hivex.Hivex(sys.argv[1])
print(h)
val = {
2014 Aug 16
7
[hivex] [PATCH 0/6] Python fixes for node_set_value
...erals:
`sed 's/u"/"/' -i python/t/*.py`
Support for Unicode literals was removed in 3.0 and restored in 3.3 (PEP-414)
[1]: https://www.redhat.com/archives/libguestfs/2014-August/msg00051.html
Peter Wu (6):
python: use errors more specific than RuntimeError
python: use PyErr_NoMemory
python: check some types for get_value
python: fix crash by validating key and value
python: add heavier tests for setvalue
generator: Fix mixed tabs/spaces
configure.ac | 4 -
generator/generator.ml | 570 +++++++++++++++++++++--------------------
python/t/200...
2019 Aug 14
5
[PATCH libnbd 0/3] Use free callback to hold ref to AIO buffer.
Basically the same as this patch series, but for Python:
https://www.redhat.com/archives/libguestfs/2019-August/msg00235.html
plus adding the 590 asynch test at the end.
Rich.
2019 Jul 16
2
[PATCH libnbd v2] generator: Define new Closure type
As before, but this one has working Python bindings. OCaml still TBD.
Rich.
2019 Aug 09
0
[PATCH libnbd 1/2] generator: Handle closure args (cbargs) specially.
...; PyErr_SetString (PyExc_RuntimeError, \"PyList_Size failed\");\n";
- pr " return NULL;\n";
- pr " }\n";
- pr " %s = malloc (sizeof (uint32_t) * %s);\n" n len;
- pr " if (%s == NULL) {\n" n;
- pr " PyErr_NoMemory ();\n";
- pr " return NULL;\n";
- pr " }\n";
- pr " for (size_t _i = 0; _i < %s; ++_i)\n" len;
- pr " %s[_i] = PyLong_AsUnsignedLong (PyList_GetItem (%s, _i));\n" n n
- | ArrayAndLen _ -> assert false
| Bool...
2019 Aug 12
14
[PATCH libnbd 0/7] Add free callbacks and remove valid_flag.
As proposed here:
https://www.redhat.com/archives/libguestfs/2019-August/msg00130.html
I didn't actually read Eric's replies to that yet because I've been
concentrating on writing these patches all day. Anyway here they are
and I'll look at what Eric said about the proposal next.
Rich.
2019 Jul 24
0
[PATCH libnbd 1/3] generator: Change Closure so it describes single callbacks.
...quot;;
- (* Allocate the persistent closure user_data. *)
- List.iter (
- function
- | Closure (false, _) -> ()
- | Closure (true, cls) ->
- pr " user_data = malloc (sizeof *user_data);\n";
- pr " if (user_data == NULL) {\n";
- pr " PyErr_NoMemory ();\n";
- pr " return NULL;\n";
- pr " }\n"
- | _ -> ()
- ) args;
-
(* Parse the Python parameters. *)
pr " if (!PyArg_ParseTuple (args, (char *) \"O\"";
List.iter (
@@ -4054,7 +4008,7 @@ let print_python_binding name { a...
2019 Jul 24
6
[PATCH libnbd 0/3] Implement closure lifetimes.
This implements most of what I wrote here:
https://www.redhat.com/archives/libguestfs/2019-July/msg00213.html