Ticket #3921 (closed bug: fixed)

Opened 2 years ago

Last modified 22 months ago

hsc2hs and Windows line endings on linux

Reported by: guest Owned by:
Priority: normal Milestone:
Component: hsc2hs Version: 6.12.1
Keywords: Windows line endings Cc: lonetiger@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Compile-time crash Difficulty:
Test Case: Blocked By:
Blocking: Related Tickets:

Description (last modified by igloo) (diff)

There seems to be a problem when compiling a file under Linux which has Windows line endings and uses #let 's in the file.

A simple example would be

module Main where

#let alignment t = "%lu", (unsigned long)offsetof(struct {char x__; t (y__); }, y__)

main :: IO ()
main = return ()

which does nothing really, but should compile.

this fails under linux (when the file was saved using windows line endings) with the error

1.Broken.hsc:4: error: expected identifier or ‘(’ before ‘)’ token
2.compiling Broken_hsc_make.c failed

looking at the generated .c file

4.#include "/usr/lib/ghc-6.12.1/template-hsc.h"
5.#line 3 "Broken.hsc"
6.#define hsc_alignment(t ) printf ( "%lu", (unsigned long)offsetof(struct {char x__; t (y__); }, y__)
7.);
8.  <truncated>

on line 6 the closing ");" was pushed to a new line, 7, but this causes the define to end unexpectedly and cauzes the syntax error mention above. This is presumably because only the "\n" and the "\r" are left in there.

also the generated code contains a mixture of both endings, which is no problem for ghc and gcc but might be for some editors:

18.    fputs ("\r\n"
19.           "", stdout);
20.    fputs ("\n"
21.           "", stdout);

Attachments

Broken.hsc Download (142 bytes) - added by guest 2 years ago.
The example hsc file
Broken_hsc_make.c Download (0.7 KB) - added by guest 2 years ago.
The generated file

Change History

Changed 2 years ago by guest

The example hsc file

Changed 2 years ago by guest

The generated file

Changed 2 years ago by guest

  • cc lonetiger@… added

Changed 22 months ago by igloo

  • description modified (diff)

Changed 22 months ago by igloo

  • status changed from new to closed
  • resolution set to fixed

Thanks for the report. This is fixed in 6.12.2:

Wed Mar 24 00:06:55 GMT 2010  Ian Lynagh <igloo@earth.li>
  * Strip out ^M characters to stop gcc getting confused
Note: See TracTickets for help on using tickets.