mirror of
https://github.com/Tencent/MMKV.git
synced 2026-10-17 04:30:56 +08:00
add MMKV_ASSERT()
This commit is contained in:
@@ -20,7 +20,6 @@
|
||||
|
||||
#include "CodedInputData.h"
|
||||
#include "PBUtility.h"
|
||||
#include <cassert>
|
||||
#include <stdexcept>
|
||||
|
||||
#ifdef MMKV_IOS_OR_MAC
|
||||
@@ -35,7 +34,7 @@ namespace mmkv {
|
||||
|
||||
CodedInputData::CodedInputData(const void *oData, size_t length)
|
||||
: m_ptr((uint8_t *) oData), m_size(length), m_position(0) {
|
||||
assert(m_ptr);
|
||||
MMKV_ASSERT(m_ptr);
|
||||
}
|
||||
|
||||
CodedInputData::~CodedInputData() {
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
#ifdef MMKV_IOS_OR_MAC
|
||||
|
||||
# include "PBUtility.h"
|
||||
# include <cassert>
|
||||
# include <stdexcept>
|
||||
|
||||
# if __has_feature(objc_arc)
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
|
||||
#include "CodedOutputData.h"
|
||||
#include "PBUtility.h"
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
|
||||
@@ -35,7 +34,7 @@ using namespace std;
|
||||
namespace mmkv {
|
||||
|
||||
CodedOutputData::CodedOutputData(void *ptr, size_t len) : m_ptr((uint8_t *) ptr), m_size(len), m_position(0) {
|
||||
assert(m_ptr);
|
||||
MMKV_ASSERT(m_ptr);
|
||||
}
|
||||
|
||||
uint8_t *CodedOutputData::curWritePointer() {
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
#ifdef MMKV_IOS_OR_MAC
|
||||
|
||||
# include "PBUtility.h"
|
||||
# include <cassert>
|
||||
# include <cstring>
|
||||
# include <stdexcept>
|
||||
|
||||
|
||||
@@ -467,6 +467,7 @@
|
||||
CLANG_WARN_SEMICOLON_BEFORE_METHOD_BODY = YES;
|
||||
CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
GCC_PREPROCESSOR_DEFINITIONS = "NDEBUG=1";
|
||||
GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES;
|
||||
GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES;
|
||||
GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES;
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
|
||||
#include "MMKVPredef.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <fcntl.h>
|
||||
|
||||
namespace mmkv {
|
||||
@@ -88,7 +87,7 @@ class InterProcessLock {
|
||||
public:
|
||||
InterProcessLock(FileLock *fileLock, LockType lockType)
|
||||
: m_fileLock(fileLock), m_lockType(lockType), m_enable(true) {
|
||||
assert(m_fileLock);
|
||||
MMKV_ASSERT(m_fileLock);
|
||||
}
|
||||
|
||||
bool m_enable;
|
||||
|
||||
+3
-3
@@ -641,8 +641,8 @@ bool MMKV::ensureMemorySize(size_t newSize) {
|
||||
}
|
||||
|
||||
size_t MMKV::readActualSize() {
|
||||
assert(m_file->getMemory());
|
||||
assert(m_metaFile->isFileValid());
|
||||
MMKV_ASSERT(m_file->getMemory());
|
||||
MMKV_ASSERT(m_metaFile->isFileValid());
|
||||
|
||||
uint32_t actualSize = 0;
|
||||
memcpy(&actualSize, m_file->getMemory(), Fixed32Size);
|
||||
@@ -659,7 +659,7 @@ size_t MMKV::readActualSize() {
|
||||
}
|
||||
|
||||
void MMKV::oldStyleWriteActualSize(size_t actualSize) {
|
||||
assert(m_file->getMemory());
|
||||
MMKV_ASSERT(m_file->getMemory());
|
||||
|
||||
m_actualSize = actualSize;
|
||||
memcpy(m_file->getMemory(), &actualSize, Fixed32Size);
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#define MMKV_MMKVMETAINFO_H
|
||||
|
||||
#include "aes/AESCrypt.h"
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
|
||||
@@ -56,19 +55,19 @@ struct MMKVMetaInfo {
|
||||
} m_lastConfirmedMetaInfo;
|
||||
|
||||
void write(void *ptr) {
|
||||
assert(ptr);
|
||||
MMKV_ASSERT(ptr);
|
||||
memcpy(ptr, this, sizeof(MMKVMetaInfo));
|
||||
}
|
||||
|
||||
void writeCRCAndActualSizeOnly(void *ptr) {
|
||||
assert(ptr);
|
||||
MMKV_ASSERT(ptr);
|
||||
auto other = (MMKVMetaInfo *) ptr;
|
||||
other->m_crcDigest = m_crcDigest;
|
||||
other->m_actualSize = m_actualSize;
|
||||
}
|
||||
|
||||
void read(const void *ptr) {
|
||||
assert(ptr);
|
||||
MMKV_ASSERT(ptr);
|
||||
memcpy(this, ptr, sizeof(MMKVMetaInfo));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#ifndef MMKV_SRC_MMKVPREDEF_H
|
||||
#define MMKV_SRC_MMKVPREDEF_H
|
||||
|
||||
#include <cassert>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
@@ -157,6 +158,12 @@ using MMKVMap = std::unordered_map<std::string, mmkv::MMBuffer>;
|
||||
template <typename T>
|
||||
void unused(const T &) {}
|
||||
|
||||
#ifndef NDEBUG
|
||||
# define MMKV_ASSERT(var) ::assert(var)
|
||||
#else
|
||||
# define MMKV_ASSERT(var) mmkv::unused(var)
|
||||
#endif
|
||||
|
||||
} // namespace mmkv
|
||||
|
||||
#endif //MMKV_SRC_MMKVPREDEF_H
|
||||
|
||||
+1
-1
@@ -130,7 +130,7 @@ void MemoryFile::reloadFromFile() {
|
||||
# endif
|
||||
if (isFileValid()) {
|
||||
MMKVWarning("calling reloadFromFile while the cache [%s] is still valid", m_name.c_str());
|
||||
assert(0);
|
||||
MMKV_ASSERT(0);
|
||||
clearMemoryCache();
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ class ScopedLock {
|
||||
|
||||
public:
|
||||
explicit ScopedLock(T *oLock) : m_lock(oLock) {
|
||||
assert(m_lock);
|
||||
MMKV_ASSERT(m_lock);
|
||||
lock();
|
||||
}
|
||||
|
||||
|
||||
@@ -78,21 +78,6 @@ void ThreadLock::ThreadOnce(ThreadOnceToken_t *onceToken, void (*callback)()) {
|
||||
pthread_once(onceToken, callback);
|
||||
}
|
||||
|
||||
//# ifndef NDEBUG
|
||||
//static uint64_t gettid() {
|
||||
//# ifdef MMKV_MAC
|
||||
// uint64_t tid = 0;
|
||||
// pthread_threadid_np(nullptr, &tid);
|
||||
// return tid;
|
||||
//# elif defined MMKV_LINUX
|
||||
// return ::gettid();
|
||||
//# else
|
||||
// assert(0);
|
||||
// return 0;
|
||||
//# endif
|
||||
//}
|
||||
//# endif
|
||||
|
||||
void ThreadLock::Sleep(int ms) {
|
||||
constexpr auto MILLI_SECOND_MULTIPLIER = 1000;
|
||||
constexpr auto NANO_SECOND_MULTIPLIER = MILLI_SECOND_MULTIPLIER * MILLI_SECOND_MULTIPLIER;
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
|
||||
#include "AESCrypt.h"
|
||||
#include "openssl/openssl_aes.h"
|
||||
#include <cassert>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
@@ -39,7 +38,7 @@ AESCrypt::AESCrypt(const void *key, size_t keyLength, const void *iv, size_t ivL
|
||||
m_aesKey = new AES_KEY;
|
||||
memset(m_aesKey, 0, sizeof(AES_KEY));
|
||||
int ret = AES_set_encrypt_key(m_key, AES_KEY_BITSET_LEN, m_aesKey);
|
||||
assert(ret == 0);
|
||||
MMKV_ASSERT(ret == 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -521,7 +521,7 @@
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
GCC_PREPROCESSOR_DEFINITIONS = NDEBUG;
|
||||
GCC_PREPROCESSOR_DEFINITIONS = "NDEBUG=1";
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.9;
|
||||
OTHER_LDFLAGS = "-ObjC";
|
||||
"OTHER_LDFLAGS[sdk=iphoneos*]" = (
|
||||
|
||||
@@ -152,7 +152,7 @@ static BOOL g_hasCalledInitializeMMKV = NO;
|
||||
}
|
||||
if (!relativePath) {
|
||||
MMKVError("Getting a multi-process MMKV [%@] without setting groupDir makes no sense", mmapID);
|
||||
assert(0);
|
||||
MMKV_ASSERT(0);
|
||||
}
|
||||
}
|
||||
NSString *kvKey = [MMKV mmapKeyWithMMapID:mmapID relativePath:relativePath];
|
||||
|
||||
Reference in New Issue
Block a user