groveller's :define-constants doesn't work with cenum

Bug #1272009 reported by Martin Kielhorn
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
CFFI
Confirmed
Undecided
Unassigned

Bug Description

I tried to use the cffi groveller to create a binding for <linux/videodev2.h>

The following definition:

(cenum (v4l2_buf_type :define-constants t) ((:capture "V4L2_BUF_TYPE_VIDEO_CAPTURE")))

leads to this code in the auto-generated C-file:

  /* constant section for CAPTURE */
#ifdef V4L2_BUF_TYPE_VIDEO_CAPTURE
  fputs("(cl:defconstant ", output);
  fputs("capture", output);
  fputs(" ", output);
  if(_64_BIT_VALUE_FITS_SIGNED_P(V4L2_BUF_TYPE_VIDEO_CAPTURE))
    fprintf(output, "%lli", (int64_t) V4L2_BUF_TYPE_VIDEO_CAPTURE);
  else
    fprintf(output, "%llu", (uint64_t) V4L2_BUF_TYPE_VIDEO_CAPTURE);
  fputs(")\n", output);
#else
  fputs("(cl:warn 'cffi-grovel:missing-definition :name 'CAPTURE)\n", output);
#endif

The V4L2_BUF_TYPE_VIDEO_CAPTURE is part of a C enum and no preprocessor macro.
Therefore, the #ifdef is undefined and the processed grovel file just contains the line

(cl:warn 'cffi-grovel:missing-definition :name 'CAPTURE)

instead of the expected constant definition.

I use cffi_0.11.2 and SBCL 1.1.14.30-ba008a7 on x86_64 GNU/Linux.

description: updated
description: updated
description: updated
description: updated
Revision history for this message
Luís Oliveira (luismbo) wrote : Re: [Bug 1272009] [NEW] groveller's :define-constants doesn't work with cenum

[cc'ing Stelian Ionescu]

On Thu, Jan 23, 2014 at 5:37 PM, Martin Kielhorn
<email address hidden> wrote:
> (cenum (v4l2_buf_type :define-constants t) ((:capture
> "V4L2_BUF_TYPE_VIDEO_CAPTURE")))
[...]
> /* constant section for CAPTURE */
> #ifdef V4L2_BUF_TYPE_VIDEO_CAPTURE

Stelian: git-blame says you implemented the :DEFINE-CONSTANTS option
for CENUM. The implementation delegates the work to the CONSTANT
grovel form but that shouldn't work because the C preprocessor doesn't
know about enums. Did that ever work?

Luís Oliveira (luismbo)
Changed in cffi:
status: New → Confirmed
Revision history for this message
Elias Martenson (lokedhs) wrote :

I came across this problem when building a CFFI interface to RabbitMQ, which also uses enums extensively.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.