-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ARROW-70: Add adapt 'lite' DCHECK macros from Kudu as also used in Parquet #33
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// 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. | ||
|
||
#ifndef ARROW_UTIL_LOGGING_H | ||
#define ARROW_UTIL_LOGGING_H | ||
|
||
#include <iostream> | ||
|
||
namespace arrow { | ||
|
||
// Stubbed versions of macros defined in glog/logging.h, intended for | ||
// environments where glog headers aren't available. | ||
// | ||
// Add more as needed. | ||
|
||
// Log levels. LOG ignores them, so their values are abitrary. | ||
|
||
#define ARROW_INFO 0 | ||
#define ARROW_WARNING 1 | ||
#define ARROW_ERROR 2 | ||
#define ARROW_FATAL 3 | ||
|
||
#define ARROW_LOG_INTERNAL(level) arrow::internal::CerrLog(level) | ||
#define ARROW_LOG(level) ARROW_LOG_INTERNAL(ARROW_##level) | ||
|
||
#define ARROW_CHECK(condition) \ | ||
(condition) ? 0 : ARROW_LOG(FATAL) << "Check failed: " #condition " " | ||
|
||
#ifdef NDEBUG | ||
#define ARROW_DFATAL ARROW_WARNING | ||
|
||
#define DCHECK(condition) while (false) arrow::internal::NullLog() | ||
#define DCHECK_EQ(val1, val2) while (false) arrow::internal::NullLog() | ||
#define DCHECK_NE(val1, val2) while (false) arrow::internal::NullLog() | ||
#define DCHECK_LE(val1, val2) while (false) arrow::internal::NullLog() | ||
#define DCHECK_LT(val1, val2) while (false) arrow::internal::NullLog() | ||
#define DCHECK_GE(val1, val2) while (false) arrow::internal::NullLog() | ||
#define DCHECK_GT(val1, val2) while (false) arrow::internal::NullLog() | ||
|
||
#else | ||
#define ARROW_DFATAL ARROW_FATAL | ||
|
||
#define DCHECK(condition) ARROW_CHECK(condition) | ||
#define DCHECK_EQ(val1, val2) ARROW_CHECK((val1) == (val2)) | ||
#define DCHECK_NE(val1, val2) ARROW_CHECK((val1) != (val2)) | ||
#define DCHECK_LE(val1, val2) ARROW_CHECK((val1) <= (val2)) | ||
#define DCHECK_LT(val1, val2) ARROW_CHECK((val1) < (val2)) | ||
#define DCHECK_GE(val1, val2) ARROW_CHECK((val1) >= (val2)) | ||
#define DCHECK_GT(val1, val2) ARROW_CHECK((val1) > (val2)) | ||
|
||
#endif // NDEBUG | ||
|
||
namespace internal { | ||
|
||
class NullLog { | ||
public: | ||
template<class T> | ||
NullLog& operator<<(const T& t) { | ||
return *this; | ||
} | ||
}; | ||
|
||
class CerrLog { | ||
public: | ||
CerrLog(int severity) // NOLINT(runtime/explicit) | ||
: severity_(severity), | ||
has_logged_(false) { | ||
} | ||
|
||
~CerrLog() { | ||
if (has_logged_) { | ||
std::cerr << std::endl; | ||
} | ||
if (severity_ == ARROW_FATAL) { | ||
exit(1); | ||
} | ||
} | ||
|
||
template<class T> | ||
CerrLog& operator<<(const T& t) { | ||
has_logged_ = true; | ||
std::cerr << t; | ||
return *this; | ||
} | ||
|
||
private: | ||
const int severity_; | ||
bool has_logged_; | ||
}; | ||
|
||
} // namespace internal | ||
|
||
} // namespace arrow | ||
|
||
#endif // ARROW_UTIL_LOGGING_H |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you prefer this or
DCHECK(type)
? For checks like this I think I prefer this without explicit comparison, but its not a strong preference.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a strong preference either.