Menu

#1336 Anonymous unions in structs go out of order with cffi (and fails with uffi and clisp)

None
closed-wont-fix
nobody
5
2019-02-05
2013-09-24
White Flame
No

The simple CvMat matrix struct in OpenCV's C interface contains an inline union near the middle of the struct.

With the CFFI target, the union is moved to the end of the defcstruct, which misaligns all the slot definitions.

I tested this problem with the other Lisp targets, where in UFFI & CLISP a partial output file is generated which appears to also leave the union until the end of the struct before exiting with an error regarding rendering the split-out union type.

From inspecting the generated output, Allegro support seems not to suffer from this problem at all, as it does not do Lisp-side dereferencing of struct members.

Simplest degenerate input case:

# types_c.h
struct CvMat {
  union {
    uchar* ptr;
  } data;

  int rows;
};

CFFI output:

;; $ swig -cffi -module cl-opencv types_c.h

(cffi:defcstruct CvMat
    (rows :int)
    (data :pointer)) ;; incorrect order, 'data' should come before 'rows'

(cffi:defcunion CvMat_data
    (ptr :pointer))

Error outputs:

$ swig -uffi -module cl-opencv types_c.h
Unsupported data type: CvMat_data (was: CvMat_data)
$ swig -clisp -module cl-opencv types_c.h
Structure CvMat has a slot that we can't deal with.
nodeType: insert, name: , type: 

As CFFI is likely the most popular of the problematic Lisp targets, fixing the reordering issue would be of greater value than dealing with the failures in the other 2 targets.

Tested with the most current Git master checkout.

Workaround is to manually modify the ordering in the generated defcstruct form.

1 Attachments

Discussion

  • William Fulton

    William Fulton - 2019-02-05
    • status: open --> closed-wont-fix
    • Group: -->
     
  • William Fulton

    William Fulton - 2019-02-05

    Closing all open CFFI issues as CFFI has been disabled, please see https://github.com/swig/swig/issues/1447

     

Log in to post a comment.