Skip to content

Commit

Permalink
#2358 use a temporary instance of the bindings so we don't end up cac…
Browse files Browse the repository at this point in the history
…hing the display pointer, rename bindings classes so we can more easily differentiate the singletons from regular instances

git-svn-id: https://xpra.org/svn/Xpra/trunk@23193 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Jul 19, 2019
1 parent 7947e91 commit c1f3198
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/xpra/sound/pulseaudio/pulseaudio_common_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def get_x11_property(atom_name):
try:
from xpra.gtk_common.error import xswallow
from xpra.x11.bindings.posix_display_source import X11DisplayContext #@UnresolvedImport
from xpra.x11.bindings.window_bindings import X11WindowBindings
from xpra.x11.bindings.window_bindings import X11WindowBindingsInstance
except ImportError as e:
log("get_x11_property(%s)", atom_name, exc_info=True)
log.error("Error: unable to query X11 property '%s':", atom_name)
Expand All @@ -30,7 +30,7 @@ def get_x11_property(atom_name):
try:
with X11DisplayContext(display) as dc:
with xswallow:
X11Window = X11WindowBindings()
X11Window = X11WindowBindingsInstance()
root = X11Window.getDefaultRootWindow()
log("getDefaultRootWindow()=%#x", root)
try:
Expand Down
2 changes: 1 addition & 1 deletion src/xpra/x11/bindings/core_bindings.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ cdef extern from "X11/Xlib.h":
pass
ctypedef CARD32 Atom

cdef class _X11CoreBindings:
cdef class X11CoreBindingsInstance:
cdef Display * display
cdef char * display_name
cdef Atom xatom(self, str_or_int)
Expand Down
6 changes: 3 additions & 3 deletions src/xpra/x11/bindings/core_bindings.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ cdef extern from "X11/Xlib.h":
from xpra.x11.bindings.display_source cimport get_display
from xpra.x11.bindings.display_source import get_display_name

cdef _X11CoreBindings singleton = None
cdef X11CoreBindingsInstance singleton = None
def X11CoreBindings():
global singleton
if singleton is None:
singleton = _X11CoreBindings()
singleton = X11CoreBindingsInstance()
return singleton

#for debugging, we can hook this function which will log the caller:
Expand All @@ -77,7 +77,7 @@ def set_context_check(fn):
context_check = fn


cdef class _X11CoreBindings:
cdef class X11CoreBindingsInstance:

def __cinit__(self):
assert is_X11(), "cannot load X11 bindings with wayland under python3 / GTK3"
Expand Down
8 changes: 4 additions & 4 deletions src/xpra/x11/bindings/keyboard_bindings.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -241,16 +241,16 @@ cdef s(const char *v):
# to the original C xmodmap code


from xpra.x11.bindings.core_bindings cimport _X11CoreBindings
from xpra.x11.bindings.core_bindings cimport X11CoreBindingsInstance

cdef _X11KeyboardBindings singleton = None
cdef X11KeyboardBindingsInstance singleton = None
def X11KeyboardBindings():
global singleton
if singleton is None:
singleton = _X11KeyboardBindings()
singleton = X11KeyboardBindingsInstance()
return singleton

cdef class _X11KeyboardBindings(_X11CoreBindings):
cdef class X11KeyboardBindingsInstance(X11CoreBindingsInstance):

cdef XModifierKeymap* work_keymap
cdef int min_keycode
Expand Down
5 changes: 3 additions & 2 deletions src/xpra/x11/bindings/posix_display_source.pyx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is part of Xpra.
# Copyright (C) 2008, 2009 Nathaniel Smith <[email protected]>
# Copyright (C) 2010-2018 Antoine Martin <[email protected]>
# Copyright (C) 2010-2019 Antoine Martin <[email protected]>
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
# later version. See the file COPYING for details.

Expand All @@ -15,6 +15,7 @@ from xpra.x11.bindings.display_source cimport set_display, get_display
from xpra.x11.bindings.display_source import set_display_name
from libc.stdint cimport uintptr_t


