Re: [Haskell-cafe] FFI question

On Tue, Sep 9, 2014 at 10:36 PM, Vasili I. Galchin
Adam,
Did a find/grep under my posix-realtime directory .. no definition of MCL_CURRENT, MCL_FUTURE or MCL_CURRENTandFUTURE!! But If I comment out the case arm MCL_CURRENTandFUTURE in my LockMem.hsc file and run "cabal build" from the directory where my *.cabal file lives .. clean compile ... Sigh!??!!
Vasya
On Mon, Sep 8, 2014 at 7:36 AM, adam vogt
wrote: Hi Vasili
Does the sys/mman.h or another included header actually define MCL_CURRENTandFUTURE?
Regards, Adam
On Sep 8, 2014 4:45 AM, "Vasili I. Galchin"
wrote: Following is a fragment generated by hsc2hs from LockedMem.hsc:
#line 93 "LockedMem.hsc" hsc_const (MCL_CURRENTandFUTURE); hsc_fputs (")\n" "", hsc_stdout()); hsc_line (94, "LockedMem.hsc"); hsc_fputs ("\n" "foreign import ccall unsafe \"sys/mman.h mlockall\"\n" " c_mlockall :: CInt -> IO CInt\n" "\n" "\n" "-- | unlock all mapped pages of a process!\n" "unlockAllMemory :: IO () \n" "unlockAllMemory = do\n" " throwErrnoIfMinus1 \"unlockAllMemory\" (c_munlockall)\n" " return ()\n" "\n" "foreign import ccall unsafe \"sys/mman.h munlockall\"\n" " c_munlockall :: IO CInt\n" "", hsc_stdout()); return 0;
On Mon, Sep 8, 2014 at 2:11 AM, Vasili I. Galchin
wrote: Hello,
I need memory refreshing about FFI because I need to fix a bug (plus I got down a rat hole because of Ukraine war :-(). Following a snippet of something I wrote:
-- | lock all of the memory space of a process lockAllMemory :: LockAllFlags -> IO () lockAllMemory flags = do throwErrnoIfMinus1 "lockAllMemory" (c_mlockall cflags) return () where cflags = case flags of CURRENT -> (#const MCL_CURRENT) FUTURE -> (#const MCL_FUTURE) CURRENTandFUTURE -> (#const MCL_CURRENTandFUTURE)
it is a file called LockedMem.hsc and the third arm CURRENTandFUTURE I just added to fix the this bug ..
MCL_CURRENTandFUTURE ends up in LockedMem_make.c(sp??) but I get a undeclared nasty message when I try to build LockedMem.hsc... my bad... . Please help so I can go back to help Ukraine.
Kind regarsd,
Vasya
Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Tue, Sep 9, 2014 at 11:36 PM, Vasili I. Galchin
Did a find/grep under my posix-realtime directory .. no definition of MCL_CURRENT, MCL_FUTURE or MCL_CURRENTandFUTURE!! But If I comment out the case arm MCL_CURRENTandFUTURE in my LockMem.hsc file and run "cabal build" from the directory where my *.cabal file lives .. clean compile ... Sigh!??!!
The fact that they start with uppercase tells me that they are from C, not
Haskell. The implication of their relationship with mlockall is that they
come from a related system header file, namely

oops ... let me check ..
on the other hand after rereading man page on POSIX mlockall I noticed
that "flags" formal parameter .. .I noticed that can be OR'd .. hence
I want to OR MCL_CURRENT and MCL_FUTURE ... fix this then ...
back to helping Ukraina before V.V.Putin does more nastiness ....
Kind thanks,
Vasya
On Tue, Sep 9, 2014 at 10:41 PM, Brandon Allbery
On Tue, Sep 9, 2014 at 11:36 PM, Vasili I. Galchin
wrote: Did a find/grep under my posix-realtime directory .. no definition of MCL_CURRENT, MCL_FUTURE or MCL_CURRENTandFUTURE!! But If I comment out the case arm MCL_CURRENTandFUTURE in my LockMem.hsc file and run "cabal build" from the directory where my *.cabal file lives .. clean compile ... Sigh!??!!
The fact that they start with uppercase tells me that they are from C, not Haskell. The implication of their relationship with mlockall is that they come from a related system header file, namely
. I note that neither my FreeBSD nor my OS X system defines MCL_CURRENTandFUTURE in /usr/include/sys/mman.h, although the other two are defined.
-- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

Bottom line is how can I do arithmetic (addition) on two #const's ???
I can hard code a "3" => nasty solution ...
Kind thanks,
Vasili
On Tue, Sep 9, 2014 at 10:53 PM, Vasili I. Galchin
oops ... let me check ..
on the other hand after rereading man page on POSIX mlockall I noticed that "flags" formal parameter .. .I noticed that can be OR'd .. hence I want to OR MCL_CURRENT and MCL_FUTURE ... fix this then ...
back to helping Ukraina before V.V.Putin does more nastiness ....
Kind thanks,
Vasya
On Tue, Sep 9, 2014 at 10:41 PM, Brandon Allbery
wrote: On Tue, Sep 9, 2014 at 11:36 PM, Vasili I. Galchin
wrote: Did a find/grep under my posix-realtime directory .. no definition of MCL_CURRENT, MCL_FUTURE or MCL_CURRENTandFUTURE!! But If I comment out the case arm MCL_CURRENTandFUTURE in my LockMem.hsc file and run "cabal build" from the directory where my *.cabal file lives .. clean compile ... Sigh!??!!
The fact that they start with uppercase tells me that they are from C, not Haskell. The implication of their relationship with mlockall is that they come from a related system header file, namely
. I note that neither my FreeBSD nor my OS X system defines MCL_CURRENTandFUTURE in /usr/include/sys/mman.h, although the other two are defined.
-- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

quoth "Vasili I. Galchin",
Bottom line is how can I do arithmetic (addition) on two #const's ???
I'm sorry to say I haven't been following the thread, but on the face of it, this seems easy to me - you just use the (C) addition operator! like, (#const CPPSYMA + CPPSYMB) I assume you're using hsc2hs. Donn
participants (3)
-
Brandon Allbery
-
Donn Cave
-
Vasili I. Galchin