Ticket #2 (new defect)

Opened 20 months ago

Last modified 11 months ago

Language.C fails doesn't support Mac OS X blocks notation

Reported by: ezyang Owned by: benedikt
Priority: major Milestone: 0.4.0
Component: parser Version: 0.3.1.1
Keywords: Cc: ezyang@…

Description

This is causing  Bug 29 for c2hs.

Steps to reproduce:

1. Get stdlib.h from Mac OS X 10.6 (Snow Leopard). I've attached the file from my machine here for convenience.
2. Attempt to parse the header file with the default GCC preprocessor as such:

Prelude Language.C Language.C.System.GCC> either show (show . pretty)
  `fmap` parseCFile (newGCC "gcc") Nothing [] "/usr/include/stdlib.h"
"/usr/include/stdlib.h:272: (column 20) [ERROR]  >>> Syntax Error !
  Syntax error !
  The symbol `^' does not fit here.
"

Expected result: parse is successful, possibly just ignoring BLOCKS notation.

Here is the segment of the header file in question:

#ifdef __BLOCKS__
int      atexit_b(void (^)(void));
void    *bsearch_b(const void *, const void *, size_t,
            size_t, int (^)(const void *, const void *));
#endif /* __BLOCKS__ */

Attachments

stdlib.h Download (11.5 KB) - added by ezyang 20 months ago.
stdlib.h file from Mac OS X

Change History

Changed 20 months ago by ezyang

stdlib.h file from Mac OS X

Changed 20 months ago by ezyang

  • summary changed from Language.C fails to parse stdlib.h on Mac OS X to Language.C fails doesn't support Mac OS X blocks notation

Investigating further, it seems that the preprocessor is incorrectly assuming BLOCKS support, when Language.C doesn't support it; so this is a question of undef'ing the macro when we run the preprocessor, or adding blocks support to Language.C. I've modified the ticket accordingly.

Changed 11 months ago by benedikt

To highlight the workaround suggested above by Edward, I'm forwarding this post by aaron to the language-c mailing list (May 2010):
On May 30 2010, Aaron Tomb wrote

Kevin Ballard wrote:
There is a (relatively) new extension for C called Blocks[1] that Apple introduced in Mac OS X 10.6. Block declarations look
similar to function declarations except for using in place of *. Unfortunately Language.C doesn't understand this and ends
up triggering a parse error when processing the system header files (even /usr/include/stdlib.h has this issue). Is there any
way to work around this issue?

Complete support for blocks would certainly be a big (though
potentially valuable) job. However, if what you want is just to be
able to parse C files that include Mac OS X 10.6 header files, there's
a simpler solution. All of the uses of blocks in the header files are
wrapped in #ifdef __BLOCKS__/#endif. So you can just pass -U__BLOCKS__
to CPP and the parse errors will go away.

Note: See TracTickets for help on using tickets.