cdef extern from "X11/Xlib.h":
ctypedef struct Display:
pass
Expand All @@ -40,9 +41,9 @@ cdef do_init_posix_display_source(display_name):
def close_display_source(uintptr_t ptr):
assert ptr!=0, "invalid NULL display pointer"
cdef Display * display = <Display *> ptr
cdef int v = XCloseDisplay(display)
set_display(NULL)
set_display_name("CLOSED")
cdef int v = XCloseDisplay(display)
return v


Expand Down
8 changes: 4 additions & 4 deletions src/xpra/x11/bindings/randr_bindings.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,16 @@ cdef extern from "X11/extensions/Xrandr.h":

short XRRConfigCurrentRate(XRRScreenConfiguration *config)

from xpra.x11.bindings.core_bindings cimport _X11CoreBindings
from xpra.x11.bindings.core_bindings cimport X11CoreBindingsInstance

cdef _RandRBindings singleton = None
cdef RandRBindingsInstance singleton = None
def RandRBindings():
global singleton
if singleton is None:
singleton = _RandRBindings()
singleton = RandRBindingsInstance()
return singleton

cdef class _RandRBindings(_X11CoreBindings):
cdef class RandRBindingsInstance(X11CoreBindingsInstance):

cdef int _has_randr
cdef object _added_modes
Expand Down
11 changes: 7 additions & 4 deletions src/xpra/x11/bindings/window_bindings.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ from __future__ import absolute_import

import struct

from libc.stdint cimport uintptr_t

from xpra.gtk_common.error import XError
from xpra.os_util import strtobytes

Expand Down Expand Up @@ -387,18 +389,18 @@ class PropertyOverflow(PropertyError):
pass


from xpra.x11.bindings.core_bindings cimport _X11CoreBindings
from xpra.x11.bindings.core_bindings cimport X11CoreBindingsInstance

cdef int CONFIGURE_GEOMETRY_MASK = CWX | CWY | CWWidth | CWHeight

cdef _X11WindowBindings singleton = None
cdef X11WindowBindingsInstance singleton = None
def X11WindowBindings():
global singleton
if singleton is None:
singleton = _X11WindowBindings()
singleton = X11WindowBindingsInstance()
return singleton

cdef class _X11WindowBindings(_X11CoreBindings):
cdef class X11WindowBindingsInstance(X11CoreBindingsInstance):

cdef object has_xshape

Expand Down Expand Up @@ -435,6 +437,7 @@ cdef class _X11WindowBindings(_X11CoreBindings):
% (extension, cmajor, cminor, major, minor))

def getDefaultRootWindow(self):
assert self.display
return XDefaultRootWindow(self.display)


Expand Down
8 changes: 4 additions & 4 deletions src/xpra/x11/bindings/xi2_bindings.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -315,16 +315,16 @@ CLASS_INFO = {
}


from xpra.x11.bindings.core_bindings cimport _X11CoreBindings
from xpra.x11.bindings.core_bindings cimport X11CoreBindingsInstance

cdef _X11XI2Bindings singleton = None
cdef X11CoreBindingsInstance singleton = None
def X11XI2Bindings():
global singleton
if singleton is None:
singleton = _X11XI2Bindings()
singleton = X11XI2BindingsInstance()
return singleton

cdef class _X11XI2Bindings(_X11CoreBindings):
cdef class X11XI2BindingsInstance(X11CoreBindingsInstance):

cdef int opcode
cdef object events
Expand Down
8 changes: 4 additions & 4 deletions src/xpra/x11/bindings/ximage.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -890,16 +890,16 @@ cdef window_pixmap_wrapper(Display *xdisplay, Window xwindow):
pw.init(xdisplay, xwindow, width, height)
return pw

from xpra.x11.bindings.core_bindings cimport _X11CoreBindings
from xpra.x11.bindings.core_bindings cimport X11CoreBindingsInstance

cdef _XImageBindings singleton = None
cdef XImageBindingsInstance singleton = None
def XImageBindings():
global singleton
if singleton is None:
singleton = _XImageBindings()
singleton = XImageBindingsInstance()
return singleton

cdef class _XImageBindings(_X11CoreBindings):
cdef class XImageBindingsInstance(X11CoreBindingsInstance):
cdef int has_xshm

def __cinit__(self):
Expand Down

0 comments on commit c1f3198

Please sign in to comment.