From 325443098aa6dadf613498df54db33715635c37a Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Wed, 24 Jun 2020 07:34:20 -0500 Subject: [PATCH 01/12] Simplify context handling --- gen_wrap.py | 100 ++++++++++++++++++++++------------------------ islpy/__init__.py | 20 +++++----- 2 files changed, 59 insertions(+), 61 deletions(-) diff --git a/gen_wrap.py b/gen_wrap.py index e4ae97b..1a373b8 100644 --- a/gen_wrap.py +++ b/gen_wrap.py @@ -407,12 +407,6 @@ class IslTypeError(Error, TypeError): _context_use_map = {{}} -def _deref_ctx(ctx_data, ctx_iptr): - _context_use_map[ctx_iptr] -= 1 - if _context_use_map[ctx_iptr] == 0: - del _context_use_map[ctx_iptr] - lib.isl_ctx_free(ctx_data) - def _get_last_error_str(ctx_data): code = lib.isl_ctx_last_error(ctx_data) @@ -426,50 +420,31 @@ def _get_last_error_str(ctx_data): class _ISLObjectBase(object): - def __init__(self, _data): - self._setup(_data) + def __init__(self, _data, context): + self._setup(_data, context) - def _setup(self, data): + def _setup(self, data, context): assert not hasattr(self, "data") assert isinstance(data, ffi.CData) - self.data = data - - self._set_ctx_data() - iptr = self._ctx_iptr - _context_use_map[iptr] = _context_use_map.get(iptr, 0) + 1 + self.data = data + self.context = context def _reset(self, data): assert self.data is not None assert isinstance(data, ffi.CData) - _deref_ctx(self._ctx_data, self._ctx_iptr) self.data = data - self._set_ctx_data() - iptr = self._ctx_iptr - _context_use_map[iptr] = _context_use_map.get(iptr, 0) + 1 - - def _set_ctx_data(self): - self._ctx_data = self._get_ctx_data() - self._ctx_iptr = int(ffi.cast("intptr_t", self._get_ctx_data())) - def _release(self): if self.data is None: raise Error("cannot release already-released object") - data = self.data - if _deref_ctx is not None: - _deref_ctx(self._ctx_data, self._ctx_iptr) - else: - # This can happen if we're called super-late in cleanup. - # Since everything else is already mopped up, we really - # can't do what it takes to mop up this context. - # So we leak it (i.e. leave it for the OS to clean up.) - pass - self.data = None return data + def get_ctx(self): + return self.context + def __eq__(self, other): return (type(self) == type(other) and self.data == other.data) @@ -477,6 +452,20 @@ class _ISLObjectBase(object): return not self.__eq__(other) +class Context(_ISLObjectBase): + def __init__(self, _data, context): + raise RuntimeError("This method is stubbed out.") + + def _setup(self, data, context=None): + assert not hasattr(self, "data") + assert isinstance(data, ffi.CData) + self.data = data + self.context = self + + def __del__(self): + if self.data is not None: + lib.isl_ctx_free(self.data) + class _EnumBase(object): @classmethod def find_value(cls, v): @@ -1091,6 +1080,8 @@ def write_classes_to_wrapper(wrapper_f): gen("# {{{ declare classes") gen("") for cls_name in CLASSES: + if cls_name == "ctx": + continue py_cls = isl_class_to_py_class(cls_name) gen("class {cls}(_ISLObjectBase):".format(cls=py_cls)) with Indentation(gen): @@ -1099,9 +1090,6 @@ def write_classes_to_wrapper(wrapper_f): if cls_name == "ctx": gen(""" - def _get_ctx_data(self): - return self.data - def __del__(self): if self.data is not None: self._release() @@ -1110,13 +1098,9 @@ def write_classes_to_wrapper(wrapper_f): else: gen(""" - def _get_ctx_data(self): - return lib.isl_{cls}_get_ctx(self.data) - def __del__(self): if self.data is not None: lib.isl_{cls}_free(self.data) - _deref_ctx(self._ctx_data, self._ctx_iptr) """ .format(cls=cls_name)) gen("") @@ -1130,7 +1114,7 @@ def write_classes_to_wrapper(wrapper_f): if data == ffi.NULL: raise Error("failed to copy instance of {py_cls}") - return {py_cls}(_data=data) + return {py_cls}(_data=data, context=self.context) """ .format(cls=cls_name, py_cls=py_cls)) @@ -1176,7 +1160,7 @@ def gen_callback_wrapper(gen, cb, func_name, has_userptr): passed_args.append("_py_%s" % arg.name) pre_call( - "_py_{name} = {py_cls}(_data={name})" + "_py_{name} = {py_cls}(_data={name}, context=_ctx)" .format( name=arg.name, py_cls=isl_class_to_py_class(arg.base_type))) @@ -1285,15 +1269,17 @@ def write_method_wrapper(gen, cls_name, meth): ret_descrs = [] def emit_context_check(arg_idx, arg_name): + pre_call("_ctx = {arg_name}.context".format(arg_name=arg_name)) if arg_idx == 0: - pre_call("_ctx_data = {arg_name}._ctx_data".format(arg_name=arg_name)) + pass else: pre_call(""" - if _ctx_data != {arg_name}._ctx_data: + if _ctx != {arg_name}.context: raise Error("mismatched context in {arg_name}") """.format(arg_name=arg_name)) arg_idx = 0 + print(meth, cls_name) while arg_idx < len(meth.args): arg = meth.args[arg_idx] @@ -1382,7 +1368,7 @@ def write_method_wrapper(gen, cls_name, meth): check('if {c_name}[0] == lib.isl_bool_error:'.format(c_name=c_name)) with Indentation(check): check('raise Error("call to \\"{0}\\" failed: %s" ' - '% _get_last_error_str(_ctx_data))'.format(meth.c_name)) + '% _get_last_error_str(_ctx.data))'.format(meth.c_name)) else: ret_vals.append("{c_name}[0]".format(c_name=c_name)) ret_descrs.append("%s (integer)" % arg.name) @@ -1413,12 +1399,12 @@ def write_method_wrapper(gen, cls_name, meth): "be cast to a Val" % _type({name})) _cdata_{name} = lib.isl_val_int_from_si( - {arg0_name}._get_ctx_data(), {name}) + {arg0_name}.context.data, {name}) if _cdata_{name} == ffi.NULL: raise Error("isl_val_int_from_si failed") - {val_name} = Val(_data=_cdata_{name}) + {val_name} = Val(_data=_cdata_{name}, context=_ctx) """ .format(**fmt_args)) @@ -1499,7 +1485,7 @@ def write_method_wrapper(gen, cls_name, meth): if _retptr_{name} == ffi.NULL: _ret_{name} = None else: - _ret_{name} = {py_cls}(_data=_retptr_{name}[0]) + _ret_{name} = {py_cls}(_data=_retptr_{name}[0], context=_ctx) """ .format(name=arg.name, cls=arg.base_type, py_cls=py_cls)) @@ -1536,13 +1522,13 @@ def write_method_wrapper(gen, cls_name, meth): check("if _result == lib.isl_stat_error:") with Indentation(check): check('raise Error("call to \\"{0}\\" failed: %s" ' - '% _get_last_error_str(_ctx_data))'.format(meth.c_name)) + '% _get_last_error_str(_ctx.data))'.format(meth.c_name)) elif meth.return_base_type == "isl_bool" and not meth.return_ptr: check("if _result == lib.isl_bool_error:") with Indentation(check): check('raise Error("call to \\"{0}\\" failed: %s" ' - '% _get_last_error_str(_ctx_data))'.format(meth.c_name)) + '% _get_last_error_str(_ctx.data))'.format(meth.c_name)) ret_vals.insert(0, "_result == lib.isl_bool_true") ret_descrs.insert(0, "bool") @@ -1576,16 +1562,23 @@ def write_method_wrapper(gen, cls_name, meth): raise SignatureNotSupported("non-give return") py_ret_cls = isl_class_to_py_class(ret_cls) - safety( + if ret_cls == "ctx": + safety( "_result = None if " "(_result == ffi.NULL or _result is None) " "else {0}(_data=_result)" .format(py_ret_cls)) + else: + safety( + "_result = None if " + "(_result == ffi.NULL or _result is None) " + "else {0}(_data=_result, context=_ctx)" + .format(py_ret_cls)) check(""" if _result is None: raise Error("call to {c_method} failed: %s" - % _get_last_error_str(_ctx_data)) + % _get_last_error_str(_ctx.data)) """ .format(c_method=meth.c_name)) @@ -1797,6 +1790,9 @@ def gen_wrapper(include_dirs, include_barvinok=False, isl_version=None): wrapper_gen("") for meth in methods: + if meth.name.endswith("get_ctx"): + continue + if meth.name.endswith("_si") or meth.name.endswith("_ui"): val_versions = [ meth2 diff --git a/islpy/__init__.py b/islpy/__init__.py index 6f54ba1..82c558e 100644 --- a/islpy/__init__.py +++ b/islpy/__init__.py @@ -138,7 +138,7 @@ def _add_functionality(): def context_init(self, _data=None): if _data is not None: - super(Context, self).__init__(_data) + super(Context, self).__init__(_data=_data, context=self) else: new_ctx = Context.alloc() self._setup(new_ctx.data) @@ -175,7 +175,8 @@ def _add_functionality(): if s is not None: raise TypeError("may not pass _data and string at the same time") - _isl._ISLObjectBase.__init__(self, _data) + assert context is not None + _isl._ISLObjectBase.__init__(self, _data, context=context) else: if s is None: raise TypeError("'s' argument not supplied") @@ -192,7 +193,7 @@ def _add_functionality(): self.data = None raise else: - self._setup(new_me._release()) + self._setup(new_me._release(), context) def generic_getstate(self): ctx = self.get_ctx() @@ -203,7 +204,7 @@ def _add_functionality(): def generic_setstate(self, data): ctx, new_str = data new_inst = self.read_from_str(ctx, new_str) - self._setup(new_inst._release()) + self._setup(new_inst._release(), ctx) for cls in ALL_CLASSES: if hasattr(cls, "read_from_str"): @@ -216,6 +217,7 @@ def _add_functionality(): # {{{ str, repr, hash def generic_str(self): + print(self.get_ctx(), type(self.get_ctx())) prn = Printer.to_str(self.get_ctx()) getattr(prn, "print_"+self._base_name)(self) return prn.get_str() @@ -462,12 +464,12 @@ def _add_functionality(): # {{{ Id - def id_init(self, name=None, user=None, context=None, _data=None): + def id_init(self, context, name=None, user=None, _data=None): if _data is not None: if name is not None: raise TypeError("may not pass _data and name at the same time") - _isl._ISLObjectBase.__init__(self, _data) + _isl._ISLObjectBase.__init__(self, _data, context) return if name is None: @@ -477,7 +479,7 @@ def _add_functionality(): context = DEFAULT_CONTEXT new_me = self.alloc(context, name, user) - self._setup(new_me._release()) + self._setup(new_me._release(), context) Id.__init__ = id_init #Id.user = property(Id.get_user) # FIXME: reenable @@ -787,7 +789,7 @@ def _add_functionality(): if src is not None: raise TypeError("may not pass _data and src at the same time") - _isl._ISLObjectBase.__init__(self, _data) + _isl._ISLObjectBase.__init__(self, _data, context) return if src is None: @@ -803,7 +805,7 @@ def _add_functionality(): else: raise TypeError("'src' must be int or string") - self._setup(new_me._release()) + self._setup(new_me._release(), context) def val_rsub(self, other): return -self + other -- GitLab From 6b2f83fb7c1b3d8f175fd9ecd3cbed1017e0d498 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Wed, 24 Jun 2020 13:35:45 -0500 Subject: [PATCH 02/12] Make only one context own the isl_ctx --- gen_wrap.py | 32 ++++++++++++++++++++++++-------- islpy/__init__.py | 15 ++++----------- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/gen_wrap.py b/gen_wrap.py index 1a373b8..b299530 100644 --- a/gen_wrap.py +++ b/gen_wrap.py @@ -452,20 +452,36 @@ class _ISLObjectBase(object): return not self.__eq__(other) -class Context(_ISLObjectBase): - def __init__(self, _data, context): - raise RuntimeError("This method is stubbed out.") +class Context(object): + def __init__(self, _data=None, own=True): + if _data is None: + new_ctx = Context.alloc() + _data = new_ctx.data + new_ctx._release() + self.data = _data + # whether this Context object owns the isl_ctx object. + # If so, the isl_ctx object will be freed once this object is deleted. + self.own = own - def _setup(self, data, context=None): - assert not hasattr(self, "data") - assert isinstance(data, ffi.CData) + @property + def context(self): + return self + + def _release(self): + self.data = None + + def _reset(self, data, own=True): self.data = data - self.context = self + self.own = own def __del__(self): - if self.data is not None: + if self.data is not None and self.own: lib.isl_ctx_free(self.data) + def __eq__(self, other): + return self.data == other.data + + class _EnumBase(object): @classmethod def find_value(cls, v): diff --git a/islpy/__init__.py b/islpy/__init__.py index 82c558e..6f6c9d9 100644 --- a/islpy/__init__.py +++ b/islpy/__init__.py @@ -136,14 +136,6 @@ EXPR_CLASSES = tuple(cls for cls in ALL_CLASSES def _add_functionality(): # {{{ Context - def context_init(self, _data=None): - if _data is not None: - super(Context, self).__init__(_data=_data, context=self) - else: - new_ctx = Context.alloc() - self._setup(new_ctx.data) - new_ctx._release() - def context_getstate(self): if self.data == DEFAULT_CONTEXT.data: return ("default",) @@ -152,11 +144,12 @@ def _add_functionality(): def context_setstate(self, data): if data[0] == "default": - self._setup(DEFAULT_CONTEXT.data) + self._reset(DEFAULT_CONTEXT.data, False) else: - context_init(self) + new_ctx = Context.alloc() + self._reset(new_ctx.data) + new_ctx._release() - Context.__init__ = context_init Context.__getstate__ = context_getstate Context.__setstate__ = context_setstate -- GitLab From c41bf3528feaa23931c1891729fd8bb62e4962e6 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Wed, 24 Jun 2020 14:16:15 -0500 Subject: [PATCH 03/12] Add a __reduce__ and clarify --- gen_wrap.py | 7 +++++-- islpy/__init__.py | 12 ++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/gen_wrap.py b/gen_wrap.py index b299530..c3f3711 100644 --- a/gen_wrap.py +++ b/gen_wrap.py @@ -453,7 +453,7 @@ class _ISLObjectBase(object): class Context(object): - def __init__(self, _data=None, own=True): + def __init__(self, _data=None): if _data is None: new_ctx = Context.alloc() _data = new_ctx.data @@ -461,7 +461,10 @@ class Context(object): self.data = _data # whether this Context object owns the isl_ctx object. # If so, the isl_ctx object will be freed once this object is deleted. - self.own = own + # This is only done for default context and is a hack for __getstate__ + # New pickling method __reduce__ will make this moot, but keep this + # here for unpickling previously pickled isl_ctx objects + self.own = False @property def context(self): diff --git a/islpy/__init__.py b/islpy/__init__.py index 6f6c9d9..7ab5744 100644 --- a/islpy/__init__.py +++ b/islpy/__init__.py @@ -132,10 +132,21 @@ _CHECK_DIM_TYPES = [ EXPR_CLASSES = tuple(cls for cls in ALL_CLASSES if "Aff" in cls.__name__ or "Polynomial" in cls.__name__) +def _get_default_ctx(): + return DEFAULT_CONTEXT + +def _get_a_ctx(): + return Context.alloc() def _add_functionality(): # {{{ Context + def context_reduce(self): + if self.data == DEFAULT_CONTEXT.data: + return (_get_default_ctx, ()) + else: + return (_get_a_ctx, ()) + def context_getstate(self): if self.data == DEFAULT_CONTEXT.data: return ("default",) @@ -152,6 +163,7 @@ def _add_functionality(): Context.__getstate__ = context_getstate Context.__setstate__ = context_setstate + Context.__reduce__ = context_reduce # }}} -- GitLab From 087678b27088d0fcbd118eefdd8aaed60593238b Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Wed, 24 Jun 2020 14:20:28 -0500 Subject: [PATCH 04/12] Keep a owning instance --- gen_wrap.py | 11 ++++++----- islpy/__init__.py | 6 +++++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/gen_wrap.py b/gen_wrap.py index c3f3711..0e9c6e2 100644 --- a/gen_wrap.py +++ b/gen_wrap.py @@ -459,11 +459,11 @@ class Context(object): _data = new_ctx.data new_ctx._release() self.data = _data - # whether this Context object owns the isl_ctx object. + # self.own iswhether this Context object owns the isl_ctx object. # If so, the isl_ctx object will be freed once this object is deleted. - # This is only done for default context and is a hack for __getstate__ - # New pickling method __reduce__ will make this moot, but keep this - # here for unpickling previously pickled isl_ctx objects + # This is only done for default context and is a hack for __getstate__. + # New pickling method __reduce__ will make this unnecessary, but keep + # this here for unpickling previously pickled isl_ctx objects. self.own = False @property @@ -473,9 +473,10 @@ class Context(object): def _release(self): self.data = None - def _reset(self, data, own=True): + def _reset(self, data, own=True, owning_instance=None): self.data = data self.own = own + self.owning_instance = owning_instance def __del__(self): if self.data is not None and self.own: diff --git a/islpy/__init__.py b/islpy/__init__.py index 7ab5744..157f3ef 100644 --- a/islpy/__init__.py +++ b/islpy/__init__.py @@ -132,12 +132,15 @@ _CHECK_DIM_TYPES = [ EXPR_CLASSES = tuple(cls for cls in ALL_CLASSES if "Aff" in cls.__name__ or "Polynomial" in cls.__name__) + def _get_default_ctx(): return DEFAULT_CONTEXT + def _get_a_ctx(): return Context.alloc() + def _add_functionality(): # {{{ Context @@ -155,7 +158,8 @@ def _add_functionality(): def context_setstate(self, data): if data[0] == "default": - self._reset(DEFAULT_CONTEXT.data, False) + self._reset(DEFAULT_CONTEXT.data, own=False, + owning_instance=DEFAULT_CONTEXT) else: new_ctx = Context.alloc() self._reset(new_ctx.data) -- GitLab From 4fa070f39cdfb7adbc4a5f7bdf01edd1774af200 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Wed, 24 Jun 2020 14:36:43 -0500 Subject: [PATCH 05/12] Move context parameter to end --- islpy/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/islpy/__init__.py b/islpy/__init__.py index 157f3ef..e126d68 100644 --- a/islpy/__init__.py +++ b/islpy/__init__.py @@ -173,7 +173,7 @@ def _add_functionality(): # {{{ generic initialization, pickling - def obj_init(self, s=None, context=None, _data=None): + def obj_init(self, s=None, _data=None, context=None): """Construct a new object from :class:`str` s. :arg context: a :class:`islpy.Context` to use. If not supplied, use a @@ -473,7 +473,7 @@ def _add_functionality(): # {{{ Id - def id_init(self, context, name=None, user=None, _data=None): + def id_init(self, name=None, user=None, _data=None, context=None): if _data is not None: if name is not None: raise TypeError("may not pass _data and name at the same time") @@ -793,7 +793,7 @@ def _add_functionality(): # {{{ Val - def val_init(self, src=None, context=None, _data=None): + def val_init(self, src=None, _data=None, context=None): if _data is not None: if src is not None: raise TypeError("may not pass _data and src at the same time") -- GitLab From 612356f3116bf581dee04de62dcc14c48bc2622f Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Wed, 24 Jun 2020 14:42:21 -0500 Subject: [PATCH 06/12] Use get_ctx instead of .context --- gen_wrap.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/gen_wrap.py b/gen_wrap.py index 0e9c6e2..75bd3ed 100644 --- a/gen_wrap.py +++ b/gen_wrap.py @@ -466,8 +466,7 @@ class Context(object): # this here for unpickling previously pickled isl_ctx objects. self.own = False - @property - def context(self): + def get_ctx(self): return self def _release(self): @@ -1134,7 +1133,7 @@ def write_classes_to_wrapper(wrapper_f): if data == ffi.NULL: raise Error("failed to copy instance of {py_cls}") - return {py_cls}(_data=data, context=self.context) + return {py_cls}(_data=data, context=self.get_ctx()) """ .format(cls=cls_name, py_cls=py_cls)) @@ -1289,12 +1288,12 @@ def write_method_wrapper(gen, cls_name, meth): ret_descrs = [] def emit_context_check(arg_idx, arg_name): - pre_call("_ctx = {arg_name}.context".format(arg_name=arg_name)) + pre_call("_ctx = {arg_name}.get_ctx()".format(arg_name=arg_name)) if arg_idx == 0: pass else: pre_call(""" - if _ctx != {arg_name}.context: + if _ctx != {arg_name}.get_ctx(): raise Error("mismatched context in {arg_name}") """.format(arg_name=arg_name)) @@ -1419,7 +1418,7 @@ def write_method_wrapper(gen, cls_name, meth): "be cast to a Val" % _type({name})) _cdata_{name} = lib.isl_val_int_from_si( - {arg0_name}.context.data, {name}) + {arg0_name}.get_ctx().data, {name}) if _cdata_{name} == ffi.NULL: raise Error("isl_val_int_from_si failed") -- GitLab From 98c402127d0975413ffa8891584e3c726b07d28f Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Wed, 24 Jun 2020 15:11:01 -0500 Subject: [PATCH 07/12] Remove debug print --- islpy/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/islpy/__init__.py b/islpy/__init__.py index e126d68..e169396 100644 --- a/islpy/__init__.py +++ b/islpy/__init__.py @@ -226,7 +226,6 @@ def _add_functionality(): # {{{ str, repr, hash def generic_str(self): - print(self.get_ctx(), type(self.get_ctx())) prn = Printer.to_str(self.get_ctx()) getattr(prn, "print_"+self._base_name)(self) return prn.get_str() -- GitLab From 22f9b0647f699396029ad13b4d5d0fc4c1b4aa21 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Wed, 24 Jun 2020 15:15:26 -0500 Subject: [PATCH 08/12] Reduce diff --- islpy/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/islpy/__init__.py b/islpy/__init__.py index e169396..7c53b99 100644 --- a/islpy/__init__.py +++ b/islpy/__init__.py @@ -173,7 +173,7 @@ def _add_functionality(): # {{{ generic initialization, pickling - def obj_init(self, s=None, _data=None, context=None): + def obj_init(self, s=None, context=None, _data=None): """Construct a new object from :class:`str` s. :arg context: a :class:`islpy.Context` to use. If not supplied, use a @@ -472,7 +472,7 @@ def _add_functionality(): # {{{ Id - def id_init(self, name=None, user=None, _data=None, context=None): + def id_init(self, name=None, user=None, context=None, _data=None): if _data is not None: if name is not None: raise TypeError("may not pass _data and name at the same time") @@ -792,7 +792,7 @@ def _add_functionality(): # {{{ Val - def val_init(self, src=None, _data=None, context=None): + def val_init(self, src=None, context=None, _data=None): if _data is not None: if src is not None: raise TypeError("may not pass _data and src at the same time") -- GitLab From c6ba1814376debc8385891fb7f19f0f96dfe0227 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Thu, 25 Jun 2020 15:00:33 -0500 Subject: [PATCH 09/12] Remove code for supporting old pickle files --- gen_wrap.py | 13 ++----------- islpy/__init__.py | 17 ----------------- 2 files changed, 2 insertions(+), 28 deletions(-) diff --git a/gen_wrap.py b/gen_wrap.py index 75bd3ed..b64ab4e 100644 --- a/gen_wrap.py +++ b/gen_wrap.py @@ -459,12 +459,6 @@ class Context(object): _data = new_ctx.data new_ctx._release() self.data = _data - # self.own iswhether this Context object owns the isl_ctx object. - # If so, the isl_ctx object will be freed once this object is deleted. - # This is only done for default context and is a hack for __getstate__. - # New pickling method __reduce__ will make this unnecessary, but keep - # this here for unpickling previously pickled isl_ctx objects. - self.own = False def get_ctx(self): return self @@ -472,13 +466,11 @@ class Context(object): def _release(self): self.data = None - def _reset(self, data, own=True, owning_instance=None): + def _reset(self, data, own=True): self.data = data - self.own = own - self.owning_instance = owning_instance def __del__(self): - if self.data is not None and self.own: + if self.data is not None: lib.isl_ctx_free(self.data) def __eq__(self, other): @@ -1298,7 +1290,6 @@ def write_method_wrapper(gen, cls_name, meth): """.format(arg_name=arg_name)) arg_idx = 0 - print(meth, cls_name) while arg_idx < len(meth.args): arg = meth.args[arg_idx] diff --git a/islpy/__init__.py b/islpy/__init__.py index 7c53b99..49a72a7 100644 --- a/islpy/__init__.py +++ b/islpy/__init__.py @@ -150,23 +150,6 @@ def _add_functionality(): else: return (_get_a_ctx, ()) - def context_getstate(self): - if self.data == DEFAULT_CONTEXT.data: - return ("default",) - else: - return (None,) - - def context_setstate(self, data): - if data[0] == "default": - self._reset(DEFAULT_CONTEXT.data, own=False, - owning_instance=DEFAULT_CONTEXT) - else: - new_ctx = Context.alloc() - self._reset(new_ctx.data) - new_ctx._release() - - Context.__getstate__ = context_getstate - Context.__setstate__ = context_setstate Context.__reduce__ = context_reduce # }}} -- GitLab From 22451c66e1cfbe39eb7998e11fa20d85227c3801 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Thu, 25 Jun 2020 15:02:37 -0500 Subject: [PATCH 10/12] Bump version --- islpy/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/islpy/version.py b/islpy/version.py index b24042b..5cea885 100644 --- a/islpy/version.py +++ b/islpy/version.py @@ -1,2 +1,2 @@ -VERSION = (2019, 1, 2) +VERSION = (2020, 1) VERSION_TEXT = ".".join(str(i) for i in VERSION) -- GitLab From 739781176d86e563c9b444ed50bf77f4019d315c Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Thu, 25 Jun 2020 15:04:13 -0500 Subject: [PATCH 11/12] Fix context check --- gen_wrap.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gen_wrap.py b/gen_wrap.py index b64ab4e..2872459 100644 --- a/gen_wrap.py +++ b/gen_wrap.py @@ -1280,9 +1280,8 @@ def write_method_wrapper(gen, cls_name, meth): ret_descrs = [] def emit_context_check(arg_idx, arg_name): - pre_call("_ctx = {arg_name}.get_ctx()".format(arg_name=arg_name)) if arg_idx == 0: - pass + pre_call("_ctx = {arg_name}.get_ctx()".format(arg_name=arg_name)) else: pre_call(""" if _ctx != {arg_name}.get_ctx(): -- GitLab From bdaf6d18b587283e6f957cc76e91f1d18b836873 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Thu, 25 Jun 2020 15:05:33 -0500 Subject: [PATCH 12/12] Remove unnecessary arg --- gen_wrap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gen_wrap.py b/gen_wrap.py index 2872459..f000e87 100644 --- a/gen_wrap.py +++ b/gen_wrap.py @@ -466,7 +466,7 @@ class Context(object): def _release(self): self.data = None - def _reset(self, data, own=True): + def _reset(self, data): self.data = data def __del__(self): -- GitLab