Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org
You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..." Today's Topics: 1. Re: ODP: howto Pipe (PICCA Frederic-Emmanuel) 2. Re: ODP: howto Pipe (Marcin Mrotek) ---------------------------------------------------------------------- Message: 1 Date: Sat, 20 Feb 2016 14:18:46 +0000 From: PICCA Frederic-Emmanuel <frederic-emmanuel.pi...@synchrotron-soleil.fr> To: "The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell" <beginners@haskell.org> Subject: Re: [Haskell-beginners] ODP: howto Pipe Message-ID: <a2a20ec3b8560d408356cac2fc148e53b303b...@sun-dag3.synchrotron-soleil.fr> Content-Type: text/plain; charset="us-ascii" In fact I got the segfault also with the P.print... So I rewrote the solve function like this withDiffractometer :: Diffractometer -> (Ptr HklEngineList -> IO b) -> IO b withDiffractometer d fun = do let f_engines = difEngineList d withForeignPtr f_engines fun solveTrajPipe' :: Diffractometer -> Pipe Engine Geometry IO () solveTrajPipe' dif = flip evalStateT dif $ forever $ do -- Inside here we are using `StateT Int (Consumer a IO) r` e <- lift await dif <- get let name = engineName e solutions <- lift . lift $ withDiffractometer dif $ \engines -> withCString name $ \cname -> do engine <- c_hkl_engine_list_engine_get_by_name engines cname nullPtr n <- c_hkl_engine_pseudo_axis_names_get engine >>= darrayStringLen solve' engine n e >>= getSolution0 put dif lift $ yield solutions using the evalStateT. It works with million of evaluations :) but now if I remove the get and put lines, I get the segfault. This segfault is located in the solve' method solve' :: Ptr HklEngine -> CSize -> Engine -> IO (ForeignPtr HklGeometryList) solve' engine n (Engine _ ps _) = do let positions = [v | (Parameter _ v _) <- ps] withArray positions $ \values -> c_hkl_engine_pseudo_axis_values_set engine values n unit nullPtr >>= newForeignPtr c_hkl_geometry_list_free so to my opinion I do not manage correctly the life time of my dif object, but I do not understand how I can ensure this life time in until the solve' method proceed. Cheers Frederic ------------------------------ Message: 2 Date: Sun, 21 Feb 2016 10:25:31 +0100 From: Marcin Mrotek <marcin.jan.mro...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] ODP: howto Pipe Message-ID: <cajcfpzn+zjovsutvmnnynddrihgtbwd+mjfb-cc3ny4by78...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 First of all, (StateT Diffractometer (Pipe Engine Geometry IO) ()) isn't the same as (Pipe Engine Geometry (StateT Diffractometer IO) ()), although I'm not sure what exactly the difference will be, as I've never used it the former way. This might be again a question for the Pipes mailing list. Secondly: > but now if I remove the get and put lines, I get the segfault. Okay, I have no idea. As I see it, this shouldn't happen, as you're getting and putting the same pointer all the time. What if you remove the StateT altogether and just use the `dif` from the function argument, are you still getting segfaults? Also what about writting the function without using pipes, and using Pipes.mapM to make it a pipe like I mentioned? (if the only Pipes operation you're doing are an `await` in the beginning and a `yield` at the end, Pipes.mapM covers it) Best regards, Marcin Mrotek ------------------------------ Subject: Digest Footer _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ End of Beginners Digest, Vol 92, Issue 24 *****************************************