git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Alexey Borzenkov <snaury@gmail.com>
To: Johannes Sixt <j.sixt@viscovery.net>
Cc: Marius Storm-Olsen <mstormo@gmail.com>,
	git@vger.kernel.org, Johannes.Schindelin@gmx.de,
	msysgit@googlegroups.com, gitster@pobox.com, j6t@kdbg.org,
	lznuaa@gmail.com, raa.lkml@gmail.com,
	Marius Storm-Olsen <marius.storm-olsen@nokia.com>
Subject: Re: [PATCH 04/15] Set _O_BINARY as default fmode for both MinGW and  MSVC
Date: Thu, 17 Sep 2009 00:00:38 +0400	[thread overview]
Message-ID: <e2480c70909161300o3db4b416k8f33ccce2f987c55@mail.gmail.com> (raw)
In-Reply-To: <4AB10F01.9010703@viscovery.net>

On Wed, Sep 16, 2009 at 8:14 PM, Johannes Sixt <j.sixt@viscovery.net> wrote:
>> MinGW set the _CRT_fmode to set both the default fmode and
>> _O_BINARY on stdin/stdout/stderr. Rather use the main()
>> define in mingw.h to set this for both MinGW and MSVC.
>>
>> This will ensure that a MinGW and MSVC build will handle
>> input and output identically.
> This one breaks t5302-pack-index.sh (test 15, "[index v1] 2) create a
> stealth corruption in a delta base reference") in my MinGW build. I have
> yet to find out what exactly goes wrong and how it could be fixed.

Looks like calling _setmode in main is too late for something. :-/

I tried defining int _fmode in mingw.c (which sets msvcrt's _fmode
early, without calling _setmode), and it didn't work either (i.e. the
bug was still happening). So the culprit must be in _setmode. I also
tried logging what index_obj_offset and index_obj_nr are showing, and
here are results:

/* with _CRT_fmode = _O_BINARY */
index_obj_offset: 844032
index_obj_nr: 205

/* without _CRT_fmode = _O_BINARY */
index_obj_offset: 844235
index_obj_nr: 298

I then tried to see what git show-index actually returns there, and
here are several top lines of the results:

/* with _CRT_fmode = _O_BINARY */
850186 0106e17481932f5c223fafadc1d26abc6adf40d6
203652 01179d82b18c252824e20e190543e0e84950d820
15576 0246ff570c396c37ff08c0f5f9d88c84fc21a297
851536 035e7e54cee9eb197af435b6b6dcced489c233f6
376062 03a6f56dbbb556425ef8c43c31519b32eb5629a4
39452 0471b3b8ab8da19f3968dc238e9555f4e48ce858
8230 0483297992ed4cd5ab3b5790912b1f03598ea660
72292 0508b858e01f0367552fb14722388ba48dbd36f7

/* without _CRT_fmode = _O_BINARY */
844235 01a8d3f6d063d48baf40ee656804aa58486a34b2
851754 035e7e54cee9eb197af435b6b6dcced489c233f6
851844 04ff7bd225fbb4842697af96c147a4ddecb6a657
848233 088ddcb945af72c47348b65a63992c71b6b9dbe8
849676 088e69e7ab273e35b4f63ecb1b915a3997f13dff
14825 09bd72201f82a0da14a52230e2ccd0e43529e779
9848 0a5916ad398380ba103d98bad6fa4f2b20b74e75
695905 0ae5469e687083bbf954262873ee8c0c7d017e75

As you can see the hashes are completely different! Unfortunately I
also can't pinpoint where this actually happens... :-/

*several minutes later*

Searching which executables set _fmode and which don't I found the
culprit. test-genrandom.c didn't include git-compat-util.h, so mingw.h
was never included. This caused different random data to be generated,
and as it seems more importantly, of different sizes. Can be fixed
with this patch:

diff --git a/test-genrandom.c b/test-genrandom.c
index 8ad276d..b3c28d9 100644
--- a/test-genrandom.c
+++ b/test-genrandom.c
@@ -4,8 +4,7 @@
  * Copyright (C) 2007 by Nicolas Pitre, licensed under the GPL version 2.
  */

