Пример #1
0
def brlcad_copy(obj, debug_msg):
    """
    Returns a copy of the obj using a buffer allocated via bu_malloc.
    This is needed when BRLCAD frees the memory pointed to by the passed in pointer - yes that happens !
    """
    count = ctypes.sizeof(obj)
    obj_copy = libbn.bu_malloc(count, debug_msg)
    ctypes.memmove(obj_copy, ctypes.addressof(obj), count)
    return type(obj).from_address(obj_copy)
Пример #2
0
def brlcad_copy(obj, debug_msg):
    """
    Returns a copy of the obj using a buffer allocated via bu_malloc.
    This is needed when BRLCAD frees the memory pointed to by the passed in pointer - yes that happens !
    """
    count = ctypes.sizeof(obj)
    obj_copy = libbn.bu_malloc(count, debug_msg)
    ctypes.memmove(obj_copy, ctypes.addressof(obj), count)
    return type(obj).from_address(obj_copy)
Пример #3
0
def brlcad_new(obj_type, debug_msg=None):
    """
    Returns a new obj of class <obj_type> using a buffer allocated via bu_malloc.
    Needed for creating objects which will be freed by BRL-CAD code.
    """
    if not debug_msg:
        debug_msg = obj_type.__class__.__name__
    count = ctypes.sizeof(obj_type)
    obj_buf = libbn.bu_malloc(count, debug_msg)
    return obj_type.from_address(obj_buf)
Пример #4
0
def brlcad_new(obj_type, debug_msg=None):
    """
    Returns a new obj of class <obj_type> using a buffer allocated via bu_malloc.
    Needed for creating objects which will be freed by BRL-CAD code.
    """
    if not debug_msg:
        debug_msg = obj_type.__class__.__name__
    count = ctypes.sizeof(obj_type)
    obj_buf = libbn.bu_malloc(count, debug_msg)
    return obj_type.from_address(obj_buf)