[Cffi-devel] cffi-grovel bitfield

Frank fau at riseup.net
Mon Jan 26 09:33:04 UTC 2015


We could add a new construct like this for c-enums holding bitfields?

(define-grovel-syntax bitfieldenum (name-and-opts &rest masks)
  (destructuring-bind (name &key base-type)
      (ensure-list name-and-opts)
    (c-section-header out "bitfieldenum" name)
    (c-export out name)
    (c-format out "(cffi:defbitfield (")
    (c-print-symbol out name t)
    (when base-type
      (c-printf out " ")
      (c-print-symbol out base-type t))
    (c-format out ")~%")
    (dolist (mask masks)
      (destructuring-bind ((lisp-name &rest c-names) &key documentation)
          mask
        (declare (ignore documentation))
        (check-type lisp-name symbol)
        (loop for c-name in c-names do  ;XXX Why multiple c-names ?
          (check-type c-name string)
          (c-format out "  (")
          (c-print-symbol out lisp-name)
          (c-format out " ")
          (c-print-integer-constant out c-name base-type)
          (c-format out ")~%"))))
    (c-format out ")~%")))


On Sun, 2015-01-25 at 19:01 -0700, Frank wrote:
> Hello,
> Thanks for your reply.  Atm I work around this so I'm good.  I may pick
> up on that and have a closer look and get back on this later.
> 
> On Sun, 2015-01-25 at 23:06 +0000, Luís Oliveira wrote:
> > Hello Frank,
> > 
> > On Sat, Jan 17, 2015 at 9:27 AM, Frank <fau at riseup.net> wrote:
> > > enum uv_tcp_flags {
> > >   /* Used with uv_tcp_bind, when an IPv6 address is used. */
> > >   UV_TCP_IPV6ONLY = 1
> > > };
> > [...]
> > > #ifdef UV_TCP_IPV6ONLY
> > > fprintf(output, "%d", UV_TCP_IPV6ONLY);
> > > #else
> > > fputs("\n  #.(cl:progn (cl:warn 'cffi-grovel:missing-definition :name
> > > 'IPV6-ONLY) -1)", output);
> > > #endif
> > > fputs(")", output);
> > > fputs(")\n", output);
> > >
> > > Obviously the #ifdef guard is the culprit here.  Maybe you guys want to
> > > fix this?
> > 
> > Well, there's a purpose to that #ifdef, and it works nicely when
> > dealing with macro constants rather than enums.
> > 
> > I'm not sure what the best way is to cater to your use case. We have
> > CENUM and CONSTANTENUM for CFFI:DEFCFENUM, but only BITFIELD for
> > CFFI:DEFBITFIELD. The naming is a bit inconsistent.
> > 
> > But naming aside, do you feel like adding (and testing) an option to
> > CFFI:DEFBITFIELD that does what you want? A pull request on GitHub
> > would be great!
> > 
> > Thanks,
> > 
> 
> 
> 
> _______________________________________________
> Cffi-devel mailing list
> Cffi-devel at common-lisp.net
> http://mailman.common-lisp.net/cgi-bin/mailman/listinfo/cffi-devel

-------------- next part --------------
A non-text attachment was scrubbed...
Name: grovel.lisp.patch
Type: text/x-patch
Size: 1229 bytes
Desc: not available
URL: <https://mailman.common-lisp.net/pipermail/cffi-devel/attachments/20150126/e63937d5/attachment.bin>


More information about the cffi-devel mailing list