-#include <stdio.h>
-#include <stdlib.h>
+#include "git-compat-util.h"

 int main(int argc, char *argv[])
 {

Or maybe there's a hidden bug in git that gets uncovered with slightly
different random data, I don't know. I'm glad I could finally solve
this mindbending issue. :)

  reply	other threads:[~2009-09-16 20:00 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-16  8:20 [PATCH v4 00/15] Build Git with MSVC Marius Storm-Olsen
2009-09-16  8:20 ` [PATCH 01/15] Avoid declaration after statement Marius Storm-Olsen
2009-09-16  8:20   ` [PATCH 02/15] Add define guards to compat/win32.h Marius Storm-Olsen
2009-09-16  8:20     ` [PATCH 03/15] Change regerror() declaration from K&R style to ANSI C (C89) Marius Storm-Olsen
2009-09-16  8:20       ` [PATCH 04/15] Set _O_BINARY as default fmode for both MinGW and MSVC Marius Storm-Olsen
2009-09-16  8:20         ` [PATCH 05/15] Fix __stdcall placement and function prototype Marius Storm-Olsen
2009-09-16  8:20           ` [PATCH 06/15] Test for WIN32 instead of __MINGW32_ Marius Storm-Olsen
2009-09-16  8:20             ` [PATCH 07/15] Add empty header files for MSVC port Marius Storm-Olsen
2009-09-16  8:20               ` [PATCH 08/15] Add MinGW header files to build git with MSVC Marius Storm-Olsen
2009-09-16  8:20                 ` [PATCH 09/15] Add platform files for MSVC porting Marius Storm-Olsen
2009-09-16  8:20                   ` [PATCH 10/15] Make usage of windows.h lean and mean Marius Storm-Olsen
2009-09-16  8:20                     ` [PATCH 11/15] Define strncasecmp and ftruncate for MSVC Marius Storm-Olsen
2009-09-16  8:20                       ` [PATCH 12/15] Add MSVC to Makefile Marius Storm-Olsen
2009-09-16  8:20                         ` [PATCH 13/15] Add README for MSVC build Marius Storm-Olsen
2009-09-16  8:20                           ` [PATCH 14/15] Add scripts to generate projects for other buildsystems (MSVC vcproj, QMake) Marius Storm-Olsen
2009-09-16  8:20                             ` [RFC 15/15] Tag GIT_VERSION when Git is built with MSVC Marius Storm-Olsen
2009-09-17 20:18                               ` Johannes Sixt
2009-09-18  6:44                                 ` Marius Storm-Olsen
2009-09-17 20:28                             ` [PATCH 14/15] Add scripts to generate projects for other buildsystems (MSVC vcproj, QMake) Johannes Sixt
2009-09-18  6:59                               ` Marius Storm-Olsen
2009-09-18  8:21                                 ` Johannes Sixt
2009-09-23 15:04                             ` Sebastian Schuberth
2009-09-23 20:37                               ` Johannes Schindelin
2009-09-24  6:05                                 ` Marius Storm-Olsen
2009-09-23 10:03                 ` Add MinGW header files to build git with MSVC Sebastian Schuberth
2009-09-23 11:29                   ` Marius Storm-Olsen
2009-09-25  0:18                     ` [msysGit] " Frank Li
2009-09-16 16:14         ` [PATCH 04/15] Set _O_BINARY as default fmode for both MinGW and MSVC Johannes Sixt
2009-09-16 20:00           ` Alexey Borzenkov [this message]
2009-09-17  7:11             ` Johannes Sixt
2009-09-17  7:25               ` Junio C Hamano
2009-09-17  7:27               ` Marius Storm-Olsen
2009-09-17  7:36                 ` Johannes Sixt
2009-09-17  7:53                   ` Marius Storm-Olsen
2009-09-17  8:10                     ` Johannes Sixt
2009-09-17  8:14                       ` Marius Storm-Olsen
2009-09-17  8:39                       ` Alexey Borzenkov
2009-09-17  8:45                         ` Marius Storm-Olsen
2009-09-17  8:57                           ` Alexey Borzenkov
2009-09-17  9:03                         ` Johannes Sixt
2009-09-17  9:28                           ` Marius Storm-Olsen
2009-09-17 13:02                           ` Alexey Borzenkov
2009-09-17 13:30                             ` Johannes Sixt
2009-09-17  8:02         ` Marius Storm-Olsen
2009-09-17 10:44           ` Johannes Sixt
     [not found]             ` <4AB212FA.9080102@viscovery.netm>
2009-09-17 11:04               ` Marius Storm-Olsen
2009-09-16  9:42     ` [msysGit] [PATCH 02/15] Add define guards to compat/win32.h Erik Faye-Lund
2009-09-16 10:10       ` Marius Storm-Olsen
2009-09-23  9:44   ` Avoid declaration after statement Sebastian Schuberth
2009-09-25 13:34     ` Erik Faye-Lund

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e2480c70909161300o3db4b416k8f33ccce2f987c55@mail.gmail.com \
    --to=snaury@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j.sixt@viscovery.net \
    --cc=j6t@kdbg.org \
    --cc=lznuaa@gmail.com \
    --cc=marius.storm-olsen@nokia.com \
    --cc=mstormo@gmail.com \
    --cc=msysgit@googlegroups.com \
    --cc=raa.lkml@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).