Skip to content

Commit

Permalink
add cython implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan-Ailenei authored and ionelmc committed May 25, 2020
1 parent c07ce8f commit aa8f1e5
Show file tree
Hide file tree
Showing 9 changed files with 9,468 additions and 4,775 deletions.
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hunter
2 changes: 1 addition & 1 deletion src/hunter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
from .actions import StackPrinter
from .actions import VarsPrinter
from .actions import VarsSnooper

try:
if os.environ.get("PUREPYTHONHUNTER"):
raise ImportError("Cython speedups are disabled.")

from ._event import Event
from ._predicates import And as _And
from ._predicates import Backlog as _Backlog
from ._predicates import From as _From
from ._predicates import Not as _Not
from ._predicates import Or as _Or
Expand Down
2,756 changes: 1,612 additions & 1,144 deletions src/hunter/_event.c

Large diffs are not rendered by default.

25 changes: 21 additions & 4 deletions src/hunter/_event.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ from tokenize import TokenError
from tokenize import generate_tokens

from cpython.pythread cimport PyThread_get_thread_ident
from cpython cimport bool

from ._tracer cimport Tracer

Expand Down Expand Up @@ -40,13 +41,21 @@ cdef class Event:
tracer (:class:`hunter.tracer.Tracer`): The :class:`~hunter.tracer.Tracer` instance that created the event.
Needed for the ``calls`` and ``depth`` fields.
"""
def __init__(self, FrameType frame, str kind, object arg, Tracer tracer):
def __init__(self, FrameType frame, str kind, object arg, Tracer tracer=None, object depth=UNSET, object calls=UNSET, object threading_support=UNSET):
if tracer is None:
if UNSET in (depth, calls, threading_support):
raise TypeError("Depth, calls and threading support need to be specified when creating and event")
else:
depth = tracer.depth
calls = tracer.calls
threading_support = tracer.threading_support

self.arg = arg
self.frame = frame
self.kind = kind
self.depth = tracer.depth
self.calls = tracer.calls
self.threading_support = tracer.threading_support
self.depth = depth
self.calls = calls
self.threading_support = threading_support
self.detached = False

self._code = UNSET
Expand Down Expand Up @@ -121,6 +130,14 @@ cdef class Event:
event._thread = self._thread
return event

def set_frame(self, frame):
self.frame = <FrameType>frame

def make_fake_event(self):
self._locals = {}
self._globals = {}
self.detached = True

@property
def threadid(self):
cdef long current
Expand Down
Loading

0 comments on commit aa8f1e5

Please sign in to comment.