Skip to content

Commit c529d6d

Browse files
committed
We accidentally introduce a break change for
removing ctl_tlb_mode.
1 parent fe41e72 commit c529d6d

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

bindings/python/unicorn/unicorn_py3/unicorn.py

+34-1
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
"""
44

55
from __future__ import annotations
6-
from typing import TYPE_CHECKING, Any, Callable, Dict, Generic, Iterable, Iterator, Optional, Sequence, Tuple, Type, TypeVar, Union
6+
from typing import TYPE_CHECKING, Any, Callable, Dict, Generic, Iterable, Iterator, Optional, Sequence, Tuple, Type, TypeVar, Union, ParamSpec
77

88
import ctypes
99
import functools
1010
import weakref
11+
import warnings
1112

1213
from unicorn import unicorn_const as uc
1314
from .arch.types import uc_err, uc_engine, uc_context, uc_hook_h, UcReg, VT
@@ -631,6 +632,29 @@ class Uc(RegStateManager):
631632
"""Unicorn Engine class.
632633
"""
633634

635+
# Code snippet modified from:
636+
# https://stackoverflow.com/questions/2536307/decorators-in-the-python-standard-lib-deprecated-specifically
637+
638+
639+
@staticmethod
640+
def __deprecated(msg: str):
641+
__rT = TypeVar('rT') # return type
642+
__pT = ParamSpec('pT') # parameters type
643+
def __deprecated_inner(func: Callable[__pT, __rT]) -> Callable[__pT, __rT]:
644+
"""Use this decorator to mark functions as deprecated.
645+
Every time the decorated function runs, it will emit
646+
a "deprecation" warning."""
647+
@functools.wraps(func)
648+
def new_func(*args: Uc.__pT.args, **kwargs: Uc.__pT.kwargs):
649+
warnings.simplefilter('always', DeprecationWarning) # turn off filter
650+
warnings.warn("Call to a deprecated function {}. {}".format(func.__name__, msg),
651+
category=DeprecationWarning,
652+
stacklevel=2)
653+
warnings.simplefilter('default', DeprecationWarning) # reset filter
654+
return func(*args, **kwargs)
655+
return new_func
656+
return __deprecated_inner
657+
634658
@staticmethod
635659
def __is_compliant() -> bool:
636660
"""Checks whether Unicorn binding version complies with Unicorn library.
@@ -1435,6 +1459,15 @@ def ctl_flush_tb(self) -> None:
14351459

14361460
self.__ctl_w(uc.UC_CTL_TB_FLUSH)
14371461

1462+
@__deprecated("You should use ctl_set_tlb_mode instead.")
1463+
def ctl_tlb_mode(self, mode: int) -> None:
1464+
"""Deprecated, please use ctl_set_tlb_mode instead.
1465+
1466+
Args:
1467+
mode: tlb mode to use (see UC_TLB_* constants)
1468+
"""
1469+
self.ctl_set_tlb_mode(mode)
1470+
14381471
def ctl_set_tlb_mode(self, mode: int) -> None:
14391472
"""Set TLB mode.
14401473

0 commit comments

Comments
 (0)