settings: localize global data Move the settings global data teardown into its own separate function, instead of intermingled with the global state.
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
diff --git a/src/global.c b/src/global.c
index d2a25a5..0642977 100644
--- a/src/global.c
+++ b/src/global.c
@@ -11,6 +11,7 @@
#include "hash.h"
#include "sysdir.h"
#include "filter.h"
+#include "settings.h"
#include "merge_driver.h"
#include "pool.h"
#include "streams/registry.h"
@@ -37,15 +38,14 @@ static git_global_init_fn git__init_callbacks[] = {
git_openssl_stream_global_init,
git_mbedtls_stream_global_init,
git_mwindow_global_init,
- git_pool_global_init
+ git_pool_global_init,
+ git_settings_global_init
};
static git_global_shutdown_fn git__shutdown_callbacks[ARRAY_SIZE(git__init_callbacks)];
static git_atomic git__n_shutdown_callbacks;
static git_atomic git__n_inits;
-char *git__user_agent;
-char *git__ssl_ciphers;
void git__on_shutdown(git_global_shutdown_fn callback)
{
@@ -93,9 +93,6 @@ static void shutdown_common(void)
if (cb != NULL)
cb();
}
-
- git__free(git__user_agent);
- git__free(git__ssl_ciphers);
}
/**
diff --git a/src/global.h b/src/global.h
index db41dad..2a7c727 100644
--- a/src/global.h
+++ b/src/global.h
@@ -35,7 +35,4 @@ typedef void (*git_global_shutdown_fn)(void);
extern void git__on_shutdown(git_global_shutdown_fn callback);
-extern const char *git_libgit2__user_agent(void);
-extern const char *git_libgit2__ssl_ciphers(void);
-
#endif
diff --git a/src/settings.c b/src/settings.c
index 69ebcb7..0426093 100644
--- a/src/settings.c
+++ b/src/settings.c
@@ -29,6 +29,28 @@
#include "streams/openssl.h"
#include "streams/mbedtls.h"
+/* Declarations for tuneable settings */
+extern size_t git_mwindow__window_size;
+extern size_t git_mwindow__mapped_limit;
+extern size_t git_mwindow__file_limit;
+extern size_t git_indexer__max_objects;
+extern bool git_disable_pack_keep_file_checks;
+
+char *git__user_agent;
+char *git__ssl_ciphers;
+
+static void git_settings_global_shutdown(void)
+{
+ git__free(git__user_agent);
+ git__free(git__ssl_ciphers);
+}
+
+int git_settings_global_init(void)
+{
+ git__on_shutdown(git_settings_global_shutdown);
+ return 0;
+}
+
int git_libgit2_version(int *major, int *minor, int *rev)
{
*major = LIBGIT2_VER_MAJOR;
@@ -56,13 +78,6 @@ int git_libgit2_features(void)
;
}
-/* Declarations for tuneable settings */
-extern size_t git_mwindow__window_size;
-extern size_t git_mwindow__mapped_limit;
-extern size_t git_mwindow__file_limit;
-extern size_t git_indexer__max_objects;
-extern bool git_disable_pack_keep_file_checks;
-
static int config_level_to_sysdir(int config_level)
{
int val = -1;
@@ -88,9 +103,6 @@ static int config_level_to_sysdir(int config_level)
return val;
}
-extern char *git__user_agent;
-extern char *git__ssl_ciphers;
-
const char *git_libgit2__user_agent(void)
{
return git__user_agent;
diff --git a/src/settings.h b/src/settings.h
new file mode 100644
index 0000000..dc42ce9
--- /dev/null
+++ b/src/settings.h
@@ -0,0 +1,11 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
+
+extern int git_settings_global_init(void);
+
+extern const char *git_libgit2__user_agent(void);
+extern const char *git_libgit2__ssl_ciphers(void);
diff --git a/src/streams/openssl.c b/src/streams/openssl.c
index 6a490d1..58265c1 100644
--- a/src/streams/openssl.c
+++ b/src/streams/openssl.c
@@ -12,6 +12,7 @@
#include <ctype.h>
#include "global.h"
+#include "settings.h"
#include "posix.h"
#include "stream.h"
#include "streams/socket.h"
diff --git a/src/transports/http.h b/src/transports/http.h
index c02109c..5c360b8 100644
--- a/src/transports/http.h
+++ b/src/transports/http.h
@@ -9,6 +9,7 @@
#define INCLUDE_transports_http_h__
#include "buffer.h"
+#include "settings.h"
#include "httpclient.h"
#define GIT_HTTP_REPLAY_MAX 15
diff --git a/tests/core/useragent.c b/tests/core/useragent.c
index c6c5220..2ce935b 100644
--- a/tests/core/useragent.c
+++ b/tests/core/useragent.c
@@ -1,5 +1,5 @@
#include "clar_libgit2.h"
-#include "global.h"
+#include "settings.h"
void test_core_useragent__get(void)
{