From ekarttun at cs.helsinki.fi Sat Sep 2 07:24:13 2006 From: ekarttun at cs.helsinki.fi (Einar Karttunen) Date: Sat Sep 2 07:11:19 2006 Subject: [C2hs] Matching defined types (lookupDftMarshIn "CH" [DefinedET gcry_cipher_hd_t h; "CH"]) Message-ID: <20060902112413.GB20228@localdomain> Hello I have a library that defines handles which are pointers as something like typedef void* ch_t; Wrapping with C2HS I can do: {#pointer ch_t as CH #} But when I try to use it like: {#fun ch_close {`CH'} -> `()' #} C2HS complains: >>> Missing "in" marshaller! There is no default marshaller for this combination of Haskell and C type: Haskell type: CH C type : (CH) When looking at the internals it comes to a call like: lookupDftMarshIn "CH" [DefinedET ch_t h; "CH"] Why don't they match and what should be changed to make things work? - Einar Karttunen From ekarttun at cs.helsinki.fi Sat Sep 2 09:15:03 2006 From: ekarttun at cs.helsinki.fi (Einar Karttunen) Date: Sat Sep 2 09:02:08 2006 Subject: [C2hs] GHC 6.6 support patch Message-ID: <20060902131503.GA21228@localdomain> Hello This switches to the new Set API. GHC 6.2 only supports the old one, 6.4 both and 6.6 only the new one. - Einar Karttunen -------------- next part -------------- New patches: [Switch to new Data.Set API as required by GHC 6.6 Einar Karttunen **20060902110758] { hunk ./c2hs/c/CLexer.x 79 -import qualified Data.Set as Set (mkSet, addToSet, elementOf) +import qualified Data.Set as Set (fromList, insert, member) hunk ./c2hs/c/CLexer.x 595 - if ident `Set.elementOf` tdefs + if ident `Set.member` tdefs hunk ./c2hs/c/CLexer.x 708 - alex_tdefs = Set.mkSet builtins + alex_tdefs = Set.fromList builtins hunk ./c2hs/c/CLexer.x 753 - POk s{alex_tdefs = tdefs `Set.addToSet` ident} ()) + POk s{alex_tdefs = ident `Set.insert` tdefs} ()) hunk ./c2hs/c/CParser.y 90 -import Data.Set (Set, mkSet, union, elementOf) } Context: [Cancel previous patch installing the c2hs library Manuel M T Chakravarty **20060525181726] [Teach c2hs about C style line pragmas for accurate source location info. Duncan Coutts **20060524174216] [Fix typo Jelmer Vernooij **20060208004733] [Install helper library for use by other packages Jelmer Vernooij **20060207224532] [Use PreCST for CParser to avoid unnecessary module deps Duncan Coutts **20060523142434] [Make the C parser test prog build again. Duncan Coutts **20060523135822 This program is useful for reproducing C parser errors for when users send in their .i files. Just run: ./parse foo.i Build using: ghc --make Main.hs -o parse ../i -i../../../base/general -i../../../base/admin -i../../../base/errors -i../../../base/state -i../../../base/syms -i../../state ] [change handling of marshallers for dynamic function hooks Udo Stenzel **20060515142639] [minor beautification Udo Stenzel **20060430215444] [support fun hooks for FunPtrs inside structs Udo Stenzel **20060429235956 This is a bit hackish at times, as I cut-and-paste-coded a bit. Though pending cleanup, it seems to work. ] [improve translation of apath to identifier Udo Stenzel **20060429235900] [allow call hooks for FunPtrs inside structures Udo Stenzel **20060429155023] [Allow escape sequences in the file name part of #line directives Duncan Coutts **20060406214715] [darcs.haskell.org repo Manuel M T Chakravarty **20060514224852] [calculate size of embedded arrays correctly Udo Stenzel **20060502231635] [Adapt Setup.hs to Cabal in GHC 6.4.2 Manuel M T Chakravarty **20060429012513 ** WARNING: This will break the build on GHC 6.4.1 and earlier! ** On GHC 6.4.1 and earlier omit this patch or follow the instructions in `Setup.hs'. ] [Version 0.14.6 credits Manuel M T Chakravarty **20060429012404] [tolerate variadic functions Udo Stenzel **20060423234358 This adds support for pointers to variadic functions in structs. They cannot be called, but the rest of the struct is accessible without c2hs bombing out. ] [enum define workaround example Manuel M T Chakravarty **20051219124518] [TAG c2hs 0.14.5 Manuel M T Chakravarty **20051212115038] Patch bundle hash: 5f1445db4ff69f59d140a6bd5050d210007d5ea6 From ekarttun at cs.helsinki.fi Sat Sep 2 09:28:04 2006 From: ekarttun at cs.helsinki.fi (Einar Karttunen) Date: Sat Sep 2 09:15:08 2006 Subject: [C2hs] A new kind of output marshallers *- (patch attached) Message-ID: <20060902132804.GA21372@localdomain> Hello When wrapping libraries that return error codes from functions a monadic output marshaller that does not return a value is very useful. This implements *- output marshallers that take the value and consume it, but don't return a result. This is used like: foo_error_t foo_something(random, arguments); type Err = {#type foo_error_t#} {#fun {`Foo', `Bar'} -> `()' handleError*- #} handleError :: Err -> IO () handleError ... - Einar Karttunen -------------- next part -------------- New patches: [Support for *- out marshallers Einar Karttunen **20060902132122 Implement *- out marshallers that are a monadic action but their return values are ignored. This is very useful for converting error codes into exceptions. ] { hunk ./c2hs/chs/CHS.hs 68 --- parm -> [ident_1 [`*' | `-']] verbhs [`&'] [ident_2 [`*' | `-']] +-- parm -> [ident_1 [`*' | `-']] verbhs [`&'] [ident_2 [`*'] [`-']] hunk ./c2hs/chs/CHS.hs 276 + | CHSIOVoidArg -- drops argument, but in monad hunk ./c2hs/chs/CHS.hs 563 - CHSValArg -> id - CHSIOArg -> showString "*" - CHSVoidArg -> showString "-") + CHSValArg -> id + CHSIOArg -> showString "*" + CHSVoidArg -> showString "-" + CHSIOVoidArg -> showString "*-") hunk ./c2hs/chs/CHS.hs 964 + parseOptMarsh (CHSTokIdent _ ide:CHSTokStar _ :CHSTokMinus _:toks) = + return (Just (ide, CHSIOVoidArg) , toks) hunk ./c2hs/gen/GenBind.hs 842 + CHSParm _ _ twoCVal (Just (omIde, CHSIOVoidArg)) _ -> + " " ++ identToLexeme omIde ++ " res >> \n" hunk ./c2hs/gen/GenBind.hs 851 - CHSParm _ _ _ (Just (_, CHSVoidArg)) _ -> retArgs - _ -> "res'":retArgs + CHSParm _ _ _ (Just (_, CHSVoidArg)) _ -> retArgs + CHSParm _ _ _ (Just (_, CHSIOVoidArg)) _ -> retArgs + _ -> "res'":retArgs hunk ./c2hs/gen/GenBind.hs 892 - notVoid (Just (_, kind)) = kind /= CHSVoidArg + notVoid (Just (_, kind)) = kind /= CHSVoidArg && kind /= CHSIOVoidArg hunk ./c2hs/gen/GenBind.hs 918 - CHSVoidArg -> "" - CHSIOArg -> omApp ++ ">>= \\" ++ outBndr ++ " -> " - CHSValArg -> "let {" ++ outBndr ++ " = " ++ + CHSVoidArg -> "" + CHSIOVoidArg -> omApp ++ ">>" + CHSIOArg -> omApp ++ ">>= \\" ++ outBndr ++ " -> " + CHSValArg -> "let {" ++ outBndr ++ " = " ++ hunk ./c2hs/gen/GenBind.hs 923 - retArg = if omArgKind == CHSVoidArg then "" else outBndr + retArg = if omArgKind == CHSVoidArg || omArgKind == CHSIOVoidArg then "" else outBndr hunk ./doc/c2hs/c2hs.sgml 372 -[ hunk ./doc/c2hs/c2hs.sgml 740 -parm -> [ident_1 [`*' | `-']] verbhs [`&'] [ident_2 [`*' | `-']] +parm -> [ident_1 [`*' | `-']] verbhs [`&'] [ident_2 [`*'] [`-']] } Context: [Cancel previous patch installing the c2hs library Manuel M T Chakravarty **20060525181726] [Teach c2hs about C style line pragmas for accurate source location info. Duncan Coutts **20060524174216] [Fix typo Jelmer Vernooij **20060208004733] [Install helper library for use by other packages Jelmer Vernooij **20060207224532] [Use PreCST for CParser to avoid unnecessary module deps Duncan Coutts **20060523142434] [Make the C parser test prog build again. Duncan Coutts **20060523135822 This program is useful for reproducing C parser errors for when users send in their .i files. Just run: ./parse foo.i Build using: ghc --make Main.hs -o parse ../i -i../../../base/general -i../../../base/admin -i../../../base/errors -i../../../base/state -i../../../base/syms -i../../state ] [change handling of marshallers for dynamic function hooks Udo Stenzel **20060515142639] [minor beautification Udo Stenzel **20060430215444] [support fun hooks for FunPtrs inside structs Udo Stenzel **20060429235956 This is a bit hackish at times, as I cut-and-paste-coded a bit. Though pending cleanup, it seems to work. ] [improve translation of apath to identifier Udo Stenzel **20060429235900] [allow call hooks for FunPtrs inside structures Udo Stenzel **20060429155023] [Allow escape sequences in the file name part of #line directives Duncan Coutts **20060406214715] [darcs.haskell.org repo Manuel M T Chakravarty **20060514224852] [calculate size of embedded arrays correctly Udo Stenzel **20060502231635] [Adapt Setup.hs to Cabal in GHC 6.4.2 Manuel M T Chakravarty **20060429012513 ** WARNING: This will break the build on GHC 6.4.1 and earlier! ** On GHC 6.4.1 and earlier omit this patch or follow the instructions in `Setup.hs'. ] [Version 0.14.6 credits Manuel M T Chakravarty **20060429012404] [tolerate variadic functions Udo Stenzel **20060423234358 This adds support for pointers to variadic functions in structs. They cannot be called, but the rest of the struct is accessible without c2hs bombing out. ] [enum define workaround example Manuel M T Chakravarty **20051219124518] [TAG c2hs 0.14.5 Manuel M T Chakravarty **20051212115038] Patch bundle hash: 493766174e50ca758b23cd42097cf82cd9befb16 From duncan.coutts at worc.ox.ac.uk Tue Sep 12 08:46:28 2006 From: duncan.coutts at worc.ox.ac.uk (Duncan Coutts) Date: Tue Sep 12 08:33:34 2006 Subject: [C2hs] patch applied (c2hs): Switch to new Data.Set API as required by GHC 6.6 Message-ID: <20060912124628.GA20605@cvs.haskell.org> Sat Sep 2 04:07:58 PDT 2006 Einar Karttunen * Switch to new Data.Set API as required by GHC 6.6 M ./c2hs/c/CLexer.x -4 +4 M ./c2hs/c/CParser.y -1 From chak at cse.unsw.edu.au Tue Sep 12 22:17:38 2006 From: chak at cse.unsw.edu.au (chak@cse.unsw.edu.au) Date: Tue Sep 12 22:04:42 2006 Subject: [C2hs] patch applied (c2hs): Support for *- out marshallers Message-ID: <20060913021738.GA1897@cvs.haskell.org> Sat Sep 2 06:21:22 PDT 2006 Einar Karttunen * Support for *- out marshallers Implement *- out marshallers that are a monadic action but their return values are ignored. This is very useful for converting error codes into exceptions. M ./c2hs/chs/CHS.hs -4 +8 M ./c2hs/gen/GenBind.hs -7 +11 M ./doc/c2hs/c2hs.sgml -2 +6 From chak at cse.unsw.edu.au Tue Sep 12 22:19:13 2006 From: chak at cse.unsw.edu.au (Manuel M T Chakravarty) Date: Tue Sep 12 22:06:52 2006 Subject: [C2hs] A new kind of output marshallers *- (patch attached) In-Reply-To: <20060902132804.GA21372@localdomain> References: <20060902132804.GA21372@localdomain> Message-ID: <1158113953.9862.198.camel@trinity.localdomain> Hi Einar, > When wrapping libraries that return error codes from functions > a monadic output marshaller that does not return a value is > very useful. This implements *- output marshallers that take > the value and consume it, but don't return a result. > > This is used like: > > foo_error_t foo_something(random, arguments); > > type Err = {#type foo_error_t#} > > {#fun {`Foo', `Bar'} -> `()' handleError*- #} > > handleError :: Err -> IO () > handleError ... Yes, that certainly makes sense. Thanks for also updating the documentation! I have pushed the patch into the public repo. Thanks for the contribution. Cheers, Manuel From chak at cse.unsw.edu.au Tue Sep 12 22:26:02 2006 From: chak at cse.unsw.edu.au (Manuel M T Chakravarty) Date: Tue Sep 12 22:13:37 2006 Subject: [C2hs] Matching defined types (lookupDftMarshIn "CH" [DefinedET gcry_cipher_hd_t h; "CH"]) In-Reply-To: <20060902112413.GB20228@localdomain> References: <20060902112413.GB20228@localdomain> Message-ID: <1158114362.9862.206.camel@trinity.localdomain> Einar, > I have a library that defines handles which are pointers > as something like > typedef void* ch_t; > > Wrapping with C2HS I can do: > {#pointer ch_t as CH #} > > But when I try to use it like: > {#fun ch_close {`CH'} -> `()' #} > > C2HS complains: > >>> Missing "in" marshaller! > There is no default marshaller for this combination of Haskell and C type: > Haskell type: CH > C type : (CH) > > When looking at the internals it comes to a call like: > lookupDftMarshIn "CH" [DefinedET ch_t h; "CH"] > > Why don't they match and what should be changed to make things work? Default marshaller don't know anything about the type names introduced by pointer hooks. However, it would be great if this would work. (I actually thought about it, but never got around to implementing it.) At the moment, the matching happens in two purely statically defined functions: GenBind.lookupDftMarshIn and GenBind.lookupDftMarshOut. There is actually a FIXME in the comment preceding the functions suggesting something more dynamic. If you would be willing to extend the implementation along the lines of this comment, that would be terrific! If you have any problems/questions about how to do it, I'd be happy to assist. (But I'll be away for nearly two weeks from Saturday - due to ICFP. I guess, I will have email there, but maybe not very much time to answer.) Manuel From jelmer at samba.org Wed Sep 13 08:28:57 2006 From: jelmer at samba.org (Jelmer Vernooij) Date: Wed Sep 13 08:16:07 2006 Subject: [C2hs] darcs patch: Fix warning with newer versions of autoconf. Message-ID: <20060913122857.67D985C48E8@ganieda.lan.vernstok.nl> Wed Sep 13 12:28:20 UTC 2006 Jelmer Vernooij * Fix warning with newer versions of autoconf. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: text/x-darcs-patch Size: 3214 bytes Desc: A darcs patch for your repository! Url : http://www.haskell.org/pipermail/c2hs/attachments/20060913/1265f563/attachment.bin From chak at cse.unsw.edu.au Thu Sep 14 12:31:31 2006 From: chak at cse.unsw.edu.au (chak@cse.unsw.edu.au) Date: Thu Sep 14 12:18:31 2006 Subject: [C2hs] patch applied (c2hs): Fix warning with newer versions of autoconf. Message-ID: <20060914163131.GA18727@cvs.haskell.org> Wed Sep 13 05:28:20 PDT 2006 Jelmer Vernooij * Fix warning with newer versions of autoconf. M ./doc/c2hs/Makefile.in +1 From chak at cse.unsw.edu.au Thu Sep 14 12:31:27 2006 From: chak at cse.unsw.edu.au (Manuel M T Chakravarty) Date: Thu Sep 14 12:19:11 2006 Subject: [C2hs] darcs patch: Fix warning with newer versions of autoconf. In-Reply-To: <20060913122857.67D985C48E8@ganieda.lan.vernstok.nl> References: <20060913122857.67D985C48E8@ganieda.lan.vernstok.nl> Message-ID: <1158251487.24606.74.camel@trinity.localdomain> > * Fix warning with newer versions of autoconf. Pushed to the public repo. Thansk! Manuel From ganesh at earth.li Sat Sep 23 09:53:12 2006 From: ganesh at earth.li (Ganesh Sittampalam) Date: Sat Sep 23 09:39:43 2006 Subject: [C2hs] c2hs repo problems on Windows Message-ID: Hi, At some point in the history of the c2hs repo, the files hipar/base/todo and hipar/base/TODO both exist. This is not good for people who want to get the repo on Windows :-) After playing around a bit, I have made a version of the repo that can be got fine from Windows. It doesn't involve modifying any existing patches, just adding a couple of new ones and reordering them in the repo so that the two files todo and TODO never exist simultaneously. My fixed up repo is at http://urchin.earth.li/darcs/ganesh/c2hs - I believe that you can sort out the main c2hs repo by getting a fresh copy from my repo, pulling in all the outstanding changes from the original c2hs repo, and then swapping the new one into place. A more detailed explanation: The current repo starts off with hipar/base/todo. At some point later, hipar/base/TODO is introduced. Later still, in the patch "rearranging darcs repo", hipar/base is renamed to base and the new base/todo is deleted. I wrote a patch that renames hipar/base/todo to hipar/base/todo-lowercase. This solves the name conflict for Windows, but annoyingly it conflicts with the delete of base/todo later on, so another patch is needed to resolve this conflict. There's also a final patch at the end to actually delete the renamed todo-lowercase file, because I got confused when resolving the conflict and didn't do it then, and I only realised after the person I was helping on #darcs had pulled from me. So the sequence of patches in the modified repo is: - Original import - Rename hipar/base/todo to hipar/base/todo-lowercase - "rearranging darcs repo" and all its dependencies - Resolve conflict between rename of todo and delete of todo - Rest of the patches - Actually delete base/todo-lowercase Cheers, Ganesh From aeyakovenko at gmail.com Fri Sep 29 21:23:42 2006 From: aeyakovenko at gmail.com (Anatoly Yakovenko) Date: Fri Sep 29 20:29:43 2006 Subject: [C2hs] cant figure out how to use c2hs, what am i doing wrong? Message-ID: I have a simple fftw wrapper which c2hs builds into a .hs file, but when i try to use it i get an error: $ ghc -v --make -fffi Main.hs Glasgow Haskell Compiler, Version 6.4.2, for Haskell 98, compiled by GHC version 6.4.2 Using package config file: /usr/lib/ghc-6.4.2/package.conf Hsc static flags: -static *** Chasing dependencies: Chasing modules from: Main.hs *** Deleting temp files Deleting: Fftw.chs:2:0: parse error on input `import' here is my Fftw.chs: module Fftw (fftwNew, fftwDestroy, fftwExecute) import C2HS #include "fftw3.h" data Fftw = Fftw Integer CPtrDiff CPtrDiff CPtrDiff fftwNew::IO Integer -> Fftw fftwNew size = do input <- {#call unsafe fftw_malloc#} 8*size output <- {#call unsafe fftw_malloc#} 8*size plan <- {#call unsafe fftw_plan_r2r_1d#} size input output 0 0 return !$ Fftw size input output plan fftwSize::Fftw -> Integer fftwSize (Fftw size _ _ _ ) = size fftwDestroy::Fftw -> IO () fftwDestroy (Fftw _ input output plan) = do {#call unsafe fftw_free#} input {#call unsafe fftw_free#} output {#call unsafe fftw_destroy_plan#} plan fftwExecute::IO Fftw [Double] -> [Double] fftwExecute (Fftw size input output plan) inp = do pokeArray input (take size inp) {#call unsafe fftw_execute#} plan return !$ peekArray size output and my Main.hs: module Main where import Fftw main :: IO () main = do fft <- fftwNew 128 putStrLn $ show $ "done"