示例#1
0
    def register_double_linked_list_record_type(self,
                                                record_type,
                                                forward,
                                                backward,
                                                sentinels=None):
        """
        Declares a structure to be a double linked list management structure.

        register_double_linked_list_record_type(struct_Entry, 'next', 'previous')

        C code example:
            struct Entry {
                struct Entry * next;
                struct Entry * previous;
            }

        Most of the time, these structure type are used as fields of a parent struct_A
        record as to either:
         a) maintain a list of struct_B elements/children
         b) chain to a list of struct_A siblings

        The difference between case a) and b) is handled by the following function

          register_linked_list_field_and_type(struct_type, field_name, list_entry_type, list_entry_field_name, offset)

        Impacts:
        The effect will be the structure type's instance will NOT be validated, or loaded
        by the ListModel Constraints validator.
        No member, pointers members will be loaded.
        But elements of the list can be iterated upon with ListModel._iterate_double_linked_list,
        At what point, address validation of both forward and backward pointer
        occurs before loading of pointee elements.

        :param record_type: the ctypes.Structure type that holds double linked list pointers fields
        :param forward: the forward pointer
        :param backward: the backward pointer
        :return: None
        """
        if not issubclass(record_type, ctypes.Structure) and not issubclass(
                record_type, ctypes.Union):
            raise TypeError('Feed me a ctypes record rype')
        # test field existences in instance
        flink_type = getattr(record_type, forward)
        blink_type = getattr(record_type, backward)
        # test field existences in type
        d = dict(basicmodel.get_record_type_fields(record_type))
        flink_type = d[forward]
        blink_type = d[backward]
        if not self._ctypes.is_pointer_type(flink_type):
            raise TypeError('The %s field is not a pointer.', forward)
        if not self._ctypes.is_pointer_type(blink_type):
            raise TypeError('The %s field is not a pointer.', backward)
        if sentinels is None:
            sentinels = [0]  # Null pointer
        # ok - save that structure information
        self._double_link_list_types[record_type] = (forward, backward,
                                                     sentinels)
        return
示例#2
0
    def register_double_linked_list_record_type(self, record_type, forward, backward, sentinels=None):
        """
        Declares a structure to be a double linked list management structure.

        register_double_linked_list_record_type(struct_Entry, 'next', 'previous')

        C code example:
            struct Entry {
                struct Entry * next;
                struct Entry * previous;
            }

        Most of the time, these structure type are used as fields of a parent struct_A
        record as to either:
         a) maintain a list of struct_B elements/children
         b) chain to a list of struct_A siblings

        The difference between case a) and b) is handled by the following function

          register_linked_list_field_and_type(struct_type, field_name, list_entry_type, list_entry_field_name, offset)

        Impacts:
        The effect will be the structure type's instance will NOT be validated, or loaded
        by the ListModel Constraints validator.
        No member, pointers members will be loaded.
        But elements of the list can be iterated upon with ListModel._iterate_double_linked_list,
        At what point, address validation of both forward and backward pointer
        occurs before loading of pointee elements.

        :param record_type: the ctypes.Structure type that holds double linked list pointers fields
        :param forward: the forward pointer
        :param backward: the backward pointer
        :return: None
        """
        if not issubclass(record_type, ctypes.Structure) and not issubclass(record_type, ctypes.Union):
            raise TypeError('Feed me a ctypes record rype')
        # test field existences in instance
        flink_type = getattr(record_type, forward)
        blink_type = getattr(record_type, backward)
        # test field existences in type
        d = dict(basicmodel.get_record_type_fields(record_type))
        flink_type = d[forward]
        blink_type = d[backward]
        if not self._ctypes.is_pointer_type(flink_type):
            raise TypeError('The %s field is not a pointer.', forward)
        if not self._ctypes.is_pointer_type(blink_type):
            raise TypeError('The %s field is not a pointer.', backward)
        if sentinels is None:
            sentinels = {0} # Null pointer
        # ok - save that structure information
        self._double_link_list_types[record_type] = (forward, backward, sentinels)
        return
