From 72cae5221c87d0062b20342076bfaeba296c60fc Mon Sep 17 00:00:00 2001 From: Fierralin Date: Wed, 22 Apr 2020 18:39:04 +0800 Subject: [PATCH] Move NULL to nullptr (#2027) * Move NULL to nullptr Signed-off-by: Fierralin * Try fix Signed-off-by: Fierralin --- .../AnnService/inc/Core/Common/CommonUtils.h | 6 +- .../thirdparty/annoy/src/annoygomodule.h | 4 +- .../src/index/thirdparty/annoy/src/annoylib.h | 34 ++--- .../thirdparty/annoy/src/annoyluamodule.cc | 12 +- .../index/thirdparty/annoy/src/annoymodule.cc | 138 +++++++++--------- .../faiss/gpu/utils/DeviceMemory.cpp | 10 +- .../faiss_benchmark/faiss_benchmark_test.cpp | 8 +- .../faiss_benchmark/faiss_bitset_test.cpp | 8 +- core/src/index/unittest/test_annoy.cpp | 4 +- core/src/index/unittest/test_hnsw.cpp | 4 +- core/src/index/unittest/test_knowhere.cpp | 8 +- core/src/index/unittest/test_wrapper.cpp | 32 ++-- 12 files changed, 134 insertions(+), 134 deletions(-) diff --git a/core/src/index/thirdparty/SPTAG/AnnService/inc/Core/Common/CommonUtils.h b/core/src/index/thirdparty/SPTAG/AnnService/inc/Core/Common/CommonUtils.h index 4bc8fbb60f..96a8d0b4fa 100644 --- a/core/src/index/thirdparty/SPTAG/AnnService/inc/Core/Common/CommonUtils.h +++ b/core/src/index/thirdparty/SPTAG/AnnService/inc/Core/Common/CommonUtils.h @@ -63,13 +63,13 @@ namespace SPTAG static double GetVector(char* cstr, const char* sep, std::vector& arr, DimensionType& NumDim) { char* current; - char* context = NULL; + char* context = nullptr; DimensionType i = 0; double sum = 0; arr.clear(); current = strtok_s(cstr, sep, &context); - while (current != NULL && (i < NumDim || NumDim < 0)) { + while (current != nullptr && (i < NumDim || NumDim < 0)) { try { float val = (float)atof(current); arr.push_back(val); @@ -80,7 +80,7 @@ namespace SPTAG } sum += arr[i] * arr[i]; - current = strtok_s(NULL, sep, &context); + current = strtok_s(nullptr, sep, &context); i++; } diff --git a/core/src/index/thirdparty/annoy/src/annoygomodule.h b/core/src/index/thirdparty/annoy/src/annoygomodule.h index 005ed06558..c5fb408419 100644 --- a/core/src/index/thirdparty/annoy/src/annoygomodule.h +++ b/core/src/index/thirdparty/annoy/src/annoygomodule.h @@ -44,10 +44,10 @@ class AnnoyIndex { ptr->get_nns_by_vector(w, n, search_k, result, distances); }; void getNnsByItem(int item, int n, int search_k, vector* result) { - ptr->get_nns_by_item(item, n, search_k, result, NULL); + ptr->get_nns_by_item(item, n, search_k, result, nullptr); }; void getNnsByVector(const float* w, int n, int search_k, vector* result) { - ptr->get_nns_by_vector(w, n, search_k, result, NULL); + ptr->get_nns_by_vector(w, n, search_k, result, nullptr); }; int getNItems() { diff --git a/core/src/index/thirdparty/annoy/src/annoylib.h b/core/src/index/thirdparty/annoy/src/annoylib.h index e0ed29fd46..b418869894 100644 --- a/core/src/index/thirdparty/annoy/src/annoylib.h +++ b/core/src/index/thirdparty/annoy/src/annoylib.h @@ -824,15 +824,15 @@ struct Manhattan : Minkowski { template class AnnoyIndexInterface { public: - // Note that the methods with an **error argument will allocate memory and write the pointer to that string if error is non-NULL + // Note that the methods with an **error argument will allocate memory and write the pointer to that string if error is non-nullptr virtual ~AnnoyIndexInterface() {}; - virtual bool add_item(S item, const T* w, char** error=NULL) = 0; - virtual bool build(int q, char** error=NULL) = 0; - virtual bool unbuild(char** error=NULL) = 0; - virtual bool save(const char* filename, bool prefault=false, char** error=NULL) = 0; + virtual bool add_item(S item, const T* w, char** error=nullptr) = 0; + virtual bool build(int q, char** error=nullptr) = 0; + virtual bool unbuild(char** error=nullptr) = 0; + virtual bool save(const char* filename, bool prefault=false, char** error=nullptr) = 0; virtual void unload() = 0; - virtual bool load(const char* filename, bool prefault=false, char** error=NULL) = 0; - virtual bool load_index(void* index_data, const int64_t& index_size, char** error = NULL) = 0; + virtual bool load(const char* filename, bool prefault=false, char** error=nullptr) = 0; + virtual bool load_index(void* index_data, const int64_t& index_size, char** error = nullptr) = 0; virtual T get_distance(S i, S j) const = 0; virtual void get_nns_by_item(S item, size_t n, int search_k, vector* result, vector* distances, faiss::ConcurrentBitsetPtr& bitset = nullptr) const = 0; @@ -846,7 +846,7 @@ class AnnoyIndexInterface { virtual void verbose(bool v) = 0; virtual void get_item(S item, T* v) const = 0; virtual void set_seed(int q) = 0; - virtual bool on_disk_build(const char* filename, char** error=NULL) = 0; + virtual bool on_disk_build(const char* filename, char** error=nullptr) = 0; }; template @@ -894,12 +894,12 @@ public: return _f; } - bool add_item(S item, const T* w, char** error=NULL) { + bool add_item(S item, const T* w, char** error=nullptr) { return add_item_impl(item, w, error); } template - bool add_item_impl(S item, const W& w, char** error=NULL) { + bool add_item_impl(S item, const W& w, char** error=nullptr) { if (_loaded) { set_error_from_string(error, "You can't add an item to a loaded index"); return false; @@ -924,7 +924,7 @@ public: return true; } - bool on_disk_build(const char* file, char** error=NULL) { + bool on_disk_build(const char* file, char** error=nullptr) { _on_disk = true; _fd = open(file, O_RDWR | O_CREAT | O_TRUNC, (int) 0600); if (_fd == -1) { @@ -945,7 +945,7 @@ public: return true; } - bool build(int q, char** error=NULL) { + bool build(int q, char** error=nullptr) { if (_loaded) { set_error_from_string(error, "You can't build a loaded index"); return false; @@ -997,7 +997,7 @@ public: return true; } - bool unbuild(char** error=NULL) { + bool unbuild(char** error=nullptr) { if (_loaded) { set_error_from_string(error, "You can't unbuild a loaded index"); return false; @@ -1010,7 +1010,7 @@ public: return true; } - bool save(const char* filename, bool prefault=false, char** error=NULL) { + bool save(const char* filename, bool prefault=false, char** error=nullptr) { if (!_built) { set_error_from_string(error, "You can't save an index that hasn't been built"); return false; @@ -1022,7 +1022,7 @@ public: unlink(filename); FILE *f = fopen(filename, "wb"); - if (f == NULL) { + if (f == nullptr) { set_error_from_errno(error, "Unable to open"); return false; } @@ -1044,7 +1044,7 @@ public: void reinitialize() { _fd = 0; - _nodes = NULL; + _nodes = nullptr; _loaded = false; _n_items = 0; _n_nodes = 0; @@ -1071,7 +1071,7 @@ public: if (_verbose) showUpdate("unloaded\n"); } - bool load(const char* filename, bool prefault=false, char** error=NULL) { + bool load(const char* filename, bool prefault=false, char** error=nullptr) { _fd = open(filename, O_RDONLY, (int)0400); if (_fd == -1) { set_error_from_errno(error, "Unable to open"); diff --git a/core/src/index/thirdparty/annoy/src/annoyluamodule.cc b/core/src/index/thirdparty/annoy/src/annoyluamodule.cc index 76fec7c9e0..4f483d2d3d 100644 --- a/core/src/index/thirdparty/annoy/src/annoyluamodule.cc +++ b/core/src/index/thirdparty/annoy/src/annoyluamodule.cc @@ -21,7 +21,7 @@ #include "kissrandom.h" #if LUA_VERSION_NUM == 501 -#define compat_setfuncs(L, funcs) luaL_register(L, NULL, funcs) +#define compat_setfuncs(L, funcs) luaL_register(L, nullptr, funcs) #define compat_rawlen lua_objlen #else #define compat_setfuncs(L, funcs) luaL_setfuncs(L, funcs, 0) @@ -203,7 +203,7 @@ public: Searcher s(L); int item = getItemIndex(L, 2, s.self->get_n_items()); s.self->get_nns_by_item(item, s.n, s.search_k, &s.result, - s.include_distances ? &s.distances : NULL); + s.include_distances ? &s.distances : nullptr); return s.pushResults(L); } @@ -213,7 +213,7 @@ public: AnnoyT* vec = &(_vec[0]); toVector(L, 2, s.self->get_f(), vec); s.self->get_nns_by_vector(vec, s.n, s.search_k, &s.result, - s.include_distances ? &s.distances : NULL); + s.include_distances ? &s.distances : nullptr); return s.pushResults(L); } @@ -246,7 +246,7 @@ public: static const luaL_Reg funcs[] = { {"__gc", &ThisClass::gc}, {"__tostring", &ThisClass::tostring}, - {NULL, NULL}, + {nullptr, nullptr}, }; return funcs; } @@ -264,7 +264,7 @@ public: {"get_distance", &ThisClass::get_distance}, {"get_n_items", &ThisClass::get_n_items}, {"on_disk_build", &ThisClass::on_disk_build}, - {NULL, NULL}, + {nullptr, nullptr}, }; return funcs; } @@ -304,7 +304,7 @@ static int lua_an_make(lua_State* L) { static const luaL_Reg LUA_ANNOY_FUNCS[] = { {"AnnoyIndex", lua_an_make}, - {NULL, NULL}, + {nullptr, nullptr}, }; extern "C" { diff --git a/core/src/index/thirdparty/annoy/src/annoymodule.cc b/core/src/index/thirdparty/annoy/src/annoymodule.cc index f15a0cc692..6121a2bc41 100644 --- a/core/src/index/thirdparty/annoy/src/annoymodule.cc +++ b/core/src/index/thirdparty/annoy/src/annoymodule.cc @@ -96,7 +96,7 @@ public: _index.get_nns_by_item(item, n, search_k, result, &distances_internal); distances->insert(distances->begin(), distances_internal.begin(), distances_internal.end()); } else { - _index.get_nns_by_item(item, n, search_k, result, NULL); + _index.get_nns_by_item(item, n, search_k, result, nullptr); } }; void get_nns_by_vector(const float* w, size_t n, int search_k, vector* result, vector* distances) const { @@ -107,7 +107,7 @@ public: _index.get_nns_by_vector(&w_internal[0], n, search_k, result, &distances_internal); distances->insert(distances->begin(), distances_internal.begin(), distances_internal.end()); } else { - _index.get_nns_by_vector(&w_internal[0], n, search_k, result, NULL); + _index.get_nns_by_vector(&w_internal[0], n, search_k, result, nullptr); } }; int32_t get_n_items() const { return _index.get_n_items(); }; @@ -133,14 +133,14 @@ typedef struct { static PyObject * py_an_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) { py_annoy *self = (py_annoy *)type->tp_alloc(type, 0); - if (self == NULL) { - return NULL; + if (self == nullptr) { + return nullptr; } - const char *metric = NULL; + const char *metric = nullptr; - static char const * kwlist[] = {"f", "metric", NULL}; + static char const * kwlist[] = {"f", "metric", nullptr}; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i|s", (char**)kwlist, &self->f, &metric)) - return NULL; + return nullptr; if (!metric) { // This keeps coming up, see #368 etc PyErr_WarnEx(PyExc_FutureWarning, "The default argument for metric will be removed " @@ -158,7 +158,7 @@ py_an_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) { self->ptr = new AnnoyIndex(self->f); } else { PyErr_SetString(PyExc_ValueError, "No such metric"); - return NULL; + return nullptr; } return (PyObject *)self; @@ -168,11 +168,11 @@ py_an_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) { static int py_an_init(py_annoy *self, PyObject *args, PyObject *kwargs) { // Seems to be needed for Python 3 - const char *metric = NULL; + const char *metric = nullptr; int f; - static char const * kwlist[] = {"f", "metric", NULL}; + static char const * kwlist[] = {"f", "metric", nullptr}; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i|s", (char**)kwlist, &f, &metric)) - return (int) NULL; + return (int) nullptr; return 0; } @@ -187,7 +187,7 @@ py_an_dealloc(py_annoy* self) { static PyMemberDef py_annoy_members[] = { {(char*)"f", T_INT, offsetof(py_annoy, f), 0, (char*)""}, - {NULL} /* Sentinel */ + {nullptr} /* Sentinel */ }; @@ -196,15 +196,15 @@ py_an_load(py_annoy *self, PyObject *args, PyObject *kwargs) { char *filename, *error; bool prefault = false; if (!self->ptr) - return NULL; - static char const * kwlist[] = {"fn", "prefault", NULL}; + return nullptr; + static char const * kwlist[] = {"fn", "prefault", nullptr}; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|b", (char**)kwlist, &filename, &prefault)) - return NULL; + return nullptr; if (!self->ptr->load(filename, prefault, &error)) { PyErr_SetString(PyExc_IOError, error); free(error); - return NULL; + return nullptr; } Py_RETURN_TRUE; } @@ -215,15 +215,15 @@ py_an_save(py_annoy *self, PyObject *args, PyObject *kwargs) { char *filename, *error; bool prefault = false; if (!self->ptr) - return NULL; - static char const * kwlist[] = {"fn", "prefault", NULL}; + return nullptr; + static char const * kwlist[] = {"fn", "prefault", nullptr}; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|b", (char**)kwlist, &filename, &prefault)) - return NULL; + return nullptr; if (!self->ptr->save(filename, prefault, &error)) { PyErr_SetString(PyExc_IOError, error); free(error); - return NULL; + return nullptr; } Py_RETURN_TRUE; } @@ -265,21 +265,21 @@ static PyObject* py_an_get_nns_by_item(py_annoy *self, PyObject *args, PyObject *kwargs) { int32_t item, n, search_k=-1, include_distances=0; if (!self->ptr) - return NULL; + return nullptr; - static char const * kwlist[] = {"i", "n", "search_k", "include_distances", NULL}; + static char const * kwlist[] = {"i", "n", "search_k", "include_distances", nullptr}; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii|ii", (char**)kwlist, &item, &n, &search_k, &include_distances)) - return NULL; + return nullptr; if (!check_constraints(self, item, false)) { - return NULL; + return nullptr; } vector result; vector distances; Py_BEGIN_ALLOW_THREADS; - self->ptr->get_nns_by_item(item, n, search_k, &result, include_distances ? &distances : NULL); + self->ptr->get_nns_by_item(item, n, search_k, &result, include_distances ? &distances : nullptr); Py_END_ALLOW_THREADS; return get_nns_to_python(result, distances, include_distances); @@ -315,22 +315,22 @@ py_an_get_nns_by_vector(py_annoy *self, PyObject *args, PyObject *kwargs) { PyObject* v; int32_t n, search_k=-1, include_distances=0; if (!self->ptr) - return NULL; + return nullptr; - static char const * kwlist[] = {"vector", "n", "search_k", "include_distances", NULL}; + static char const * kwlist[] = {"vector", "n", "search_k", "include_distances", nullptr}; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Oi|ii", (char**)kwlist, &v, &n, &search_k, &include_distances)) - return NULL; + return nullptr; vector w(self->f); if (!convert_list_to_vector(v, self->f, &w)) { - return NULL; + return nullptr; } vector result; vector distances; Py_BEGIN_ALLOW_THREADS; - self->ptr->get_nns_by_vector(&w[0], n, search_k, &result, include_distances ? &distances : NULL); + self->ptr->get_nns_by_vector(&w[0], n, search_k, &result, include_distances ? &distances : nullptr); Py_END_ALLOW_THREADS; return get_nns_to_python(result, distances, include_distances); @@ -341,12 +341,12 @@ static PyObject* py_an_get_item_vector(py_annoy *self, PyObject *args) { int32_t item; if (!self->ptr) - return NULL; + return nullptr; if (!PyArg_ParseTuple(args, "i", &item)) - return NULL; + return nullptr; if (!check_constraints(self, item, false)) { - return NULL; + return nullptr; } vector v(self->f); @@ -365,24 +365,24 @@ py_an_add_item(py_annoy *self, PyObject *args, PyObject* kwargs) { PyObject* v; int32_t item; if (!self->ptr) - return NULL; - static char const * kwlist[] = {"i", "vector", NULL}; + return nullptr; + static char const * kwlist[] = {"i", "vector", nullptr}; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "iO", (char**)kwlist, &item, &v)) - return NULL; + return nullptr; if (!check_constraints(self, item, true)) { - return NULL; + return nullptr; } vector w(self->f); if (!convert_list_to_vector(v, self->f, &w)) { - return NULL; + return nullptr; } char* error; if (!self->ptr->add_item(item, &w[0], &error)) { PyErr_SetString(PyExc_Exception, error); free(error); - return NULL; + return nullptr; } Py_RETURN_NONE; @@ -392,15 +392,15 @@ static PyObject * py_an_on_disk_build(py_annoy *self, PyObject *args, PyObject *kwargs) { char *filename, *error; if (!self->ptr) - return NULL; - static char const * kwlist[] = {"fn", NULL}; + return nullptr; + static char const * kwlist[] = {"fn", nullptr}; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s", (char**)kwlist, &filename)) - return NULL; + return nullptr; if (!self->ptr->on_disk_build(filename, &error)) { PyErr_SetString(PyExc_IOError, error); free(error); - return NULL; + return nullptr; } Py_RETURN_TRUE; } @@ -409,10 +409,10 @@ static PyObject * py_an_build(py_annoy *self, PyObject *args, PyObject *kwargs) { int q; if (!self->ptr) - return NULL; - static char const * kwlist[] = {"n_trees", NULL}; + return nullptr; + static char const * kwlist[] = {"n_trees", nullptr}; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i", (char**)kwlist, &q)) - return NULL; + return nullptr; bool res; char* error; @@ -422,7 +422,7 @@ py_an_build(py_annoy *self, PyObject *args, PyObject *kwargs) { if (!res) { PyErr_SetString(PyExc_Exception, error); free(error); - return NULL; + return nullptr; } Py_RETURN_TRUE; @@ -432,13 +432,13 @@ py_an_build(py_annoy *self, PyObject *args, PyObject *kwargs) { static PyObject * py_an_unbuild(py_annoy *self) { if (!self->ptr) - return NULL; + return nullptr; char* error; if (!self->ptr->unbuild(&error)) { PyErr_SetString(PyExc_Exception, error); free(error); - return NULL; + return nullptr; } Py_RETURN_TRUE; @@ -448,7 +448,7 @@ py_an_unbuild(py_annoy *self) { static PyObject * py_an_unload(py_annoy *self) { if (!self->ptr) - return NULL; + return nullptr; self->ptr->unload(); @@ -460,12 +460,12 @@ static PyObject * py_an_get_distance(py_annoy *self, PyObject *args) { int32_t i, j; if (!self->ptr) - return NULL; + return nullptr; if (!PyArg_ParseTuple(args, "ii", &i, &j)) - return NULL; + return nullptr; if (!check_constraints(self, i, false) || !check_constraints(self, j, false)) { - return NULL; + return nullptr; } double d = self->ptr->get_distance(i,j); @@ -476,7 +476,7 @@ py_an_get_distance(py_annoy *self, PyObject *args) { static PyObject * py_an_get_n_items(py_annoy *self) { if (!self->ptr) - return NULL; + return nullptr; int32_t n = self->ptr->get_n_items(); return PyInt_FromLong(n); @@ -485,7 +485,7 @@ py_an_get_n_items(py_annoy *self) { static PyObject * py_an_get_n_trees(py_annoy *self) { if (!self->ptr) - return NULL; + return nullptr; int32_t n = self->ptr->get_n_trees(); return PyInt_FromLong(n); @@ -495,9 +495,9 @@ static PyObject * py_an_verbose(py_annoy *self, PyObject *args) { int verbose; if (!self->ptr) - return NULL; + return nullptr; if (!PyArg_ParseTuple(args, "i", &verbose)) - return NULL; + return nullptr; self->ptr->verbose((bool)verbose); @@ -509,9 +509,9 @@ static PyObject * py_an_set_seed(py_annoy *self, PyObject *args) { int q; if (!self->ptr) - return NULL; + return nullptr; if (!PyArg_ParseTuple(args, "i", &q)) - return NULL; + return nullptr; self->ptr->set_seed(q); @@ -535,12 +535,12 @@ static PyMethodDef AnnoyMethods[] = { {"get_n_trees",(PyCFunction)py_an_get_n_trees, METH_NOARGS, "Returns the number of trees in the index."}, {"verbose",(PyCFunction)py_an_verbose, METH_VARARGS, ""}, {"set_seed",(PyCFunction)py_an_set_seed, METH_VARARGS, "Sets the seed of Annoy's random number generator."}, - {NULL, NULL, 0, NULL} /* Sentinel */ + {nullptr, nullptr, 0, nullptr} /* Sentinel */ }; static PyTypeObject PyAnnoyType = { - PyVarObject_HEAD_INIT(NULL, 0) + PyVarObject_HEAD_INIT(nullptr, 0) "annoy.Annoy", /*tp_name*/ sizeof(py_annoy), /*tp_basicsize*/ 0, /*tp_itemsize*/ @@ -581,7 +581,7 @@ static PyTypeObject PyAnnoyType = { }; static PyMethodDef module_methods[] = { - {NULL} /* Sentinel */ + {nullptr} /* Sentinel */ }; #if PY_MAJOR_VERSION >= 3 @@ -591,10 +591,10 @@ static PyMethodDef module_methods[] = { ANNOY_DOC, /* m_doc */ -1, /* m_size */ module_methods, /* m_methods */ - NULL, /* m_reload */ - NULL, /* m_traverse */ - NULL, /* m_clear */ - NULL, /* m_free */ + nullptr, /* m_reload */ + nullptr, /* m_traverse */ + nullptr, /* m_clear */ + nullptr, /* m_free */ }; #endif @@ -602,7 +602,7 @@ PyObject *create_module(void) { PyObject *m; if (PyType_Ready(&PyAnnoyType) < 0) - return NULL; + return nullptr; #if PY_MAJOR_VERSION >= 3 m = PyModule_Create(&moduledef); @@ -610,8 +610,8 @@ PyObject *create_module(void) { m = Py_InitModule("annoylib", module_methods); #endif - if (m == NULL) - return NULL; + if (m == nullptr) + return nullptr; Py_INCREF(&PyAnnoyType); PyModule_AddObject(m, "Annoy", (PyObject *)&PyAnnoyType); diff --git a/core/src/index/thirdparty/faiss/gpu/utils/DeviceMemory.cpp b/core/src/index/thirdparty/faiss/gpu/utils/DeviceMemory.cpp index df00892e3b..2ce721986a 100644 --- a/core/src/index/thirdparty/faiss/gpu/utils/DeviceMemory.cpp +++ b/core/src/index/thirdparty/faiss/gpu/utils/DeviceMemory.cpp @@ -13,9 +13,9 @@ namespace faiss { namespace gpu { DeviceMemoryReservation::DeviceMemoryReservation() - : state_(NULL), + : state_(nullptr), device_(0), - data_(NULL), + data_(nullptr), size_(0), stream_(0) { } @@ -41,7 +41,7 @@ DeviceMemoryReservation::DeviceMemoryReservation( size_ = m.size_; stream_ = m.stream_; - m.data_ = NULL; + m.data_ = nullptr; } DeviceMemoryReservation::~DeviceMemoryReservation() { @@ -50,7 +50,7 @@ DeviceMemoryReservation::~DeviceMemoryReservation() { state_->returnAllocation(*this); } - data_ = NULL; + data_ = nullptr; } DeviceMemoryReservation& @@ -66,7 +66,7 @@ DeviceMemoryReservation::operator=(DeviceMemoryReservation&& m) { size_ = m.size_; stream_ = m.stream_; - m.data_ = NULL; + m.data_ = nullptr; return *this; } diff --git a/core/src/index/unittest/faiss_benchmark/faiss_benchmark_test.cpp b/core/src/index/unittest/faiss_benchmark/faiss_benchmark_test.cpp index ea01c61b35..a08b19daed 100644 --- a/core/src/index/unittest/faiss_benchmark/faiss_benchmark_test.cpp +++ b/core/src/index/unittest/faiss_benchmark/faiss_benchmark_test.cpp @@ -94,7 +94,7 @@ hdf5_read(const std::string& file_name, const std::string& dataset_name, H5T_cla assert(t_class == dataset_class || !"Illegal dataset class type"); dataspace = H5Dget_space(dataset); /* dataspace handle */ - H5Sget_simple_extent_dims(dataspace, dims_out, NULL); + H5Sget_simple_extent_dims(dataspace, dims_out, nullptr); n_out = dims_out[0]; d_out = dims_out[1]; @@ -102,20 +102,20 @@ hdf5_read(const std::string& file_name, const std::string& dataset_name, H5T_cla offset[0] = offset[1] = 0; count[0] = dims_out[0]; count[1] = dims_out[1]; - H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, offset, NULL, count, NULL); + H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, offset, nullptr, count, nullptr); /* Define the memory dataspace. */ dimsm[0] = dims_out[0]; dimsm[1] = dims_out[1]; dimsm[2] = 1; - memspace = H5Screate_simple(3, dimsm, NULL); + memspace = H5Screate_simple(3, dimsm, nullptr); /* Define memory hyperslab. */ offset_out[0] = offset_out[1] = offset_out[2] = 0; count_out[0] = dims_out[0]; count_out[1] = dims_out[1]; count_out[2] = 1; - H5Sselect_hyperslab(memspace, H5S_SELECT_SET, offset_out, NULL, count_out, NULL); + H5Sselect_hyperslab(memspace, H5S_SELECT_SET, offset_out, nullptr, count_out, nullptr); /* Read data from hyperslab in the file into the hyperslab in memory and display. */ switch (t_class) { diff --git a/core/src/index/unittest/faiss_benchmark/faiss_bitset_test.cpp b/core/src/index/unittest/faiss_benchmark/faiss_bitset_test.cpp index da4809746d..bd8fa1fff8 100644 --- a/core/src/index/unittest/faiss_benchmark/faiss_bitset_test.cpp +++ b/core/src/index/unittest/faiss_benchmark/faiss_bitset_test.cpp @@ -102,7 +102,7 @@ hdf5_read(const std::string& file_name, const std::string& dataset_name, H5T_cla assert(t_class == dataset_class || !"Illegal dataset class type"); dataspace = H5Dget_space(dataset); /* dataspace handle */ - H5Sget_simple_extent_dims(dataspace, dims_out, NULL); + H5Sget_simple_extent_dims(dataspace, dims_out, nullptr); n_out = dims_out[0]; d_out = dims_out[1]; @@ -110,20 +110,20 @@ hdf5_read(const std::string& file_name, const std::string& dataset_name, H5T_cla offset[0] = offset[1] = 0; count[0] = dims_out[0]; count[1] = dims_out[1]; - H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, offset, NULL, count, NULL); + H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, offset, nullptr, count, nullptr); /* Define the memory dataspace. */ dimsm[0] = dims_out[0]; dimsm[1] = dims_out[1]; dimsm[2] = 1; - memspace = H5Screate_simple(3, dimsm, NULL); + memspace = H5Screate_simple(3, dimsm, nullptr); /* Define memory hyperslab. */ offset_out[0] = offset_out[1] = offset_out[2] = 0; count_out[0] = dims_out[0]; count_out[1] = dims_out[1]; count_out[2] = 1; - H5Sselect_hyperslab(memspace, H5S_SELECT_SET, offset_out, NULL, count_out, NULL); + H5Sselect_hyperslab(memspace, H5S_SELECT_SET, offset_out, nullptr, count_out, nullptr); /* Read data from hyperslab in the file into the hyperslab in memory and display. */ switch (t_class) { diff --git a/core/src/index/unittest/test_annoy.cpp b/core/src/index/unittest/test_annoy.cpp index c3f56a7515..9faf0b0e9b 100644 --- a/core/src/index/unittest/test_annoy.cpp +++ b/core/src/index/unittest/test_annoy.cpp @@ -219,8 +219,8 @@ main() { } printf("gen xb and ids done! \n"); - // srand((unsigned)time(NULL)); - auto random_seed = (unsigned)time(NULL); + // srand((unsigned)time(nullptr)); + auto random_seed = (unsigned)time(nullptr); printf("delete ids: \n"); for (int i = 0; i < nq; i++) { auto tmp = rand_r(&random_seed) % nb; diff --git a/core/src/index/unittest/test_hnsw.cpp b/core/src/index/unittest/test_hnsw.cpp index b225e363f6..71c18cee83 100644 --- a/core/src/index/unittest/test_hnsw.cpp +++ b/core/src/index/unittest/test_hnsw.cpp @@ -154,8 +154,8 @@ main() { } // printf("gen xb and ids done! \n"); - // srand((unsigned)time(NULL)); - auto random_seed = (unsigned)time(NULL); + // srand((unsigned)time(nullptr)); + auto random_seed = (unsigned)time(nullptr); // printf("delete ids: \n"); for (int i = 0; i < nq; i++) { auto tmp = rand_r(&random_seed) % nb; diff --git a/core/src/index/unittest/test_knowhere.cpp b/core/src/index/unittest/test_knowhere.cpp index 2d6a783247..1e2fccf5c3 100644 --- a/core/src/index/unittest/test_knowhere.cpp +++ b/core/src/index/unittest/test_knowhere.cpp @@ -29,22 +29,22 @@ TEST_F(KnowhereTest, KNOWHERE_RESOURCE_TEST) { #ifdef MILVUS_GPU_VERSION fiu_init(0); - fiu_enable("check_config_gpu_resource_enable_fail", 1, NULL, 0); + fiu_enable("check_config_gpu_resource_enable_fail", 1, nullptr, 0); s = milvus::engine::KnowhereResource::Initialize(); ASSERT_FALSE(s.ok()); fiu_disable("check_config_gpu_resource_enable_fail"); - fiu_enable("KnowhereResource.Initialize.disable_gpu", 1, NULL, 0); + fiu_enable("KnowhereResource.Initialize.disable_gpu", 1, nullptr, 0); s = milvus::engine::KnowhereResource::Initialize(); ASSERT_TRUE(s.ok()); fiu_disable("KnowhereResource.Initialize.disable_gpu"); - fiu_enable("check_gpu_resource_config_build_index_fail", 1, NULL, 0); + fiu_enable("check_gpu_resource_config_build_index_fail", 1, nullptr, 0); s = milvus::engine::KnowhereResource::Initialize(); ASSERT_FALSE(s.ok()); fiu_disable("check_gpu_resource_config_build_index_fail"); - fiu_enable("check_gpu_resource_config_search_fail", 1, NULL, 0); + fiu_enable("check_gpu_resource_config_search_fail", 1, nullptr, 0); s = milvus::engine::KnowhereResource::Initialize(); ASSERT_FALSE(s.ok()); fiu_disable("check_gpu_resource_config_search_fail"); diff --git a/core/src/index/unittest/test_wrapper.cpp b/core/src/index/unittest/test_wrapper.cpp index 503768d31d..7798701838 100644 --- a/core/src/index/unittest/test_wrapper.cpp +++ b/core/src/index/unittest/test_wrapper.cpp @@ -115,35 +115,35 @@ TEST_P(KnowhereWrapperTest, BASE_TEST) { index_->GetDeviceId(); fiu_init(0); - fiu_enable("VecIndexImpl.BuildAll.throw_knowhere_exception", 1, NULL, 0); - fiu_enable("BFIndex.BuildAll.throw_knowhere_exception", 1, NULL, 0); - fiu_enable("IVFMixIndex.BuildAll.throw_knowhere_exception", 1, NULL, 0); + fiu_enable("VecIndexImpl.BuildAll.throw_knowhere_exception", 1, nullptr, 0); + fiu_enable("BFIndex.BuildAll.throw_knowhere_exception", 1, nullptr, 0); + fiu_enable("IVFMixIndex.BuildAll.throw_knowhere_exception", 1, nullptr, 0); auto s = index_->BuildAll(nb, xb.data(), ids.data(), conf); fiu_disable("IVFMixIndex.BuildAll.throw_knowhere_exception"); fiu_disable("BFIndex.BuildAll.throw_knowhere_exception"); fiu_disable("VecIndexImpl.BuildAll.throw_knowhere_exception"); - fiu_enable("VecIndexImpl.BuildAll.throw_std_exception", 1, NULL, 0); - fiu_enable("BFIndex.BuildAll.throw_std_exception", 1, NULL, 0); - fiu_enable("IVFMixIndex.BuildAll.throw_std_exception", 1, NULL, 0); + fiu_enable("VecIndexImpl.BuildAll.throw_std_exception", 1, nullptr, 0); + fiu_enable("BFIndex.BuildAll.throw_std_exception", 1, nullptr, 0); + fiu_enable("IVFMixIndex.BuildAll.throw_std_exception", 1, nullptr, 0); s = index_->BuildAll(nb, xb.data(), ids.data(), conf); fiu_disable("IVFMixIndex.BuildAll.throw_std_exception"); fiu_disable("BFIndex.BuildAll.throw_std_exception"); fiu_disable("VecIndexImpl.BuildAll.throw_std_exception"); - fiu_enable("VecIndexImpl.Add.throw_knowhere_exception", 1, NULL, 0); + fiu_enable("VecIndexImpl.Add.throw_knowhere_exception", 1, nullptr, 0); s = index_->Add(nb, xb.data(), ids.data()); fiu_disable("VecIndexImpl.Add.throw_knowhere_exception"); - fiu_enable("VecIndexImpl.Add.throw_std_exception", 1, NULL, 0); + fiu_enable("VecIndexImpl.Add.throw_std_exception", 1, nullptr, 0); s = index_->Add(nb, xb.data(), ids.data()); fiu_disable("VecIndexImpl.Add.throw_std_exception"); - fiu_enable("VecIndexImpl.Search.throw_knowhere_exception", 1, NULL, 0); + fiu_enable("VecIndexImpl.Search.throw_knowhere_exception", 1, nullptr, 0); s = index_->Search(nq, xq.data(), res_dis.data(), res_ids.data(), searchconf); fiu_disable("VecIndexImpl.Search.throw_knowhere_exception"); - fiu_enable("VecIndexImpl.Search.throw_std_exception", 1, NULL, 0); + fiu_enable("VecIndexImpl.Search.throw_std_exception", 1, nullptr, 0); s = index_->Search(nq, xq.data(), res_dis.data(), res_ids.data(), searchconf); fiu_disable("VecIndexImpl.Search.throw_std_exception"); } @@ -229,17 +229,17 @@ TEST_P(KnowhereWrapperTest, SERIALIZE_TEST) { { std::string file_location = "/tmp/knowhere_gpu_file"; fiu_init(0); - fiu_enable("VecIndex.write_index.throw_knowhere_exception", 1, NULL, 0); + fiu_enable("VecIndex.write_index.throw_knowhere_exception", 1, nullptr, 0); auto s = write_index(index_, file_location); ASSERT_FALSE(s.ok()); fiu_disable("VecIndex.write_index.throw_knowhere_exception"); - fiu_enable("VecIndex.write_index.throw_std_exception", 1, NULL, 0); + fiu_enable("VecIndex.write_index.throw_std_exception", 1, nullptr, 0); s = write_index(index_, file_location); ASSERT_FALSE(s.ok()); fiu_disable("VecIndex.write_index.throw_std_exception"); - fiu_enable("VecIndex.write_index.throw_no_space_exception", 1, NULL, 0); + fiu_enable("VecIndex.write_index.throw_no_space_exception", 1, nullptr, 0); s = write_index(index_, file_location); ASSERT_FALSE(s.ok()); fiu_disable("VecIndex.write_index.throw_no_space_exception"); @@ -294,7 +294,7 @@ TEST_P(KnowhereWrapperTest, SERIALIZE_TEST) { // conf.metric_type = knowhere::METRICTYPE::L2; // fiu_init(0); -// fiu_enable("IVFPQConfAdapter.Match.empty_resset", 1, NULL, 0); +// fiu_enable("IVFPQConfAdapter.Match.empty_resset", 1, nullptr, 0); // try { // ivf_pq_conf->Match(conf); // } catch (std::exception& e) { @@ -319,12 +319,12 @@ TEST(BFIndex, test_bf_index_fail) { milvus::engine::Config config; fiu_init(0); - fiu_enable("BFIndex.Build.throw_knowhere_exception", 1, NULL, 0); + fiu_enable("BFIndex.Build.throw_knowhere_exception", 1, nullptr, 0); auto err_code = bf_ptr->Build(config); ASSERT_EQ(err_code, milvus::KNOWHERE_UNEXPECTED_ERROR); fiu_disable("BFIndex.Build.throw_knowhere_exception"); - fiu_enable("BFIndex.Build.throw_std_exception", 1, NULL, 0); + fiu_enable("BFIndex.Build.throw_std_exception", 1, nullptr, 0); err_code = bf_ptr->Build(config); ASSERT_EQ(err_code, milvus::KNOWHERE_ERROR); fiu_disable("BFIndex.Build.throw_std_exception");