Skip to content

Commit

Permalink
fix 32/64 bit issue with getslice. closes tomerfiliba-org#41
Browse files Browse the repository at this point in the history
  • Loading branch information
tomerfiliba committed Sep 11, 2011
1 parent aed5203 commit 95bc275
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 17 deletions.
35 changes: 18 additions & 17 deletions rpyc/core/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions rpyc/core/netref.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,23 @@ 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):
kwargs = tuple(kwargs.items())
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())
Expand Down
11 changes: 11 additions & 0 deletions rpyc/core/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down

0 comments on commit 95bc275

Please sign in to comment.