Skip to content

Commit d79e680

Browse files
Abseil Teamcopybara-github
authored andcommitted
Add nullability annotations to some very-commonly-used APIs.
Manual annotation of these APIs specifically helps us avoid inferring them with tooling as having conflicted nullability due to a small number of incorrect uses out of many, many uses. These annotations have no runtime impact. PiperOrigin-RevId: 739258146 Change-Id: Id18bd1f0313c5b196e1d9e8ed4d1ce057dfcd582
1 parent 930a70d commit d79e680

File tree

9 files changed

+22
-11
lines changed

9 files changed

+22
-11
lines changed

absl/flags/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ cc_library(
245245
":reflection",
246246
"//absl/base:config",
247247
"//absl/base:core_headers",
248+
"//absl/base:nullability",
248249
"//absl/strings",
249250
],
250251
)

absl/flags/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ absl_cc_library(
218218
absl::flags_internal
219219
absl::flags_reflection
220220
absl::core_headers
221+
absl::nullability
221222
absl::strings
222223
)
223224

absl/flags/flag.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
#include "absl/base/attributes.h"
3737
#include "absl/base/config.h"
38+
#include "absl/base/nullability.h"
3839
#include "absl/base/optimization.h"
3940
#include "absl/flags/commandlineflag.h"
4041
#include "absl/flags/config.h"
@@ -106,15 +107,15 @@ template <typename T>
106107
// thread-safe, but is potentially expensive. Avoid setting flags in general,
107108
// but especially within performance-critical code.
108109
template <typename T>
109-
void SetFlag(absl::Flag<T>* flag, const T& v) {
110+
void SetFlag(absl::Flag<T>* absl_nonnull flag, const T& v) {
110111
flags_internal::FlagImplPeer::InvokeSet(*flag, v);
111112
}
112113

113114
// Overload of `SetFlag()` to allow callers to pass in a value that is
114115
// convertible to `T`. E.g., use this overload to pass a "const char*" when `T`
115116
// is `std::string`.
116117
template <typename T, typename V>
117-
void SetFlag(absl::Flag<T>* flag, const V& v) {
118+
void SetFlag(absl::Flag<T>* absl_nonnull flag, const V& v) {
118119
T value(v);
119120
flags_internal::FlagImplPeer::InvokeSet(*flag, value);
120121
}

absl/log/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,7 @@ absl_cc_library(
747747
absl::log_internal_fnmatch
748748
absl::memory
749749
absl::no_destructor
750+
absl::nullability
750751
absl::strings
751752
absl::synchronization
752753
absl::optional

absl/log/internal/BUILD.bazel

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,11 +462,12 @@ cc_library(
462462
"//absl/log:__subpackages__",
463463
],
464464
deps = [
465+
":fnmatch",
465466
"//absl/base",
466467
"//absl/base:config",
467468
"//absl/base:core_headers",
468469
"//absl/base:no_destructor",
469-
"//absl/log/internal:fnmatch",
470+
"//absl/base:nullability",
470471
"//absl/memory",
471472
"//absl/strings",
472473
"//absl/synchronization",

absl/log/internal/vlog_config.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
#include "absl/base/attributes.h"
3636
#include "absl/base/config.h"
37+
#include "absl/base/nullability.h"
3738
#include "absl/base/optimization.h"
3839
#include "absl/base/thread_annotations.h"
3940
#include "absl/strings/string_view.h"
@@ -60,7 +61,7 @@ constexpr int kUseFlag = (std::numeric_limits<int16_t>::min)();
6061
class VLogSite final {
6162
public:
6263
// `f` must not be destroyed until the program exits.
63-
explicit constexpr VLogSite(const char* f)
64+
explicit constexpr VLogSite(const char* absl_nonnull f)
6465
: file_(f), v_(kUninitialized), next_(nullptr) {}
6566
VLogSite(const VLogSite&) = delete;
6667
VLogSite& operator=(const VLogSite&) = delete;
@@ -116,7 +117,7 @@ class VLogSite final {
116117
ABSL_ATTRIBUTE_NOINLINE bool SlowIsEnabled5(int stale_v);
117118

118119
// This object is too size-sensitive to use absl::string_view.
119-
const char* const file_;
120+
const char* absl_nonnull const file_;
120121
std::atomic<int> v_;
121122
std::atomic<VLogSite*> next_;
122123
};

absl/synchronization/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ cc_library(
140140
"//absl/base:core_headers",
141141
"//absl/base:dynamic_annotations",
142142
"//absl/base:malloc_internal",
143+
"//absl/base:nullability",
143144
"//absl/base:raw_logging_internal",
144145
"//absl/base:tracing_internal",
145146
"//absl/debugging:stacktrace",

absl/synchronization/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ absl_cc_library(
109109
absl::core_headers
110110
absl::dynamic_annotations
111111
absl::malloc_internal
112+
absl::nullability
112113
absl::raw_logging_internal
113114
absl::stacktrace
114115
absl::symbolize

absl/synchronization/mutex.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
#include "absl/base/internal/low_level_alloc.h"
7171
#include "absl/base/internal/thread_identity.h"
7272
#include "absl/base/internal/tsan_mutex_interface.h"
73+
#include "absl/base/nullability.h"
7374
#include "absl/base/port.h"
7475
#include "absl/base/thread_annotations.h"
7576
#include "absl/synchronization/internal/kernel_timeout.h"
@@ -580,14 +581,15 @@ class ABSL_SCOPED_LOCKABLE MutexLock {
580581
// Calls `mu->Lock()` and returns when that call returns. That is, `*mu` is
581582
// guaranteed to be locked when this object is constructed. Requires that
582583
// `mu` be dereferenceable.
583-
explicit MutexLock(Mutex* mu) ABSL_EXCLUSIVE_LOCK_FUNCTION(mu) : mu_(mu) {
584+
explicit MutexLock(Mutex* absl_nonnull mu) ABSL_EXCLUSIVE_LOCK_FUNCTION(mu)
585+
: mu_(mu) {
584586
this->mu_->Lock();
585587
}
586588

587589
// Like above, but calls `mu->LockWhen(cond)` instead. That is, in addition to
588590
// the above, the condition given by `cond` is also guaranteed to hold when
589591
// this object is constructed.
590-
explicit MutexLock(Mutex* mu, const Condition& cond)
592+
explicit MutexLock(Mutex* absl_nonnull mu, const Condition& cond)
591593
ABSL_EXCLUSIVE_LOCK_FUNCTION(mu)
592594
: mu_(mu) {
593595
this->mu_->LockWhen(cond);
@@ -601,7 +603,7 @@ class ABSL_SCOPED_LOCKABLE MutexLock {
601603
~MutexLock() ABSL_UNLOCK_FUNCTION() { this->mu_->Unlock(); }
602604

603605
private:
604-
Mutex* const mu_;
606+
Mutex* absl_nonnull const mu_;
605607
};
606608

607609
// ReaderMutexLock
@@ -610,11 +612,12 @@ class ABSL_SCOPED_LOCKABLE MutexLock {
610612
// releases a shared lock on a `Mutex` via RAII.
611613
class ABSL_SCOPED_LOCKABLE ReaderMutexLock {
612614
public:
613-
explicit ReaderMutexLock(Mutex* mu) ABSL_SHARED_LOCK_FUNCTION(mu) : mu_(mu) {
615+
explicit ReaderMutexLock(Mutex* absl_nonnull mu) ABSL_SHARED_LOCK_FUNCTION(mu)
616+
: mu_(mu) {
614617
mu->ReaderLock();
615618
}
616619

617-
explicit ReaderMutexLock(Mutex* mu, const Condition& cond)
620+
explicit ReaderMutexLock(Mutex* absl_nonnull mu, const Condition& cond)
618621
ABSL_SHARED_LOCK_FUNCTION(mu)
619622
: mu_(mu) {
620623
mu->ReaderLockWhen(cond);
@@ -628,7 +631,7 @@ class ABSL_SCOPED_LOCKABLE ReaderMutexLock {
628631
~ReaderMutexLock() ABSL_UNLOCK_FUNCTION() { this->mu_->ReaderUnlock(); }
629632

630633
private:
631-
Mutex* const mu_;
634+
Mutex* absl_nonnull const mu_;
632635
};
633636

634637
// WriterMutexLock

0 commit comments

Comments
 (0)