Skip to content

Commit

Permalink
on 64 bit systems, format=32 actually means a Long (which is 64-bits)…
Browse files Browse the repository at this point in the history
… so we have to use struct "L" format

git-svn-id: https://xpra.org/svn/Xpra/trunk@1226 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Jul 31, 2012
1 parent 9ad53b0 commit c2ee8c1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
28 changes: 16 additions & 12 deletions src/xpra/platform/clipboard_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,23 @@ def _do_munge_raw_selection_to_wire(self, target, dtype, dformat, data):
""" this method is overriden in xclipboard to parse X11 atoms """
# Other types need special handling, and all types need to be
# converting into an endian-neutral format:
debug("_do_munge_raw_selection_to_wire(%s,%s,%s,%s:%s)", target, dtype, dformat, type(data), len(data))
debug("_do_munge_raw_selection_to_wire(%s, %s, %s, %s:%s)", target, dtype, dformat, type(data), len(data or ""))
if dformat == 32:
sizeof_long = struct.calcsize("=I")
assert sizeof_long == 4, "struct.calcsize('=I)=%s" % sizeof_long
binfmt = "=" + "I" * (len(data) // sizeof_long)
#important note: on 64 bits, format=32 means 8 bytes, not 4
#that's just the way it is...
sizeof_long = struct.calcsize('@L')
assert sizeof_long in (4, 8), "struct.calcsize('@L')=%s" % sizeof_long
binfmt = "@" + "L" * (len(data) // sizeof_long)
ints = struct.unpack(binfmt, data)
return ("integers", ints)
return "integers", ints
elif dformat == 16:
sizeof_short = struct.calcsize("=H")
assert sizeof_short == 2
sizeof_short = struct.calcsize('=H')
assert sizeof_short == 2, "struct.calcsize('=H')=%s" % sizeof_short
binfmt = "=" + "H" * (len(data) // sizeof_short)
ints = struct.unpack(binfmt, data)
return ("integers", ints)
return "integers", ints
elif dformat == 8:
return ("bytes", data)
return "bytes", data
else:
log.error("unhandled format %s for clipboard data type %s" % (dformat, dtype))
return None, None
Expand All @@ -118,7 +120,9 @@ def _munge_wire_selection_to_raw(self, encoding, dtype, dformat, data):
format_char = "B"
else:
raise Exception("unknown encoding format: %s" % dformat)
return struct.pack("=" + format_char * len(data), *data)
fstr = "@" + format_char * len(data)
debug("struct.pack(%s, %s)", fstr, data)
return struct.pack(fstr, *data)
else:
raise Exception("unhanled encoding: %s" % encoding)

Expand All @@ -129,15 +133,15 @@ def _process_clipboard_request(self, packet):
if name in self._clipboard_proxies:
proxy = self._clipboard_proxies[name]
def got_contents(dtype, dformat, data):
debug("got_contents(%s,%s,%s)", dtype, dformat, len(data or []))
debug("got_contents(%s, %s, %s:%s) data=%s, str(data)=%s", dtype, dformat, type(data), len(data or ""), list(bytearray(data or "")[:200]), str(data)[:200])
def no_contents():
self.send(["clipboard-contents-none", request_id, selection])
if dtype is None or data is None:
no_contents()
return
munged = self._munge_raw_selection_to_wire(target, dtype, dformat, data)
wire_encoding, wire_data = munged
log("clipboard raw -> wire: %r -> %r", (dtype, dformat, data), munged)
debug("clipboard raw -> wire: %r -> %r", (dtype, dformat, data), munged)
if wire_encoding is None:
no_contents()
return
Expand Down
6 changes: 3 additions & 3 deletions src/xpra/xposix/xclipboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ def __init__(self, send_packet_cb):
ClipboardProtocolHelperBase.__init__(self, send_packet_cb, ["CLIPBOARD", "PRIMARY", "SECONDARY"])

def _do_munge_raw_selection_to_wire(self, target, datatype, dataformat, data):
debug("_do_munge_raw_selection_to_wire(%s, %s, %s, %s)", target, datatype, dataformat, data)
if format == 32 and type in ("ATOM", "ATOM_PAIR"):
# Convert to strings and send that. Bizarrely, the atoms are
# not actual X atoms, but an array of GdkAtom's reinterpreted
# as a byte buffer.
atoms = gdk_atom_objects_from_gdk_atom_array(data)
atom_names = [str(atom) for atom in atoms]
debug("_do_munge_raw_selection_to_wire(%s, %s, %s, %s:%s) atoms=%s, atom_names=%s", target, datatype, dataformat, type(data), len(data), atoms, atom_names)
if target=="TARGET":
atom_names.remove("SAVE_TARGETS")
atom_names.remove("COMPOUND_TEXT")
return ("atoms", atom_names)
return "atoms", atom_names
return ClipboardProtocolHelperBase._do_munge_raw_selection_to_wire(self, target, datatype, dataformat, data)

def _munge_wire_selection_to_raw(self, encoding, datatype, dataformat, data):
debug("_munge_wire_selection_to_raw(%s, %s, %s, %s)", encoding, datatype, dataformat, data)
debug("_munge_wire_selection_to_raw(%s, %s, %s, %s:%s)", encoding, datatype, dataformat, type(data), len(data or ""))
if encoding == "atoms":
import gtk.gdk
gdk_atoms = [gtk.gdk.atom_intern(a) for a in data]
Expand Down

0 comments on commit c2ee8c1

Please sign in to comment.