summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <[email protected]>2016-10-31 21:12:03 +0100
committerCarlos Martín Nieto <[email protected]>2016-10-31 21:14:08 +0100
commita37f7f30ff94e32b20866cf2fa28496c60826278 (patch)
treee329c89e802e83dcbfa615e366350afe4412ab01
parentadb1770ff3f9d7b242ba8b8eac31186db92a46d5 (diff)
Panic if libgit2 is not thread-aware
Go calling C is inherently multi-threaded. If libgit2 cannot handle threading, then we're going to crash at some random point. Crash right at the start so we know what's happening.
-rw-r--r--git.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/git.go b/git.go
index a3c40e3..53b1a12 100644
--- a/git.go
+++ b/git.go
@@ -124,6 +124,15 @@ func init() {
C.git_libgit2_init()
+ // Due to the multithreaded nature of Go and its interaction with
+ // calling C functions, we cannot work with a library that was not built
+ // with multi-threading support. The most likely outcome is a segfault
+ // or panic at an incomprehensible time, so let's make it easy by
+ // panicking right here.
+ if Features()&FeatureThreads == 0 {
+ panic("libgit2 was not built with threading support")
+ }
+
// This is not something we should be doing, as we may be
// stomping all over someone else's setup. The user should do
// this themselves or use some binding/wrapper which does it