Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in set_binary_mode out for cygwin #3818

Closed
vicuna opened this issue Oct 23, 2005 · 5 comments
Closed

Bug in set_binary_mode out for cygwin #3818

vicuna opened this issue Oct 23, 2005 · 5 comments
Labels

Comments

@vicuna
Copy link

vicuna commented Oct 23, 2005

Original bug ID: 3818
Reporter: administrator
Status: closed
Resolution: fixed
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)

Bug description

Full_Name: George Necula
Version: 3.08.4
OS: Win XP/cygwin
Submission from: adsl-63-204-134-90.dsl.snfc21.pacbell.net (63.204.134.90)

I have discovered that "set_binary_mode_out c true" has no effect on cygwin. In
fact, this function does nothing except when compiling for Windows (but not for
cygwin).

This is a big problem because it prevents the use of the -pp option for ocamlc
on cygwin. camlp4 will print the AST to stdout and will use set_binary_mode_out.
When ocamlc reads in the AST it segfaults. The workaround is to make sure you
add pr_o.cmo to the preprocessor command, to ensure that Ocaml source is piped
to stdout.

@vicuna
Copy link
Author

vicuna commented Oct 24, 2005

Comment author: administrator

I have done my own experiment and I saw translation to \r\n:

let _ = set_binary_mode_out stdout true in
print_string "one\ntwo"

I checked with emacs hexl-mode and I saw that \r\n is present there.

Ah, I installed cygwin in DOS mode!!! This must be it. But this still argues that set_binary_mode_out should do something, because you do not know how cygwin was installed.

But here is the actual thing that hit me:

If you try to use camlp4 the ocamlc compiler crashes:

ocamlc -pp "camlp4o pa_macro.cmo" -I +camlp4 -c foo.ml

  • this crashes because the preprocessor outputs the binary format AST to stdout, which ocamlc redirects to a temporary file (in driver/pparse.ml). The camlp4o command uses pr_dump.cmo by default and you can see right at the top of camlp4/meta/pr_dump.ml that it uses set_binary_mode_out to set stdout to binary.

I can work around this problem in two ways. I can add pr_o.cmo to the camlp4o command above, which will make camlp4 print Ocaml source not binary AST. Or, I can change ocamlc to not pipe the results of the pretty printer to stdout, but send it directly to the temporary file (change format string in driver/pparse.ml to use format string "%s %s -o %s"). Clearly in this later case the code in pr_dump.ml is able to set the binary mode because it uses open_out_bin instead of set_binary_mode_out.

As you can see, if you do not fix the set_binary_mode_out (which I think should be done), we must fix how the preprocessor is invoked in ocamlc.

George.

