Skip to content

Commit

Permalink
Just keep the old frame around, for better or worse we need this side…
Browse files Browse the repository at this point in the history
…-effect inducing reference for some tests that need the frames (the StackPrinter action).
  • Loading branch information
ionelmc committed Oct 29, 2022
1 parent 1948cab commit 2c654eb
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/hunter/_tracer.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ cdef extern from *:
ctypedef extern class types.FrameType[object PyFrameObject, check_size ignore]:
pass

ctypedef extern class types.CodeType[object PyCodeObject]:
ctypedef extern class types.CodeType[object PyCodeObject, check_size ignore]:
cdef object co_filename
cdef object co_name
cdef int co_argcount
Expand Down
7 changes: 6 additions & 1 deletion tests/eviltracer.pxd
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
# cython: language_level=3str
cimport cython


cdef extern from "vendor/_compat.h":
"""
#if PY_VERSION_HEX >= 0x030900A4
#if PY_VERSION_HEX >= 0x030B00A7
#include "internal/pycore_frame.h"
#endif
"""

ctypedef struct PyObject

ctypedef class types.FrameType[object PyFrameObject, check_size ignore]:
pass

@cython.final
cdef class EvilTracer:
Expand Down
1 change: 1 addition & 0 deletions tests/eviltracer.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ cdef class EvilTracer:
return
detached_event = fast_detach(event, lambda obj: obj)
detached_event.detached = False
detached_event.frame = event.frame
self._calls.append(detached_event)

def __enter__(self):
Expand Down
31 changes: 6 additions & 25 deletions tests/test_tracer.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
from __future__ import print_function

import asyncio
import faulthandler
import functools
import os
import pickle
import platform
import sys
import threading
from io import StringIO
from pprint import pprint
from urllib.parse import urlencode

import pytest

Expand All @@ -27,16 +30,7 @@

from utils import DebugCallPrinter

try:
from urllib import urlencode
except ImportError:
from urllib.parse import urlencode

try:
from cStringIO import StringIO
except ImportError:
from io import StringIO

faulthandler.enable()

if hunter.Tracer.__module__ == 'hunter.tracer':

Expand Down Expand Up @@ -469,19 +463,6 @@ def foo():
assert out.getvalue().endswith("node += 'x'\n")


def test_pickle():
out = []
with hunter.trace(
lambda event: out.append(pickle.dumps(event)),
):

def foo():
pass

foo()
assert out == []


def test_fullsource_decorator_issue(LineMatcher):
out = StringIO()
with trace(kind='call', action=CodePrinter(stream=out)):
Expand Down Expand Up @@ -1450,7 +1431,7 @@ def a():
)


def test_pickle(LineMatcher):
def test_pickle():
out = []

def pickler(event):
Expand All @@ -1467,7 +1448,7 @@ def foo():

foo()

with pytest.raises(TypeError, match="cannot pickle 'hunter._?event.Event' object") as exc:
with pytest.raises(TypeError, match="can.+t pickle '?hunter._?event.Event'? objects?") as exc:
pickle.dumps(out)


Expand Down

0 comments on commit 2c654eb

Please sign in to comment.