Skip to content

Commit 95ad2a6

Browse files
committed
Merge branch 'sp/msysgit'
* sp/msysgit: compat/ has subdirectories: do not omit them in 'make clean' Fix typo in nedmalloc warning fix MinGW: Teach Makefile to detect msysgit and apply specific settings Fix warnings in nedmalloc when compiling with GCC 4.4.0 Add custom memory allocator to MinGW and MacOS builds MinGW readdir reimplementation to support d_type connect.c: Support PuTTY plink and TortoisePlink as SSH on Windows git: browsing paths with spaces when using the start command MinGW: fix warning about implicit declaration of _getch() test-chmtime: work around Windows limitation Work around a regression in Windows 7, causing erase_in_line() to crash sometimes Quiet make: do not leave Windows behind MinGW: GCC >= 4 does not need SNPRINTF_SIZE_CORR anymore Conflicts: Makefile
2 parents 0a17b2c + 021fcd9 commit 95ad2a6

File tree

13 files changed

+7194
-9
lines changed

13 files changed

+7194
-9
lines changed

Makefile

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ all::
191191
#
192192
# Define NO_CROSS_DIRECTORY_HARDLINKS if you plan to distribute the installed
193193
# programs as a tar, where bin/ and libexec/ might be on different file systems.
194+
#
195+
# Define USE_NED_ALLOCATOR if you want to replace the platforms default
196+
# memory allocators with the nedmalloc allocator written by Niall Douglas.
194197

195198
GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE
196199
@$(SHELL_PATH) ./GIT-VERSION-GEN
@@ -856,7 +859,6 @@ ifneq (,$(findstring MINGW,$(uname_S)))
856859
pathsep = ;
857860
NO_PREAD = YesPlease
858861
NO_OPENSSL = YesPlease
859-
NO_CURL = YesPlease
860862
NO_LIBGEN_H = YesPlease
861863
NO_SYMLINK_HEAD = YesPlease
862864
NO_IPV6 = YesPlease
@@ -865,7 +867,6 @@ ifneq (,$(findstring MINGW,$(uname_S)))
865867
NO_STRCASESTR = YesPlease
866868
NO_STRLCPY = YesPlease
867869
NO_MEMMEM = YesPlease
868-
NO_PTHREADS = YesPlease
869870
NEEDS_LIBICONV = YesPlease
870871
OLD_ICONV = YesPlease
871872
NO_C99_FORMAT = YesPlease
@@ -880,14 +881,26 @@ ifneq (,$(findstring MINGW,$(uname_S)))
880881
NO_ST_BLOCKS_IN_STRUCT_STAT = YesPlease
881882
NO_NSEC = YesPlease
882883
USE_WIN32_MMAP = YesPlease
884+
USE_NED_ALLOCATOR = YesPlease
883885
UNRELIABLE_FSTAT = UnfortunatelyYes
884886
OBJECT_CREATION_USES_RENAMES = UnfortunatelyNeedsTo
885887
COMPAT_CFLAGS += -D__USE_MINGW_ACCESS -DNOGDI -Icompat -Icompat/regex -Icompat/fnmatch
886-
COMPAT_CFLAGS += -DSNPRINTF_SIZE_CORR=1
887888
COMPAT_CFLAGS += -DSTRIP_EXTENSION=\".exe\"
888889
COMPAT_OBJS += compat/mingw.o compat/fnmatch/fnmatch.o compat/regex/regex.o compat/winansi.o
889890
EXTLIBS += -lws2_32
890891
X = .exe
892+
ifneq (,$(wildcard ../THIS_IS_MSYSGIT))
893+
htmldir=doc/git/html/
894+
prefix =
895+
INSTALL = /bin/install
896+
EXTLIBS += /mingw/lib/libz.a
897+
NO_R_TO_GCC_LINKER = YesPlease
898+
INTERNAL_QSORT = YesPlease
899+
THREADED_DELTA_SEARCH = YesPlease
900+
else
901+
NO_CURL = YesPlease
902+
NO_PTHREADS = YesPlease
903+
endif
891904
endif
892905
ifneq (,$(findstring arm,$(uname_M)))
893906
ARM_SHA1 = YesPlease
@@ -1188,6 +1201,11 @@ ifdef UNRELIABLE_FSTAT
11881201
BASIC_CFLAGS += -DUNRELIABLE_FSTAT
11891202
endif
11901203

1204+
ifdef USE_NED_ALLOCATOR
1205+
COMPAT_CFLAGS += -DUSE_NED_ALLOCATOR -DOVERRIDE_STRDUP -DNDEBUG -DREPLACE_SYSTEM_ALLOCATOR -Icompat/nedmalloc
1206+
COMPAT_OBJS += compat/nedmalloc/nedmalloc.o
1207+
endif
1208+
11911209
ifeq ($(TCLTK_PATH),)
11921210
NO_TCLTK=NoThanks
11931211
endif
@@ -1262,7 +1280,7 @@ SHELL = $(SHELL_PATH)
12621280

