GHC RTS question

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

GHC RTS question

Artyom Kazak
Hello everybody!
I want to write a little program, that will receive a string as command-line argument and write it in the file. But if this string contains '+RTS', GHC runtime won't pass the rest of the string to my program.
What can I do to avoid this?

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: GHC RTS question

Felipe Lessa
On Sun, Feb 21, 2010 at 05:45:22PM +0200, Artyom Kazak wrote:
> Hello everybody!
> I want to write a little program, that will receive a string as command-line
> argument and write it in the file. But if this string contains '+RTS', GHC
> runtime won't pass the rest of the string to my program.
> What can I do to avoid this?

Use -RTS, as in

$ ghc -V
The Glorious Glasgow Haskell Compilation System, version 6.10.4

$ ghc +RTS -V
ghc: no input files
Usage: For basic information, try the `--help' option.

$ ghc +RTS -RTS -V
The Glorious Glasgow Haskell Compilation System, version 6.10.4

--
Felipe.
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: GHC RTS question

Daniel Fischer-4
In reply to this post by Artyom Kazak
Am Sonntag 21 Februar 2010 16:45:22 schrieb Artyom Kazak:
> Hello everybody!
> I want to write a little program, that will receive a string as
> command-line argument and write it in the file. But if this string
> contains '+RTS', GHC runtime won't pass the rest of the string to my
> program.
> What can I do to avoid this?

Enclose it in double quotes (perhaps single quotes would also work)

$ ./proggy "argwith +RTS in" harmlessArg otherHarmlessArg
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: GHC RTS question

Artyom Kazak
> Enclose it in double quotes (perhaps single quotes would also work)
No, I want my program to work the same way as UNIX "echo" does.
Without any double quotes.
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: GHC RTS question

Daniel Fischer-4
Am Sonntag 21 Februar 2010 18:20:43 schrieb Artyom Kazak:
> > Enclose it in double quotes (perhaps single quotes would also work)
>
> No, I want my program to work the same way as UNIX "echo" does.
> Without any double quotes.

Okay, what about

"If you absolutely positively want all the rest of the options in a command
line to go to the program (and not the RTS), use a ––RTS."

$ ./prog +RTS --RTS +RTS

? (BTW, enclosing in quotes doesn't work anyway if the argument consists
*only* of "+RTS", same as with echo, echo "-e" doesn't output '-e' either).

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: GHC RTS question

Artyom Kazak
2010/2/21 Daniel Fischer <[hidden email]>:

> Am Sonntag 21 Februar 2010 18:20:43 schrieb Artyom Kazak:
>> > Enclose it in double quotes (perhaps single quotes would also work)
>>
>> No, I want my program to work the same way as UNIX "echo" does.
>> Without any double quotes.
>
> Okay, what about
>
> "If you absolutely positively want all the rest of the options in a command
> line to go to the program (and not the RTS), use a ––RTS."
>
> $ ./prog +RTS --RTS +RTS
>
> ? (BTW, enclosing in quotes doesn't work anyway if the argument consists
> *only* of "+RTS", same as with echo, echo "-e" doesn't output '-e' either).
>
>

So, if I type "./prog +RTS --RTS +RTS", the output will be "+RTS". But
I want the output to be equal to the input IN ALL CASES, without any
quotes, additional options, etc. I want all the command line to go to
my program. How can I do it? (The only way I know now - hacking the
GHC. If there are no other ways, I'll do it.)
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: GHC RTS question

Max Bolingbroke-2
On 21 February 2010 18:58, Artyom Kazak <[hidden email]> wrote:
> So, if I type "./prog +RTS --RTS +RTS", the output will be "+RTS". But
> I want the output to be equal to the input IN ALL CASES, without any
> quotes, additional options, etc. I want all the command line to go to
> my program. How can I do it? (The only way I know now - hacking the
> GHC. If there are no other ways, I'll do it.)

You might be able to get somewhere by writing a custom "main" function
in C and linking it in. According to
http://haskell.org/ghc/docs/latest/html/users_guide/options-phases.html
if a lib specified with the -l option during compilation contains a
"main", that will be used in preference to the one from HSrts.

You could presumably just extend argv with the "+RTS" "--RTS" entries
and then call into the one from HSrts, so this might even be quite
easy.

Cheers,
Max
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: GHC RTS question

Daniel Fischer-4
In reply to this post by Artyom Kazak
Am Sonntag 21 Februar 2010 19:58:12 schrieb Artyom Kazak:

> 2010/2/21 Daniel Fischer <[hidden email]>:
> > Am Sonntag 21 Februar 2010 18:20:43 schrieb Artyom Kazak:
> >> > Enclose it in double quotes (perhaps single quotes would also work)
> >>
> >> No, I want my program to work the same way as UNIX "echo" does.
> >> Without any double quotes.
> >
> > Okay, what about
> >
> > "If you absolutely positively want all the rest of the options in a
> > command line to go to the program (and not the RTS), use a ––RTS."
> >
> > $ ./prog +RTS --RTS +RTS
> >
> > ? (BTW, enclosing in quotes doesn't work anyway if the argument
> > consists *only* of "+RTS", same as with echo, echo "-e" doesn't output
> > '-e' either).
>
> So, if I type "./prog +RTS --RTS +RTS", the output will be "+RTS". But
> I want the output to be equal to the input IN ALL CASES, without any
> quotes, additional options, etc. I want all the command line to go to
> my program. How can I do it? (The only way I know now - hacking the
> GHC. If there are no other ways, I'll do it.)

Shell wrapper:

$ cat wopTest
./opTest +RTS --RTS $@

$ cat opTest.hs
module Main (main) where

import System.Environment (getArgs)

main = mapM_ print =<< getArgs

$ ./wopTest +RTS -sstderr -RTS
"+RTS"
"-sstderr"
"-RTS"

Other than that, hacking GHC is the only way I can think of either, since
looking for RTS-options is a fixed (and generally necessary) part of the
RTS.

But why do you want that behaviour so much that you'd be willing to hack
GHC?

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: GHC RTS question

Anthony Cowley
In reply to this post by Artyom Kazak
On Sun, Feb 21, 2010 at 1:58 PM, Artyom Kazak <[hidden email]> wrote:
> So, if I type "./prog +RTS --RTS +RTS", the output will be "+RTS". But
> I want the output to be equal to the input IN ALL CASES, without any
> quotes, additional options, etc. I want all the command line to go to
> my program. How can I do it? (The only way I know now - hacking the
> GHC. If there are no other ways, I'll do it.)

How about a wrapper script? Something like,

#! /usr/bin/env bash
./prog --RTS $*

Just use that as the front-end to your Haskell program.

Anthony
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: GHC RTS question

Ben Millwood
In reply to this post by Max Bolingbroke-2
On Sun, Feb 21, 2010 at 7:10 PM, Max Bolingbroke
<[hidden email]> wrote:
>
> You might be able to get somewhere by writing a custom "main" function
> in C and linking it in. According to
> http://haskell.org/ghc/docs/latest/html/users_guide/options-phases.html
> if a lib specified with the -l option during compilation contains a
> "main", that will be used in preference to the one from HSrts.
>

I think the neater way of doing this would be to use the FFI, with a
foreign export declaration making your haskell main available to a
wrapper C file, which would then initialise the RTS with a
slightly-modified argc and argv.
See http://www.haskell.org/ghc/docs/latest/html/users_guide/ffi-ghc.html
for details on how to do that.

I also think it's strange, though, that adding RTS hooks is not
optional. GHC should support some method of disabling them, in my
opinion.
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: GHC RTS question

Lennart Augustsson
Supply a fix for the problem, and it will probably get included.
There has probably been little demand for this feature so far.

  -- Lennart

On Sun, Feb 21, 2010 at 10:21 PM, Ben Millwood <[hidden email]> wrote:

> On Sun, Feb 21, 2010 at 7:10 PM, Max Bolingbroke
> <[hidden email]> wrote:
>>
>> You might be able to get somewhere by writing a custom "main" function
>> in C and linking it in. According to
>> http://haskell.org/ghc/docs/latest/html/users_guide/options-phases.html
>> if a lib specified with the -l option during compilation contains a
>> "main", that will be used in preference to the one from HSrts.
>>
>
> I think the neater way of doing this would be to use the FFI, with a
> foreign export declaration making your haskell main available to a
> wrapper C file, which would then initialise the RTS with a
> slightly-modified argc and argv.
> See http://www.haskell.org/ghc/docs/latest/html/users_guide/ffi-ghc.html
> for details on how to do that.
>
> I also think it's strange, though, that adding RTS hooks is not
> optional. GHC should support some method of disabling them, in my
> opinion.
> _______________________________________________
> Haskell-Cafe mailing list
> [hidden email]
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: GHC RTS question

Ivan Lazar Miljenovic
On 22 February 2010 10:55, Lennart Augustsson <[hidden email]> wrote:
> Supply a fix for the problem, and it will probably get included.
> There has probably been little demand for this feature so far.

But it is a little bit weird where if you have an application that you
release into production (which, admittedly, I've never done), then end
users are able to fiddle with settings which they shouldnt' really
touch (though there's not really that much that I can see that they'd
be able to do wrong with just RTS settings...).


--
Ivan Lazar Miljenovic
[hidden email]
IvanMiljenovic.wordpress.com
Joan Crawford  - "I, Joan Crawford, I believe in the dollar.
Everything I earn, I spend." -
http://www.brainyquote.com/quotes/authors/j/joan_crawford.html
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: GHC RTS question

Vo Minh Thu
2010/2/22 Ivan Miljenovic <[hidden email]>:
> On 22 February 2010 10:55, Lennart Augustsson <[hidden email]> wrote:
>> Supply a fix for the problem, and it will probably get included.
>> There has probably been little demand for this feature so far.
>
> But it is a little bit weird where if you have an application that you
> release into production (which, admittedly, I've never done), then end
> users are able to fiddle with settings which they shouldnt' really
> touch (though there's not really that much that I can see that they'd
> be able to do wrong with just RTS settings...).

Isn't the same situation with java, or even with any application using
some config files, or with dynamic libraries ?

Cheers,
Thu
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: GHC RTS question

Roman Cheplyaka-2
In reply to this post by Anthony Cowley
* Anthony Cowley <[hidden email]> [2010-02-21 14:15:00-0500]

> On Sun, Feb 21, 2010 at 1:58 PM, Artyom Kazak <[hidden email]> wrote:
> > So, if I type "./prog +RTS --RTS +RTS", the output will be "+RTS". But
> > I want the output to be equal to the input IN ALL CASES, without any
> > quotes, additional options, etc. I want all the command line to go to
> > my program. How can I do it? (The only way I know now - hacking the
> > GHC. If there are no other ways, I'll do it.)
>
> How about a wrapper script? Something like,
>
> #! /usr/bin/env bash
> ./prog --RTS $*
>
> Just use that as the front-end to your Haskell program.

If you want Haskell program to get exactly the same arguments that were
passed to the wrapper, use

  ./prog --RTS "$@"

Otherwise it will work wrong if arguments contain quoted field
separators (e.g. spaces).

--
Roman I. Cheplyaka :: http://ro-che.info/
"Don't let school get in the way of your education." - Mark Twain
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe