Merge upstream (skunkwerks) and update Snappy to 1.1.8
diff --git a/.gitignore b/.gitignore
index 17d172f..d722831 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,3 +11,37 @@
 c_src/snappy/*.d
 c_src/*.d
 compile_commands.json
+
+### Elixir ###
+/_build
+/cover
+/deps
+/doc
+/.fetch
+erl_crash.dump
+*.ez
+*.beam
+/config/*.secret.exs
+.elixir_ls/
+
+### Elixir Patch ###
+
+### Erlang ###
+.eunit
+*.o
+*.plt
+.concrete/DEV_MODE
+
+# rebar 2.x
+.rebar
+rel/example_project
+ebin/*.beam
+deps
+
+# rebar 3
+.rebar3
+_build/
+_checkouts/
+
+### Erlang Patch ###
+rebar3.crashdump
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..16c6297
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,27 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+language: erlang
+
+otp_release:
+  - 22.0
+  - 21.3
+  - 20.3
+  - 19.3
+  - 18.2
+  - 17.5
+
+script:
+  - make check
diff --git a/README.md b/README.md
index f4c945d..b851eec 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@
 
 Google snappy's official repository and bug tracking system is at:
 
-* http://code.google.com/p/snappy/
+* https://github.com/google/snappy
 
 Its source is included in this project.
 
diff --git a/c_src/erl_nif_compat.h b/c_src/erl_nif_compat.h
index b8eb9b0..0fc5528 100644
--- a/c_src/erl_nif_compat.h
+++ b/c_src/erl_nif_compat.h
@@ -27,66 +27,6 @@
 #include "erl_nif.h"
 
 
-#if ERL_NIF_MAJOR_VERSION == 0 && ERL_NIF_MINOR_VERSION == 1
-#define OTP_R13B03
-#elif ERL_NIF_MAJOR_VERSION == 1 && ERL_NIF_MINOR_VERSION == 0
-#define OTP_R13B04
-#elif ERL_NIF_MAJOR_VERSION == 2 && ERL_NIF_MINOR_VERSION == 0
-#define OTP_R14A
-#define OTP_R14B
-#define OTP_R14B01
-#elif ERL_NIF_MAJOR_VERSION == 2 && ERL_NIF_MINOR_VERSION == 1
-#define OTP_R14B02
-#endif
-
-
-#ifdef OTP_R13B03
-
-#define enif_open_resource_type_compat enif_open_resource_type
-#define enif_alloc_resource_compat enif_alloc_resource
-#define enif_release_resource_compat enif_release_resource
-#define enif_alloc_binary_compat enif_alloc_binary
-#define enif_alloc_compat enif_alloc
-#define enif_release_binary_compat enif_release_binary
-#define enif_free_compat enif_free
-#define enif_get_atom_compat enif_get_atom
-#define enif_priv_data_compat enif_get_data
-#define enif_make_uint_compat enif_make_ulong
-
-#define enif_make_existing_atom_compat(E, N, R, Enc) \
-    enif_make_existing_atom(E, N, R)
-
-#define enif_make_string_compat(E, B, Enc) \
-    enif_make_string(E, B)
-
-#endif /* R13B03 */
-
-
-#ifdef OTP_R13B04
-
-#define enif_open_resource_type_compat enif_open_resource_type
-#define enif_alloc_resource_compat enif_alloc_resource
-#define enif_release_resource_compat enif_release_resource
-#define enif_alloc_binary_compat enif_alloc_binary
-#define enif_realloc_binary_compat enif_realloc_binary
-#define enif_release_binary_compat enif_release_binary
-#define enif_alloc_compat enif_alloc
-#define enif_free_compat enif_free
-#define enif_get_atom_compat enif_get_atom
-#define enif_priv_data_compat enif_priv_data
-#define enif_make_string_compat enif_make_string
-#define enif_make_uint_compat enif_make_uint
-
-#define enif_make_existing_atom_compat(E, N, R, Enc) \
-    enif_make_existing_atom(E, N, R)
-
-
-#endif /* R13B04 */
-
-
-/* OTP R14A and future releases */
-#if !defined(OTP_R13B03) && !defined(OTP_R13B04)
-
 #define enif_open_resource_type_compat(E, N, D, F, T) \
     enif_open_resource_type(E, NULL, N, D, F, T)
 
@@ -119,8 +59,6 @@
 #define enif_make_existing_atom_compat enif_make_existing_atom
 #define enif_make_uint_compat enif_make_uint
 
-#endif  /* R14 and future releases */
-
 
 #ifdef __cplusplus
 }
diff --git a/c_src/snappy_nif.cc b/c_src/snappy_nif.cc
index a8d8665..f9d0139 100644
--- a/c_src/snappy_nif.cc
+++ b/c_src/snappy_nif.cc
@@ -47,6 +47,8 @@
         ErlNifBinary& getBin();
 
     private:
+        void EnsureSize(size_t append_length);
+
         ErlNifEnv* env;
         ErlNifBinary bin;
         size_t length;
@@ -71,6 +73,7 @@
 SnappyNifSink::Append(const char *data, size_t n)
 {
     if(data != (SC_PTR(bin.data) + length)) {
+        EnsureSize(n);
         memcpy(bin.data + length, data, n);
     }
     length += n;
@@ -79,16 +82,7 @@
 char*
 SnappyNifSink::GetAppendBuffer(size_t len, char* scratch)
 {
-    size_t sz;
-    
-    if((length + len) > bin.size) {
-        sz = (len * 4) < 8192 ? 8192 : (len * 4);
-
-        if(!enif_realloc_binary_compat(env, &bin, bin.size + sz)) {
-            throw std::bad_alloc();
-        }
-    }
-
+    EnsureSize(len);
     return SC_PTR(bin.data) + length;
 }
 
@@ -103,6 +97,19 @@
     return bin;
 }
 
+void
+SnappyNifSink::EnsureSize(size_t append_length)
+{
+    size_t sz;
+
+    if((length + append_length) > bin.size) {
+        sz = (append_length * 4) < 8192 ? 8192 : (append_length * 4);
+
+        if(!enif_realloc_binary_compat(env, &bin, bin.size + sz)) {
+            throw std::bad_alloc();
+        }
+    }
+}
 
 static inline ERL_NIF_TERM
 make_atom(ErlNifEnv* env, const char* name)