Skip to content

bindgen gets confused with arrays in generics. #1557

Open
@emilio

Description

@emilio

Input C/C++ Header

/// Header data with an inline length. Consumers that use HeaderWithLength as the
/// Header type in HeaderSlice can take advantage of ThinArc.
template<typename H>
struct StyleHeaderWithLength {
  /// The fixed-sized data.
  H header;
  /// The slice length.
  unsigned length;

  bool operator==(const StyleHeaderWithLength& other) const {
    return header == other.header &&
           length == other.length;
  }
  bool operator!=(const StyleHeaderWithLength& other) const {
    return header != other.header ||
           length != other.length;
  }
};

/// Structure to allow Arc-managing some fixed-sized data and a variably-sized
/// slice in a single allocation.
template<typename H, typename T>
struct StyleHeaderSlice {
  /// The fixed-sized data.
  H header;
  /// The dynamically-sized data.
  T slice;

  bool operator==(const StyleHeaderSlice& other) const {
    return header == other.header &&
           slice == other.slice;
  }
  bool operator!=(const StyleHeaderSlice& other) const {
    return header != other.header ||
           slice != other.slice;
  }
};

template<typename H, typename T>
using StyleHeaderSliceWithLength = StyleHeaderSlice<StyleHeaderWithLength<H>, T>;

/// The object allocated by an Arc<T>
template<typename T>
struct StyleArcInner {
  unsigned count;
  T data;

  bool operator==(const StyleArcInner& other) const {
    return count == other.count &&
           data == other.data;
  }
  bool operator!=(const StyleArcInner& other) const {
    return count != other.count ||
           data != other.data;
  }
};

template<typename H, typename T>
struct StyleThinArc {
  StyleArcInner<StyleHeaderSliceWithLength<H, T[1]>> *ptr;
};

Bindgen Invocation

$ bindgen input.h

Actual Results

// ...

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct StyleThinArc {
    pub ptr: *mut StyleArcInner<T>,
}

Which obviously doesn't compile.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions