Unable to use enums that start with numbers



Hello,

I'm adding GObject introspection to an existing GObject based library (libInstPatch) written in C.  For this purpose I am willing to update the C API to make a good binding, even if it breaks backwards compatibility (though I'd like to avoid that if possible).

I've gone through and annotated the majority of the API and am able to load the binding in Python.  However, I noticed an issue with an enum, which looks like the following:

typedef enum
{
  IPATCH_SAMPLE_INVALID = 0,
  IPATCH_SAMPLE_8BIT    = 1,
  IPATCH_SAMPLE_16BIT   = 2,
  IPATCH_SAMPLE_24BIT   = 3,
  IPATCH_SAMPLE_32BIT   = 4,
  IPATCH_SAMPLE_FLOAT   = 5,
  IPATCH_SAMPLE_DOUBLE  = 6,
  IPATCH_SAMPLE_REAL24BIT = 7
} IpatchSampleWidth;


The enum ends up being Ipatch.SampleWidth, which is as expected.  However, the values turn in to 8BIT, 16BIT, 24BIT, and 32BIT which are invalid Python variable names.  It seems like g-ir-scanner should have warned about this.

Any tips on the best way to fix these?  For the moment I changed them to read IPATCH_SAMPLE_BIT8 (BIT8), etc. and added #defines for the old names for backwards compatibility with the C API, but I was wondering if there was a better way.  I tried rename-to, but that doesn't seem to work on a per enum value basis.

Another question I have is what might be a good way to represent a value where multiple enums are combined as flags.  In the C API, an audio sample format is represented by a single unsigned integer which has bit fields for different parts of the format (bit width, channel count, sign/unsigned, and byte order).  These values are usually just logically OR'd together.  One thought which comes to mind for adding a binding for this is using a struct with bit fields and creating a boxed type from it.  That would definitely break the C API though and methods would need to be provided for accessing the fields of the sample format.

Thank you in advance for any assistance on this.

Best regards,

Element Green



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]