Merge branch 'master' into repo-init
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437
diff --git a/src/common.h b/src/common.h
index 821ee88..287df60 100644
--- a/src/common.h
+++ b/src/common.h
@@ -49,7 +49,6 @@ typedef SSIZE_T ssize_t;
#include "git2/common.h"
#include "util.h"
#include "thread-utils.h"
-#include "errors.h"
#include "bswap.h"
#define GIT_PATH_MAX 4096
diff --git a/src/errors.c b/src/errors.c
index ac73402..df8b822 100644
--- a/src/errors.c
+++ b/src/errors.c
@@ -1,34 +1,6 @@
#include "common.h"
#include "thread-utils.h" /* for GIT_TLS */
-#if defined(GIT_TLS)
-/* compile-time constant initialization required */
-GIT_TLS int git_errno = 0;
-
-#elif defined(GIT_HAS_PTHREAD)
-
-static pthread_key_t errno_key;
-
-static void init_errno(void) __attribute__((constructor));
-static void init_errno(void)
-{
- pthread_key_create(&errno_key, free);
-}
-
-int *git__errno_storage(void)
-{
- int *e = pthread_getspecific(errno_key);
- if (!e) {
-#undef calloc
- e = calloc(1, sizeof(*e));
-#define calloc(a,b) GIT__FORBID_MALLOC
- pthread_setspecific(errno_key, e);
- }
- return e;
-}
-
-#endif
-
static struct {
int num;
const char *str;
diff --git a/src/errors.h b/src/errors.h
deleted file mode 100644
index d22a03b..0000000
--- a/src/errors.h
+++ /dev/null
@@ -1,24 +0,0 @@
-#ifndef INCLUDE_errors_h__
-#define INCLUDE_errors_h__
-
-#include "git2/errors.h"
-
-/* convenience functions */
-GIT_INLINE(int) git_int_error(int code)
-{
- git_errno = code;
- return code;
-}
-
-GIT_INLINE(int) git_os_error(void)
-{
- return git_int_error(GIT_EOSERR);
-}
-
-GIT_INLINE(void) *git_ptr_error(int code)
-{
- git_errno = code;
- return NULL;
-}
-
-#endif
diff --git a/src/fileops.c b/src/fileops.c
index 5f5944c..7b11c9c 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -5,13 +5,13 @@
int gitfo_open(const char *path, int flags)
{
int fd = open(path, flags | O_BINARY);
- return fd >= 0 ? fd : git_os_error();
+ return fd >= 0 ? fd : GIT_EOSERR;
}
int gitfo_creat(const char *path, int mode)
{
int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, mode);
- return fd >= 0 ? fd : git_os_error();
+ return fd >= 0 ? fd : GIT_EOSERR;
}
int gitfo_read(git_file fd, void *buf, size_t cnt)
@@ -22,11 +22,11 @@ int gitfo_read(git_file fd, void *buf, size_t cnt)
if (r < 0) {
if (errno == EINTR || errno == EAGAIN)
continue;
- return git_os_error();
+ return GIT_EOSERR;
}
if (!r) {
errno = EPIPE;
- return git_os_error();
+ return GIT_EOSERR;
}
cnt -= r;
b += r;
@@ -42,11 +42,11 @@ int gitfo_write(git_file fd, void *buf, size_t cnt)
if (r < 0) {
if (errno == EINTR || errno == EAGAIN)
continue;
- return git_os_error();
+ return GIT_EOSERR;
}
if (!r) {
errno = EPIPE;
- return git_os_error();
+ return GIT_EOSERR;
}
cnt -= r;
b += r;
@@ -93,7 +93,7 @@ off_t gitfo_size(git_file fd)
{
struct stat sb;
if (gitfo_fstat(fd, &sb))
- return git_os_error();
+ return GIT_EOSERR;
return sb.st_size;
}
@@ -152,13 +152,13 @@ int gitfo_move_file(char *from, char *to)
if (!rename(from, to))
return GIT_SUCCESS;
- return git_os_error();
+ return GIT_EOSERR;
}
int gitfo_map_ro(git_map *out, git_file fd, off_t begin, size_t len)
{
if (git__mmap(out, len, GIT_PROT_READ, GIT_MAP_SHARED, fd, begin) < GIT_SUCCESS)
- return git_os_error();
+ return GIT_EOSERR;
return GIT_SUCCESS;
}
@@ -276,7 +276,7 @@ int gitfo_dirent(
dir = opendir(path);
if (!dir)
- return git_os_error();
+ return GIT_EOSERR;
while ((de = readdir(dir)) != NULL) {
size_t de_len;
diff --git a/src/git2/common.h b/src/git2/common.h
index 9d014c0..bbeec41 100644
--- a/src/git2/common.h
+++ b/src/git2/common.h
@@ -55,6 +55,8 @@
__attribute__((visibility("default"))) \
GIT_TLS \
type
+#elif defined(_MSC_VER)
+# define GIT_EXTERN_TLS(type) __declspec(dllexport) GIT_TLS type
#else
# define GIT_EXTERN_TLS(type) extern GIT_TLS type
#endif
diff --git a/src/git2/errors.h b/src/git2/errors.h
index 98bce48..627e67c 100644
--- a/src/git2/errors.h
+++ b/src/git2/errors.h
@@ -33,16 +33,6 @@
*/
GIT_BEGIN_DECL
-/** The git errno. */
-#if defined(GIT_TLS)
-GIT_EXTERN_TLS(int) git_errno;
-
-#elif defined(GIT_HAS_PTHREAD)
-# define git_errno (*git__errno_storage())
-GIT_EXTERN(int *) git__errno_storage(void);
-
-#endif
-
/**
* strerror() for the Git library
* @param num The error code to explain
diff --git a/src/unix/map.c b/src/unix/map.c
index a41bae0..3008008 100644
--- a/src/unix/map.c
+++ b/src/unix/map.c
@@ -40,7 +40,7 @@ int git__mmap(git_map *out, size_t len, int prot, int flags, int fd, off_t offse
out->data = mmap(NULL, len, mprot, mflag, fd, offset);
if (!out->data || out->data == MAP_FAILED)
- return git_os_error();
+ return GIT_EOSERR;
out->len = len;
return GIT_SUCCESS;
diff --git a/src/util.c b/src/util.c
index debf526..a3b62ef 100644
--- a/src/util.c
+++ b/src/util.c
@@ -3,30 +3,6 @@
#include <stdarg.h>
#include <stdio.h>
-void *git__malloc(size_t n)
-{
- void *r = malloc(n);
- if (!r)
- return git_ptr_error(GIT_ENOMEM);
- return r;
-}
-
-void *git__calloc(size_t a, size_t b)
-{
- void *r = calloc(a, b);
- if (!r)
- return git_ptr_error(GIT_ENOMEM);
- return r;
-}
-
-char *git__strdup(const char *s)
-{
- char *r = strdup(s);
- if (!r)
- return git_ptr_error(GIT_ENOMEM);
- return r;
-}
-
int git__fmt(char *buf, size_t buf_sz, const char *fmt, ...)
{
va_list va;
diff --git a/src/util.h b/src/util.h
index 5f64725..808b20d 100644
--- a/src/util.h
+++ b/src/util.h
@@ -3,28 +3,16 @@
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
-extern void *git__malloc(size_t);
-extern void *git__calloc(size_t, size_t);
-extern char *git__strdup(const char *);
-
-#ifndef GIT__NO_HIDE_MALLOC
-# define GIT__FORBID_MALLOC do_not_use_malloc_directly
-
-# ifdef malloc
-# undef malloc
-# endif
-# define malloc(a) GIT__FORBID_MALLOC
-
-# ifdef calloc
-# undef calloc
-# endif
-# define calloc(a,b) GIT__FORBID_MALLOC
-
-# ifdef strdup
-# undef strdup
-# endif
-# define strdup(a) GIT__FORBID_MALLOC
-#endif
+/*
+ * Don't wrap malloc/calloc.
+ * Use the default versions in glibc, and make
+ * sure that any methods that allocate memory
+ * return a GIT_ENOMEM error when allocation
+ * fails.
+ */
+#define git__malloc malloc
+#define git__calloc calloc
+#define git__strdup strdup
extern int git__fmt(char *, size_t, const char *, ...)
GIT_FORMAT_PRINTF(3, 4);
diff --git a/tests/t0001-errno.c b/tests/t0001-errno.c
deleted file mode 100644
index acb12d3..0000000
--- a/tests/t0001-errno.c
+++ /dev/null
@@ -1,12 +0,0 @@
-#include "test_lib.h"
-#include "errors.h"
-
-BEGIN_TEST(errno_zero_on_init)
- must_be_true(git_errno == 0);
-END_TEST
-
-BEGIN_TEST(set_ENOTOID)
- must_be_true(GIT_ENOTOID != 0);
- git_errno = GIT_ENOTOID;
- must_be_true(git_errno == GIT_ENOTOID);
-END_TEST
diff --git a/wscript b/wscript
index 104de86..85f7385 100644
--- a/wscript
+++ b/wscript
@@ -74,15 +74,15 @@ def build(bld):
# command '[build|clean|install|uninstall]-static'
if bld.variant == 'static':
- build_library(bld, 'cstlib')
+ build_library(bld, 'static')
# command '[build|clean|install|uninstall]-shared'
elif bld.variant == 'shared':
- build_library(bld, 'cshlib')
+ build_library(bld, 'shared')
# command '[build|clean]-tests'
elif bld.variant == 'tests':
- build_library(bld, 'cshlib')
+ build_library(bld, 'objects')
build_tests(bld)
# command 'build|clean|install|uninstall': by default, run
@@ -91,9 +91,15 @@ def build(bld):
from waflib import Options
Options.commands = [bld.cmd + '-shared', bld.cmd + '-static'] + Options.commands
-def build_library(bld, lib_str):
- directory = bld.path
+def build_library(bld, build_type):
+
+ BUILD = {
+ 'shared' : bld.shlib,
+ 'static' : bld.stlib,
+ 'objects' : bld.objects
+ }
+ directory = bld.path
sources = directory.ant_glob('src/*.c')
# Compile platform-dependant code
@@ -106,15 +112,12 @@ def build_library(bld, lib_str):
sources.append('src/ppc/sha1.c')
else:
sources.append('src/block-sha1/sha1.c')
-
- features = ['c', lib_str]
-
#------------------------------
# Build the main library
#------------------------------
# either as static or shared;
- bld(features=features,
+ BUILD[build_type](
source=sources,
target='git2',
includes='src',
@@ -123,8 +126,8 @@ def build_library(bld, lib_str):
)
# On Unix systems, build the Pkg-config entry file
- if bld.env.PLATFORM == 'unix':
- bld(rule="""sed -e 's#@prefix@#$(prefix)#' -e 's#@libdir@#$(libdir)#' < ${SRC} > ${TGT}""",
+ if bld.env.PLATFORM == 'unix' and bld.is_install:
+ bld(rule="""sed -e 's#@prefix@#${PREFIX}#' -e 's#@libdir@#${LIBDIR}#' < ${SRC} > ${TGT}""",
source='libgit2.pc.in',
target='libgit2.pc',
install_path='${LIBDIR}/pkgconfig',
@@ -134,6 +137,13 @@ def build_library(bld, lib_str):
bld.install_files('${PREFIX}/include', directory.find_node('src/git2.h'))
bld.install_files('${PREFIX}/include/git2', directory.ant_glob('src/git2/*.h'))
+ # On Unix systems, let them know about installation
+ if bld.env.PLATFORM == 'unix' and bld.cmd in ['install-static', 'install-shared']:
+ bld.add_post_fun(call_ldconfig)
+
+def call_ldconfig(bld):
+ bld.exec_command('/sbin/ldconfig')
+
def grep_test_header(text, test_file):
return '\n'.join(l for l in test_file.read().splitlines() if text in l)
@@ -144,7 +154,7 @@ def build_tests(bld):
return
directory = bld.path
- resources_path = directory.find_node('tests/resources/').abspath()
+ resources_path = directory.find_node('tests/resources/').abspath().replace('\\', '/')
# Common object with the Test library methods
bld.objects(source=['tests/test_helpers.c', 'tests/test_lib.c'], includes=['src', 'tests'], target='test_helper')
@@ -167,7 +177,6 @@ def build_tests(bld):
includes=['src', 'tests'],
defines=['TEST_TOC="%s.toc"' % test_name, 'TEST_RESOURCES="%s"' % resources_path],
install_path=None,
- shlibpath=[directory.find_node('build/tests/').abspath()],
use=['test_helper', 'git2'] + ALL_LIBS # link with all the libs we know
# libraries which are not enabled won't link
)
@@ -200,28 +209,17 @@ class _run_tests(Context):
fun = 'run_tests'
def run_tests(ctx):
- import shutil, tempfile, sys, os
+ import shutil, tempfile, sys
failed = False
test_folder = tempfile.mkdtemp()
- build_folder = ctx.path.find_node('build/tests/')
test_glob = 'build/tests/t????-*'
- environ = os.environ.copy()
- environ_tail = ""
if sys.platform == 'win32':
test_glob += '.exe'
- environ_var, environ_separator = 'PATH', ';'
- else:
- environ_var, environ_separator = 'LD_LIBRARY_PATH', ':'
-
- if environ_var in environ:
- environ_tail = environ_separator + environ[environ_var]
-
- environ[environ_var] = build_folder.abspath() + environ_tail
for test in ctx.path.ant_glob(test_glob):
- if ctx.exec_command(test.abspath(), cwd=test_folder, env=environ) != 0:
+ if ctx.exec_command(test.abspath(), cwd=test_folder) != 0:
failed = True
break