Esempio n. 1
0
    def test_cant_use_closed_handle(self):
        from hpy.universal import _debug
        mod = self.make_module("""
            HPyDef_METH(f, "f", f_impl, HPyFunc_O, .doc="double close")
            static HPy f_impl(HPyContext *ctx, HPy self, HPy arg)
            {
                HPy h = HPy_Dup(ctx, arg);
                HPy_Close(ctx, h);
                HPy_Close(ctx, h); // double close
                return HPy_Dup(ctx, ctx->h_None);
            }

            HPyDef_METH(g, "g", g_impl, HPyFunc_O, .doc="use after close")
            static HPy g_impl(HPyContext *ctx, HPy self, HPy arg)
            {
                HPy h = HPy_Dup(ctx, arg);
                HPy_Close(ctx, h);
                return HPy_Repr(ctx, h);
            }

            @EXPORT(f)
            @EXPORT(g)
            @INIT
        """)
        n = 0
        def callback():
            nonlocal n
            n += 1
        _debug.set_on_invalid_handle(callback)
        mod.f('foo')   # double close
        assert n == 1
        mod.g('bar')   # use-after-close
        assert n == 2
Esempio n. 2
0
 def __exit__(self, exc_type, exc_val, exc_tb):
     from hpy.universal import _debug
     _debug.set_on_invalid_handle(None)
Esempio n. 3
0
 def __enter__(self):
     from hpy.universal import _debug
     _debug.set_on_invalid_handle(self._capture_report)
     return self