Replaced custom deprecated decorator with simple DeprecationWarning (#2110)
This commit is contained in:
@@ -9,11 +9,9 @@ import ctypes
|
||||
import functools
|
||||
import weakref
|
||||
import warnings
|
||||
|
||||
from unicorn import unicorn_const as uc
|
||||
from .arch.types import uc_err, uc_engine, uc_context, uc_hook_h, UcReg, VT
|
||||
|
||||
# __version__ = f'{uc.UC_VERSION_MAJOR}.{uc.UC_VERSION_MINOR}.{uc.UC_VERSION_PATCH}'
|
||||
|
||||
MemRegionStruct = Tuple[int, int, int]
|
||||
TBStruct = Tuple[int, int, int]
|
||||
@@ -632,25 +630,6 @@ class Uc(RegStateManager):
|
||||
"""Unicorn Engine class.
|
||||
"""
|
||||
|
||||
# Code snippet modified from:
|
||||
# https://stackoverflow.com/questions/2536307/decorators-in-the-python-standard-lib-deprecated-specifically
|
||||
@staticmethod
|
||||
def __deprecated(msg: str):
|
||||
def __deprecated_inner(func: Callable) -> Callable:
|
||||
"""Use this decorator to mark functions as deprecated.
|
||||
Every time the decorated function runs, it will emit
|
||||
a "deprecation" warning."""
|
||||
@functools.wraps(func)
|
||||
def new_func(*args, **kwargs):
|
||||
warnings.simplefilter('always', DeprecationWarning) # turn off filter
|
||||
warnings.warn("Call to a deprecated function {}. {}".format(func.__name__, msg),
|
||||
category=DeprecationWarning,
|
||||
stacklevel=2)
|
||||
warnings.simplefilter('default', DeprecationWarning) # reset filter
|
||||
return func(*args, **kwargs)
|
||||
return new_func
|
||||
return __deprecated_inner
|
||||
|
||||
@staticmethod
|
||||
def __is_compliant() -> bool:
|
||||
"""Checks whether Unicorn binding version complies with Unicorn library.
|
||||
@@ -1455,15 +1434,6 @@ class Uc(RegStateManager):
|
||||
|
||||
self.__ctl_w(uc.UC_CTL_TB_FLUSH)
|
||||
|
||||
@__deprecated("You should use ctl_set_tlb_mode instead.")
|
||||
def ctl_tlb_mode(self, mode: int) -> None:
|
||||
"""Deprecated, please use ctl_set_tlb_mode instead.
|
||||
|
||||
Args:
|
||||
mode: tlb mode to use (see UC_TLB_* constants)
|
||||
"""
|
||||
self.ctl_set_tlb_mode(mode)
|
||||
|
||||
def ctl_set_tlb_mode(self, mode: int) -> None:
|
||||
"""Set TLB mode.
|
||||
|
||||
@@ -1475,6 +1445,16 @@ class Uc(RegStateManager):
|
||||
(ctypes.c_uint, mode)
|
||||
)
|
||||
|
||||
# For backward compatibility...
|
||||
def ctl_tlb_mode(self, mode: int) -> None:
|
||||
"""Deprecated, please use ctl_set_tlb_mode instead.
|
||||
|
||||
Args:
|
||||
mode: tlb mode to use (see UC_TLB_* constants)
|
||||
"""
|
||||
warnings.warn('Deprecated method, use ctl_set_tlb_mode', DeprecationWarning)
|
||||
self.ctl_set_tlb_mode(mode)
|
||||
|
||||
def ctl_get_tcg_buffer_size(self) -> int:
|
||||
"""Retrieve TCG buffer size.
|
||||
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
import regress
|
||||
import sys
|
||||
import unittest
|
||||
from unicorn import *
|
||||
from unicorn.x86_const import *
|
||||
|
||||
|
||||
# Very basic testing to ensure the old api exists
|
||||
# and we correctly implement __deprecated
|
||||
@unittest.skipIf(sys.version_info < (3, 7), reason="requires python3.7 or higher")
|
||||
class OldCtl(regress.RegressTest):
|
||||
def runTest(self):
|
||||
mu = Uc(UC_ARCH_X86, UC_MODE_32)
|
||||
mu.ctl_tlb_mode(UC_TLB_CPU)
|
||||
mu.ctl_set_tlb_mode(UC_TLB_VIRTUAL)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
regress.main()
|
||||
|
||||
Reference in New Issue
Block a user