Given this C code:
enum uv_tcp_flags { /* Used with uv_tcp_bind, when an IPv6 address is used. */ UV_TCP_IPV6ONLY = 1 };
The following cffi-grovel form fails:
(bitfield (uv-tcp-flags) ((:ipv6-only "UV_TCP_IPV6ONLY")))
The C-file generated by cffi-grovel looks like this:
/* bitfield section for UV-TCP-FLAGS */ fputs("(cffi:defbitfield (", output); fputs("uv-tcp-flags", output); fputs(")", output); fputs("\n (", output); fputs(":ipv6-only", output); fputs(" ", output); #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?
Hello Frank,
On Sat, Jan 17, 2015 at 9:27 AM, Frank fau@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,
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@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,
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@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@common-lisp.net http://mailman.common-lisp.net/cgi-bin/mailman/listinfo/cffi-devel
On Mon, Jan 26, 2015 at 9:33 AM, Frank fau@riseup.net wrote:
We could add a new construct like this for c-enums holding bitfields?
(define-grovel-syntax bitfieldenum (name-and-opts &rest masks)
[...]
Sounds good, but perhaps we can refactor things such that we have only CENUM and BITFIELD -- ditching CONSTANTENUM and BITFIELDENUM -- and whether they expect constants or enums becomes a parameter. Makes sense?