-----Original Message-----
From: Michel Mauny [mailto:michel@mauny.net]
Sent: Monday, October 24, 2005 10:49 AM
To: necula@cs.berkeley.edu
Cc: caml@pauillac.inria.fr; caml-bugs@pauillac.inria.fr
Subject: Re: [Caml-devel] Bug in set_binary_mode out for
cygwin (#3818)

George,

As you noticed, set_binary_mode_out has no effect on Cygwin.

However, I'm not sure this is the source of your problem:
stdout seems to be already in "binary mode" in Cygwin.
Printing "\n" | od -c shows no translation of newlines, while
translations of "\n" into "\r\n"
do occur when printing to files.

Do you have a small example showing the bug in camlp4?

Cheers,

-- Michel

necula@cs.berkeley.edu wrote:

Full_Name: George Necula
Version: 3.08.4
OS: Win XP/cygwin
Submission from: adsl-63-204-134-90.dsl.snfc21.pacbell.net
(63.204.134.90)

I have discovered that "set_binary_mode_out c true" has no
effect on
cygwin. In
fact, this function does nothing except when compiling for Windows
(but not for
cygwin).

This is a big problem because it prevents the use of the -pp option
for ocamlc
on cygwin. camlp4 will print the AST to stdout and will use
set_binary_mode_out.
When ocamlc reads in the AST it segfaults. The workaround is to make
sure you
add pr_o.cmo to the preprocessor command, to ensure that
Ocaml source
is piped
to stdout.


Caml-devel mailing list
Caml-devel@yquem.inria.fr
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-devel

--
Michel

Mail: michel@mauny.net
Tél: (+33) 1 3080 9638 (Home)
(+33) 8 7379 9638 (VoIP@Home)
(+33) 6 7319 3516 (Cell.)
(+33) 1 4552 5388 (ENSTA)
(+33) 1 3963 5796 (INRIA)

@vicuna
Copy link
Author

vicuna commented Oct 24, 2005

Comment author: administrator

George,

As you noticed, set_binary_mode_out has no effect on Cygwin.

However, I'm not sure this is the source of your problem: stdout seems
to be already in "binary mode" in Cygwin. Printing "\n" | od -c shows
no translation of newlines, while translations of "\n" into "\r\n"
do occur when printing to files.

Do you have a small example showing the bug in camlp4?

Cheers,

-- Michel

necula@cs.berkeley.edu wrote:

Full_Name: George Necula
Version: 3.08.4
OS: Win XP/cygwin
Submission from: adsl-63-204-134-90.dsl.snfc21.pacbell.net (63.204.134.90)

I have discovered that "set_binary_mode_out c true" has no effect on
cygwin. In
fact, this function does nothing except when compiling for Windows
(but not for
cygwin).

This is a big problem because it prevents the use of the -pp option
for ocamlc
on cygwin. camlp4 will print the AST to stdout and will use
set_binary_mode_out.
When ocamlc reads in the AST it segfaults. The workaround is to make
sure you
add pr_o.cmo to the preprocessor command, to ensure that Ocaml source
is piped
to stdout.


Caml-devel mailing list
Caml-devel@yquem.inria.fr
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-devel

--
Michel

Mail: michel@mauny.net
Tél: (+33) 1 3080 9638 (Home)
(+33) 8 7379 9638 (VoIP@Home)
(+33) 6 7319 3516 (Cell.)
(+33) 1 4552 5388 (ENSTA)
(+33) 1 3963 5796 (INRIA)

@vicuna
Copy link
Author

vicuna commented Oct 25, 2005

Comment author: administrator

Merci beaucoup! Ca marche.

George.

-----Original Message-----
From: Michel Mauny [mailto:caml-bugs@pauillac.inria.fr]
Sent: Tuesday, October 25, 2005 1:47 PM
To: necula@cs.berkeley.edu
Subject: Re: Bug in set_binary_mode out for cygwin (#3818)

I have discovered that "set_binary_mode_out c true" has no
effect on cygwin.
In
fact, this function does nothing except when compiling for Windows
(but not
for
cygwin).

Right. I activated set_binary_mode_out (as well as the predicate
caml_channel_binary_mode) on Cygwin.

The patch is easy:

diff -r1.71 byterun/io.c
125c125
< #ifdef _WIN32

#if defined(_WIN32) || defined(CYGWIN)
516c516
< #ifdef _WIN32


#if defined(_WIN32) || defined(CYGWIN)

then make clean', configure' and rebuild ocaml.

-- Michel

@vicuna
Copy link
Author

vicuna commented Oct 25, 2005

Comment author: administrator

I have discovered that "set_binary_mode_out c true" has no effect on cygwin.
In
fact, this function does nothing except when compiling for Windows (but not
for
cygwin).

Right. I activated set_binary_mode_out (as well as the predicate
caml_channel_binary_mode) on Cygwin.

The patch is easy:

diff -r1.71 byterun/io.c
125c125
< #ifdef _WIN32

#if defined(_WIN32) || defined(CYGWIN)
516c516
< #ifdef _WIN32


#if defined(_WIN32) || defined(CYGWIN)

then make clean', configure' and rebuild ocaml.

-- Michel

@vicuna
Copy link
Author

vicuna commented Oct 25, 2005

Comment author: administrator

Don't do the suggested change in driver/pparse.ml, it would break using sed as
a
preprocessor. -DD

Fixed 2005-10-25 -MM

@vicuna vicuna closed this as completed Oct 25, 2005
@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant