* [PATCH] fixincludes: vxworks: remove unnecessary parentheses in ioctl wrapper macro
@ 2018-06-29 9:54 Rasmus Villemoes
2018-09-03 9:46 ` Olivier Hainque
0 siblings, 1 reply; 4+ messages in thread
From: Rasmus Villemoes @ 2018-06-29 9:54 UTC (permalink / raw)
To: gcc-patches; +Cc: bkorb, Olivier Hainque, Rasmus Villemoes
The rationale for the fixinclude ioctl macro wrapper is, as far as I can
tell (https://gcc.gnu.org/ml/gcc-patches/2012-09/msg01619.html)
Fix 2: Add hack for ioctl() on VxWorks.
ioctl() is supposed to be variadic, but VxWorks only has a three
argument version with the third argument of type int. This messes up
when the third argument is not implicitly convertible to int. This
adds a macro which wraps around ioctl() and explicitly casts the third
argument to an int. This way, the most common use case of ioctl (with
a const char * for the third argument) will compile in C++, where
pointers must be explicitly casted to int.
However, we have existing C++ code that calls the ioctl function via
::ioctl(foo, bar, baz)
and obviously this breaks when it gets expanded to
::(ioctl)(foo, bar, (int)(baz))
Since the GNU C preprocessor already prevents recursive expansion of
function-like macros, the parentheses around ioctl are unnecessary.
Incidentally, there is also a macro sioIoctl() in the vxworks sioLib.h
header that expands to
((pSioChan)->pDrvFuncs->ioctl (pSioChan, cmd, arg))
which also breaks when that gets further expanded to
((pSioChan)->pDrvFuncs->(ioctl) (pSioChan, cmd, (int)(arg)))
This patch partly fixes that issue as well, but the third argument to
the pDrvFuncs->ioctl method should be void*, so the cast to (int) is
slightly annoying. Internally, we've simply patched the sioIoctl macro:
(((pSioChan)->pDrvFuncs->ioctl) (pSioChan, cmd, arg))
==changelog==
fixincludes/
* inclhack.def (vxworks_ioctl_macro): Remove parentheses from
expansion of ioctl macro.
* fixincl.x: Regenerate.
---
fixincludes/inclhack.def | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fixincludes/inclhack.def b/fixincludes/inclhack.def
index c1f5a13eda4..f7d2124ba74 100644
--- a/fixincludes/inclhack.def
+++ b/fixincludes/inclhack.def
@@ -4902,7 +4902,7 @@ fix = {
c_fix = format;
c_fix_arg = "%0\n"
- "#define ioctl(fd, func, arg) (ioctl)(fd, func, (int)(arg))\n";
+ "#define ioctl(fd, func, arg) ioctl(fd, func, (int)(arg))\n";
c_fix_arg = "extern[\t ]+int[\t ]+ioctl[\t ]*\\([\t ,[:alnum:]]*\\);";
test_text = "extern int ioctl ( int asdf1234, int jkl , int qwerty ) ;";
--
2.16.4
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] fixincludes: vxworks: remove unnecessary parentheses in ioctl wrapper macro
2018-06-29 9:54 [PATCH] fixincludes: vxworks: remove unnecessary parentheses in ioctl wrapper macro Rasmus Villemoes
@ 2018-09-03 9:46 ` Olivier Hainque
2018-09-03 15:25 ` Bruce Korb
0 siblings, 1 reply; 4+ messages in thread
From: Olivier Hainque @ 2018-09-03 9:46 UTC (permalink / raw)
To: Rasmus Villemoes; +Cc: Olivier Hainque, GCC Patches, bkorb
Hi Rasmus,
> On 29 Jun 2018, at 11:47, Rasmus Villemoes <rv@rasmusvillemoes.dk> wrote:
> - "#define ioctl(fd, func, arg) (ioctl)(fd, func, (int)(arg))\n";
> + "#define ioctl(fd, func, arg) ioctl(fd, func, (int)(arg))\n";
ok by me, thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] fixincludes: vxworks: remove unnecessary parentheses in ioctl wrapper macro
2018-09-03 9:46 ` Olivier Hainque
@ 2018-09-03 15:25 ` Bruce Korb
2018-09-03 15:29 ` Olivier Hainque
0 siblings, 1 reply; 4+ messages in thread
From: Bruce Korb @ 2018-09-03 15:25 UTC (permalink / raw)
To: Olivier Hainque; +Cc: rv, GCC Patches
On Mon, Sep 3, 2018 at 2:46 AM Olivier Hainque <hainque@adacore.com> wrote:
> > - "#define ioctl(fd, func, arg) (ioctl)(fd, func, (int)(arg))\n";
> > + "#define ioctl(fd, func, arg) ioctl(fd, func, (int)(arg))\n";
>
> ok by me, thanks.
Shouldn't this qualify as "trivial"? :)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] fixincludes: vxworks: remove unnecessary parentheses in ioctl wrapper macro
2018-09-03 15:25 ` Bruce Korb
@ 2018-09-03 15:29 ` Olivier Hainque
0 siblings, 0 replies; 4+ messages in thread
From: Olivier Hainque @ 2018-09-03 15:29 UTC (permalink / raw)
To: Bruce Korb; +Cc: Olivier Hainque, rv, GCC Patches
> On 3 Sep 2018, at 17:25, Bruce Korb <bkorb@gnu.org> wrote:
>
> On Mon, Sep 3, 2018 at 2:46 AM Olivier Hainque <hainque@adacore.com> wrote:
>>> - "#define ioctl(fd, func, arg) (ioctl)(fd, func, (int)(arg))\n";
>>> + "#define ioctl(fd, func, arg) ioctl(fd, func, (int)(arg))\n";
>>
>> ok by me, thanks.
>
> Shouldn't this qualify as "trivial"? :)
Probably, though I kept thinking there might
have been a particular reason, which I couldn't
grasp, why the parens had been introduced back
then.
Thanks for chiming in :-)
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-09-03 15:29 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-29 9:54 [PATCH] fixincludes: vxworks: remove unnecessary parentheses in ioctl wrapper macro Rasmus Villemoes
2018-09-03 9:46 ` Olivier Hainque
2018-09-03 15:25 ` Bruce Korb
2018-09-03 15:29 ` Olivier Hainque
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).