示例#3
0
 def toString(self, prefix='', maxDepth=10):
     if maxDepth < 0:
         return '#(- not printed by Excessive recursion - )'
     s = '{\n'
     if hasattr(self, '_ctype_'):
         items = [
             n for n, t in basicmodel.get_record_type_fields(self._ctype_)
         ]
     else:
         log.warning('no _ctype_')
         items = [n for n in self.__dict__.keys() if n != '_ctype_']
     for attrname in items:
         attr = getattr(self, attrname)
         typ = type(attr)
         s += "%s%s: %s\n" % (
             prefix, attrname,
             self._attrToString(
                 attr, attrname, typ, prefix + '\t', maxDepth=maxDepth - 1))
     s += '}'
     return s
示例#4
0
    def register_single_linked_list_record_type(self,
                                                record_type,
                                                forward,
                                                sentinels=None):
        """
        Declares a structure to be a single linked list management structure.

        register_single_linked_list_record_type(struct_SListEntry, 'forward')

        C code example:
            struct SListEntry {
                struct SListEntry * next;
            }

        Impacts:
        The effect will be the structure type's instance will NOT be validated, or loaded
        by the ListModel Constraints validator.
        No member, pointers members will be loaded.
        But elements of the list can be iterated upon with ListModel._iterate_double_linked_list,
        At what point, address validation of both forward and backward pointer
        occurs before loading of pointee elements.

        :param record_type: the ctypes.Structure type that holds double linked list pointers fields
        :param forward: the list pointer fieldname
        :return: None
        """
        if not issubclass(record_type, ctypes.Structure) and not issubclass(
                record_type, ctypes.Union):
            raise TypeError('Feed me a ctypes record rype')
        # test field existences in instance
        flink_type = getattr(record_type, forward)
        # test field existences in type
        d = dict(basicmodel.get_record_type_fields(record_type))
        flink_type = d[forward]
        if not self._ctypes.is_pointer_type(flink_type):
            raise TypeError('The %s field is not a pointer.', forward)
        if sentinels is None:
            sentinels = [0]  # Null pointer
        # ok - save that structure information
        self._single_link_list_types[record_type] = (forward, sentinels)
        return
示例#5
0
 def toString(self, prefix='', maxDepth=10):
     if maxDepth < 0:
         return '#(- not printed by Excessive recursion - )'
     s = '{\n'
     if hasattr(self, '_ctype_'):
         items = [n for n, t in basicmodel.get_record_type_fields(self._ctype_)]
     else:
         log.warning('no _ctype_')
         items = [n for n in self.__dict__.keys() if n != '_ctype_']
     for attrname in items:
         attr = getattr(self, attrname)
         typ = type(attr)
         s += "%s%s: %s\n" % (prefix,
                              attrname,
                              self._attrToString(
                                  attr,
                                  attrname,
                                  typ,
                                  prefix + '\t',
                                  maxDepth=maxDepth - 1))
     s += '}'
     return s
示例#6
0
    def register_single_linked_list_record_type(self, record_type, forward, sentinels=None):
        """
        Declares a structure to be a single linked list management structure.

        register_single_linked_list_record_type(struct_SListEntry, 'forward')

        C code example:
            struct SListEntry {
                struct SListEntry * next;
            }

        Impacts:
        The effect will be the structure type's instance will NOT be validated, or loaded
        by the ListModel Constraints validator.
        No member, pointers members will be loaded.
        But elements of the list can be iterated upon with ListModel._iterate_double_linked_list,
        At what point, address validation of both forward and backward pointer
        occurs before loading of pointee elements.

        :param record_type: the ctypes.Structure type that holds double linked list pointers fields
        :param forward: the list pointer fieldname
        :return: None
        """
        if not issubclass(record_type, ctypes.Structure) and not issubclass(record_type, ctypes.Union):
            raise TypeError('Feed me a ctypes record rype')
        # test field existences in instance
        flink_type = getattr(record_type, forward)
        # test field existences in type
        d = dict(basicmodel.get_record_type_fields(record_type))
        flink_type = d[forward]
        if not self._ctypes.is_pointer_type(flink_type):
            raise TypeError('The %s field is not a pointer.', forward)
        if sentinels is None:
            sentinels = {0} # Null pointer
        # ok - save that structure information
        self._single_link_list_types[record_type] = (forward, sentinels)
        return