12631281
all:: shell_compatibility_test $(ALL_PROGRAMS) $(BUILT_INS) $(OTHER_PROGRAMS) GIT-BUILD-OPTIONS
12641282
ifneq (,$X)
1265-
$(foreach p,$(patsubst %$X,%,$(filter %$X,$(ALL_PROGRAMS) $(BUILT_INS) git$X)), test '$p' -ef '$p$X' || $(RM) '$p';)
1283+
$(QUIET_BUILT_IN)$(foreach p,$(patsubst %$X,%,$(filter %$X,$(ALL_PROGRAMS) $(BUILT_INS) git$X)), test '$p' -ef '$p$X' || $(RM) '$p';)
12661284
endif
12671285

12681286
all::
@@ -1704,7 +1722,7 @@ distclean: clean
17041722
$(RM) configure
17051723

17061724
clean:
1707-
$(RM) *.o mozilla-sha1/*.o arm/*.o ppc/*.o compat/*.o xdiff/*.o \
1725+
$(RM) *.o mozilla-sha1/*.o arm/*.o ppc/*.o compat/*.o compat/*/*.o xdiff/*.o \
17081726
$(LIB_FILE) $(XDIFF_LIB)
17091727
$(RM) $(ALL_PROGRAMS) $(BUILT_INS) git$X
17101728
$(RM) $(TEST_PROGRAMS)

compat/mingw.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "../git-compat-util.h"
22
#include "win32.h"
3+
#include <conio.h>
34
#include "../strbuf.h"
45

56
unsigned int _CRT_fmode = _O_BINARY;
@@ -1171,3 +1172,62 @@ char *getpass(const char *prompt)
11711172
fputs("\n", stderr);
11721173
return strbuf_detach(&buf, NULL);
11731174
}
1175+
1176+
#ifndef NO_MINGW_REPLACE_READDIR
1177+
/* MinGW readdir implementation to avoid extra lstats for Git */
1178+
struct mingw_DIR
1179+
{
1180+
struct _finddata_t dd_dta; /* disk transfer area for this dir */
1181+
struct mingw_dirent dd_dir; /* Our own implementation, including d_type */
1182+
long dd_handle; /* _findnext handle */
1183+
int dd_stat; /* 0 = next entry to read is first entry, -1 = off the end, positive = 0 based index of next entry */
1184+
char dd_name[1]; /* given path for dir with search pattern (struct is extended) */
1185+
};
1186+
1187+
struct dirent *mingw_readdir(DIR *dir)
1188+
{
1189+
WIN32_FIND_DATAA buf;
1190+
HANDLE handle;
1191+
struct mingw_DIR *mdir = (struct mingw_DIR*)dir;
1192+
1193+
if (!dir->dd_handle) {
1194+
errno = EBADF; /* No set_errno for mingw */
1195+
return NULL;
1196+
}
1197+
1198+
if (dir->dd_handle == (long)INVALID_HANDLE_VALUE && dir->dd_stat == 0)
1199+
{
1200+
handle = FindFirstFileA(dir->dd_name, &buf);
1201+
DWORD lasterr = GetLastError();
1202+
dir->dd_handle = (long)handle;
1203+
if (handle == INVALID_HANDLE_VALUE && (lasterr != ERROR_NO_MORE_FILES)) {
1204+
errno = err_win_to_posix(lasterr);
1205+
return NULL;
1206+
}
1207+
} else if (dir->dd_handle == (long)INVALID_HANDLE_VALUE) {
1208+
return NULL;
1209+
} else if (!FindNextFileA((HANDLE)dir->dd_handle, &buf)) {
1210+
DWORD lasterr = GetLastError();
1211+
FindClose((HANDLE)dir->dd_handle);
1212+
dir->dd_handle = (long)INVALID_HANDLE_VALUE;
1213+
/* POSIX says you shouldn't set errno when readdir can't
1214+
find any more files; so, if another error we leave it set. */
1215+
if (lasterr != ERROR_NO_MORE_FILES)
1216+
errno = err_win_to_posix(lasterr);
1217+
return NULL;
1218+
}
1219+
1220+
/* We get here if `buf' contains valid data. */
1221+
strcpy(dir->dd_dir.d_name, buf.cFileName);
1222+
++dir->dd_stat;
1223+
1224+
/* Set file type, based on WIN32_FIND_DATA */
1225+
mdir->dd_dir.d_type = 0;
1226+
if (buf.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
1227+
mdir->dd_dir.d_type |= DT_DIR;
1228+
else
1229+
mdir->dd_dir.d_type |= DT_REG;
1230+
1231+
return (struct dirent*)&dir->dd_dir;
1232+
}
1233+
#endif // !NO_MINGW_REPLACE_READDIR

compat/mingw.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,32 @@ int main(int argc, const char **argv) \
235235
return mingw_main(argc, argv); \
236236
} \
237237
static int mingw_main(c,v)
238+
239+
#ifndef NO_MINGW_REPLACE_READDIR
240+
/*
241+
* A replacement of readdir, to ensure that it reads the file type at
242+
* the same time. This avoid extra unneeded lstats in git on MinGW
243+
*/
244+
#undef DT_UNKNOWN
245+
#undef DT_DIR
246+
#undef DT_REG
247+
#undef DT_LNK
248+
#define DT_UNKNOWN 0
249+
#define DT_DIR 1
250+
#define DT_REG 2
251+
#define DT_LNK 3
252+
253+
struct mingw_dirent
254+
{
255+
long d_ino; /* Always zero. */
256+
union {
257+
unsigned short d_reclen; /* Always zero. */
258+
unsigned char d_type; /* Reimplementation adds this */
259+
};
260+
unsigned short d_namlen; /* Length of name in d_name. */
261+
char d_name[FILENAME_MAX]; /* File name. */
262+
};
263+
#define dirent mingw_dirent
264+
#define readdir(x) mingw_readdir(x)
265+
struct dirent *mingw_readdir(DIR *dir);
266+
#endif // !NO_MINGW_REPLACE_READDIR

