From 253577c686445a8743e6569e1553dbf54d1887b3 Mon Sep 17 00:00:00 2001 From: totaam Date: Mon, 31 May 2021 13:46:09 +0700 Subject: [PATCH] #3031 convert to new buffer api --- xpra/gtk_common/gtk3/gdk_atoms.pyx | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/xpra/gtk_common/gtk3/gdk_atoms.pyx b/xpra/gtk_common/gtk3/gdk_atoms.pyx index 7630a642ce..365785e1bd 100644 --- a/xpra/gtk_common/gtk3/gdk_atoms.pyx +++ b/xpra/gtk_common/gtk3/gdk_atoms.pyx @@ -14,7 +14,9 @@ from libc.stdint cimport uintptr_t #pylint: disable=syntax-error cdef extern from "Python.h": - int PyObject_AsReadBuffer(object obj, void ** buffer, Py_ssize_t * buffer_len) except -1 + int PyObject_GetBuffer(object obj, Py_buffer *view, int flags) + void PyBuffer_Release(Py_buffer *view) + int PyBUF_ANY_CONTIGUOUS cdef extern from "gtk-3.0/gdk/gdk.h": ctypedef void* GdkAtom @@ -29,15 +31,15 @@ cdef extern from "gtk-3.0/gdk/gdkproperty.h": def gdk_atom_objects_from_gdk_atom_array(atom_string): - cdef const GdkAtom * array = NULL - cdef GdkAtom atom - cdef gchar* name - cdef Py_ssize_t array_len_bytes = 0 - cdef uintptr_t gdk_atom_value = 0 - assert PyObject_AsReadBuffer(atom_string, &array, &array_len_bytes)==0 - cdef unsigned int array_len = array_len_bytes // sizeof(GdkAtom) + cdef Py_buffer py_buf + if PyObject_GetBuffer(atom_string, &py_buf, PyBUF_ANY_CONTIGUOUS): + raise Exception("failed to read atom buffer of %s" % type(atom_string)) + cdef unsigned int array_len = py_buf.len // sizeof(GdkAtom) objects = [] cdef unsigned int i + cdef const GdkAtom * array = py_buf.buf + cdef GdkAtom atom + cdef gchar* name for i in range(array_len): atom = array[i] if atom==GDK_NONE: