Example #1
0
# Copyright (c) 2010 Center for Bioinformatics, University of Hamburg
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#

from gt.dlload import gtlib
from ctypes import CFUNCTYPE, c_void_p, c_char_p, addressof

funcdef = CFUNCTYPE(None, c_void_p, c_char_p, c_char_p)
defhand = funcdef.in_dll(gtlib, "gt_warning_default_handler")
gtlib.gt_warning_disable.restype = None
gtlib.gt_warning_disable.argtypes = []
gtlib.gt_warning_set_handler.restype = None
gtlib.gt_warning_set_handler.argtypes = [funcdef, c_void_p]

def warning_disable():
    gtlib.gt_warning_disable()

def warning_enable_default():
    gtlib.gt_warning_set_handler(addressof(defhand), None)
Example #2
0
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#

from gt.dlload import gtlib
from ctypes import CFUNCTYPE, c_void_p, c_char_p, addressof

funcdef = CFUNCTYPE(None, c_void_p, c_char_p, c_char_p)
defhand = funcdef.in_dll(gtlib, "gt_warning_default_handler")
gtlib.gt_warning_disable.restype = None
gtlib.gt_warning_disable.argtypes = []
gtlib.gt_warning_set_handler.restype = None
gtlib.gt_warning_set_handler.argtypes = [funcdef, c_void_p]


def warning_disable():
    gtlib.gt_warning_disable()


def warning_enable_default():
    gtlib.gt_warning_set_handler(addressof(defhand), None)
Example #3
0
# Constants
word_bytes = sizeof(c_uword)
assert word_bytes in (4, 8), f"word_bytes must be 4 or 8 and is {word_bytes}!"
word_bit = word_bytes * 8
sign_bit = 1 << (word_bit - 1)
hex0x_word_width = word_bytes * 2 + 2  # Width of a hex word with leading "0x"
uword_max = c_uword(-1).value

# Functions from mit.h

# Errors
mit_error = errcheck(MitErrorCode)

# Bind `mit_run` as a function and as a function pointer, because
# for some reason we can't call it when bound as a pointer.
_run = c_mit_fn.in_dll(libmit, "mit_run")
run_ptr = POINTER(c_mit_fn).in_dll(libmit, "mit_run")
# `break_fn_ptr` must be bound as a `c_void_p` in order to be set to point
# to a Python callback.
break_fn_ptr = c_void_p.in_dll(libmit, "mit_break_fn")
stack_words_ptr = pointer(c_uword.in_dll(libmit, "mit_stack_words"))
stack_words = c_uword.in_dll(libmit, "mit_stack_words")
run_simple = c_mit_fn.in_dll(libmit, "mit_run_simple")
run_break = c_mit_fn.in_dll(libmit, "mit_run_break")

# run_fast = c_mit_fn.in_dll(libmit, "mit_run_fast")
# run_profile = c_mit_fn.in_dll(libmit, "mit_run_profile")


# Cannot add errcheck to a CFUNCTYPE, so wrap it manually.
def run(pc, ir, stack, stack_words, stack_depth_ptr):