git on HP NonStop
Quoted 11 lines
From: Junio C Hamano [mailto:[email protected]]
Sent: Tuesday, August 14, 2012 4:44 PM
To: Joachim Schmitz
Subject: Re: git on HP NonStopQuoted 2 lines · Joachim Schmitz
Interesting, I never mentioned Tandem did I, But still you recognized HP NonStop as that.
No, *you* did in your patch "#ifdef".
Ah, I see.
Quoted 4 lines
Quoted 2 lines
Well, I do care about that platform, but if you don't, there's not much point in me trying to get Tandem specific patches applied, is it?
As long as the change is isolated (i.e. compilation without "#define
TANDEM"
__TANDEM actually
Quoted 1 line
for other people will produce byte-for-byte identical result as before),
and
Quoted 2 lines
cleanly made (i.e. the resulting source code is not littered with "#ifdef TANDEM" in many places), I do not think there is a reason not to have such
a
Quoted 1 line
patchset.
It isn't in many places, only 2 places in git-compat-util.h so far:/usr/local/bin/diff -EBbu ./git-compat-util.h.orig ./git-compat-util.h
git-compat-util.h 2012-08-12 11:26:46 -0500 renamed from git-compat-util.h.orig 2012-07-30 15:50:38 -0500 +2 -1
@@ -74,7 +74,8 @@ # define _XOPEN_SOURCE 500 # endif #elif !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__USLC__) && - !defined(_M_UNIX) && !defined(__sgi) && !defined(__DragonFly__) + !defined(_M_UNIX) && !defined(__sgi) && !defined(__DragonFly__) && \ + !defined(__TANDEM) #define _XOPEN_SOURCE 600 /* glibc2 and AIX 5.3L need 500, OpenBSD needs
600 for S_ISLNK() */
#define _XOPEN_SOURCE_EXTENDED 1 /* AIX 5.3L needs this */ #endif
@@ -98,6 +99,11 @@
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
+#ifdef __TANDEM
+# include <strings.h> /* for strcasecmp() */
+ typedef int intptr_t; /* not "int *" ?!? */
+ typedef unsigned int uintptr_t; /* not "unsigned int *" ?!? */ +#endif
#include <errno.h>
#include <limits.h>
#include <sys/param.h>
Too much? The 2nd part is not necessary NonStop specific, any idea for a better way?
There there's Makefile:/usr/local/bin/diff -EBbu ./Makefile.orig ./Makefile
Makefile 2012-08-14 06:07:16 -0500 renamed from Makefile.orig 2012-07-30 15:50:38 -0500 +10 -0
@@ -1297,6 +1297,45 @@ NO_CURL = NO_EXPAT = endif +ifeq ($(uname_S),NONSTOP_KERNEL) + CC = cc -c99 # needs some C99 features, "inline" is just one of them + CFLAGS= -g -O + prefix = /usr/local + + # as detected by './configure' + #NO_CURL = YesPlease # missdetected, disabled, see below + NEEDS_SSL_WITH_CURL = YesPlease # added manually, see above + HAVE_LIBCHARSET_H=YesPlease + NEEDS_LIBICONV = YesPlease # needs libiconv first, changed further
down
+ NO_SYS_SELECT_H=UnfortunatelyYes
+ NO_D_TYPE_IN_DIRENT = YesPlease
+ NO_HSTRERROR=YesPlease
+ NO_STRCASESTR=YesPlease
+ NO_FNMATCH_CASEFOLD = YesPlease
+ NO_MEMMEM = YesPlease
+ NO_STRLCPY = YesPlease
+ NO_SETENV = YesPlease
+ NO_UNSETENV = YesPlease
+ NO_MKDTEMP = YesPlease
+ NO_MKSTEMPS = YesPlease
+ OLD_ICONV=UnfortunatelyYes # currently libiconv-1.9.1
+ NO_REGEX=YesPlease # Why? ToDo?
+ NO_PTHREADS=UnfortunatelyYes # ToDo? Using PUT, maybe?
+
+ # our's are in ${prefix}/bin
+ PERL_PATH = ${prefix}/bin/perl
+ PYTHON_PATH = ${prefix}/bin/python+
+ # not detected (nor checked for) by './configure'
+ COMPAT_CFLAGS += -DSA_RESTART=0 # we don't have SA_RESTART on
NonStop
+ COMPAT_CFLAGS += -DHAVE_STRING_H=1 # needed incompat/fnmatch/fnmatch.c
+ NO_ST_BLOCKS_IN_STRUCT_STAT = YesPlease # we don't have that on
NonStop
+ NO_NSEC = YesPlease # we don't have that on NonStop + NO_PREAD = YesPlease # we could use floss_pread though? + NO_MMAP = YesPlease # we could use floss_mmap though? + # newly implemented further down + NO_POLL = YesPlease # we could use floss_poll though?
+endif
ifneq (,$(findstring MINGW,$(uname_S)))
pathsep = ;
NO_PREAD = YesPlease
@@ -1526,6 +1565,11 @@
LIB_4_CRYPTO = $(OPENSSL_LINK) -lcrypto
endif
endif
+ifndef NO_GETTEXT
+ifndef LIBC_CONTAINS_LIBINTL
+ EXTLIBS += -lintl
+endif
+endif
ifdef NEEDS_LIBICONV
ifdef ICONVDIR
BASIC_CFLAGS += -I$(ICONVDIR)/include
@@ -1538,11 +1582,6 @@
ifdef NEEDS_LIBGEN
EXTLIBS += -lgen Endif
-ifndef NO_GETTEXT
-ifndef LIBC_CONTAINS_LIBINTL
- EXTLIBS += -lintl
-endif
-endif
ifdef NEEDS_SOCKET
EXTLIBS += -lsocket
endif
@@ -1591,6 +1630,11 @@
BASIC_CFLAGS += -DNO_GETTEXT
USE_GETTEXT_SCHEME ?= fallthrough
endif
+ifdef NO_POLL
+ NO_SYS_POLL_H = YesPlease
+ COMPAT_CFLAGS += -DNO_POLL -Icompat/win32 # so it finds poll.h
+ COMPAT_OBJS += compat/win32/poll.o
+endif
ifdef NO_STRCASESTR
COMPAT_CFLAGS += -DNO_STRCASESTR
COMPAT_OBJS += compat/strcasestr.oHow das that look to you?
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Finally, I would prefer to see any message that is addressed to me as the project maintainer to be Cc'ed to the list. I feel 80% of my time writing
this
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
message wasted, as the contents of it would have helped not just you but 4 other people who want to get their toes in the development community, but you robbed them the chance of seeing it.
Sorry for having wasted your time, but you could just as easily have CCed the list on your reply, couldn't you?
No, responding to a private message in public without permission goes
against
Quoted 1 line
generally accepted netiquette (I am OK if you respond to this or to the
previous
Quoted 1 line
message from me in public).
OK, understood and accepted. Herewith you have my permission ;-)
Quoted 5 lines
Quoted 3 lines
The use of
getrlimit(RLIMIT_NOFILE, ...)vs.sysconf(_SC_OPEN_MAX)insha1_file.c, I believe the later to be more portable, also it is used in other places already (namelycompat/win32/poll.c)Careful. Getting rid of the use of
getrlimit()from shared code by
introducing
Quoted 1 line
our own abstraction to be implemented in compat/* for each platform is
fine,
Quoted 1 line
but that does not mean
sysconf()is acceptable by all platforms (your
finding
Quoted 1 line
use of
sysconf()in compat/win32 merely means Win is OK with it).
Well. NonStop is OK with it too.
And I've brackets with #ifdef _SC_OPEN_MAX, just like in compat/win23:/usr/local/bin/diff -EBbu ./sha1_file.c.orig ./sha1_file.c
sha1_file.c 2012-08-14 02:42:03 -0500 renamed from sha1_file.c.orig 2012-07-30 15:50:38 -0500 +4 -0
@@ -747,6 +747,9 @@ return error("packfile %s index unavailable", p->pack_name); if (!pack_max_fds) { +#ifdef _SC_OPEN_MAX + unsigned int max_fds = sysconf(_SC_OPEN_MAX); +#else struct rlimit lim; unsigned int max_fds;
@@ -754,6 +757,7 @@ die_errno("cannot get RLIMIT_NOFILE"); max_fds = lim.rlim_cur; +#endif /* Save 3 for stdin/stdout/stderr, 22 for work */ if (25 < max_fds)
Can it get any better?
Quoted 4 lines
Quoted 2 lines
The use of
curl_easy_strerror()inhelp.cwithout checking for a proper curl version (>=7.12.0)I do not recall the minimum version of curl we support offhand, but if
there is a
Quoted 1 line
clean workaround that would be good.
Well, I really have none but to disable that part:/usr/local/bin/diff -EBbu ./http.c.orig ./http.c
http.c 2012-08-14 02:49:43 -0500 renamed from http.c.orig 2012-07-30 15:50:38 -0500 +1 -0
@@ -805,10 +805,12 @@ ret = HTTP_REAUTH; } } else { +#if LIBCURL_VERSION_NUM >= 0x070c00 /* no curl_easy_strerror() before that
*/
if (!curl_errorstr[0])
strlcpy(curl_errorstr,curl_easy_strerror(results.curl_result),
sizeof(curl_errorstr));
+#endif
ret = HTTP_ERROR;
}
} else {It certainly is a workaround, whether it is clean or clean enough for now is to you to decide ;-)
Bye, Jojo
Review line 105
Quoted 8 lines · Joachim Schmitz
(quoted diff) +4
-0@@ -98,6 +99,11 @@ #include <stdlib.h> #include <stdarg.h> #include <string.h> +#ifdef __TANDEM +# include <strings.h> /* for strcasecmp() */ + typedef int intptr_t; /* not "int *" ?!? */ + typedef unsigned int uintptr_t; /* not "unsigned int *" ?!? */
Of course not. intptr_t is an integral value capable of holding a pointer; it is not a pointer to int (because that would really be redundant to int*.)
Quoted 8 lines
From: Jan Engelhardt [mailto:[email protected]]
Sent: Sunday, August 19, 2012 6:26 PM
To: Joachim Schmitz
Cc: 'Junio C Hamano'; [email protected]
Subject: RE: git on HP NonStopOn Tuesday 2012-08-14 17:52, Joachim Schmitz wrote:
Quoted 10 lines
Review line 105
Quoted 8 lines
(quoted diff) +4
-0@@ -98,6 +99,11 @@ #include <stdlib.h> #include <stdarg.h> #include <string.h> +#ifdef __TANDEM +# include <strings.h> /* for strcasecmp() */ + typedef int intptr_t; /* not "int *" ?!? */ + typedef unsigned int uintptr_t; /* not "unsigned int *" ?!? */Of course not.
intptr_tis an integral value capable of holding a pointer;
it is not
Quoted 1 line
a pointer to int (because that would really be redundant to int*.)
OK, thanks for the clarification.
Another issue I stumbled across:
There are numerous places (well, some 10) were something like the following is done
int var = var;
char *othervar = othervar;
Here this leads to Compiler warnings 'variable "var" is used before its value is set' on NonStop. This self-initialization seems to be a GCC extension (?), but even gcc has a -Winit-self option to warn about this. Shouldn't that better be like the following?
int var = 0;
char *othervar = NULL;
What is the reason for using that self-init stuff? I don't think it is really portable, is it?
Bye, Jojo
Am 8/20/2012 12:36, schrieb Joachim Schmitz:
Quoted 7 lines
int var = var;
char *othervar = othervar;...
What is the reason for using that self-init stuff? I don't think it is really portable, is it?
It is used to avoid "var may be used uninitialized" warnings for some compilers. Officially (according to the C standard), it is undefined behavior. But I've observed considerable resistance by Junio to fix this properly. Therefore, unless you can show that your compiler generates unusable code you better live with the "self-initialization" warnings.
-- Hannes
Quoted 10 lines
From: Johannes Sixt [mailto:[email protected]]
Sent: Monday, August 20, 2012 12:57 PM
To: Joachim Schmitz
Cc: 'Jan Engelhardt'; 'Junio C Hamano'; [email protected]
Subject: Re: git on HP NonStopAm 8/20/2012 12:36, schrieb Joachim Schmitz:
Quoted 3 lines
int var = var;
char *othervar = othervar;
Quoted 6 lines
Quoted 4 lines
...
What is the reason for using that self-init stuff? I don't think it is really portable, is it?
It is used to avoid "var may be used uninitialized" warnings for some
compilers.
Well, it results in a similar warning on NonStop. "var is used before it is set" and I think this is equally bad.
In either case we don't know what the content of that var is.
E.g. in wt_status.c the variable 'status' is set at only one place, but later it is switched on. If lucky we get to the default case and die. So why not just
int status = 0;
Quoted 1 line
Officially (according to the C standard), it is undefined behavior.
Yes, I had that suspicion. Not good to rely in this...
Quoted 1 line
But I've observed considerable resistance by Junio to fix this properly.
What's the reason behind that?
Quoted 2 lines
Therefore, unless
you can show that your compiler generates unusable code you better live
with
Quoted 1 line
the "self-initialization" warnings.
So far I can't, so I guess I'll have to live with the warnings, but don't quite like it.
Quoted 1 line
-- Hannes
Bye, Jojo
Quoted 6 lines · Johannes Sixt
Am 8/20/2012 12:36, schrieb Joachim Schmitz:
Quoted 5 lines
int var = var;
char *othervar = othervar;...
Quoted 7 lines
Quoted 2 lines
What is the reason for using that self-init stuff? I don't think it is really portable, is it?
It is used to avoid "var may be used uninitialized" warnings for some compilers. Officially (according to the C standard), it is undefined behavior. But I've observed considerable resistance by Junio to fix this properly.
I had resisted
- int foo = foo;
+ int foo = 0;in the past. If some compiler is not seeing that "foo" is never used uninitialized, such a compiler will generate an unnecessary initialization, so it is not a _proper_ fix anyway (in fact, I do not think a proper fix exists, short of simplifying the code so that less sophisticated compilers can see that "foo" is never used uninitialized).
So, no, I never resisted a "proper" fix. I resisted swapping an unsatisfactory workaround with another.
Between the two unsatisfactory workarounds, the latter (explicit and unnecessary assignment to an innocuous value) is lessor of two evils, so I do not particularly mind it, though. Indeed, I think more recent history shows that we have such changes.
Quoted 22 lines
From: Junio C Hamano [mailto:[email protected]]
Sent: Monday, August 20, 2012 6:30 PM
To: Johannes Sixt
Cc: Joachim Schmitz; 'Jan Engelhardt'; [email protected]
Subject: Re: git on HP NonStopQuoted 6 lines · Johannes Sixt
Am 8/20/2012 12:36, schrieb Joachim Schmitz:
Quoted 5 lines
int var = var;
char *othervar = othervar;...
Quoted 7 lines
Quoted 2 lines
What is the reason for using that self-init stuff? I don't think it is really portable, is it?
It is used to avoid "var may be used uninitialized" warnings for some compilers. Officially (according to the C standard), it is undefined behavior. But I've observed considerable resistance by Junio to fix this properly.
Quoted 6 lines
I had resisted
- int foo = foo; + int foo = 0;in the past. If some compiler is not seeing that "foo" is never used
uninitialized,
Quoted 1 line
such a compiler will generate an unnecessary initialization, so it is not
a
Quoted 2 lines
_proper_ fix anyway (in fact, I do not think a proper fix exists, short of simplifying the code so that less sophisticated compilers can see that
"foo" is
Quoted 3 lines
never used uninitialized).
So, no, I never resisted a "proper" fix. I resisted swapping an
unsatisfactory
Quoted 4 lines
workaround with another.
Between the two unsatisfactory workarounds, the latter (explicit and unnecessary assignment to an innocuous value) is lessor of two evils, so I
do not
Quoted 1 line
particularly mind it, though. Indeed, I think more recent history shows
that we
Quoted 1 line
have such changes.
OK, so let's have a look at code, current git,builtin/cat-file.c, line 196:
void *contents = contents;
This variable is set later in an if branch (if (print_contents == BATCH), but not in the else branch. It is later used always under the same condition as the one under which it is set.
Apparently is is malloc_d storage (there a "free(content);"), so there's no harm al all in initializing it with NULL, even if it only appeases a stupid compiler.
The next one, builtin/fast-export.c, line 486:
struct commit *commit = commit;
it is set in a switch statement, but not in every case, as far as I can see. Hmm, maybe it is, and I just get lost in the code
And it is used directly after the switch, hopefully set to something reasonable.
Why take the risk and not set it to NULL?
Next one, builtin/rev-list.c, line 390:
int reaches = reaches, all = all;
revs.commits = find_bisection(revs.commits, &reaches, &all,
bisect_find_all);Seem pretty pointless to initialize them, provided find_bisection doesn't read them. Does it?
I'm too Next one, lazy to check... I'd just set them to 0 and stop worrying.
Next one, fast-import.c, line 2268:
struct object_entry *oe = oe;
os gets set in en if and an else branch, but not in then intermediate else if branch!
It is checked for !NULL later, so it should really get initialized to NULL in the first place!
Same file, line 2437, same variable name, same story!
Same file, line 2616, variable e, it is used in an if branch but set after that!
Same file again, line 2917, variable oe again. Same story as above.
Next file, ll-merge.c, line
static const struct ll_merge_options default_opts;
Somewhat different story here, compiler warning claims " const variable
"default_opts" requires an initializer"
Possible fix:
static const struct ll_merge_options default_opts = {0};next file, match-trees.c, line 75ff:
const unsigned char *elem1 = elem1;
const unsigned char *elem2 = elem2;
const char *path1 = path1;
const char *path2 = path2;
unsigned mode1 = mode1;
unsigned mode2 = mode2;Some get set, some not, depending on code path, but all get used, with possibly bogus content.
Next file, merge-recursive.c, line 1903:
struct tree *mrtree = mrtree;
passed on my address to another function, which hopefully knows how to treat
it. It woult be learer and simpler to just have
struct tree *mrtree = NULL;wouldn't it?
Next file, run-command.c, line 272:
int failed_errno = failed_errno;
Set deeply nested in some cases. Seems to be used reasonably, but again, why take chanses= 0 is a goot errno ;-)
Next file, submodule.c, line 265:
struct commit *left = left, *right = right;
As far as I can see it is not set properly before it gets used in some cases.
Next filen, transport.c, line 106:
int cmp = cmp, len;
I seem to see code paths whet it is used without being set properly
Next file, vcs-svn/svndiff.c, line 299.... oh, that one has been fixed and initialized to -1.
Next (and last) file, wt-status.c, line 267:
int status = status;
It apparently does get set properly before use. So here it once may once again just make a compiler happy to set it to 0.
Bye, Jojo
Quoted 10 lines · Joachim Schmitz
OK, so let's have a look at code, current git,
builtin/cat-file.c, line 196:void *contents = contents;This variable is set later in an if branch (if (
print_contents== BATCH), but not in the else branch. It is later used always under the same condition as the one under which it is set.
Apparently is ismalloc_dstorage (there a "free(content);"), so there's no harm al all in initializing it with NULL, even if it only appeases a stupid compiler.
It actually is harmful. See below.
Quoted 7 lines
The next one,
builtin/fast-export.c, line 486:struct commit *commit = commit;it is set in a switch statement, but not in every case, as far as I can see. Hmm, maybe it is, and I just get lost in the code
And it is used directly after the switch, hopefully set to something reasonable.
Why take the risk and not set it to NULL?
Ditto.
Quoted 8 lines
Next one,
builtin/rev-list.c, line 390:int reaches = reaches, all = all; revs.commits = find_bisection(revs.commits, &reaches, &all, bisect_find_all);Seem pretty pointless to initialize them, provided
find_bisectiondoesn't read them. Does it?
That is why they are not initializations but marks to the compiler to signal "you may be stupid enough to think they are used before initialized or assigned, but that is not the case". Initializing them would be pointless.
Quoted 5 lines
Next one,
fast-import.c, line 2268:struct object_entry *oe = oe;os gets set in en if and an else branch, but not in then intermediate else if branch!
Look again. If the recent code is too complex for you to understand, go back to 10e8d68 (Correct compiler warnings in fast-import., 2007-02-06) and read the function.
The control flow of the early part of that function dictates that either oe is assigned *or* inline_data is set to 1. When inline_data is false, oe is always set.
The compiler was too stupid to read that, and that is why the (confusing) idiom to mark it for the stupid compiler was used.
There are a few reasons why I do not think this self-assignment idiom or initializing the variable to an innocuous-looking random value is a particularly good thing to do when you see compiler warnings.
If the compiler suspects the variable might be unused, you should always look at it and follow the flow yourself. Once you know it is a false alarm, you can use the idiom to squelch the warning, and it at the same serves as a note to others that you verified the flow and made sure it is a false warning.
When the next person wants to touch the code, if the person knows the use of the idiom, it only serves as a warning to be extra careful not to introduce a new codepath that reads the variable without setting, as the compiler no longer helps him. If the person who touches the code is as clueless as the compiler and cannot follow the codepath to see the variable is never used uninitialized, the result will be a lot worse.
That is the reason why I do not think the idiom to squelch the compiler is such a good thing. Careless people touch the code, so "oe = oe" initialization carefully placed in the original version does not necessarily stay as a useful documentation.
But if you use "oe = NULL" as a way to squelch the warning in the first place, it is no better than "oe = oe". In a sense, it is even worse, as it just looks like any other initialization and gives a false impression that the remainder of the code is written in such a way that it tolerates oe being NULL in any codepath, or there is some assignment before that before the code reaches places where oe cannot be NULL. That is different from what "oe = oe" initializaion documents---in the codepath protected by "if (inline_data)", it isn't just "oe can safely be NULL there"; instead it is "oe can safely be *any* value there, because we don't use it". Of course, if you explicitly initialized oe to NULL, even if you introduce a codepath where oe cannot be NULL later, you won't get a warning from the compiler, so it is no better than "oe = oe".
And that is the reason why I do not think initialization to an innocuous-looking random value (e.g. NULL) is a good answer, either.
When both are not good, replacing "oe = oe" with "oe = NULL" didn't make much sense, especially when the former _could_ be used better by more careful people. And that is the resistance J6t remembers.
But when recent compilers started to warn "oe = oe" that itself is undefined, the equation changed. The idiom ceased to be a way to squelch the incorrect compiler warning (which was the primary point of its use---the documentation value is secondary, as what we document is "we are squelching a false alarm", but we no longer are squelching anything).
See 4a5de8d (vcs-svn: avoid self-assignment in dummy initialization of pre_off, 2012-06-01), and 58ebd98 (vcs-svn/svndiff.c: squelch false "unused" warning from gcc, 2012-01-27) that it updated, for an example of how we are migrating away from "oe = oe" idiom.
In any case, I already said initializing to 0 is OK in my previous message, I think, so if you are seeing warning from the compiler on uninitialized variables in your new code, you know you should
(1) first follow the codepath to make sure it is a false alarm (if
it isn't, fix the code);
(2) then see if you can simplify your code so that it is crystal clear even to the stupid compiler that you are not using an uninitialized variable; and
(3) if you can't, then initialize it to some known bad value, avoiding the "oe = oe" idiom.
Is there anything more to discuss on this topic?
Quoted 15 lines
-----Original Message-----
From: Junio C Hamano [mailto:[email protected]]
Sent: Tuesday, August 21, 2012 4:06 AM
To: Joachim Schmitz
Cc: 'Johannes Sixt'; 'Jan Engelhardt'; [email protected]
Subject: Re: git on HP NonStopQuoted 4 lines · Joachim Schmitz
OK, so let's have a look at code, current git,
builtin/cat-file.c, line 196:void *contents = contents;
Quoted 8 lines
Quoted 6 lines
This variable is set later in an if branch (if (
print_contents== BATCH), but not in the else branch. It is later used always under the same condition as the one under which it is set. Apparently is ismalloc_dstorage (there a "free(content);"), so there's no harm al all in initializing it with NULL, even if it only appeases a stupid compiler.It actually is harmful. See below.
Harmful to initialize with NULL or to use that undefined behavoir?
I checked what our compiler does here: after having warned about "vlues us used before it is set: it actually dies seem to have initializes the value to 0 resp. NULL.
So here there's no harm done in avoiding undefined behavior and set it to 0 resp NULL in the first place.
Quoted 7 lines
Quoted 6 lines
The next one,
builtin/fast-export.c, line 486:
struct commit *commit = commit; it is set in a switch
statement, but not in every case, as far as I can see. Hmm, maybe it is, and I just get lost in the code And it is used directly after the switch, hopefully set to something reasonable. Why take the risk and not set it to NULL?
Quoted 6 lines
Ditto.
Quoted 4 lines
Next one,
builtin/rev-list.c, line 390:
int reaches = reaches, all = all;revs.commits = find_bisection(revs.commits, &reaches,
&all,
Quoted 6 lines
Quoted 4 lines
bisect_find_all);Seem pretty pointless to initialize them, provided
find_bisectiondoesn't read them. Does it?That is why they are not initializations but marks to the compiler to
signal "you
Quoted 1 line
may be stupid enough to think they are used before initialized or
assigned, but
Quoted 9 lines
that is not the case". Initializing them would be pointless.
Quoted 5 lines
Next one,
fast-import.c, line 2268:struct object_entry *oe = oe;os gets set in en if and an else branch, but not in then intermediate else if branch!
Look again. If the recent code is too complex for you to understand, go
back to
Quoted 1 line
10e8d68 (Correct compiler warnings in fast-import., 2007-02-06) and read
the
Quoted 3 lines
function.
The control flow of the early part of that function dictates that either
oe is
Quoted 1 line
assigned *or*
inline_datais set to 1. Wheninline_datais false, oe is
always
Quoted 7 lines
set.
The compiler was too stupid to read that, and that is why the (confusing) idiom to mark it for the stupid compiler was used.
There are a few reasons why I do not think this self-assignment idiom or initializing the variable to an innocuous-looking random value is a
particularly
Quoted 3 lines
good thing to do when you see compiler warnings.
If the compiler suspects the variable might be unused, you should always
look
Quoted 1 line
at it and follow the flow yourself. Once you know it is a false alarm,
you can
Quoted 1 line
use the idiom to squelch the warning, and it at the same serves as a note
to
Quoted 3 lines
others that you verified the flow and made sure it is a false warning.
When the next person wants to touch the code, if the person knows the use
of
Quoted 1 line
the idiom, it only serves as a warning to be extra careful not to
introduce a new
Quoted 1 line
codepath that reads the variable without setting, as the compiler no
longer
Quoted 1 line
helps him. If the person who touches the code is as clueless as the
compiler
Quoted 1 line
and cannot follow the codepath to see the variable is never used
uninitialized,
Quoted 3 lines
the result will be a lot worse.
That is the reason why I do not think the idiom to squelch the compiler is
such a
Quoted 1 line
good thing. Careless people touch the code, so "oe = oe" initialization
carefully
Quoted 4 lines
placed in the original version does not necessarily stay as a useful documentation.
But if you use "oe = NULL" as a way to squelch the warning in the first
place, it
Quoted 1 line
is no better than "oe = oe". In a sense, it is even worse, as it just
looks like any
Quoted 1 line
other initialization and gives a false impression that the remainder of
the code
Quoted 1 line
is written in such a way that it tolerates oe being NULL in any codepath,
or
Quoted 1 line
there is some assignment before that before the code reaches places where
oe
Quoted 1 line
cannot be NULL. That is different from what "oe = oe" initializaion
documents--
Quoted 1 line
-in the codepath protected by "if (
inline_data)", it isn't just "oe can
safely be
Quoted 1 line
NULL there"; instead it is "oe can safely be *any* value there, because we
don't
Quoted 1 line
use it". Of course, if you explicitly initialized oe to NULL, even if you
introduce
Quoted 4 lines
a codepath where oe cannot be NULL later, you won't get a warning from the compiler, so it is no better than "oe = oe".
And that is the reason why I do not think initialization to an
innocuous-looking
Quoted 7 lines
random value (e.g. NULL) is a good answer, either.
When both are not good, replacing "oe = oe" with "oe = NULL" didn't make much sense, especially when the former _could_ be used better by more careful people. And that is the resistance J6t remembers.
But when recent compilers started to warn "oe = oe" that itself is
undefined,
Quoted 1 line
the equation changed. The idiom ceased to be a way to squelch the
incorrect
Quoted 1 line
compiler warning (which was the primary point of its use---the
documentation
Quoted 1 line
value is secondary, as what we document is "we are squelching a false
alarm",
Quoted 3 lines
but we no longer are squelching anything).
See 4a5de8d (vcs-svn: avoid self-assignment in dummy initialization of
pre_off,
Quoted 1 line
2012-06-01), and 58ebd98 (
vcs-svn/svndiff.c: squelch false "unused"
warning
Quoted 1 line
from gcc, 2012-01-27) that it updated, for an example of how we are
migrating
Quoted 3 lines
away from "oe = oe" idiom.
In any case, I already said initializing to 0 is OK in my previous
message, I think,
Quoted 1 line
so if you are seeing warning from the compiler on uninitialized variables
in
Quoted 5 lines
your new code, you know you should
(1) first follow the codepath to make sure it is a false alarm (if
it isn't, fix the code);
Quoted 8 lines
(2) then see if you can simplify your code so that it is crystal clear even to the stupid compiler that you are not using an uninitialized variable; and
(3) if you can't, then initialize it to some known bad value, avoiding the "oe = oe" idiom.
Is there anything more to discuss on this topic?
Which of the ones I told you about should get fixed?
Bye, Jojo
Quoted 24 lines · Joachim Schmitz
Quoted 15 lines
-----Original Message-----
From: Junio C Hamano [mailto:[email protected]]
Sent: Tuesday, August 21, 2012 4:06 AM
To: Joachim Schmitz
Cc: 'Johannes Sixt'; 'Jan Engelhardt'; [email protected]
Subject: Re: git on HP NonStopQuoted 4 lines · Joachim Schmitz
OK, so let's have a look at code, current git,
builtin/cat-file.c, line 196:void *contents = contents;Quoted 8 lines
Quoted 6 lines
This variable is set later in an if branch (if (
print_contents== BATCH), but not in the else branch. It is later used always under the same condition as the one under which it is set. Apparently is ismalloc_dstorage (there a "free(content);"), so there's no harm al all in initializing it with NULL, even if it only appeases a stupid compiler.It actually is harmful. See below.
Quoted 8 lines
Harmful to initialize with NULL or to use that undefined behavoir?
I checked what our compiler does here: after having warned about "vlues us used before it is set: it actually dies seem to have initializes the value to 0 resp. NULL.
So here there's no harm done in avoiding undefined behavior and set it to 0 resp NULL in the first place.
There is harm in tricking future programmers into thinking that the initialization actually means something, which some of them do.
It's unlikely that you're the one to maintain that code forever, and the "var = var" idiom is used widely within git with a clear meaning as a hint to programmers who read a bit of git code. If they aren't used to that idiom, they usually investigate it in the code and pretty quickly realize that what it means.
Signature · 7 lines
Andreas Ericsson [email protected] OP5 AB www.op5.se Tel: +46 8-230225 Fax: +46 8-230231 Considering the successes of the wars on alcohol, poverty, drugs and terror, I think we should give some serious thought to declaring war on peace.
Quoted 40 lines
From: Andreas Ericsson [mailto:[email protected]]
Sent: Thursday, August 23, 2012 10:24 AM
To: Joachim Schmitz
Cc: 'Junio C Hamano'; 'Johannes Sixt'; 'Jan Engelhardt'; [email protected]
Subject: Re: git on HP NonStopQuoted 24 lines · Joachim Schmitz
Quoted 15 lines
-----Original Message-----
From: Junio C Hamano [mailto:[email protected]]
Sent: Tuesday, August 21, 2012 4:06 AM
To: Joachim Schmitz
Cc: 'Johannes Sixt'; 'Jan Engelhardt'; [email protected]
Subject: Re: git on HP NonStopQuoted 4 lines · Joachim Schmitz
OK, so let's have a look at code, current git,
builtin/cat-file.c, line 196:void *contents = contents;Quoted 8 lines
Quoted 6 lines
This variable is set later in an if branch (if (
print_contents== BATCH), but not in the else branch. It is later used always under the same condition as the one under which it is set. Apparently is ismalloc_dstorage (there a "free(content);"), so there's no harm al all in initializing it with NULL, even if it only appeases a stupid compiler.It actually is harmful. See below.
Quoted 8 lines
Harmful to initialize with NULL or to use that undefined behavoir?
I checked what our compiler does here: after having warned about "vlues us used before it is set: it actually dies seem to have initializes the value to 0 resp. NULL.
So here there's no harm done in avoiding undefined behavior and set it to 0 resp NULL in the first place.
Quoted 2 lines
There is harm in tricking future programmers into thinking that the initialization actually means something, which some of them do.
Hmm, OK, I can agree to that.
Quoted 1 line
It's unlikely that you're the one to maintain that code forever,
It is unlike for me to ever have to maintain this code. Currently that's Junio's job and I won't apply for in ;-)
Quoted 1 line
and the "var = var" idiom is used widely within git
This is overstating it a bit. I went thru the entire code and reported all places I could find in an earlier email. I went back and counted: It is used in 11 files, at 15 places, for 21 variables.
OK, I may have missed a few more that were in code paths my compiler didn't see, but still some 21+ isn't really much.
Quoted 1 line
with a clear meaning
Only if you call undefined behavior a 'clear meaning"!
Quoted 3 lines
as a hint to programmers who read a bit of git code. If they aren't used to that idiom, they usually investigate it in the code and pretty quickly realize that what it means.
Whether I realize what it means, is irrelevant, my compiler does not and warns about it, and as per the ANSI/ICO C standard it invokes undefined behavior.
If a proper initialization is meaningless for these cases, don't do them at all, let the stupid compiler complain about it and the clever programmer check whether the warning is useful, but don't avoid a compiler warning on one compiler by introducing undefined behavior and provoke a compiler warning on another.
Bye, Jojo