This is an automated email from the ASF dual-hosted git repository.
wangdan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pegasus.git
The following commit(s) were added to refs/heads/master by this push:
new 1d2e0c6ff fix: resolve undeclared names that are reported while
building alloc.h in debug mode (#1392)
1d2e0c6ff is described below
commit 1d2e0c6ff6a2eea6b777a6e8b3989c66f5624ade
Author: Dan Wang <[email protected]>
AuthorDate: Wed Mar 15 16:31:20 2023 +0800
fix: resolve undeclared names that are reported while building alloc.h in
debug mode (#1392)
https://github.com/apache/incubator-pegasus/issues/1391
While building `alloc.h` in debug mode, `#ifndef NDEBUG` will be true and
triggered, which means
`CHECK_EQ_MSG` and `fmt::ptr` will be compiled. However, since
`utils/fmt_logging.h` is not included,
compilation will fail and report undeclared names. Therefore,
`utils/fmt_logging.h` should be included
once `#ifndef NDEBUG` is true.
---
src/utils/alloc.cpp | 10 ++++++----
src/utils/alloc.h | 16 +++++++++++-----
2 files changed, 17 insertions(+), 9 deletions(-)
diff --git a/src/utils/alloc.cpp b/src/utils/alloc.cpp
index 8e02b11c5..62b6ccf8c 100644
--- a/src/utils/alloc.cpp
+++ b/src/utils/alloc.cpp
@@ -17,6 +17,10 @@
#include "utils/alloc.h"
+// The check for the definition of CACHELINE_SIZE has to be put after
including "utils/alloc.h",
+// where CACHELINE_SIZE is defined in "utils/ports.h".
+#ifdef CACHELINE_SIZE
+
#include <cstdlib>
#include "utils/fmt_logging.h"
@@ -24,8 +28,6 @@
namespace dsn {
-#ifdef CACHELINE_SIZE
-
/* extern */ void *cacheline_aligned_alloc(size_t size)
{
if (dsn_unlikely(size == 0)) {
@@ -50,6 +52,6 @@ namespace dsn {
/* extern */ void cacheline_aligned_free(void *mem_block) { free(mem_block); }
-#endif
-
} // namespace dsn
+
+#endif // CACHELINE_SIZE
diff --git a/src/utils/alloc.h b/src/utils/alloc.h
index 4e4a22acd..195f740f6 100644
--- a/src/utils/alloc.h
+++ b/src/utils/alloc.h
@@ -17,18 +17,24 @@
#pragma once
+#include "utils/ports.h"
+
+// The check for the definition of CACHELINE_SIZE has to be put after
including "utils/ports.h",
+// where CACHELINE_SIZE is defined.
+#ifdef CACHELINE_SIZE
+
#include <stddef.h>
#include <algorithm>
#include <functional>
#include <memory>
#include <new>
-#include "utils/ports.h"
+#ifndef NDEBUG
+#include "utils/fmt_logging.h"
+#endif
namespace dsn {
-#ifdef CACHELINE_SIZE
-
extern void *cacheline_aligned_alloc(size_t size);
extern void cacheline_aligned_free(void *mem_block);
@@ -79,6 +85,6 @@ cacheline_aligned_ptr<T> cacheline_aligned_alloc_array(size_t
len, const T &val)
return array;
}
-#endif
-
} // namespace dsn
+
+#endif // CACHELINE_SIZE
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]