From a6f3a61ce0f56e7fe19b95aa907612ae65ff2383 Mon Sep 17 00:00:00 2001 From: guoling Date: Tue, 29 Jan 2019 20:56:09 +0800 Subject: [PATCH 01/17] fix warning --- Android/MMKV/mmkv/src/main/cpp/MMKV.cpp | 30 ++++++++++++++----------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/Android/MMKV/mmkv/src/main/cpp/MMKV.cpp b/Android/MMKV/mmkv/src/main/cpp/MMKV.cpp index 62280ede..f2b4f59e 100644 --- a/Android/MMKV/mmkv/src/main/cpp/MMKV.cpp +++ b/Android/MMKV/mmkv/src/main/cpp/MMKV.cpp @@ -1307,28 +1307,32 @@ bool MMKV::isFileValid(const std::string &mmapID) { uint32_t crcFile = 0; MMBuffer *data = readWholeFile(crcPath.c_str()); - if (data && data->getPtr()) { - MMKVMetaInfo metaInfo; - metaInfo.read(data->getPtr()); - crcFile = metaInfo.m_crcDigest; + if (data) { + if (data->getPtr()) { + MMKVMetaInfo metaInfo; + metaInfo.read(data->getPtr()); + crcFile = metaInfo.m_crcDigest; + } delete data; } else { return false; } const int offset = pbFixed32Size(0); - size_t actualSize = 0; + uint32_t crcDigest = 0; MMBuffer *fileData = readWholeFile(kvPath.c_str()); if (fileData) { - actualSize = CodedInputData(fileData->getPtr(), fileData->length()).readFixed32(); - if (actualSize > fileData->length() - offset) { - delete fileData; - return false; - } - - uint32_t crcDigest = (uint32_t) crc32(0, (const uint8_t *) fileData->getPtr() + offset, - (uint32_t) actualSize); + if (fileData->getPtr()) { + size_t actualSize = + CodedInputData(fileData->getPtr(), fileData->length()).readFixed32(); + if (actualSize > fileData->length() - offset) { + delete fileData; + return false; + } + crcDigest = (uint32_t) crc32(0, (const uint8_t *) fileData->getPtr() + offset, + (uint32_t) actualSize); + } delete fileData; return crcFile == crcDigest; } else { From 93aef48e0ae6b3258b24e604c2f44799dee027fb Mon Sep 17 00:00:00 2001 From: guoling Date: Mon, 25 Feb 2019 21:30:45 +0800 Subject: [PATCH 02/17] hide openssl symbols --- iOS/MMKV/MMKV.xcodeproj/project.pbxproj | 62 ++++++++++--------- iOS/MMKV/MMKV/MMKV.mm | 2 +- iOS/MMKV/MMKV/aes/AESCrypt.h | 2 +- iOS/MMKV/MMKV/aes/AESCrypt.mm | 6 +- iOS/MMKV/MMKV/aes/openssl/aes.h | 9 +-- .../aes/openssl/{aes_cfb.c => aes_cfb.cpp} | 3 + .../aes/openssl/{aes_core.c => aes_core.cpp} | 5 ++ .../MMKV/aes/openssl/{cfb128.c => cfb128.cpp} | 4 ++ iOS/MMKV/MMKV/aes/openssl/md32_common.h | 16 ++--- iOS/MMKV/MMKV/aes/openssl/md5.h | 12 ++-- .../aes/openssl/{md5_dgst.c => md5_dgst.cpp} | 7 ++- iOS/MMKV/MMKV/aes/openssl/md5_locl.h | 6 +- .../aes/openssl/{md5_one.c => md5_one.cpp} | 4 ++ iOS/MMKV/MMKV/aes/openssl/modes.h | 10 +-- 14 files changed, 82 insertions(+), 66 deletions(-) rename iOS/MMKV/MMKV/aes/openssl/{aes_cfb.c => aes_cfb.cpp} (95%) rename iOS/MMKV/MMKV/aes/openssl/{aes_core.c => aes_core.cpp} (99%) rename iOS/MMKV/MMKV/aes/openssl/{cfb128.c => cfb128.cpp} (98%) rename iOS/MMKV/MMKV/aes/openssl/{md5_dgst.c => md5_dgst.cpp} (97%) rename iOS/MMKV/MMKV/aes/openssl/{md5_one.c => md5_one.cpp} (93%) diff --git a/iOS/MMKV/MMKV.xcodeproj/project.pbxproj b/iOS/MMKV/MMKV.xcodeproj/project.pbxproj index 86bbbd68..0e3699ed 100644 --- a/iOS/MMKV/MMKV.xcodeproj/project.pbxproj +++ b/iOS/MMKV/MMKV.xcodeproj/project.pbxproj @@ -16,12 +16,12 @@ CB1FD4CD2046ACBC00931B5F /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CB1FD4CC2046ACBC00931B5F /* Foundation.framework */; }; CB6DEFA9212E6F010024F0E8 /* AESCrypt.h in Headers */ = {isa = PBXBuildFile; fileRef = CB6DEF9F212E6F010024F0E8 /* AESCrypt.h */; }; CB6DEFAA212E6F010024F0E8 /* opensslconf.h in Headers */ = {isa = PBXBuildFile; fileRef = CB6DEFA1212E6F010024F0E8 /* opensslconf.h */; }; - CB6DEFAB212E6F010024F0E8 /* cfb128.c in Sources */ = {isa = PBXBuildFile; fileRef = CB6DEFA2212E6F010024F0E8 /* cfb128.c */; }; - CB6DEFAC212E6F010024F0E8 /* cfb128.c in Sources */ = {isa = PBXBuildFile; fileRef = CB6DEFA2212E6F010024F0E8 /* cfb128.c */; }; - CB6DEFAD212E6F010024F0E8 /* aes_core.c in Sources */ = {isa = PBXBuildFile; fileRef = CB6DEFA3212E6F010024F0E8 /* aes_core.c */; }; - CB6DEFAE212E6F010024F0E8 /* aes_core.c in Sources */ = {isa = PBXBuildFile; fileRef = CB6DEFA3212E6F010024F0E8 /* aes_core.c */; }; - CB6DEFAF212E6F010024F0E8 /* aes_cfb.c in Sources */ = {isa = PBXBuildFile; fileRef = CB6DEFA4212E6F010024F0E8 /* aes_cfb.c */; }; - CB6DEFB0212E6F010024F0E8 /* aes_cfb.c in Sources */ = {isa = PBXBuildFile; fileRef = CB6DEFA4212E6F010024F0E8 /* aes_cfb.c */; }; + CB6DEFAB212E6F010024F0E8 /* cfb128.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CB6DEFA2212E6F010024F0E8 /* cfb128.cpp */; }; + CB6DEFAC212E6F010024F0E8 /* cfb128.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CB6DEFA2212E6F010024F0E8 /* cfb128.cpp */; }; + CB6DEFAD212E6F010024F0E8 /* aes_core.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CB6DEFA3212E6F010024F0E8 /* aes_core.cpp */; }; + CB6DEFAE212E6F010024F0E8 /* aes_core.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CB6DEFA3212E6F010024F0E8 /* aes_core.cpp */; }; + CB6DEFAF212E6F010024F0E8 /* aes_cfb.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CB6DEFA4212E6F010024F0E8 /* aes_cfb.cpp */; }; + CB6DEFB0212E6F010024F0E8 /* aes_cfb.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CB6DEFA4212E6F010024F0E8 /* aes_cfb.cpp */; }; CB6DEFB1212E6F010024F0E8 /* aes.h in Headers */ = {isa = PBXBuildFile; fileRef = CB6DEFA5212E6F010024F0E8 /* aes.h */; }; CB6DEFB2212E6F010024F0E8 /* modes.h in Headers */ = {isa = PBXBuildFile; fileRef = CB6DEFA6212E6F010024F0E8 /* modes.h */; }; CB6DEFB3212E6F010024F0E8 /* aes_locl.h in Headers */ = {isa = PBXBuildFile; fileRef = CB6DEFA7212E6F010024F0E8 /* aes_locl.h */; }; @@ -45,10 +45,10 @@ CBDF32912192C0340028DB4D /* MMKVHandler.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = CBDF328F2192C0000028DB4D /* MMKVHandler.h */; }; CBF00476217DD7D0001BB3ED /* md5.h in Headers */ = {isa = PBXBuildFile; fileRef = CBF00471217DD7D0001BB3ED /* md5.h */; }; CBF00477217DD7D0001BB3ED /* md32_common.h in Headers */ = {isa = PBXBuildFile; fileRef = CBF00472217DD7D0001BB3ED /* md32_common.h */; }; - CBF00478217DD7D0001BB3ED /* md5_dgst.c in Sources */ = {isa = PBXBuildFile; fileRef = CBF00473217DD7D0001BB3ED /* md5_dgst.c */; }; - CBF00479217DD7D0001BB3ED /* md5_dgst.c in Sources */ = {isa = PBXBuildFile; fileRef = CBF00473217DD7D0001BB3ED /* md5_dgst.c */; }; - CBF0047A217DD7D0001BB3ED /* md5_one.c in Sources */ = {isa = PBXBuildFile; fileRef = CBF00474217DD7D0001BB3ED /* md5_one.c */; }; - CBF0047B217DD7D0001BB3ED /* md5_one.c in Sources */ = {isa = PBXBuildFile; fileRef = CBF00474217DD7D0001BB3ED /* md5_one.c */; }; + CBF00478217DD7D0001BB3ED /* md5_dgst.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CBF00473217DD7D0001BB3ED /* md5_dgst.cpp */; }; + CBF00479217DD7D0001BB3ED /* md5_dgst.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CBF00473217DD7D0001BB3ED /* md5_dgst.cpp */; }; + CBF0047A217DD7D0001BB3ED /* md5_one.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CBF00474217DD7D0001BB3ED /* md5_one.cpp */; }; + CBF0047B217DD7D0001BB3ED /* md5_one.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CBF00474217DD7D0001BB3ED /* md5_one.cpp */; }; CBF0047C217DD7D0001BB3ED /* md5_locl.h in Headers */ = {isa = PBXBuildFile; fileRef = CBF00475217DD7D0001BB3ED /* md5_locl.h */; }; /* End PBXBuildFile section */ @@ -84,9 +84,9 @@ CB1FD5152049382F00931B5F /* ScopedLock.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = ScopedLock.hpp; sourceTree = ""; }; CB6DEF9F212E6F010024F0E8 /* AESCrypt.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AESCrypt.h; sourceTree = ""; }; CB6DEFA1212E6F010024F0E8 /* opensslconf.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = opensslconf.h; sourceTree = ""; }; - CB6DEFA2212E6F010024F0E8 /* cfb128.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = cfb128.c; sourceTree = ""; }; - CB6DEFA3212E6F010024F0E8 /* aes_core.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = aes_core.c; sourceTree = ""; }; - CB6DEFA4212E6F010024F0E8 /* aes_cfb.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = aes_cfb.c; sourceTree = ""; }; + CB6DEFA2212E6F010024F0E8 /* cfb128.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = cfb128.cpp; sourceTree = ""; }; + CB6DEFA3212E6F010024F0E8 /* aes_core.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = aes_core.cpp; sourceTree = ""; }; + CB6DEFA4212E6F010024F0E8 /* aes_cfb.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = aes_cfb.cpp; sourceTree = ""; }; CB6DEFA5212E6F010024F0E8 /* aes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = aes.h; sourceTree = ""; }; CB6DEFA6212E6F010024F0E8 /* modes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = modes.h; sourceTree = ""; }; CB6DEFA7212E6F010024F0E8 /* aes_locl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = aes_locl.h; sourceTree = ""; }; @@ -102,8 +102,8 @@ CBDF328F2192C0000028DB4D /* MMKVHandler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MMKVHandler.h; sourceTree = ""; }; CBF00471217DD7D0001BB3ED /* md5.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = md5.h; sourceTree = ""; }; CBF00472217DD7D0001BB3ED /* md32_common.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = md32_common.h; sourceTree = ""; }; - CBF00473217DD7D0001BB3ED /* md5_dgst.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = md5_dgst.c; sourceTree = ""; }; - CBF00474217DD7D0001BB3ED /* md5_one.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = md5_one.c; sourceTree = ""; }; + CBF00473217DD7D0001BB3ED /* md5_dgst.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = md5_dgst.cpp; sourceTree = ""; }; + CBF00474217DD7D0001BB3ED /* md5_one.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = md5_one.cpp; sourceTree = ""; }; CBF00475217DD7D0001BB3ED /* md5_locl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = md5_locl.h; sourceTree = ""; }; /* End PBXFileReference section */ @@ -196,14 +196,14 @@ CB6DEFA0212E6F010024F0E8 /* openssl */ = { isa = PBXGroup; children = ( - CB6DEFA4212E6F010024F0E8 /* aes_cfb.c */, - CB6DEFA3212E6F010024F0E8 /* aes_core.c */, + CB6DEFA4212E6F010024F0E8 /* aes_cfb.cpp */, + CB6DEFA3212E6F010024F0E8 /* aes_core.cpp */, CB6DEFA7212E6F010024F0E8 /* aes_locl.h */, CB6DEFA5212E6F010024F0E8 /* aes.h */, - CB6DEFA2212E6F010024F0E8 /* cfb128.c */, - CBF00473217DD7D0001BB3ED /* md5_dgst.c */, + CB6DEFA2212E6F010024F0E8 /* cfb128.cpp */, + CBF00473217DD7D0001BB3ED /* md5_dgst.cpp */, CBF00475217DD7D0001BB3ED /* md5_locl.h */, - CBF00474217DD7D0001BB3ED /* md5_one.c */, + CBF00474217DD7D0001BB3ED /* md5_one.cpp */, CBF00471217DD7D0001BB3ED /* md5.h */, CBF00472217DD7D0001BB3ED /* md32_common.h */, CB6DEFA6212E6F010024F0E8 /* modes.h */, @@ -334,15 +334,15 @@ files = ( CB1FD4C320469B8800931B5F /* MiniCodedOutputData.mm in Sources */, CB8FD91C21F1B8C10005EE8F /* MMKVLog.mm in Sources */, - CB6DEFAB212E6F010024F0E8 /* cfb128.c in Sources */, - CB6DEFAF212E6F010024F0E8 /* aes_cfb.c in Sources */, + CB6DEFAB212E6F010024F0E8 /* cfb128.cpp in Sources */, + CB6DEFAF212E6F010024F0E8 /* aes_cfb.cpp in Sources */, CB1FD4962046984F00931B5F /* MMKV.mm in Sources */, CB1FD4C520469B8800931B5F /* MiniPBUtility.mm in Sources */, - CB6DEFAD212E6F010024F0E8 /* aes_core.c in Sources */, + CB6DEFAD212E6F010024F0E8 /* aes_core.cpp in Sources */, CB1FD4C420469B8800931B5F /* MiniCodedInputData.mm in Sources */, CB865F5620FF33F600427B9D /* MemoryFile.mm in Sources */, - CBF00478217DD7D0001BB3ED /* md5_dgst.c in Sources */, - CBF0047A217DD7D0001BB3ED /* md5_one.c in Sources */, + CBF00478217DD7D0001BB3ED /* md5_dgst.cpp in Sources */, + CBF0047A217DD7D0001BB3ED /* md5_one.cpp in Sources */, CB6DEFB4212E6F010024F0E8 /* AESCrypt.mm in Sources */, CB1FD4C620469B8800931B5F /* MiniPBCoder.mm in Sources */, ); @@ -354,15 +354,15 @@ files = ( CBC1A8FE20DA948A00AD5087 /* MiniCodedInputData.mm in Sources */, CB8FD91D21F1B8C10005EE8F /* MMKVLog.mm in Sources */, - CB6DEFAC212E6F010024F0E8 /* cfb128.c in Sources */, - CB6DEFB0212E6F010024F0E8 /* aes_cfb.c in Sources */, + CB6DEFAC212E6F010024F0E8 /* cfb128.cpp in Sources */, + CB6DEFB0212E6F010024F0E8 /* aes_cfb.cpp in Sources */, CBC1A8FF20DA948A00AD5087 /* MiniCodedOutputData.mm in Sources */, CBC1A90020DA948A00AD5087 /* MiniPBCoder.mm in Sources */, - CB6DEFAE212E6F010024F0E8 /* aes_core.c in Sources */, + CB6DEFAE212E6F010024F0E8 /* aes_core.cpp in Sources */, CBC1A90120DA948A00AD5087 /* MiniPBUtility.mm in Sources */, CB865F5720FF33F600427B9D /* MemoryFile.mm in Sources */, - CBF00479217DD7D0001BB3ED /* md5_dgst.c in Sources */, - CBF0047B217DD7D0001BB3ED /* md5_one.c in Sources */, + CBF00479217DD7D0001BB3ED /* md5_dgst.cpp in Sources */, + CBF0047B217DD7D0001BB3ED /* md5_one.cpp in Sources */, CB6DEFB5212E6F010024F0E8 /* AESCrypt.mm in Sources */, CBC1A90220DA948A00AD5087 /* MMKV.mm in Sources */, ); @@ -547,6 +547,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; + GENERATE_MASTER_OBJECT_FILE = NO; INFOPLIST_FILE = "$(SRCROOT)/MMKV/Resources/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; @@ -585,6 +586,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; + GENERATE_MASTER_OBJECT_FILE = NO; INFOPLIST_FILE = "$(SRCROOT)/MMKV/Resources/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; diff --git a/iOS/MMKV/MMKV/MMKV.mm b/iOS/MMKV/MMKV/MMKV.mm index 7be53e9f..2cccee1b 100644 --- a/iOS/MMKV/MMKV/MMKV.mm +++ b/iOS/MMKV/MMKV/MMKV.mm @@ -1483,7 +1483,7 @@ + (BOOL)tranlateData:(id)obj key:(NSString *)key kv:(MMKV *)kv { static NSString *md5(NSString *value) { unsigned char md[MD5_DIGEST_LENGTH] = {0}; char tmp[3] = {0}, buf[33] = {0}; - MD5((unsigned char *) value.UTF8String, [value lengthOfBytesUsingEncoding:NSUTF8StringEncoding], md); + openssl::MD5((unsigned char *) value.UTF8String, [value lengthOfBytesUsingEncoding:NSUTF8StringEncoding], md); for (int i = 0; i < MD5_DIGEST_LENGTH; i++) { sprintf(tmp, "%2.2x", md[i]); strcat(buf, tmp); diff --git a/iOS/MMKV/MMKV/aes/AESCrypt.h b/iOS/MMKV/MMKV/aes/AESCrypt.h index 0196bd9e..1ac88185 100644 --- a/iOS/MMKV/MMKV/aes/AESCrypt.h +++ b/iOS/MMKV/MMKV/aes/AESCrypt.h @@ -31,7 +31,7 @@ constexpr size_t AES_KEY_BITSET_LEN = 128; class AESCrypt { unsigned char m_vector[AES_KEY_LEN] = {0}; unsigned char m_key[AES_KEY_LEN] = {0}; - AES_KEY m_aesKey = {0}; + openssl::AES_KEY m_aesKey = {0}; int m_number = 0; public: diff --git a/iOS/MMKV/MMKV/aes/AESCrypt.mm b/iOS/MMKV/MMKV/aes/AESCrypt.mm index 48481e89..5e857fee 100644 --- a/iOS/MMKV/MMKV/aes/AESCrypt.mm +++ b/iOS/MMKV/MMKV/aes/AESCrypt.mm @@ -29,7 +29,7 @@ memcpy(m_key, key, (keyLength > AES_KEY_LEN) ? AES_KEY_LEN : keyLength); memcpy(m_vector, m_key, AES_KEY_LEN); - int ret = AES_set_encrypt_key(m_key, AES_KEY_BITSET_LEN, &m_aesKey); + int ret = openssl::AES_set_encrypt_key(m_key, AES_KEY_BITSET_LEN, &m_aesKey); assert(ret == 0); } } @@ -49,14 +49,14 @@ if (!input || !output || length == 0) { return; } - AES_cfb128_encrypt(input, output, length, &m_aesKey, m_vector, &m_number, AES_ENCRYPT); + openssl::AES_cfb128_encrypt(input, output, length, &m_aesKey, m_vector, &m_number, AES_ENCRYPT); } void AESCrypt::decrypt(const unsigned char *input, unsigned char *output, size_t length) { if (!input || !output || length == 0) { return; } - AES_cfb128_encrypt(input, output, length, &m_aesKey, m_vector, &m_number, AES_DECRYPT); + openssl::AES_cfb128_encrypt(input, output, length, &m_aesKey, m_vector, &m_number, AES_DECRYPT); } #ifndef NDEBUG diff --git a/iOS/MMKV/MMKV/aes/openssl/aes.h b/iOS/MMKV/MMKV/aes/openssl/aes.h index 33da448c..b671f614 100644 --- a/iOS/MMKV/MMKV/aes/openssl/aes.h +++ b/iOS/MMKV/MMKV/aes/openssl/aes.h @@ -13,9 +13,8 @@ # include "opensslconf.h" # include -# ifdef __cplusplus -extern "C" { -# endif + +namespace openssl { # define AES_ENCRYPT 1 # define AES_DECRYPT 0 @@ -48,8 +47,6 @@ void AES_cfb128_encrypt(const unsigned char *in, unsigned char *out, size_t length, const AES_KEY *key, unsigned char *ivec, int *num, const int enc); -# ifdef __cplusplus -} -# endif +} // namespace openssl #endif diff --git a/iOS/MMKV/MMKV/aes/openssl/aes_cfb.c b/iOS/MMKV/MMKV/aes/openssl/aes_cfb.cpp similarity index 95% rename from iOS/MMKV/MMKV/aes/openssl/aes_cfb.c rename to iOS/MMKV/MMKV/aes/openssl/aes_cfb.cpp index ffe6438b..23fe8019 100644 --- a/iOS/MMKV/MMKV/aes/openssl/aes_cfb.c +++ b/iOS/MMKV/MMKV/aes/openssl/aes_cfb.cpp @@ -15,6 +15,7 @@ * The extra state information to record how much of the 128bit block we have * used is contained in *num; */ +namespace openssl { void AES_cfb128_encrypt(const unsigned char *in, unsigned char *out, size_t length, const AES_KEY *key, @@ -24,3 +25,5 @@ void AES_cfb128_encrypt(const unsigned char *in, unsigned char *out, CRYPTO_cfb128_encrypt(in, out, length, key, ivec, num, enc, (block128_f) AES_encrypt); } + +} // namespace openssl diff --git a/iOS/MMKV/MMKV/aes/openssl/aes_core.c b/iOS/MMKV/MMKV/aes/openssl/aes_core.cpp similarity index 99% rename from iOS/MMKV/MMKV/aes/openssl/aes_core.c rename to iOS/MMKV/MMKV/aes/openssl/aes_core.cpp index 2f8c7d45..4505aada 100644 --- a/iOS/MMKV/MMKV/aes/openssl/aes_core.c +++ b/iOS/MMKV/MMKV/aes/openssl/aes_core.cpp @@ -42,6 +42,8 @@ #include "aes.h" #include "aes_locl.h" +namespace openssl { + /*- Te0[x] = S [x].[02, 01, 01, 03]; Te1[x] = S [x].[03, 02, 01, 01]; @@ -627,6 +629,7 @@ static const u32 rcon[] = { 0x1B000000, 0x36000000, /* for 128-bit blocks, Rijndael never uses more than 10 rcon values */ }; + /** * Expand the cipher key into the encryption key schedule. */ @@ -919,3 +922,5 @@ void AES_encrypt(const unsigned char *in, unsigned char *out, rk[3]; PUTU32(out + 12, s3); } + +} // namespace openssl diff --git a/iOS/MMKV/MMKV/aes/openssl/cfb128.c b/iOS/MMKV/MMKV/aes/openssl/cfb128.cpp similarity index 98% rename from iOS/MMKV/MMKV/aes/openssl/cfb128.c rename to iOS/MMKV/MMKV/aes/openssl/cfb128.cpp index 3f5a809b..019e28bf 100644 --- a/iOS/MMKV/MMKV/aes/openssl/cfb128.c +++ b/iOS/MMKV/MMKV/aes/openssl/cfb128.cpp @@ -11,6 +11,8 @@ #include "modes.h" #include +namespace openssl { + /* * The input and output encrypted as though 128bit cfb mode is being used. * The extra state information to record how much of the 128bit block we have @@ -129,3 +131,5 @@ void CRYPTO_cfb128_encrypt(const unsigned char *in, unsigned char *out, *num = n; } } + +} // namespace openssl diff --git a/iOS/MMKV/MMKV/aes/openssl/md32_common.h b/iOS/MMKV/MMKV/aes/openssl/md32_common.h index dbdddc65..08af38c0 100755 --- a/iOS/MMKV/MMKV/aes/openssl/md32_common.h +++ b/iOS/MMKV/MMKV/aes/openssl/md32_common.h @@ -81,9 +81,9 @@ #ifndef HASH_UPDATE # error "HASH_UPDATE must be defined!" #endif -#ifndef HASH_TRANSFORM -# error "HASH_TRANSFORM must be defined!" -#endif +//#ifndef HASH_TRANSFORM +//# error "HASH_TRANSFORM must be defined!" +//#endif #ifndef HASH_FINAL # error "HASH_FINAL must be defined!" #endif @@ -126,7 +126,7 @@ int HASH_UPDATE(HASH_CTX *c, const void *data_, size_t len) { - const unsigned char *data = data_; + auto data = (const unsigned char *) data_; unsigned char *p; HASH_LONG l; size_t n; @@ -182,10 +182,10 @@ int HASH_UPDATE(HASH_CTX *c, const void *data_, size_t len) return 1; } -void HASH_TRANSFORM(HASH_CTX *c, const unsigned char *data) -{ - HASH_BLOCK_DATA_ORDER(c, data, 1); -} +//void HASH_TRANSFORM(HASH_CTX *c, const unsigned char *data) +//{ +// HASH_BLOCK_DATA_ORDER(c, data, 1); +//} int HASH_FINAL(unsigned char *md, HASH_CTX *c) { diff --git a/iOS/MMKV/MMKV/aes/openssl/md5.h b/iOS/MMKV/MMKV/aes/openssl/md5.h index 18fac685..a94893f6 100755 --- a/iOS/MMKV/MMKV/aes/openssl/md5.h +++ b/iOS/MMKV/MMKV/aes/openssl/md5.h @@ -14,9 +14,8 @@ # ifndef OPENSSL_NO_MD5 # include -# ifdef __cplusplus -extern "C" { -# endif + +namespace openssl { /* * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! @@ -40,10 +39,9 @@ int MD5_Init(MD5_CTX *c); int MD5_Update(MD5_CTX *c, const void *data, size_t len); int MD5_Final(unsigned char *md, MD5_CTX *c); unsigned char *MD5(const unsigned char *d, size_t n, unsigned char *md); -void MD5_Transform(MD5_CTX *c, const unsigned char *b); -# ifdef __cplusplus -} -# endif +//void MD5_Transform(MD5_CTX *c, const unsigned char *b); + +} // namespace openssl # endif #endif diff --git a/iOS/MMKV/MMKV/aes/openssl/md5_dgst.c b/iOS/MMKV/MMKV/aes/openssl/md5_dgst.cpp similarity index 97% rename from iOS/MMKV/MMKV/aes/openssl/md5_dgst.c rename to iOS/MMKV/MMKV/aes/openssl/md5_dgst.cpp index d3b89ff0..ae59f39c 100755 --- a/iOS/MMKV/MMKV/aes/openssl/md5_dgst.c +++ b/iOS/MMKV/MMKV/aes/openssl/md5_dgst.cpp @@ -10,6 +10,7 @@ #include #include "md5_locl.h" +namespace openssl { /* * Implemented from RFC1321 The MD5 Message-Digest Algorithm */ @@ -35,8 +36,8 @@ int MD5_Init(MD5_CTX *c) # endif void md5_block_data_order(MD5_CTX *c, const void *data_, size_t num) { - const unsigned char *data = data_; - register unsigned MD32_REG_T A, B, C, D, l; + auto data = (const unsigned char *) data_; + unsigned MD32_REG_T A, B, C, D, l; # ifndef MD32_XARRAY /* See comment in crypto/sha/sha_locl.h for details. */ unsigned MD32_REG_T XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7, @@ -161,3 +162,5 @@ void md5_block_data_order(MD5_CTX *c, const void *data_, size_t num) } } #endif + +} // namespace openssl diff --git a/iOS/MMKV/MMKV/aes/openssl/md5_locl.h b/iOS/MMKV/MMKV/aes/openssl/md5_locl.h index 03e68d44..d20eaed7 100755 --- a/iOS/MMKV/MMKV/aes/openssl/md5_locl.h +++ b/iOS/MMKV/MMKV/aes/openssl/md5_locl.h @@ -11,6 +11,8 @@ #include #include "md5.h" +namespace openssl { + void md5_block_data_order(MD5_CTX *c, const void *p, size_t num); #define DATA_ORDER_IS_LITTLE_ENDIAN @@ -19,7 +21,7 @@ void md5_block_data_order(MD5_CTX *c, const void *p, size_t num); #define HASH_CTX MD5_CTX #define HASH_CBLOCK MD5_CBLOCK #define HASH_UPDATE MD5_Update -#define HASH_TRANSFORM MD5_Transform +//#define HASH_TRANSFORM MD5_Transform #define HASH_FINAL MD5_Final #define HASH_MAKE_STRING(c,s) do { \ unsigned long ll; \ @@ -66,3 +68,5 @@ void md5_block_data_order(MD5_CTX *c, const void *p, size_t num); a+=((k)+(t)+I((b),(c),(d))); \ a=ROTATE(a,s); \ a+=b; }; + +} // namespace openssl diff --git a/iOS/MMKV/MMKV/aes/openssl/md5_one.c b/iOS/MMKV/MMKV/aes/openssl/md5_one.cpp similarity index 93% rename from iOS/MMKV/MMKV/aes/openssl/md5_one.c rename to iOS/MMKV/MMKV/aes/openssl/md5_one.cpp index 30d56c0d..12278ef5 100755 --- a/iOS/MMKV/MMKV/aes/openssl/md5_one.c +++ b/iOS/MMKV/MMKV/aes/openssl/md5_one.cpp @@ -11,6 +11,8 @@ #include #include "md5.h" +namespace openssl { + unsigned char *MD5(const unsigned char *d, size_t n, unsigned char *md) { MD5_CTX c; @@ -24,3 +26,5 @@ unsigned char *MD5(const unsigned char *d, size_t n, unsigned char *md) MD5_Final(md, &c); return md; } + +} // namespace openssl diff --git a/iOS/MMKV/MMKV/aes/openssl/modes.h b/iOS/MMKV/MMKV/aes/openssl/modes.h index 6fab3d6f..e8e3f536 100644 --- a/iOS/MMKV/MMKV/aes/openssl/modes.h +++ b/iOS/MMKV/MMKV/aes/openssl/modes.h @@ -9,9 +9,8 @@ #include -#ifdef __cplusplus -extern "C" { -#endif +namespace openssl { + typedef void (*block128_f) (const unsigned char in[16], unsigned char out[16], const void *key); @@ -19,9 +18,6 @@ void CRYPTO_cfb128_encrypt(const unsigned char *in, unsigned char *out, size_t len, const void *key, unsigned char ivec[16], int *num, int enc, block128_f block); -#ifdef __cplusplus -} +} // namespace openssl #define STRICT_ALIGNMENT 1 - -#endif From e2f2c503e613ae031043853358fdfd354a15ff96 Mon Sep 17 00:00:00 2001 From: guoling Date: Mon, 25 Feb 2019 21:30:59 +0800 Subject: [PATCH 03/17] upgrade gradle --- Android/MMKV/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Android/MMKV/build.gradle b/Android/MMKV/build.gradle index 7589b64e..d81dad44 100644 --- a/Android/MMKV/build.gradle +++ b/Android/MMKV/build.gradle @@ -8,7 +8,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.3.0' + classpath 'com.android.tools.build:gradle:3.3.1' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.1' classpath 'digital.wup:android-maven-publish:3.6.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" From 0178111d93cc2c83419ad432f863dd8b91413c55 Mon Sep 17 00:00:00 2001 From: guoling Date: Mon, 25 Feb 2019 21:35:22 +0800 Subject: [PATCH 04/17] indent --- iOS/MMKV/MMKV/aes/AESCrypt.h | 2 +- iOS/MMKV/MMKV/aes/openssl/md5_dgst.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iOS/MMKV/MMKV/aes/AESCrypt.h b/iOS/MMKV/MMKV/aes/AESCrypt.h index 1ac88185..ea481f6c 100644 --- a/iOS/MMKV/MMKV/aes/AESCrypt.h +++ b/iOS/MMKV/MMKV/aes/AESCrypt.h @@ -31,7 +31,7 @@ constexpr size_t AES_KEY_BITSET_LEN = 128; class AESCrypt { unsigned char m_vector[AES_KEY_LEN] = {0}; unsigned char m_key[AES_KEY_LEN] = {0}; - openssl::AES_KEY m_aesKey = {0}; + openssl::AES_KEY m_aesKey = {0}; int m_number = 0; public: diff --git a/iOS/MMKV/MMKV/aes/openssl/md5_dgst.cpp b/iOS/MMKV/MMKV/aes/openssl/md5_dgst.cpp index ae59f39c..c76d41a1 100755 --- a/iOS/MMKV/MMKV/aes/openssl/md5_dgst.cpp +++ b/iOS/MMKV/MMKV/aes/openssl/md5_dgst.cpp @@ -37,7 +37,7 @@ int MD5_Init(MD5_CTX *c) void md5_block_data_order(MD5_CTX *c, const void *data_, size_t num) { auto data = (const unsigned char *) data_; - unsigned MD32_REG_T A, B, C, D, l; + unsigned MD32_REG_T A, B, C, D, l; # ifndef MD32_XARRAY /* See comment in crypto/sha/sha_locl.h for details. */ unsigned MD32_REG_T XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7, From 90c09d9b6ae12e6dd454e2691ee44de63874885b Mon Sep 17 00:00:00 2001 From: guoling Date: Tue, 5 Mar 2019 17:00:32 +0800 Subject: [PATCH 05/17] gradle --- Android/MMKV/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Android/MMKV/build.gradle b/Android/MMKV/build.gradle index d81dad44..49ea817e 100644 --- a/Android/MMKV/build.gradle +++ b/Android/MMKV/build.gradle @@ -8,7 +8,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.3.1' + classpath 'com.android.tools.build:gradle:3.3.2' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.1' classpath 'digital.wup:android-maven-publish:3.6.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" From a35e10749efd8cc886cdd4ee7284035d03a4ab1b Mon Sep 17 00:00:00 2001 From: guoling Date: Thu, 7 Mar 2019 11:32:45 +0800 Subject: [PATCH 06/17] fix potencial crash when m_actualSize > filesize on recover --- Android/MMKV/mmkv/src/main/cpp/MMKV.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Android/MMKV/mmkv/src/main/cpp/MMKV.cpp b/Android/MMKV/mmkv/src/main/cpp/MMKV.cpp index f2b4f59e..3e1732c4 100644 --- a/Android/MMKV/mmkv/src/main/cpp/MMKV.cpp +++ b/Android/MMKV/mmkv/src/main/cpp/MMKV.cpp @@ -341,6 +341,7 @@ void MMKV::loadFromFile() { } else { auto strategic = onMMKVFileLengthError(m_mmapID); if (strategic == OnErrorRecover) { + writeAcutalSize(m_size - Fixed32Size); loadFromFile = true; needFullWriteback = true; } From b9bf6b5ae25360f16bedad3e4c4e8f72b2ab5887 Mon Sep 17 00:00:00 2001 From: guoling Date: Thu, 7 Mar 2019 11:57:53 +0800 Subject: [PATCH 07/17] show error on ashmem size limit --- Android/MMKV/mmkv/src/main/cpp/MMKV.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Android/MMKV/mmkv/src/main/cpp/MMKV.cpp b/Android/MMKV/mmkv/src/main/cpp/MMKV.cpp index 3e1732c4..d3ab5c00 100644 --- a/Android/MMKV/mmkv/src/main/cpp/MMKV.cpp +++ b/Android/MMKV/mmkv/src/main/cpp/MMKV.cpp @@ -678,7 +678,7 @@ bool MMKV::ensureMemorySize(size_t newSize) { size_t lenNeeded = data.length() + offset + newSize; if (m_isAshmem) { if (lenNeeded > m_size) { - MMKVWarning("ashmem %s reach size limit:%zu, consider configure with larger size", + MMKVError("ashmem %s reach size limit:%zu, consider configure with larger size", m_mmapID.c_str(), m_size); return false; } From a4f72a7d87e34514375701cd551bfdfe62e0f14a Mon Sep 17 00:00:00 2001 From: guoling Date: Thu, 7 Mar 2019 14:58:51 +0800 Subject: [PATCH 08/17] fix potencial crash when m_actualSize > filesize on recover --- Android/MMKV/mmkv/src/main/cpp/MMKV.cpp | 2 +- Win32/MMKV/MMKV.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Android/MMKV/mmkv/src/main/cpp/MMKV.cpp b/Android/MMKV/mmkv/src/main/cpp/MMKV.cpp index d3ab5c00..91f19e0d 100644 --- a/Android/MMKV/mmkv/src/main/cpp/MMKV.cpp +++ b/Android/MMKV/mmkv/src/main/cpp/MMKV.cpp @@ -679,7 +679,7 @@ bool MMKV::ensureMemorySize(size_t newSize) { if (m_isAshmem) { if (lenNeeded > m_size) { MMKVError("ashmem %s reach size limit:%zu, consider configure with larger size", - m_mmapID.c_str(), m_size); + m_mmapID.c_str(), m_size); return false; } } else { diff --git a/Win32/MMKV/MMKV.cpp b/Win32/MMKV/MMKV.cpp index 446c1c7f..8c7e8c6e 100644 --- a/Win32/MMKV/MMKV.cpp +++ b/Win32/MMKV/MMKV.cpp @@ -238,6 +238,7 @@ void MMKV::loadFromFile() { if (strategic == OnErrorRecover) { loadFromFile = true; needFullWriteback = true; + writeAcutalSize(m_size - Fixed32Size); } } } @@ -1290,4 +1291,4 @@ static MMKVRecoverStrategic onMMKVFileLengthError(const std::string &mmapID) { return g_errorHandler(mmapID, MMKVErrorType::MMKVFileLength); } return OnErrorDiscard; -} \ No newline at end of file +} From fd74ac4f457d178543338fc8f897cc18742319c2 Mon Sep 17 00:00:00 2001 From: guoling Date: Thu, 7 Mar 2019 18:08:57 +0800 Subject: [PATCH 09/17] support Context.MODE_MULTI_PROCESS --- Android/MMKV/mmkv/src/main/cpp/MMKV.cpp | 2 +- Android/MMKV/mmkv/src/main/cpp/MMKV.h | 3 ++- Android/MMKV/mmkv/src/main/java/com/tencent/mmkv/MMKV.java | 5 ++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Android/MMKV/mmkv/src/main/cpp/MMKV.cpp b/Android/MMKV/mmkv/src/main/cpp/MMKV.cpp index 91f19e0d..96143e51 100644 --- a/Android/MMKV/mmkv/src/main/cpp/MMKV.cpp +++ b/Android/MMKV/mmkv/src/main/cpp/MMKV.cpp @@ -76,7 +76,7 @@ MMKV::MMKV( , m_fileLock(m_metaFile.getFd()) , m_sharedProcessLock(&m_fileLock, SharedLockType) , m_exclusiveProcessLock(&m_fileLock, ExclusiveLockType) - , m_isInterProcess((mode & MMKV_MULTI_PROCESS) != 0) + , m_isInterProcess((mode & MMKV_MULTI_PROCESS) != 0 || (mode & CONTEXT_MODE_MULTI_PROCESS) != 0) , m_isAshmem((mode & MMKV_ASHMEM) != 0) { m_fd = -1; m_ptr = nullptr; diff --git a/Android/MMKV/mmkv/src/main/cpp/MMKV.h b/Android/MMKV/mmkv/src/main/cpp/MMKV.h index 517641db..cd2d61b8 100644 --- a/Android/MMKV/mmkv/src/main/cpp/MMKV.h +++ b/Android/MMKV/mmkv/src/main/cpp/MMKV.h @@ -38,7 +38,8 @@ class AESCrypt; enum MMKVMode : uint32_t { MMKV_SINGLE_PROCESS = 0x1, MMKV_MULTI_PROCESS = 0x2, - MMKV_ASHMEM = 0x4, + CONTEXT_MODE_MULTI_PROCESS = 0x4, // in case someone mistakenly pass Context.MODE_MULTI_PROCESS + MMKV_ASHMEM = 0x8, }; class MMKV { diff --git a/Android/MMKV/mmkv/src/main/java/com/tencent/mmkv/MMKV.java b/Android/MMKV/mmkv/src/main/java/com/tencent/mmkv/MMKV.java index 144b4ee0..e8e9eba9 100644 --- a/Android/MMKV/mmkv/src/main/java/com/tencent/mmkv/MMKV.java +++ b/Android/MMKV/mmkv/src/main/java/com/tencent/mmkv/MMKV.java @@ -126,7 +126,10 @@ public static void setLogLevel(MMKVLogLevel level) { static public final int MULTI_PROCESS_MODE = 0x2; - static private final int ASHMEM_MODE = 0x4; + // in case someone mistakenly pass Context.MODE_MULTI_PROCESS + static private final int CONTEXT_MODE_MULTI_PROCESS = 0x4; + + static private final int ASHMEM_MODE = 0x8; public static MMKV mmkvWithID(String mmapID) { if (rootDir == null) { From f8790b4cd1ed482ce9f7deddac681a189691cf3b Mon Sep 17 00:00:00 2001 From: guoling Date: Thu, 7 Mar 2019 20:55:31 +0800 Subject: [PATCH 10/17] getValueActualSize --- Android/MMKV/mmkv/src/main/cpp/MMKV.cpp | 9 ++++++++- Android/MMKV/mmkv/src/main/cpp/MMKV.h | 2 +- Android/MMKV/mmkv/src/main/cpp/native-bridge.cpp | 8 +++----- .../MMKV/mmkv/src/main/java/com/tencent/mmkv/MMKV.java | 10 ++++++++-- Android/MMKV/mmkvdemo/build.gradle | 4 ++-- .../main/java/com/tencent/mmkvdemo/MainActivity.java | 3 ++- 6 files changed, 24 insertions(+), 12 deletions(-) diff --git a/Android/MMKV/mmkv/src/main/cpp/MMKV.cpp b/Android/MMKV/mmkv/src/main/cpp/MMKV.cpp index 96143e51..50057833 100644 --- a/Android/MMKV/mmkv/src/main/cpp/MMKV.cpp +++ b/Android/MMKV/mmkv/src/main/cpp/MMKV.cpp @@ -1212,12 +1212,19 @@ bool MMKV::getVectorForKey(const std::string &key, std::vector &res return false; } -size_t MMKV::getValueSizeForKey(const std::string &key) { +size_t MMKV::getValueSizeForKey(const std::string &key, bool actualSize) { if (key.empty()) { return 0; } SCOPEDLOCK(m_lock); auto &data = getDataForKey(key); + if (actualSize) { + CodedInputData input(data.getPtr(), data.length()); + auto length = input.readInt32(); + if (pbRawVarint32Size(length) + length == data.length()) { + return static_cast(length); + } + } return data.length(); } diff --git a/Android/MMKV/mmkv/src/main/cpp/MMKV.h b/Android/MMKV/mmkv/src/main/cpp/MMKV.h index cd2d61b8..b2d24a95 100644 --- a/Android/MMKV/mmkv/src/main/cpp/MMKV.h +++ b/Android/MMKV/mmkv/src/main/cpp/MMKV.h @@ -192,7 +192,7 @@ class MMKV { bool getVectorForKey(const std::string &key, std::vector &result); - size_t getValueSizeForKey(const std::string &key); + size_t getValueSizeForKey(const std::string &key, bool acutalSize); bool containsKey(const std::string &key); diff --git a/Android/MMKV/mmkv/src/main/cpp/native-bridge.cpp b/Android/MMKV/mmkv/src/main/cpp/native-bridge.cpp index e63af5ec..60069e2d 100644 --- a/Android/MMKV/mmkv/src/main/cpp/native-bridge.cpp +++ b/Android/MMKV/mmkv/src/main/cpp/native-bridge.cpp @@ -701,14 +701,12 @@ extern "C" JNIEXPORT void JNICALL Java_com_tencent_mmkv_MMKV_close(JNIEnv *env, } } -extern "C" JNIEXPORT jint JNICALL Java_com_tencent_mmkv_MMKV_valueSize(JNIEnv *env, - jobject instance, - jlong handle, - jstring oKey) { +extern "C" JNIEXPORT jint JNICALL Java_com_tencent_mmkv_MMKV_valueSize( + JNIEnv *env, jobject instance, jlong handle, jstring oKey, jboolean actualSize) { MMKV *kv = reinterpret_cast(handle); if (kv && oKey) { string key = jstring2string(env, oKey); - return kv->getValueSizeForKey(key); + return kv->getValueSizeForKey(key, (bool) actualSize); } return 0; } diff --git a/Android/MMKV/mmkv/src/main/java/com/tencent/mmkv/MMKV.java b/Android/MMKV/mmkv/src/main/java/com/tencent/mmkv/MMKV.java index e8e9eba9..e1bf10d3 100644 --- a/Android/MMKV/mmkv/src/main/java/com/tencent/mmkv/MMKV.java +++ b/Android/MMKV/mmkv/src/main/java/com/tencent/mmkv/MMKV.java @@ -439,7 +439,13 @@ public T decodeParcelable(String key, Class tClass, T // return the actual size consumption of the key's value // Note: might be a little bigger than value's length public int getValueSize(String key) { - return valueSize(nativeHandle, key); + return valueSize(nativeHandle, key, false); + } + + // return the actual size of the key's value + // String's length or byte[]'s length, etc + public int getValueActualSize(String key) { + return valueSize(nativeHandle, key, true); } public boolean containsKey(String key) { @@ -781,7 +787,7 @@ private MMKV(long handle) { private native void removeValueForKey(long handle, String key); - private native int valueSize(long handle, String key); + private native int valueSize(long handle, String key, boolean actualSize); private static native void setLogLevel(int level); diff --git a/Android/MMKV/mmkvdemo/build.gradle b/Android/MMKV/mmkvdemo/build.gradle index eb32af8a..820c4e23 100644 --- a/Android/MMKV/mmkvdemo/build.gradle +++ b/Android/MMKV/mmkvdemo/build.gradle @@ -62,9 +62,9 @@ repositories { dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') -// implementation project(':mmkv') + implementation project(':mmkv') // implementation 'com.tencent:mmkv:1.0.17' - implementation 'com.tencent:mmkv-static:1.0.17' +// implementation 'com.tencent:mmkv-static:1.0.17' implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support.constraint:constraint-layout:1.1.3' testImplementation 'junit:junit:4.12' diff --git a/Android/MMKV/mmkvdemo/src/main/java/com/tencent/mmkvdemo/MainActivity.java b/Android/MMKV/mmkvdemo/src/main/java/com/tencent/mmkvdemo/MainActivity.java index 061440aa..6e508850 100644 --- a/Android/MMKV/mmkvdemo/src/main/java/com/tencent/mmkvdemo/MainActivity.java +++ b/Android/MMKV/mmkvdemo/src/main/java/com/tencent/mmkvdemo/MainActivity.java @@ -200,7 +200,8 @@ private MMKV testMMKV(String mmapID, String cryptKey, boolean decodeOnly, String byte[] bytes = kv.decodeBytes("bytes"); Log.i("MMKV", "bytes: " + new String(bytes)); Log.i("MMKV", "bytes length = " + bytes.length - + ", value size consumption = " + kv.getValueSize("bytes")); + + ", value size consumption = " + kv.getValueSize("bytes") + + ", value size = " + kv.getValueActualSize("bytes")); if (!decodeOnly) { TestParcelable testParcelable = new TestParcelable(1024, "Hi Parcelable"); From bf6c4d40588b0665630cad6e92871cc24fe67a45 Mon Sep 17 00:00:00 2001 From: guoling Date: Thu, 7 Mar 2019 22:15:18 +0800 Subject: [PATCH 11/17] native buffer --- Android/MMKV/mmkv/src/main/cpp/MMKV.cpp | 23 ++++++++++++++ Android/MMKV/mmkv/src/main/cpp/MMKV.h | 2 ++ .../MMKV/mmkv/src/main/cpp/native-bridge.cpp | 30 ++++++++++++++++++- .../src/main/java/com/tencent/mmkv/MMKV.java | 24 +++++++++++++++ .../java/com/tencent/mmkv/NativeBuffer.java | 11 +++++++ .../com/tencent/mmkvdemo/MainActivity.java | 6 ++++ 6 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 Android/MMKV/mmkv/src/main/java/com/tencent/mmkv/NativeBuffer.java diff --git a/Android/MMKV/mmkv/src/main/cpp/MMKV.cpp b/Android/MMKV/mmkv/src/main/cpp/MMKV.cpp index 50057833..bd5a1619 100644 --- a/Android/MMKV/mmkv/src/main/cpp/MMKV.cpp +++ b/Android/MMKV/mmkv/src/main/cpp/MMKV.cpp @@ -1228,6 +1228,29 @@ size_t MMKV::getValueSizeForKey(const std::string &key, bool actualSize) { return data.length(); } +int32_t MMKV::writeValueToBuffer(const std::string &key, void *ptr, int32_t size) { + if (key.empty()) { + return -1; + } + SCOPEDLOCK(m_lock); + auto &data = getDataForKey(key); + CodedInputData input(data.getPtr(), data.length()); + auto length = input.readInt32(); + auto offset = pbRawVarint32Size(length); + if (offset + length == data.length()) { + if (length <= size) { + memcpy(ptr, (uint8_t *) data.getPtr() + offset, length); + return length; + } + } else { + if (data.length() <= size) { + memcpy(ptr, data.getPtr(), data.length()); + return static_cast(data.length()); + } + } + return -1; +} + #pragma mark - enumerate bool MMKV::containsKey(const std::string &key) { diff --git a/Android/MMKV/mmkv/src/main/cpp/MMKV.h b/Android/MMKV/mmkv/src/main/cpp/MMKV.h index b2d24a95..fb25a9a3 100644 --- a/Android/MMKV/mmkv/src/main/cpp/MMKV.h +++ b/Android/MMKV/mmkv/src/main/cpp/MMKV.h @@ -194,6 +194,8 @@ class MMKV { size_t getValueSizeForKey(const std::string &key, bool acutalSize); + int32_t writeValueToBuffer(const std::string &key, void *ptr, int32_t size); + bool containsKey(const std::string &key); size_t count(); diff --git a/Android/MMKV/mmkv/src/main/cpp/native-bridge.cpp b/Android/MMKV/mmkv/src/main/cpp/native-bridge.cpp index 60069e2d..03ee0839 100644 --- a/Android/MMKV/mmkv/src/main/cpp/native-bridge.cpp +++ b/Android/MMKV/mmkv/src/main/cpp/native-bridge.cpp @@ -706,7 +706,7 @@ extern "C" JNIEXPORT jint JNICALL Java_com_tencent_mmkv_MMKV_valueSize( MMKV *kv = reinterpret_cast(handle); if (kv && oKey) { string key = jstring2string(env, oKey); - return kv->getValueSizeForKey(key, (bool) actualSize); + return static_cast(kv->getValueSizeForKey(key, (bool) actualSize)); } return 0; } @@ -722,3 +722,31 @@ extern "C" JNIEXPORT void JNICALL Java_com_tencent_mmkv_MMKV_setLogReDirecting(J jboolean enable) { g_isLogRedirecting = (enable == JNI_TRUE); } + +extern "C" JNIEXPORT jlong JNICALL Java_com_tencent_mmkv_MMKV_createNB(JNIEnv *env, + jobject instance, + jint size) { + auto ptr = malloc(static_cast(size)); + if (!ptr) { + MMKVError("fail to create NativeBuffer:%s", strerror(errno)); + return 0; + } + return reinterpret_cast(ptr); +} + +extern "C" JNIEXPORT void JNICALL Java_com_tencent_mmkv_MMKV_destroyNB(JNIEnv *env, + jobject instance, + jlong pointer, + jint size) { + free(reinterpret_cast(pointer)); +} + +extern "C" JNIEXPORT jint JNICALL Java_com_tencent_mmkv_MMKV_writeValueToNB( + JNIEnv *env, jobject instance, jlong handle, jstring oKey, jlong pointer, jint size) { + MMKV *kv = reinterpret_cast(handle); + if (kv && oKey) { + string key = jstring2string(env, oKey); + return kv->writeValueToBuffer(key, reinterpret_cast(pointer), size); + } + return -1; +} diff --git a/Android/MMKV/mmkv/src/main/java/com/tencent/mmkv/MMKV.java b/Android/MMKV/mmkv/src/main/java/com/tencent/mmkv/MMKV.java index e1bf10d3..4f1e842b 100644 --- a/Android/MMKV/mmkv/src/main/java/com/tencent/mmkv/MMKV.java +++ b/Android/MMKV/mmkv/src/main/java/com/tencent/mmkv/MMKV.java @@ -656,6 +656,24 @@ public static MMKV mmkvWithAshmemFD(String mmapID, int fd, int metaFD, String cr public native int ashmemMetaFD(); + // native buffer + public static NativeBuffer createNativeBuffer(int size) { + long pointer = createNB(size); + if (pointer <= 0) { + return null; + } + return new NativeBuffer(pointer, size); + } + + public static void destroyNativeBuffer(NativeBuffer buffer) { + destroyNB(buffer.pointer, buffer.size); + } + + // return size written, -1 on error + public int writeValueToNativeBuffer(String key, NativeBuffer buffer) { + return writeValueToNB(nativeHandle, key, buffer.pointer, buffer.size); + } + // callback handler private static MMKVHandler gCallbackHandler; private static boolean gWantLogReDirecting = false; @@ -792,4 +810,10 @@ private MMKV(long handle) { private static native void setLogLevel(int level); private static native void setLogReDirecting(boolean enable); + + private static native long createNB(int size); + + private static native void destroyNB(long pointer, int size); + + private native int writeValueToNB(long handle, String key, long pointer, int size); } diff --git a/Android/MMKV/mmkv/src/main/java/com/tencent/mmkv/NativeBuffer.java b/Android/MMKV/mmkv/src/main/java/com/tencent/mmkv/NativeBuffer.java new file mode 100644 index 00000000..69525ff4 --- /dev/null +++ b/Android/MMKV/mmkv/src/main/java/com/tencent/mmkv/NativeBuffer.java @@ -0,0 +1,11 @@ +package com.tencent.mmkv; + +public final class NativeBuffer { + public long pointer; + public int size; + + public NativeBuffer(long ptr, int length) { + pointer = ptr; + size = length; + } +} diff --git a/Android/MMKV/mmkvdemo/src/main/java/com/tencent/mmkvdemo/MainActivity.java b/Android/MMKV/mmkvdemo/src/main/java/com/tencent/mmkvdemo/MainActivity.java index 6e508850..e197e105 100644 --- a/Android/MMKV/mmkvdemo/src/main/java/com/tencent/mmkvdemo/MainActivity.java +++ b/Android/MMKV/mmkvdemo/src/main/java/com/tencent/mmkvdemo/MainActivity.java @@ -38,6 +38,7 @@ import com.tencent.mmkv.MMKVRecoverStrategic; import com.tencent.mmkv.MMKVLogLevel; import com.getkeepsafe.relinker.ReLinker; +import com.tencent.mmkv.NativeBuffer; import org.jetbrains.annotations.Nullable; @@ -203,6 +204,11 @@ private MMKV testMMKV(String mmapID, String cryptKey, boolean decodeOnly, String + ", value size consumption = " + kv.getValueSize("bytes") + ", value size = " + kv.getValueActualSize("bytes")); + NativeBuffer nativeBuffer = MMKV.createNativeBuffer(1024); + int size = kv.writeValueToNativeBuffer("bytes", nativeBuffer); + Log.i("MMKV", "written size " + size); + MMKV.destroyNativeBuffer(nativeBuffer); + if (!decodeOnly) { TestParcelable testParcelable = new TestParcelable(1024, "Hi Parcelable"); kv.encode("parcel", testParcelable); From 2fda5f3b51c0f03073ba0f679353cd9c70a8aeea Mon Sep 17 00:00:00 2001 From: guoling Date: Thu, 7 Mar 2019 22:17:54 +0800 Subject: [PATCH 12/17] native buffer example --- .../main/java/com/tencent/mmkvdemo/MainActivity.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Android/MMKV/mmkvdemo/src/main/java/com/tencent/mmkvdemo/MainActivity.java b/Android/MMKV/mmkvdemo/src/main/java/com/tencent/mmkvdemo/MainActivity.java index e197e105..d5af58e8 100644 --- a/Android/MMKV/mmkvdemo/src/main/java/com/tencent/mmkvdemo/MainActivity.java +++ b/Android/MMKV/mmkvdemo/src/main/java/com/tencent/mmkvdemo/MainActivity.java @@ -204,10 +204,13 @@ private MMKV testMMKV(String mmapID, String cryptKey, boolean decodeOnly, String + ", value size consumption = " + kv.getValueSize("bytes") + ", value size = " + kv.getValueActualSize("bytes")); - NativeBuffer nativeBuffer = MMKV.createNativeBuffer(1024); - int size = kv.writeValueToNativeBuffer("bytes", nativeBuffer); - Log.i("MMKV", "written size " + size); - MMKV.destroyNativeBuffer(nativeBuffer); + int sizeNeeded = kv.getValueActualSize("bytes"); + NativeBuffer nativeBuffer = MMKV.createNativeBuffer(sizeNeeded); + if (nativeBuffer != null) { + int size = kv.writeValueToNativeBuffer("bytes", nativeBuffer); + Log.i("MMKV", "size Needed = " + sizeNeeded + " written size = " + size); + MMKV.destroyNativeBuffer(nativeBuffer); + } if (!decodeOnly) { TestParcelable testParcelable = new TestParcelable(1024, "Hi Parcelable"); From d230b33042715e11ac24c4d610d81ad540bda8a4 Mon Sep 17 00:00:00 2001 From: GuangfengWang Date: Fri, 8 Mar 2019 09:26:13 +0800 Subject: [PATCH 13/17] make the defaultValue work --- iOS/MMKV/MMKV/MMKV.mm | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/iOS/MMKV/MMKV/MMKV.mm b/iOS/MMKV/MMKV/MMKV.mm index 2cccee1b..7f980ed3 100644 --- a/iOS/MMKV/MMKV/MMKV.mm +++ b/iOS/MMKV/MMKV/MMKV.mm @@ -1181,7 +1181,11 @@ - (nullable NSString *)getStringForKey:(NSString *)key defaultValue:(nullable NS if (key.length <= 0) { return defaultValue; } - return [self getObjectOfClass:NSString.class forKey:key]; + NSString *valueString = [self getObjectOfClass:NSString.class forKey:key]; + if (!valueString) { + valueString = defaultValue; + } + return valueString; } - (nullable NSDate *)getDateForKey:(NSString *)key { @@ -1191,7 +1195,11 @@ - (nullable NSDate *)getDateForKey:(NSString *)key defaultValue:(nullable NSDate if (key.length <= 0) { return defaultValue; } - return [self getObjectOfClass:NSDate.class forKey:key]; + NSDate *valueDate = [self getObjectOfClass:NSDate.class forKey:key]; + if (!valueDate) { + valueDate = defaultValue; + } + return valueDate; } - (nullable NSData *)getDataForKey:(NSString *)key { @@ -1201,7 +1209,11 @@ - (nullable NSData *)getDataForKey:(NSString *)key defaultValue:(nullable NSData if (key.length <= 0) { return defaultValue; } - return [self getObjectOfClass:NSData.class forKey:key]; + NSData *valueData = [self getObjectOfClass:NSData.class forKey:key]; + if (!valueData) { + valueData = defaultValue; + } + return valueData; } - (size_t)getValueSizeForKey:(NSString *)key NS_SWIFT_NAME(valueSize(forKey:)) { From 30060de858eb756a1fe7a69dbcc831421c015f8e Mon Sep 17 00:00:00 2001 From: guoling Date: Fri, 8 Mar 2019 11:15:41 +0800 Subject: [PATCH 14/17] indent --- iOS/MMKV/MMKV/MMKV.mm | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/iOS/MMKV/MMKV/MMKV.mm b/iOS/MMKV/MMKV/MMKV.mm index 7f980ed3..20de7b92 100644 --- a/iOS/MMKV/MMKV/MMKV.mm +++ b/iOS/MMKV/MMKV/MMKV.mm @@ -1181,11 +1181,11 @@ - (nullable NSString *)getStringForKey:(NSString *)key defaultValue:(nullable NS if (key.length <= 0) { return defaultValue; } - NSString *valueString = [self getObjectOfClass:NSString.class forKey:key]; - if (!valueString) { - valueString = defaultValue; - } - return valueString; + NSString *valueString = [self getObjectOfClass:NSString.class forKey:key]; + if (!valueString) { + valueString = defaultValue; + } + return valueString; } - (nullable NSDate *)getDateForKey:(NSString *)key { @@ -1195,11 +1195,11 @@ - (nullable NSDate *)getDateForKey:(NSString *)key defaultValue:(nullable NSDate if (key.length <= 0) { return defaultValue; } - NSDate *valueDate = [self getObjectOfClass:NSDate.class forKey:key]; - if (!valueDate) { - valueDate = defaultValue; - } - return valueDate; + NSDate *valueDate = [self getObjectOfClass:NSDate.class forKey:key]; + if (!valueDate) { + valueDate = defaultValue; + } + return valueDate; } - (nullable NSData *)getDataForKey:(NSString *)key { @@ -1209,10 +1209,10 @@ - (nullable NSData *)getDataForKey:(NSString *)key defaultValue:(nullable NSData if (key.length <= 0) { return defaultValue; } - NSData *valueData = [self getObjectOfClass:NSData.class forKey:key]; - if (!valueData) { - valueData = defaultValue; - } + NSData *valueData = [self getObjectOfClass:NSData.class forKey:key]; + if (!valueData) { + valueData = defaultValue; + } return valueData; } From 3f59edf554f585d757fd879914d46c57fff2cc31 Mon Sep 17 00:00:00 2001 From: guoling Date: Thu, 14 Mar 2019 11:58:24 +0800 Subject: [PATCH 15/17] check null --- Android/MMKV/mmkv/src/main/cpp/MMKV.cpp | 12 ++++++++---- Android/MMKV/mmkv/src/main/cpp/MmapedFile.cpp | 3 +++ Android/MMKV/mmkv/src/main/cpp/native-bridge.cpp | 2 +- .../java/com/tencent/mmkv/MMKVContentProvider.java | 4 +++- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Android/MMKV/mmkv/src/main/cpp/MMKV.cpp b/Android/MMKV/mmkv/src/main/cpp/MMKV.cpp index bd5a1619..92a9d56b 100644 --- a/Android/MMKV/mmkv/src/main/cpp/MMKV.cpp +++ b/Android/MMKV/mmkv/src/main/cpp/MMKV.cpp @@ -198,8 +198,10 @@ void MMKV::initializeMMKV(const std::string &rootDir) { g_rootDir = rootDir; char *path = strdup(g_rootDir.c_str()); - mkPath(path); - free(path); + if (path) { + mkPath(path); + free(path); + } MMKVInfo("root dir: %s", g_rootDir.c_str()); } @@ -1373,8 +1375,10 @@ bool MMKV::isFileValid(const std::string &mmapID) { static void mkSpecialCharacterFileDirectory() { char *path = strdup((g_rootDir + "/" + SPECIAL_CHARACTER_DIRECTORY_NAME).c_str()); - mkPath(path); - free(path); + if (path) { + mkPath(path); + free(path); + } } static string md5(const string &value) { diff --git a/Android/MMKV/mmkv/src/main/cpp/MmapedFile.cpp b/Android/MMKV/mmkv/src/main/cpp/MmapedFile.cpp index 569134f5..279de1db 100644 --- a/Android/MMKV/mmkv/src/main/cpp/MmapedFile.cpp +++ b/Android/MMKV/mmkv/src/main/cpp/MmapedFile.cpp @@ -185,6 +185,9 @@ bool createFile(const std::string &filePath) { } else { // create parent dir char *path = strdup(filePath.c_str()); + if (!path) { + return false; + } auto ptr = strrchr(path, '/'); if (ptr) { *ptr = '\0'; diff --git a/Android/MMKV/mmkv/src/main/cpp/native-bridge.cpp b/Android/MMKV/mmkv/src/main/cpp/native-bridge.cpp index 03ee0839..44a8c067 100644 --- a/Android/MMKV/mmkv/src/main/cpp/native-bridge.cpp +++ b/Android/MMKV/mmkv/src/main/cpp/native-bridge.cpp @@ -160,7 +160,7 @@ static JNIEnv *getCurrentEnv() { MMKVRecoverStrategic onMMKVCRCCheckFail(const std::string &mmapID) { auto currentEnv = getCurrentEnv(); - if (g_currentJVM && g_callbackOnCRCFailID) { + if (currentEnv && g_callbackOnCRCFailID) { jstring str = string2jstring(currentEnv, mmapID); auto strategic = currentEnv->CallStaticIntMethod(g_cls, g_callbackOnCRCFailID, str); return static_cast(strategic); diff --git a/Android/MMKV/mmkv/src/main/java/com/tencent/mmkv/MMKVContentProvider.java b/Android/MMKV/mmkv/src/main/java/com/tencent/mmkv/MMKVContentProvider.java index 1ec10b44..6f46bdd0 100644 --- a/Android/MMKV/mmkv/src/main/java/com/tencent/mmkv/MMKVContentProvider.java +++ b/Android/MMKV/mmkv/src/main/java/com/tencent/mmkv/MMKVContentProvider.java @@ -80,7 +80,9 @@ private static String queryAuthority(Context context) { PackageManager mgr = context.getPackageManager(); if (mgr != null) { ProviderInfo providerInfo = mgr.getProviderInfo(componentName, 0); - return providerInfo.authority; + if (providerInfo != null) { + return providerInfo.authority; + } } } catch (Exception e) { e.printStackTrace(); From 174c5cbc92b101e442301e8935188e924a95fccc Mon Sep 17 00:00:00 2001 From: guoling Date: Thu, 14 Mar 2019 15:24:19 +0800 Subject: [PATCH 16/17] prepare for v1.0.18 --- Android/MMKV/gradle.properties | 2 +- Android/MMKV/mmkvdemo/build.gradle | 8 ++++---- CHANGELOG.md | 16 ++++++++++++++++ MMKV.podspec | 2 +- README.md | 6 +++--- iOS/MMKV/MMKV/Resources/Info.plist | 2 +- readme_cn.md | 4 ++-- 7 files changed, 28 insertions(+), 12 deletions(-) diff --git a/Android/MMKV/gradle.properties b/Android/MMKV/gradle.properties index 6fcf8e89..6357fba3 100644 --- a/Android/MMKV/gradle.properties +++ b/Android/MMKV/gradle.properties @@ -12,6 +12,6 @@ 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.0.17 +VERSION_NAME_PREFIX=1.0.18 #VERSION_NAME_SUFFIX=-SNAPSHOT VERSION_NAME_SUFFIX= \ No newline at end of file diff --git a/Android/MMKV/mmkvdemo/build.gradle b/Android/MMKV/mmkvdemo/build.gradle index 820c4e23..51ee0a2c 100644 --- a/Android/MMKV/mmkvdemo/build.gradle +++ b/Android/MMKV/mmkvdemo/build.gradle @@ -57,14 +57,14 @@ repositories { // } jcenter() mavenCentral() - mavenLocal() +// mavenLocal() } dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') - implementation project(':mmkv') -// implementation 'com.tencent:mmkv:1.0.17' -// implementation 'com.tencent:mmkv-static:1.0.17' +// implementation project(':mmkv') + implementation 'com.tencent:mmkv:1.0.18' +// implementation 'com.tencent:mmkv-static:1.0.18' implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support.constraint:constraint-layout:1.1.3' testImplementation 'junit:junit:4.12' diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b309bbe..34fd0b4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,21 @@ # MMKV Change Log +## v1.0.18 / 2019-03-14 +### iOS / macOS +What's new + +* Fix a bug that defaultValue was not returned while decoding a `NSCoding` value. + +### Android +What's new + +* Introducing **Native Buffer**. Checkout [wiki](https://github.com/Tencent/MMKV/wiki/android_advance#native-buffer) for details. +* Fix a potential crash when trying to recover data from file length error. + + +### Win32 +* Fix a potential crash when trying to recover data from file length error. + ## v1.0.17 / 2019-01-25 ### iOS / macOS What's new diff --git a/MMKV.podspec b/MMKV.podspec index 5072ac67..0771ea4e 100644 --- a/MMKV.podspec +++ b/MMKV.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "MMKV" - s.version = "1.0.17" + s.version = "1.0.18" s.summary = "MMKV is a cross-platform key-value storage framework developed by WeChat." s.description = <<-DESC diff --git a/README.md b/README.md index 2a9f4190..4a9d41d7 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ [![license](https://img.shields.io/badge/license-BSD_3-brightgreen.svg?style=flat)](https://github.com/Tencent/MMKV/blob/master/LICENSE.TXT) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/Tencent/MMKV/pulls) -[![Release Version](https://img.shields.io/badge/release-1.0.17-brightgreen.svg)](https://github.com/Tencent/MMKV/releases) +[![Release Version](https://img.shields.io/badge/release-1.0.18-brightgreen.svg)](https://github.com/Tencent/MMKV/releases) [![Platform](https://img.shields.io/badge/Platform-%20iOS%20%7C%20Android-brightgreen.svg)](https://github.com/Tencent/MMKV/wiki/home) 中文版本请参看[这里](./readme_cn.md) @@ -75,8 +75,8 @@ Add the following lines to `build.gradle` on your app module: ```gradle dependencies { - implementation 'com.tencent:mmkv:1.0.17' - // replace "1.0.17" with any available version + implementation 'com.tencent:mmkv:1.0.18' + // replace "1.0.18" with any available version } ``` diff --git a/iOS/MMKV/MMKV/Resources/Info.plist b/iOS/MMKV/MMKV/Resources/Info.plist index b1edd161..cd9d0cce 100644 --- a/iOS/MMKV/MMKV/Resources/Info.plist +++ b/iOS/MMKV/MMKV/Resources/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.0.17 + 1.0.18 CFBundleVersion $(CURRENT_PROJECT_VERSION) NSPrincipalClass diff --git a/readme_cn.md b/readme_cn.md index 3b7236e6..e727ef49 100644 --- a/readme_cn.md +++ b/readme_cn.md @@ -59,8 +59,8 @@ NSString *str = [mmkv getStringForKey:@"string"]; ```gradle dependencies { - implementation 'com.tencent:mmkv:1.0.17' - // replace "1.0.17" with any available version + implementation 'com.tencent:mmkv:1.0.18' + // replace "1.0.18" with any available version } ``` From 115c9c809b8ce09298f308c144bfa66285165177 Mon Sep 17 00:00:00 2001 From: guoling Date: Thu, 14 Mar 2019 15:30:47 +0800 Subject: [PATCH 17/17] update change log for v1.0.18 --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 34fd0b4b..73645823 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,12 +5,14 @@ What's new * Fix a bug that defaultValue was not returned while decoding a `NSCoding` value. +* Fix a compile error on static linking MMKV while openssl is static linked too. ### Android What's new * Introducing **Native Buffer**. Checkout [wiki](https://github.com/Tencent/MMKV/wiki/android_advance#native-buffer) for details. * Fix a potential crash when trying to recover data from file length error. +* Protect from mistakenly passing `Context.MODE_MULTI_PROCESS` to init MMKV. ### Win32