Skip to content

Commit

Permalink
Ensure pickle safety for position and dualangle
Browse files Browse the repository at this point in the history
We got away without defining __getnewargs__ in 8.2 because we didn't
require arguments to __new__, but probably still ought to have done it.

As pickled 8.2 types don't have the necessary arguments available to
them, they require compat wrappers during unpickling.
  • Loading branch information
mal committed Feb 13, 2024
1 parent e824522 commit 1e0b9bb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
18 changes: 18 additions & 0 deletions renpy/compat/pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ def make_datetime(cls, *args, **kwargs):

return cls.__new__(cls, *args, **kwargs)

class make_dualangle:
def __new__(cls):
print(cls)
return renpy.display.types.dualangle(0, 0)

class make_position:
def __new__(cls):
print(cls)
return renpy.display.types.position(0, 0)

class Unpickler(pickle.Unpickler):
date = functools.partial(make_datetime, datetime.date)
time = functools.partial(make_datetime, datetime.time)
Expand All @@ -90,6 +100,14 @@ def find_class(self, module, name):
elif name == "datetime":
return self.datetime

if module == "renpy.atl":
if name == "position":
print('POS-A')
return make_position
elif name == "DualAngle":
print('DA-A')
return make_dualangle

return super().find_class(module, name)

def load(f):
Expand Down
6 changes: 6 additions & 0 deletions renpy/display/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ def __new__(cls, absolute, relative=None):

return self

def __getnewargs__(self):
return (0, 0)

def __add__(self, other):
if isinstance(other, position):
return position(self.absolute + other.absolute,
Expand Down Expand Up @@ -258,6 +261,9 @@ def __new__(cls, absolute, relative=None):

return self

def __getnewargs__(self):
return (0, 0)

def __add__(self, other):
if isinstance(other, dualangle):
return dualangle(self.absolute + other.absolute,
Expand Down

0 comments on commit 1e0b9bb

Please sign in to comment.