compat/nedmalloc/License.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Boost Software License - Version 1.0 - August 17th, 2003
2+
3+
Permission is hereby granted, free of charge, to any person or organization
4+
obtaining a copy of the software and accompanying documentation covered by
5+
this license (the "Software") to use, reproduce, display, distribute,
6+
execute, and transmit the Software, and to prepare derivative works of the
7+
Software, and to permit third-parties to whom the Software is furnished to
8+
do so, all subject to the following:
9+
10+
The copyright notices in the Software and this entire statement, including
11+
the above license grant, this restriction and the following disclaimer,
12+
must be included in all copies of the Software, in whole or in part, and
13+
all derivative works of the Software, unless such copies or derivative
14+
works are solely in the form of machine-executable object code generated by
15+
a source language processor.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
20+
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
21+
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
22+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23+
DEALINGS IN THE SOFTWARE.

compat/nedmalloc/Readme.txt

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
nedalloc v1.05 15th June 2008:
2+
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
3+
4+
by Niall Douglas (http://www.nedprod.com/programs/portable/nedmalloc/)
5+
6+
Enclosed is nedalloc, an alternative malloc implementation for multiple
7+
threads without lock contention based on dlmalloc v2.8.4. It is more
8+
or less a newer implementation of ptmalloc2, the standard allocator in
9+
Linux (which is based on dlmalloc v2.7.0) but also contains a per-thread
10+
cache for maximum CPU scalability.
11+
12+
It is licensed under the Boost Software License which basically means
13+
you can do anything you like with it. This does not apply to the malloc.c.h
14+
file which remains copyright to others.
15+
16+
It has been tested on win32 (x86), win64 (x64), Linux (x64), FreeBSD (x64)
17+
and Apple MacOS X (x86). It works very well on all of these and is very
18+
significantly faster than the system allocator on all of these platforms.
19+
20+
By literally dropping in this allocator as a replacement for your system
21+
allocator, you can see real world improvements of up to three times in normal
22+
code!
23+
24+
To use:
25+
-=-=-=-
26+
Drop in nedmalloc.h, nedmalloc.c and malloc.c.h into your project.
27+
Configure using the instructions in nedmalloc.h. Run and enjoy.
28+
29+
To test, compile test.c. It will run a comparison between your system
30+
allocator and nedalloc and tell you how much faster nedalloc is. It also
31+
serves as an example of usage.
32+
33+
Notes:
34+
-=-=-=
35+
If you want the very latest version of this allocator, get it from the
36+
TnFOX SVN repository at svn://svn.berlios.de/viewcvs/tnfox/trunk/src/nedmalloc
37+
38+
Because of how nedalloc allocates an mspace per thread, it can cause
39+
severe bloating of memory usage under certain allocation patterns.
40+
You can substantially reduce this wastage by setting MAXTHREADSINPOOL
41+
or the threads parameter to nedcreatepool() to a fraction of the number of
42+
threads which would normally be in a pool at once. This will reduce
43+
bloating at the cost of an increase in lock contention. If allocated size
44+
is less than THREADCACHEMAX, locking is avoided 90-99% of the time and
45+
if most of your allocations are below this value, you can safely set
46+
MAXTHREADSINPOOL to one.
47+
48+
You will suffer memory leakage unless you call neddisablethreadcache()
49+
per pool for every thread which exits. This is because nedalloc cannot
50+
portably know when a thread exits and thus when its thread cache can
51+
be returned for use by other code. Don't forget pool zero, the system pool.
52+
53+
For C++ type allocation patterns (where the same sizes of memory are
54+
regularly allocated and deallocated as objects are created and destroyed),
55+
the threadcache always benefits performance. If however your allocation
56+
patterns are different, searching the threadcache may significantly slow
57+
down your code - as a rule of thumb, if cache utilisation is below 80%
58+
(see the source for neddisablethreadcache() for how to enable debug
59+
printing in release mode) then you should disable the thread cache for
60+
that thread. You can compile out the threadcache code by setting
61+
THREADCACHEMAX to zero.
62+
63+
Speed comparisons:
64+
-=-=-=-=-=-=-=-=-=
65+
See Benchmarks.xls for details.
66+
67+
The enclosed test.c can do two things: it can be a torture test or a speed
68+
test. The speed test is designed to be a representative synthetic
69+
memory allocator test. It works by randomly mixing allocations with frees
70+
with half of the allocation sizes being a two power multiple less than
71+
512 bytes (to mimic C++ stack instantiated objects) and the other half
72+
being a simple random value less than 16Kb.
73+
74+
The real world code results are from Tn's TestIO benchmark. This is a
75+
heavily multithreaded and memory intensive benchmark with a lot of branching
76+
and other stuff modern processors don't like so much. As you'll note, the
77+
test doesn't show the benefits of the threadcache mostly due to the saturation
78+
of the memory bus being the limiting factor.
79+
80+
ChangeLog:
81+
-=-=-=-=-=
82+
v1.05 15th June 2008:
83+
* { 1042 } Added error check for TLSSET() and TLSFREE() macros. Thanks to
84+
Markus Elfring for reporting this.
85+
* { 1043 } Fixed a segfault when freeing memory allocated using
86+
nedindependent_comalloc(). Thanks to Pavel Vozenilek for reporting this.
87+
88+
v1.04 14th July 2007:
89+
* Fixed a bug with the new optimised implementation that failed to lock
90+
on a realloc under certain conditions.
91+
* Fixed lack of thread synchronisation in InitPool() causing pool corruption
92+
* Fixed a memory leak of thread cache contents on disabling. Thanks to Earl
93+
Chew for reporting this.
94+
* Added a sanity check for freed blocks being valid.
95+
* Reworked test.c into being a torture test.
96+
* Fixed GCC assembler optimisation misspecification
97+
98+
v1.04alpha_svn915 7th October 2006:
99+
* Fixed failure to unlock thread cache list if allocating a new list failed.
100+
Thanks to Dmitry Chichkov for reporting this. Futher thanks to Aleksey Sanin.
101+
* Fixed realloc(0, <size>) segfaulting. Thanks to Dmitry Chichkov for
102+
reporting this.
103+
* Made config defines #ifndef so they can be overriden by the build system.
104+
Thanks to Aleksey Sanin for suggesting this.
105+
* Fixed deadlock in nedprealloc() due to unnecessary locking of preferred
106+
thread mspace when mspace_realloc() always uses the original block's mspace
107+
anyway. Thanks to Aleksey Sanin for reporting this.
108+
* Made some speed improvements by hacking mspace_malloc() to no longer lock
109+
its mspace, thus allowing the recursive mutex implementation to be removed
110+
with an associated speed increase. Thanks to Aleksey Sanin for suggesting this.
111+
* Fixed a bug where allocating mspaces overran its max limit. Thanks to
112+
Aleksey Sanin for reporting this.
113+
114+
v1.03 10th July 2006:
115+
* Fixed memory corruption bug in threadcache code which only appeared with >4
116+
threads and in heavy use of the threadcache.
117+
118+
v1.02 15th May 2006:
119+
* Integrated dlmalloc v2.8.4, fixing the win32 memory release problem and
120+
improving performance still further. Speed is now up to twice the speed of v1.01
121+
(average is 67% faster).
122+
* Fixed win32 critical section implementation. Thanks to Pavel Kuznetsov
123+
for reporting this.
124+
* Wasn't locking mspace if all mspaces were locked. Thanks to Pavel Kuznetsov
125+
for reporting this.
126+
* Added Apple Mac OS X support.
127+
128+
v1.01 24th February 2006:
129+
* Fixed multiprocessor scaling problems by removing sources of cache sloshing
130+
* Earl Chew <earl_chew <at> agilent <dot> com> sent patches for the following:
131+
1. size2binidx() wasn't working for default code path (non x86)
132+
2. Fixed failure to release mspace lock under certain circumstances which
133+
caused a deadlock
134+
135+
v1.00 1st January 2006:
136+
* First release

0 commit comments

Comments
 (0)