Displaying 20 results from an estimated 236 matches for "pyobject".
2018 Apr 06
0
[nbdkit PATCH 2/2] python: Simplify calling into plugin
PyObject_CallObject is powerful, but awkward - we have to wrap
all arguments into a temporary tuple before using it.
Let python do more of the work by using PyObject_CallFunction
anywhere that all arguments can be described by a Py_BuildValue()
format string, instead of creating one-shot arguments ourselve...
2018 Apr 11
0
[nbdkit PATCH v2 5/5] RFC: python: Track and cache per-connection state in C struct
...32 deletions(-)
diff --git a/plugins/python/python.c b/plugins/python/python.c
index ad79c80..757a0e9 100644
--- a/plugins/python/python.c
+++ b/plugins/python/python.c
@@ -389,51 +389,66 @@ py_config_complete (void)
return 0;
}
+/* All per-connection state */
+typedef struct ConnHandle {
+ PyObject *obj;
+ int fua;
+} ConnHandle;
+
static void *
py_open (int readonly)
{
PyObject *fn;
- PyObject *handle;
+ ConnHandle *h = malloc (sizeof *h);
+ if (!h) {
+ nbdkit_error ("%s: %m", script);
+ return NULL;
+ }
if (!callback_defined ("open", &fn)) {...
2016 May 05
1
[PATCH] python: use constants instead of raw values
...T
self._o = libguestfsmod.create(flags)
self._python_return_dict = python_return_dict
diff --git a/python/guestfs-py-byhand.c b/python/guestfs-py-byhand.c
index cf8576f..9e2debf 100644
--- a/python/guestfs-py-byhand.c
+++ b/python/guestfs-py-byhand.c
@@ -37,6 +37,13 @@
static PyObject **get_all_event_callbacks (guestfs_h *g, size_t *len_rtn);
+void
+guestfs_int_py_extend_module (PyObject *module)
+{
+ PyModule_AddIntMacro(module, GUESTFS_CREATE_NO_ENVIRONMENT);
+ PyModule_AddIntMacro(module, GUESTFS_CREATE_NO_CLOSE_ON_EXIT);
+}
+
PyObject *
guestfs_int_py_create (PyObjec...
2017 May 21
3
[PATCH 0/2] python: improved UTF8 decoding error handling
The Python 3 bindings currently are unable to deal with non UTF8 characters.
This series continues what proposed in RHBZ#1406906.
A new function 'set_decode_error_handler' allows the User to specify
how to deal with decoding errors.
The default behaviour will be raising a UnicodeDecodeError.
If the handler is changed to 'surrogateescape', non UTF8 characters will be escaped
in a
2018 Apr 06
6
[nbdkit PATCH 0/2] Python cleanups
I noticed these while working on adding fua support into python,
these are independent enough to push now (and I'll have to rebase
my 'optional may_trim' patch on top of this).
Eric Blake (2):
python: Use Py_XDEFREF()
python: Simplify calling into plugin
plugins/python/python.c | 106 ++++++++----------------------------------------
1 file changed, 18 insertions(+), 88
2018 Apr 19
1
Re: [nbdkit PATCH v2 5/5] RFC: python: Track and cache per-connection state in C struct
...on.c b/plugins/python/python.c
> index ad79c80..757a0e9 100644
> --- a/plugins/python/python.c
> +++ b/plugins/python/python.c
> @@ -389,51 +389,66 @@ py_config_complete (void)
> return 0;
> }
>
> +/* All per-connection state */
> +typedef struct ConnHandle {
> + PyObject *obj;
> + int fua;
> +} ConnHandle;
> +
> static void *
> py_open (int readonly)
> {
> PyObject *fn;
> - PyObject *handle;
> + ConnHandle *h = malloc (sizeof *h);
>
> + if (!h) {
> + nbdkit_error ("%s: %m", script);
> + return NULL;...
2018 Apr 11
10
[nbdkit PATCH v2 0/5] FUA support in Python scripts
First out of our four language bindings to add FUA support (for
reference, I added 'zero' support for python, perl, and ruby
back in 1.1.13, then Rich had to add it for ocaml in 1.1.20).
I tested this heavily under python 2, but for now only compile
tested under python 3; I plan to do further testing there and
make any tweaks if necessary.
I wrote patch 5 early on, but then realized I
2017 May 09
1
[PATCH v2] python: add simple wrappers for PyObject<->string functions
...----------
python/handle.c | 65 ++++++++++++++++++++++++++---------------------
2 files changed, 53 insertions(+), 84 deletions(-)
diff --git a/generator/python.ml b/generator/python.ml
index 0162733..cf08294 100644
--- a/generator/python.ml
+++ b/generator/python.ml
@@ -91,6 +91,9 @@ extern PyObject *guestfs_int_py_event_to_string (PyObject *self, PyObject *args)
extern char **guestfs_int_py_get_string_list (PyObject *obj);
extern PyObject *guestfs_int_py_put_string_list (char * const * const argv);
extern PyObject *guestfs_int_py_put_table (char * const * const argv);
+extern PyObject *gue...
2017 May 21
0
[PATCH 2/2] python: unicode decode handler error scheme setter
....py | 6 ++++++
3 files changed, 38 insertions(+), 2 deletions(-)
diff --git a/generator/python.ml b/generator/python.ml
index f7c1f80bb..66bb7f27d 100644
--- a/generator/python.ml
+++ b/generator/python.ml
@@ -82,6 +82,7 @@ put_handle (guestfs_h *g)
}
extern void guestfs_int_py_extend_module (PyObject *module);
+extern PyObject *guestfs_int_py_set_decode_error_handler (PyObject *self, PyObject *args);
extern PyObject *guestfs_int_py_create (PyObject *self, PyObject *args);
extern PyObject *guestfs_int_py_close (PyObject *self, PyObject *args);
@@ -577,6 +578,8 @@ and generate_python_module ()...
2018 Apr 11
0
[nbdkit PATCH v2 3/5] python: Update internals to plugin API level 2
...nbdkit-plugin.h>
/* XXX Apparently global state is technically wrong in Python 3, see:
@@ -430,12 +431,13 @@ py_get_size (void *handle)
static int
py_pread (void *handle, void *buf,
- uint32_t count, uint64_t offset)
+ uint32_t count, uint64_t offset, uint32_t flags)
{
PyObject *obj = handle;
PyObject *fn;
PyObject *r;
+ assert (!flags);
if (!callback_defined ("pread", &fn)) {
nbdkit_error ("%s: missing callback: %s", script, "pread");
return -1;
@@ -469,12 +471,13 @@ py_pread (void *handle, void *buf,
static int
p...
2010 Sep 09
2
[PATCH]: add libxl python binding
...if ty.signed:
+ return "Int"
+ else:
+ return "Uint"
+ if ty == libxltypes.string:
+ return "String"
+ return None
+
+def py_wrapstruct(ty):
+ l = []
+ l.append("typedef struct {")
+ l.append(" PyObject_HEAD;")
+ l.append(" %s obj;"%ty.typename);
+ l.append("}Py_%s;"%ty.rawname)
+ l.append("")
+ return "\n".join(l) + "\n"
+
+def fsanitize(name):
+ "Sanitise a function name given a C type"
+ ret = ''_'...
2017 May 09
0
[PATCH] python: add simple wrappers for PyObject<->string functions
...-------------------
python/handle.c | 52 +++++++++++++++++++++++++-------------
2 files changed, 51 insertions(+), 73 deletions(-)
diff --git a/generator/python.ml b/generator/python.ml
index 0162733..cf08294 100644
--- a/generator/python.ml
+++ b/generator/python.ml
@@ -91,6 +91,9 @@ extern PyObject *guestfs_int_py_event_to_string (PyObject *self, PyObject *args)
extern char **guestfs_int_py_get_string_list (PyObject *obj);
extern PyObject *guestfs_int_py_put_string_list (char * const * const argv);
extern PyObject *guestfs_int_py_put_table (char * const * const argv);
+extern PyObject *gue...
2020 Aug 05
5
[PATCH nbdkit 3/4] python: Allow thread model to be set from Python plugins.
This is working for me now, although possibly only on Python 3.9.
Dan suggested PyEval_InitThreads but that was deprecated in
Python 3.7.
Rich.
2019 Aug 13
0
[PATCH libnbd 2/6] generator: Create only one Python wrapper per closure.
...cbname;
+ C.print_cbarg_list cbargs;
+ pr "\n";
+ pr "{\n";
+ pr " int ret = 0;\n";
+ pr "\n";
+ pr " if (valid_flag & LIBNBD_CALLBACK_VALID) {\n";
+ pr " PyGILState_STATE py_save = PyGILState_UNLOCKED;\n";
+ pr " PyObject *py_args, *py_ret;\n";
+ List.iter (
+ function
+ | CBArrayAndLen (UInt32 n, len) ->
+ pr " PyObject *py_%s = PyList_New (%s);\n" n len;
+ pr " for (size_t i = 0; i < %s; ++i)\n" len;
+ pr " PyList_SET_ITEM (py_%s, i, PyLong_Fr...
2019 Aug 10
0
[PATCH libnbd 1/5] python: Change aio_buffer into nbd.Buffer class.
...python/t/510-aio-pwrite.py | 6 +-
5 files changed, 96 insertions(+), 61 deletions(-)
diff --git a/generator/generator b/generator/generator
index 26ab365..0107724 100755
--- a/generator/generator
+++ b/generator/generator
@@ -3981,8 +3981,10 @@ raise_exception ()
pr "extern PyObject *nbd_internal_py_%s (PyObject *self, PyObject *args);\n"
name;
) ([ "create"; "close";
- "alloc_aio_buffer"; "aio_buffer_from_bytearray";
- "aio_buffer_to_bytearray" ] @ List.map fst handle_calls);
+ "alloc_a...
2019 Nov 22
0
[PATCH nbdkit v2 05/10] python: Share common code in boolean callbacks.
...0..9445343 100644
--- a/plugins/python/python.c
+++ b/plugins/python/python.c
@@ -684,110 +684,56 @@ py_zero (void *handle, uint32_t count, uint64_t offset, uint32_t flags)
}
static int
-py_can_write (void *handle)
+boolean_callback (void *handle, const char *can_fn, const char *plain_fn)
{
PyObject *obj = handle;
PyObject *fn;
PyObject *r;
int ret;
- if (callback_defined ("can_write", &fn)) {
+ if (callback_defined (can_fn, &fn)) {
PyErr_Clear ();
r = PyObject_CallFunctionObjArgs (fn, obj, NULL);
Py_DECREF (fn);
- if (check_python_failure (&q...
2019 Nov 25
6
[nbdkit PATCH 0/5] Counterproposal for python v2 interfaces
As mentioned in my reviews, I wonder if we should make our python
callbacks look a bit more Pythonic by having kwargs added for each
new flag that we want to expose. The idea was first floated here:
https://www.redhat.com/archives/libguestfs/2018-April/msg00108.html
Note that with my proposal, there is no need for a python script to
expose a global API_VERSION variable; new flags are added
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.
2017 May 11
1
[PATCH] python: improve few exceptions thrown on error
...eError 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
--- a/python/handle.c
+++ b/python/handle.c
@@ -237,7 +237,7 @@ guestfs_int_py_event_to_string (PyObject *self, PyObject *args)
str = guestfs_event_to_string (events);
if (str == NULL) {
- PyErr_SetString (PyExc_RuntimeError, strerror (errno));
+ PyErr_SetFromErrno (PyExc_RuntimeError);
return NULL;
}
@@ -271,7 +271,7 @@ get_all_event_callbacks (guestfs_h *g, size_t *len_rtn)...
2009 Aug 14
1
Code snippet to work out which RStruct/RStructList structs are used and how
--
Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones
virt-p2v converts physical machines to virtual machines. Boot with a
live CD or over the network (PXE) and turn machines into Xen guests.
http://et.redhat.com/~rjones/virt-p2v
-------------- next part --------------
>From 9efa77d717bd9bba5f61965eb6920429b7ae5d8e Mon Sep 17 00:00:00 2001
From: Richard W.M. Jones