From 95bc2754e87bd05cbbf725d0f09211317d48b745 Mon Sep 17 00:00:00 2001 From: Tomer Filiba Date: Sun, 11 Sep 2011 22:34:30 +0300 Subject: [PATCH] fix 32/64 bit issue with getslice. closes #41 --- rpyc/core/consts.py | 35 ++++++++++++++++++----------------- rpyc/core/netref.py | 10 ++++++++++ rpyc/core/protocol.py | 11 +++++++++++ 3 files changed, 39 insertions(+), 17 deletions(-) diff --git a/rpyc/core/consts.py b/rpyc/core/consts.py index 4420ae59..5604c2c6 100644 --- a/rpyc/core/consts.py +++ b/rpyc/core/consts.py @@ -14,23 +14,24 @@ LABEL_REMOTE_REF = 4 # action handlers -HANDLE_PING = 1 -HANDLE_CLOSE = 2 -HANDLE_GETROOT = 3 -HANDLE_GETATTR = 4 -HANDLE_DELATTR = 5 -HANDLE_SETATTR = 6 -HANDLE_CALL = 7 -HANDLE_CALLATTR = 8 -HANDLE_REPR = 9 -HANDLE_STR = 10 -HANDLE_CMP = 11 -HANDLE_HASH = 12 -HANDLE_DIR = 13 -HANDLE_PICKLE = 14 -HANDLE_DEL = 15 -HANDLE_INSPECT = 16 -HANDLE_BUFFITER = 17 +HANDLE_PING = 1 +HANDLE_CLOSE = 2 +HANDLE_GETROOT = 3 +HANDLE_GETATTR = 4 +HANDLE_DELATTR = 5 +HANDLE_SETATTR = 6 +HANDLE_CALL = 7 +HANDLE_CALLATTR = 8 +HANDLE_REPR = 9 +HANDLE_STR = 10 +HANDLE_CMP = 11 +HANDLE_HASH = 12 +HANDLE_DIR = 13 +HANDLE_PICKLE = 14 +HANDLE_DEL = 15 +HANDLE_INSPECT = 16 +HANDLE_BUFFITER = 17 +HANDLE_OLDSLICING = 18 # optimized exceptions EXC_STOP_ITERATION = 1 diff --git a/rpyc/core/netref.py b/rpyc/core/netref.py index 3e82d149..d79c9470 100644 --- a/rpyc/core/netref.py +++ b/rpyc/core/netref.py @@ -163,6 +163,8 @@ def _make_method(name, doc): """creates a method with the given name and docstring that invokes :func:`syncreq` on its `self` argument""" + slicers = {"__getslice__" : "__getitem__", "__delslice__" : "__delitem__", "__setslice__" : "__setitem__"} + name = str(name) # IronPython issue #10 if name == "__call__": def __call__(_self, *args, **kwargs): @@ -170,6 +172,14 @@ def __call__(_self, *args, **kwargs): return syncreq(_self, consts.HANDLE_CALL, args, kwargs) __call__.__doc__ = doc return __call__ + elif name in slicers: # 32/64 bit issue #41 + def method(self, start, stop, *args): + if stop == sys.maxint: + stop = None + return syncreq(self, consts.HANDLE_OLDSLICING, slicers[name], name, start, stop, args) + method.__name__ = name + method.__doc__ = doc + return method else: def method(_self, *args, **kwargs): kwargs = tuple(kwargs.items()) diff --git a/rpyc/core/protocol.py b/rpyc/core/protocol.py index e13dd97a..fa47d185 100644 --- a/rpyc/core/protocol.py +++ b/rpyc/core/protocol.py @@ -539,6 +539,17 @@ def _handle_buffiter(self, oid, count): except StopIteration: pass return tuple(items) + def _handle_oldslicing(self, oid, attempt, fallback, start, stop, args): + try: + # first try __xxxitem__ + getitem = self._handle_getattr(oid, attempt) + return getitem(slice(start, stop), *args) + except Exception: + # fallback to __xxxslice__. see issue #41 + if stop is None: + stop = sys.maxint + getslice = self._handle_getattr(oid, fallback) + return getslice(start, stop, *args) # collect handlers _HANDLERS = {}