Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increased thread id struct to work on 64bit Linux, fixes #524 #525

Merged
merged 2 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions rpyc/core/brine.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,13 @@
C16 = Struct("!dd") # Successive floats (complex numbers)
I1 = Struct("!B") # Python type int w/ size [1] (ctype unsigned char)
I4 = Struct("!L") # Python type int w/ size [4] (ctype unsigned long)
# I4I4 is successive ints w/ size 4 and was introduced to pack local thread id and remote thread id
# Since PyThread_get_thread_ident returns a type of unsigned long, !LL can store both thread IDs.
I4I4 = Struct("!LL")
# I8I8 is successive ints w/ size 8 and was introduced to pack local thread id and remote thread id. Since
# PyThread_get_thread_ident returns a type of unsigned long, a platform dependent size, we
# need 8 bytes of length to support LP64/64-bit platforms. See
# - https://unix.org/whitepapers/64bit.html
# - https://en.wikipedia.org/wiki/Integer_(computer_science)#Long_integer
# TODO: Switch to native_id when 3.7 is EOL b/c PyThread_get_thread_ident is inheritly hosed due to casting.
I8I8 = Struct("!QQ")

_dump_registry = {}
_load_registry = {}
Expand Down
4 changes: 2 additions & 2 deletions rpyc/core/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def _send(self, msg, seq, args): # IO
data = brine.dump((msg, seq, args))
if self._bind_threads:
this_thread = self._get_thread()
data = brine.I4I4.pack(this_thread.id, this_thread._remote_thread_id) + data
data = brine.I8I8.pack(this_thread.id, this_thread._remote_thread_id) + data
if msg == consts.MSG_REQUEST:
this_thread._occupation_count += 1
else:
Expand Down Expand Up @@ -549,7 +549,7 @@ def _serve_bound(self, timeout, wait_for_lock):

return False

remote_thread_id, local_thread_id = brine.I4I4.unpack(message[:16])
remote_thread_id, local_thread_id = brine.I8I8.unpack(message[:16])
message = message[16:]

this = False
Expand Down