Ticket #3117 (closed merge: fixed)

Opened 4 years ago

Last modified 4 years ago

via C compilation of module importing log1p from <math.h> fails.

Reported by: int-e Owned by: igloo
Priority: normal Milestone: 6.10.2
Component: Compiler Version: 6.10.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

This module fails to compile:

{-# LANGUAGE ForeignFunctionInterface #-}
{-# OPTIONS_GHC -fvia-C #-}

foreign import ccall unsafe "math.h log1p" log1p :: Double -> Double

main = print (log1p 1)

With errors like these:

/tmp/ghc25313_0/ghc25313_0.hc: In function 'svD_entry':

/tmp/ghc25313_0/ghc25313_0.hc:66:0:
     error: 'log1p' redeclared as different kind of symbol

/usr/include/bits/mathcalls.h:132:0:
     error: previous declaration of 'log1p' was here

This is affecting the logfloat package on hackage.

The reason is that ghc doesn't generate proper prototypes for foreign imports, but that's probably ok as long as no conflicting prototypes are defined for the same function.

To accomplish this, ghc treats functions from math.h specially, but a number of these functions like log1p are not recognized. See compiler/cmm/CLabel.hs.

Attachments

update_C_math.h_functions.dpatch Download (201.0 KB) - added by int-e 4 years ago.
proposed fix.

Change History

Changed 4 years ago by int-e

proposed fix.

Changed 4 years ago by simonmar

  • owner set to simonmar
  • difficulty set to Unknown
  • milestone set to 6.10.2

I'll test and apply, thanks.

Changed 4 years ago by simonmar

  • owner changed from simonmar to igloo
  • type changed from bug to merge

Thanks, applied:

Mon Mar 23 18:36:30 GMT 2009  Bertram Felgenhauer <int-e@gmx.de>          
  * update list of C math functions
  Fix via C compilation of modules that import, say, log1p from math.h (#3117)
  
  The list is based on preprocessing Stg.h with glibc 2.6.1 headers, and
  cross-checked with the ISO C 99 standard (draft).

Changed 4 years ago by igloo

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

Merged.

Note: See TracTickets for help on using tickets.