Skip to content

Commit

Permalink
Merge pull request #862 from Tencent/dev
Browse files Browse the repository at this point in the history
for v1.2.13
  • Loading branch information
lingol authored Mar 30, 2022
2 parents eef91a7 + 112afa9 commit 96f0a15
Show file tree
Hide file tree
Showing 36 changed files with 368 additions and 143 deletions.
2 changes: 1 addition & 1 deletion Android/MMKV/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ org.gradle.jvmargs=-Xmx1536m
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

VERSION_NAME_PREFIX=1.2.12
VERSION_NAME_PREFIX=1.2.13
#VERSION_NAME_SUFFIX=-SNAPSHOT
VERSION_NAME_SUFFIX=

Expand Down
8 changes: 7 additions & 1 deletion Android/MMKV/mmkv/src/main/cpp/native-bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,12 @@ MMKV_JNI void checkReSetCryptKey(JNIEnv *env, jobject instance, jstring cryptKey
}
}

# else

MMKV_JNI jstring cryptKey(JNIEnv *env, jobject instance) {
return nullptr;
}

# endif // MMKV_DISABLE_CRYPT

MMKV_JNI void trim(JNIEnv *env, jobject instance) {
Expand Down Expand Up @@ -841,8 +847,8 @@ MMKV_JNI jlong restoreAll(JNIEnv *env, jobject obj, jstring srcDir/*, jstring ro

static JNINativeMethod g_methods[] = {
{"onExit", "()V", (void *) mmkv::onExit},
# ifndef MMKV_DISABLE_CRYPT
{"cryptKey", "()Ljava/lang/String;", (void *) mmkv::cryptKey},
# ifndef MMKV_DISABLE_CRYPT
{"reKey", "(Ljava/lang/String;)Z", (void *) mmkv::reKey},
{"checkReSetCryptKey", "(Ljava/lang/String;)V", (void *) mmkv::checkReSetCryptKey},
# endif
Expand Down
6 changes: 3 additions & 3 deletions Android/MMKV/mmkvdemo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ repositories {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation project(':mmkv')
// implementation 'com.tencent:mmkv:1.2.12'
// implementation 'com.tencent:mmkv-static:1.2.12' // this is identical to 'com.tencent:mmkv'
// implementation 'com.tencent:mmkv-shared:1.2.12'
// implementation 'com.tencent:mmkv:1.2.13'
// implementation 'com.tencent:mmkv-static:1.2.13' // this is identical to 'com.tencent:mmkv'
// implementation 'com.tencent:mmkv-shared:1.2.13'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
testImplementation 'junit:junit:4.13.2'
Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# MMKV Change Log

## v1.2.13 / 2022-03-30

### Android
* Fix crash on using Ashmem while `MMKV_DISABLE_CRYPT` macro is defined.

### iOS
* Add ability to retrieve key existece while getting value, aka `-[MMKV getXXX:forKey:hasValue:]` methods.

### POSIX
* Add ability to retrieve key existece while getting value, aka `MMKV::getXXX(key, defaultValue, hasValue)` methods.

### Win32
* Add ability to retrieve key existece while getting value, aka `MMKV::getXXX(key, defaultValue, hasValue)` methods.

## v1.2.12 / 2022-01-17
### Changes for All platforms
* Fix a bug that a subsequential `clearAll()` call may fail to take effect in multi-process mode.
Expand Down
2 changes: 1 addition & 1 deletion Core/Core.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@
CB9563D023AB2D9500ACCD39 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1240;
LastUpgradeCheck = 1330;
ORGANIZATIONNAME = lingol;
TargetAttributes = {
CB9563D723AB2D9500ACCD39 = {
Expand Down
2 changes: 1 addition & 1 deletion Core/Core.xcodeproj/xcshareddata/xcschemes/Core.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1240"
LastUpgradeVersion = "1330"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1240"
LastUpgradeVersion = "1330"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
77 changes: 70 additions & 7 deletions Core/MMKV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -607,122 +607,185 @@ bool MMKV::getVector(MMKVKey_t key, vector<string> &result) {

#endif // MMKV_APPLE

bool MMKV::getBool(MMKVKey_t key, bool defaultValue) {
bool MMKV::getBool(MMKVKey_t key, bool defaultValue, bool *hasValue) {
if (isKeyEmpty(key)) {
if (hasValue != nullptr) {
*hasValue = false;
}
return defaultValue;
}
SCOPED_LOCK(m_lock);
auto data = getDataForKey(key);
if (data.length() > 0) {
try {
CodedInputData input(data.getPtr(), data.length());
if (hasValue != nullptr) {
*hasValue = true;
}
return input.readBool();
} catch (std::exception &exception) {
MMKVError("%s", exception.what());
}
}
if (hasValue != nullptr) {
*hasValue = false;
}
return defaultValue;
}

int32_t MMKV::getInt32(MMKVKey_t key, int32_t defaultValue) {
int32_t MMKV::getInt32(MMKVKey_t key, int32_t defaultValue, bool *hasValue) {
if (isKeyEmpty(key)) {
if (hasValue != nullptr) {
*hasValue = false;
}
return defaultValue;
}
SCOPED_LOCK(m_lock);
auto data = getDataForKey(key);
if (data.length() > 0) {
try {
CodedInputData input(data.getPtr(), data.length());
if (hasValue != nullptr) {
*hasValue = true;
}
return input.readInt32();
} catch (std::exception &exception) {
MMKVError("%s", exception.what());
}
}
if (hasValue != nullptr) {
*hasValue = false;
}
return defaultValue;
}

uint32_t MMKV::getUInt32(MMKVKey_t key, uint32_t defaultValue) {
uint32_t MMKV::getUInt32(MMKVKey_t key, uint32_t defaultValue, bool *hasValue) {
if (isKeyEmpty(key)) {
if (hasValue != nullptr) {
*hasValue = false;
}
return defaultValue;
}
SCOPED_LOCK(m_lock);
auto data = getDataForKey(key);
if (data.length() > 0) {
try {
CodedInputData input(data.getPtr(), data.length());
if (hasValue != nullptr) {
*hasValue = true;
}
return input.readUInt32();
} catch (std::exception &exception) {
MMKVError("%s", exception.what());
}
}
if (hasValue != nullptr) {
*hasValue = false;
}
return defaultValue;
}

int64_t MMKV::getInt64(MMKVKey_t key, int64_t defaultValue) {
int64_t MMKV::getInt64(MMKVKey_t key, int64_t defaultValue, bool *hasValue) {
if (isKeyEmpty(key)) {
if (hasValue != nullptr) {
*hasValue = false;
}
return defaultValue;
}
SCOPED_LOCK(m_lock);
auto data = getDataForKey(key);
if (data.length() > 0) {
try {
CodedInputData input(data.getPtr(), data.length());
if (hasValue != nullptr) {
*hasValue = true;
}
return input.readInt64();
} catch (std::exception &exception) {
MMKVError("%s", exception.what());
}
}
if (hasValue != nullptr) {
*hasValue = false;
}
return defaultValue;
}

uint64_t MMKV::getUInt64(MMKVKey_t key, uint64_t defaultValue) {
uint64_t MMKV::getUInt64(MMKVKey_t key, uint64_t defaultValue, bool *hasValue) {
if (isKeyEmpty(key)) {
if (hasValue != nullptr) {
*hasValue = false;
}
return defaultValue;
}
SCOPED_LOCK(m_lock);
auto data = getDataForKey(key);
if (data.length() > 0) {
try {
CodedInputData input(data.getPtr(), data.length());
if (hasValue != nullptr) {
*hasValue = true;
}
return input.readUInt64();
} catch (std::exception &exception) {
MMKVError("%s", exception.what());
}
}
if (hasValue != nullptr) {
*hasValue = false;
}
return defaultValue;
}

float MMKV::getFloat(MMKVKey_t key, float defaultValue) {
float MMKV::getFloat(MMKVKey_t key, float defaultValue, bool *hasValue) {
if (isKeyEmpty(key)) {
if (hasValue != nullptr) {
*hasValue = false;
}
return defaultValue;
}
SCOPED_LOCK(m_lock);
auto data = getDataForKey(key);
if (data.length() > 0) {
try {
CodedInputData input(data.getPtr(), data.length());
if (hasValue != nullptr) {
*hasValue = true;
}
return input.readFloat();
} catch (std::exception &exception) {
MMKVError("%s", exception.what());
}
}
if (hasValue != nullptr) {
*hasValue = false;
}
return defaultValue;
}

double MMKV::getDouble(MMKVKey_t key, double defaultValue) {
double MMKV::getDouble(MMKVKey_t key, double defaultValue, bool *hasValue) {
if (isKeyEmpty(key)) {
if (hasValue != nullptr) {
*hasValue = false;
}
return defaultValue;
}
SCOPED_LOCK(m_lock);
auto data = getDataForKey(key);
if (data.length() > 0) {
try {
CodedInputData input(data.getPtr(), data.length());
if (hasValue != nullptr) {
*hasValue = true;
}
return input.readDouble();
} catch (std::exception &exception) {
MMKVError("%s", exception.what());
}
}
if (hasValue != nullptr) {
*hasValue = false;
}
return defaultValue;
}

Expand Down
16 changes: 9 additions & 7 deletions Core/MMKV.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ enum MMKVMode : uint32_t {
#endif
};

#define OUT

class MMKV {
#ifndef MMKV_ANDROID
std::string m_mmapKey;
Expand Down Expand Up @@ -253,19 +255,19 @@ class MMKV {
bool getVector(MMKVKey_t key, std::vector<std::string> &result);
#endif // MMKV_APPLE

bool getBool(MMKVKey_t key, bool defaultValue = false);
bool getBool(MMKVKey_t key, bool defaultValue = false, OUT bool *hasValue = nullptr);

int32_t getInt32(MMKVKey_t key, int32_t defaultValue = 0);
int32_t getInt32(MMKVKey_t key, int32_t defaultValue = 0, OUT bool *hasValue = nullptr);

uint32_t getUInt32(MMKVKey_t key, uint32_t defaultValue = 0);
uint32_t getUInt32(MMKVKey_t key, uint32_t defaultValue = 0, OUT bool *hasValue = nullptr);

int64_t getInt64(MMKVKey_t key, int64_t defaultValue = 0);
int64_t getInt64(MMKVKey_t key, int64_t defaultValue = 0, OUT bool *hasValue = nullptr);

uint64_t getUInt64(MMKVKey_t key, uint64_t defaultValue = 0);
uint64_t getUInt64(MMKVKey_t key, uint64_t defaultValue = 0, OUT bool *hasValue = nullptr);

float getFloat(MMKVKey_t key, float defaultValue = 0);
float getFloat(MMKVKey_t key, float defaultValue = 0, OUT bool *hasValue = nullptr);

double getDouble(MMKVKey_t key, double defaultValue = 0);
double getDouble(MMKVKey_t key, double defaultValue = 0, OUT bool *hasValue = nullptr);

// return the actual size consumption of the key's value
// pass actualSize = true to get value's length
Expand Down
2 changes: 1 addition & 1 deletion Core/MMKVPredef.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include <vector>
#include <unordered_map>

constexpr auto MMKV_VERSION = "v1.2.12";
constexpr auto MMKV_VERSION = "v1.2.13";

#ifdef DEBUG
# define MMKV_DEBUG
Expand Down
4 changes: 2 additions & 2 deletions MMKV.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "MMKV"
s.version = "1.2.12"
s.version = "1.2.13"
s.summary = "MMKV is a cross-platform key-value storage framework developed by WeChat."

s.description = <<-DESC
Expand Down Expand Up @@ -31,7 +31,7 @@ Pod::Spec.new do |s|
"CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF" => "NO",
}

s.dependency 'MMKVCore', '~> 1.2.12'
s.dependency 'MMKVCore', '~> 1.2.13'

end

4 changes: 2 additions & 2 deletions MMKVAppExtension.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "MMKVAppExtension"
s.version = "1.2.12"
s.version = "1.2.13"
s.summary = "MMKV is a cross-platform key-value storage framework developed by WeChat."
s.module_name = "MMKVAppExtension"

Expand Down Expand Up @@ -31,7 +31,7 @@ Pod::Spec.new do |s|
"GCC_PREPROCESSOR_DEFINITIONS" => "MMKV_IOS_EXTENSION",
}

s.dependency 'MMKVCore', '~> 1.2.12'
s.dependency 'MMKVCore', '~> 1.2.13'

end

2 changes: 1 addition & 1 deletion MMKVCore.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "MMKVCore"
s.version = "1.2.12"
s.version = "1.2.13"
s.summary = "MMKVCore for MMKV. MMKV is a cross-platform key-value storage framework developed by WeChat."

s.description = <<-DESC
Expand Down
4 changes: 2 additions & 2 deletions MMKVWatchExtension.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "MMKVWatchExtension"
s.version = "1.2.12"
s.version = "1.2.13"
s.summary = "MMKV is a cross-platform key-value storage framework developed by WeChat."
s.module_name = "MMKVWatchExtension"

Expand Down Expand Up @@ -31,7 +31,7 @@ Pod::Spec.new do |s|
"GCC_PREPROCESSOR_DEFINITIONS" => "MMKV_IOS_EXTENSION",
}

s.dependency 'MMKVCore', '~> 1.2.12'
s.dependency 'MMKVCore', '~> 1.2.13'

end

Loading

0 comments on commit 96f0a15

Please sign in to comment.