diff --git a/source/neuropod/BUILD b/source/neuropod/BUILD index 669f5a50..1c874e57 100644 --- a/source/neuropod/BUILD +++ b/source/neuropod/BUILD @@ -13,8 +13,9 @@ # limitations under the License. load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar") +load("//bazel:cc.bzl", "neuropod_cc_binary", "neuropod_cc_library") -cc_library( +neuropod_cc_library( name = "neuropod_hdrs", hdrs = [ "neuropod.hh", @@ -31,7 +32,7 @@ cc_library( ], ) -cc_library( +neuropod_cc_library( name = "options", hdrs = ["options.hh"], visibility = [ @@ -39,7 +40,7 @@ cc_library( ], ) -cc_binary( +neuropod_cc_binary( name = "libneuropod.so", linkopts = select({ "@bazel_tools//src/conditions:darwin": ["-Wl,-rpath,@loader_path"], @@ -55,7 +56,7 @@ cc_binary( ], ) -cc_library( +neuropod_cc_library( name = "neuropod_impl", srcs = [ "neuropod.cc", diff --git a/source/neuropod/bindings/BUILD b/source/neuropod/bindings/BUILD index 5c3ba204..d12affc8 100644 --- a/source/neuropod/bindings/BUILD +++ b/source/neuropod/bindings/BUILD @@ -12,7 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -cc_binary( +load("//bazel:cc.bzl", "neuropod_cc_binary", "neuropod_cc_library") + +neuropod_cc_binary( name = "neuropod_native.so", srcs = [ "neuropod_native.cc", @@ -31,7 +33,7 @@ cc_binary( ], ) -cc_library( +neuropod_cc_library( name = "bindings", srcs = [ "python_bindings.cc", diff --git a/source/neuropod/bindings/c/BUILD b/source/neuropod/bindings/c/BUILD index b283722c..99cc23c3 100644 --- a/source/neuropod/bindings/c/BUILD +++ b/source/neuropod/bindings/c/BUILD @@ -12,7 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -cc_library( +load("//bazel:cc.bzl", "neuropod_cc_library") + +neuropod_cc_library( name = "c_api", srcs = glob(["*.cc"]), hdrs = glob(["*.h"]), diff --git a/source/neuropod/bindings/c/c_api.cc b/source/neuropod/bindings/c/c_api.cc index 3f71275a..094a3c9a 100644 --- a/source/neuropod/bindings/c/c_api.cc +++ b/source/neuropod/bindings/c/c_api.cc @@ -28,10 +28,10 @@ limitations under the License. #include // NOLINTNEXTLINE(readability-identifier-naming): Ignore function case for C API methods -void NP_LoadNeuropodWithOpts(const char * neuropod_path, - const NP_RuntimeOptions *options, - NP_Neuropod ** model, - NP_Status * status) +void NP_LoadNeuropodWithOpts(const char *neuropod_path, + const NP_RuntimeOptions * /*unused*/, + NP_Neuropod **model, + NP_Status * status) { try { diff --git a/source/neuropod/bindings/java/BUILD b/source/neuropod/bindings/java/BUILD index 411490d2..754bdf99 100644 --- a/source/neuropod/bindings/java/BUILD +++ b/source/neuropod/bindings/java/BUILD @@ -13,6 +13,7 @@ # limitations under the License. load(":java_build_defs.bzl", "JAVACOPTS") +load("//bazel:cc.bzl", "neuropod_cc_binary", "neuropod_cc_library") genrule( name = "copy_link_jni_md_header", @@ -102,7 +103,7 @@ java_library( visibility = ["//visibility:public"], ) -cc_library( +neuropod_cc_library( name = "copy_jni_hdr_lib", hdrs = [ ":copy_link_jni_header", @@ -111,11 +112,15 @@ cc_library( includes = ["."], ) -cc_binary( +neuropod_cc_binary( name = "libneuropod_jni.so", srcs = glob(["src/main/native/*.cc"]) + glob(["src/main/native/*.h"]) + [ "//neuropod:libneuropod.so", ], + copts = [ + # The autogenerated headers for JNI use reserved names + "-Wno-reserved-id-macro", + ], includes = select({ "@bazel_tools//src/conditions:darwin": ["external/local_jdk/include/darwin"], "//conditions:default": ["external/local_jdk/include/linux"], diff --git a/source/neuropod/bindings/java/src/main/native/com_uber_neuropod_Neuropod.cc b/source/neuropod/bindings/java/src/main/native/com_uber_neuropod_Neuropod.cc index 64d4a8d9..03b604d4 100644 --- a/source/neuropod/bindings/java/src/main/native/com_uber_neuropod_Neuropod.cc +++ b/source/neuropod/bindings/java/src/main/native/com_uber_neuropod_Neuropod.cc @@ -111,7 +111,7 @@ JNIEXPORT jlong JNICALL Java_com_uber_neuropod_Neuropod_nativeNew__Ljava_lang_St } // NOLINTNEXTLINE(readability-identifier-naming): Ignore function case for Java API methods -JNIEXPORT void JNICALL Java_com_uber_neuropod_Neuropod_nativeDelete(JNIEnv *env, jobject obj, jlong handle) +JNIEXPORT void JNICALL Java_com_uber_neuropod_Neuropod_nativeDelete(JNIEnv *env, jobject /*unused*/, jlong handle) { try { diff --git a/source/neuropod/bindings/java/src/main/native/com_uber_neuropod_NeuropodTensor.cc b/source/neuropod/bindings/java/src/main/native/com_uber_neuropod_NeuropodTensor.cc index 339a9272..7eee577f 100644 --- a/source/neuropod/bindings/java/src/main/native/com_uber_neuropod_NeuropodTensor.cc +++ b/source/neuropod/bindings/java/src/main/native/com_uber_neuropod_NeuropodTensor.cc @@ -75,12 +75,12 @@ JNIEXPORT jlongArray JNICALL Java_com_uber_neuropod_NeuropodTensor_nativeGetDims { auto tensor = (*reinterpret_cast *>(handle))->as_tensor(); auto dims = tensor->as_tensor()->get_dims(); - jlongArray result = env->NewLongArray(dims.size()); + jlongArray result = env->NewLongArray(static_cast(dims.size())); if (!result) { throw std::runtime_error("out of memory"); } - env->SetLongArrayRegion(result, 0, dims.size(), reinterpret_cast(dims.data())); + env->SetLongArrayRegion(result, 0, static_cast(dims.size()), reinterpret_cast(dims.data())); return result; } catch (const std::exception &e) @@ -116,7 +116,7 @@ JNIEXPORT jlong JNICALL Java_com_uber_neuropod_NeuropodTensor_nativeGetNumberOfE try { auto tensor = (*reinterpret_cast *>(handle))->as_tensor(); - return tensor->get_num_elements(); + return static_cast(tensor->get_num_elements()); } catch (const std::exception &e) { diff --git a/source/neuropod/bindings/java/src/main/native/com_uber_neuropod_NeuropodTensorAllocator.cc b/source/neuropod/bindings/java/src/main/native/com_uber_neuropod_NeuropodTensorAllocator.cc index 3b3154ef..9257db78 100644 --- a/source/neuropod/bindings/java/src/main/native/com_uber_neuropod_NeuropodTensorAllocator.cc +++ b/source/neuropod/bindings/java/src/main/native/com_uber_neuropod_NeuropodTensorAllocator.cc @@ -62,7 +62,7 @@ JNIEXPORT jlong JNICALL Java_com_uber_neuropod_NeuropodTensorAllocator_nativeAll // Prepare Buffer auto globalBufferRef = env->NewGlobalRef(buffer); auto bufferAddress = env->GetDirectBufferAddress(buffer); - const neuropod::Deleter deleter = [globalBufferRef, env](void *unused) mutable { + const neuropod::Deleter deleter = [globalBufferRef, env](void * /*unused*/) mutable { env->DeleteGlobalRef(globalBufferRef); }; std::shared_ptr tensor; diff --git a/source/neuropod/bindings/java/src/main/native/jclass_register.cc b/source/neuropod/bindings/java/src/main/native/jclass_register.cc index 17b80898..a7127cc2 100644 --- a/source/neuropod/bindings/java/src/main/native/jclass_register.cc +++ b/source/neuropod/bindings/java/src/main/native/jclass_register.cc @@ -56,7 +56,7 @@ jmethodID com_uber_neuropod_NeuropodTensor_getHandle; jclass com_uber_neuropod_NeuropodJNIException; -jint JNI_VERSION = JNI_VERSION_1_8; +constexpr jint JNI_VERSION = JNI_VERSION_1_8; bool isTestMode = false; @@ -68,7 +68,7 @@ using namespace neuropod::jni; // This function is called when the JNI is loaded. // NOLINTNEXTLINE(readability-identifier-naming): Ignore function case for Java API methods -jint JNI_OnLoad(JavaVM *vm, void *reserved) +jint JNI_OnLoad(JavaVM *vm, void * /*unused*/) { // Obtain the JNIEnv from the VM and confirm JNI_VERSION JNIEnv *env; @@ -131,7 +131,7 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved) // This function is called when the JNI is unloaded. // NOLINTNEXTLINE(readability-identifier-naming): Ignore function case for Java API methods -void JNI_OnUnload(JavaVM *vm, void *reserved) +void JNI_OnUnload(JavaVM *vm, void * /*unused*/) { // Obtain the JNIEnv from the VM JNIEnv *env; diff --git a/source/neuropod/bindings/java/src/main/native/jclass_register.h b/source/neuropod/bindings/java/src/main/native/jclass_register.h index 8dbf5f98..53f073cd 100644 --- a/source/neuropod/bindings/java/src/main/native/jclass_register.h +++ b/source/neuropod/bindings/java/src/main/native/jclass_register.h @@ -52,4 +52,4 @@ extern jclass com_uber_neuropod_NeuropodJNIException; extern bool isTestMode; } // namespace jni -} // namespace neuropod \ No newline at end of file +} // namespace neuropod diff --git a/source/neuropod/bindings/neuropod_native.cc b/source/neuropod/bindings/neuropod_native.cc index ccbce8e2..4e0fe5ba 100644 --- a/source/neuropod/bindings/neuropod_native.cc +++ b/source/neuropod/bindings/neuropod_native.cc @@ -111,7 +111,9 @@ RuntimeOptions get_options_from_kwargs(py::kwargs &kwargs) { RuntimeOptions options; - for (const auto &item : kwargs) + // Note: 'item' is always a copy because the range of type 'py::kwargs' does not return a reference + // Explicitly not using a reference type + for (const auto item : kwargs) { const auto key = item.first.cast(); const auto &value = item.second; diff --git a/source/neuropod/bindings/python_bindings.cc b/source/neuropod/bindings/python_bindings.cc index 2f70f9bc..2ae860db 100644 --- a/source/neuropod/bindings/python_bindings.cc +++ b/source/neuropod/bindings/python_bindings.cc @@ -73,16 +73,16 @@ std::shared_ptr tensor_from_string_numpy(NeuropodTensorAllocator std::vector & shape) { // Unfortunately, for strings, we need to copy all the data in the tensor - auto tensor = allocator.allocate_tensor(shape); - int max_len = array.itemsize(); - int numel = tensor->get_num_elements(); + auto tensor = allocator.allocate_tensor(shape); + auto max_len = static_cast(array.itemsize()); + size_t numel = tensor->get_num_elements(); // Get a pointer to the underlying data char *data = static_cast(array.mutable_data()); std::vector out; std::string chars_to_strip("\0", 1); - for (int i = 0; i < numel * max_len; i += max_len) + for (size_t i = 0; i < numel * max_len; i += max_len) { std::string item(data + i, max_len); @@ -120,7 +120,7 @@ std::shared_ptr tensor_from_numpy(NeuropodTensorAllocator &alloc // Capture the array in our deleter so it doesn't get deallocated // until we're done auto to_delete = std::make_shared(array); - auto deleter = [to_delete](void *unused) mutable { + auto deleter = [to_delete](void * /*unused*/) mutable { py::gil_scoped_acquire gil; to_delete.reset(); }; @@ -169,7 +169,7 @@ py::array tensor_to_numpy(std::shared_ptr value) auto data = internal::NeuropodTensorRawDataAccess::get_untyped_data_ptr(*tensor); // Make sure we don't deallocate the tensor until the numpy array is deallocated - auto deleter = [value](void *unused) {}; + auto deleter = [value](void * /*unused*/) {}; auto deleter_handle = register_deleter(deleter, nullptr); auto capsule = py::capsule(deleter_handle, [](void *handle) { run_deleter(handle); }); return py::array(get_py_type(*tensor), dims, data, capsule); diff --git a/source/neuropod/conversions/BUILD b/source/neuropod/conversions/BUILD index f7be4ce4..b2a37ebf 100644 --- a/source/neuropod/conversions/BUILD +++ b/source/neuropod/conversions/BUILD @@ -12,7 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -cc_library( +load("//bazel:cc.bzl", "neuropod_cc_library") + +neuropod_cc_library( name = "eigen", hdrs = [ "eigen.hh", diff --git a/source/neuropod/core/BUILD b/source/neuropod/core/BUILD index 28dff0ce..769e00a2 100644 --- a/source/neuropod/core/BUILD +++ b/source/neuropod/core/BUILD @@ -13,8 +13,9 @@ # limitations under the License. load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar") +load("//bazel:cc.bzl", "neuropod_cc_library") -cc_library( +neuropod_cc_library( name = "core", hdrs = glob(["*.hh"]), visibility = [ @@ -26,7 +27,7 @@ cc_library( ], ) -cc_library( +neuropod_cc_library( name = "impl", srcs = glob(["*.cc"]), visibility = [ diff --git a/source/neuropod/neuropod.cc b/source/neuropod/neuropod.cc index 1c746553..f6ab8cb9 100644 --- a/source/neuropod/neuropod.cc +++ b/source/neuropod/neuropod.cc @@ -51,7 +51,7 @@ Neuropod::Neuropod(const std::string & neuropod_path, } // Load the model config and use the backend that was provided by the user -Neuropod::Neuropod(const std::string &neuropod_path, std::shared_ptr backend) +Neuropod::Neuropod(const std::string & /*unused*/, std::shared_ptr backend) : backend_(std::move(backend)) { } diff --git a/source/neuropod/serialization/BUILD b/source/neuropod/serialization/BUILD index a9a155f6..8a9fef01 100644 --- a/source/neuropod/serialization/BUILD +++ b/source/neuropod/serialization/BUILD @@ -13,8 +13,9 @@ # limitations under the License. load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar") +load("//bazel:cc.bzl", "neuropod_cc_library") -cc_library( +neuropod_cc_library( name = "serialization", hdrs = [ "serialization.hh", @@ -27,7 +28,7 @@ cc_library( ], ) -cc_library( +neuropod_cc_library( name = "impl", srcs = [ "serialization.cc", diff --git a/source/neuropod/serialization/serialization.cc b/source/neuropod/serialization/serialization.cc index 181b454a..4b706633 100644 --- a/source/neuropod/serialization/serialization.cc +++ b/source/neuropod/serialization/serialization.cc @@ -88,7 +88,7 @@ std::shared_ptr deserialize(boost::archive::binary_iarchive &ar, void serialize(boost::archive::binary_oarchive &out, const NeuropodValueMap &item) { - int num_items = item.size(); + auto num_items = static_cast(item.size()); out << num_items; for (const auto &pair : item) diff --git a/source/neuropod/tests/ope_overrides.hh b/source/neuropod/tests/ope_overrides.hh index d61f5ed3..287d66f7 100644 --- a/source/neuropod/tests/ope_overrides.hh +++ b/source/neuropod/tests/ope_overrides.hh @@ -25,7 +25,7 @@ limitations under the License. namespace detail { -std::string get_cwd() +static std::string get_cwd() { char buf[FILENAME_MAX]; getcwd(buf, FILENAME_MAX);