react-native-mmkv 3.0.0-beta.5 → 3.0.0-beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/MMKV/Core/CMakeLists.txt +1 -1
- package/MMKV/Core/Core.xcodeproj/project.pbxproj +4 -6
- package/MMKV/Core/MMBuffer.h +1 -1
- package/MMKV/Core/MMKV.cpp +70 -73
- package/MMKV/Core/MMKV.h +126 -11
- package/MMKV/Core/MMKVPredef.h +44 -3
- package/MMKV/Core/MMKV_IO.cpp +29 -21
- package/MMKV/Core/MMKV_OSX.cpp +4 -3
- package/MMKV/Core/MemoryFile_Android.cpp +27 -13
- package/MMKV/Core/MiniPBCoder.cpp +308 -9
- package/MMKV/Core/MiniPBCoder.h +36 -17
- package/MMKV/Core/MiniPBCoder_OSX.cpp +1 -0
- package/MMKV/Core/PBEncodeItem.hpp +18 -0
- package/MMKV/Core/PBUtility.h +0 -12
- package/MMKV/Core/core.vcxproj +4 -4
- package/MMKV/Core/crc32/Checksum.h +4 -1
- package/android/CMakeLists.txt +0 -1
- package/android/build.gradle +3 -0
- package/android/src/main/cpp/AndroidLogger.cpp +3 -3
- package/android/src/main/java/com/mrousavy/mmkv/MmkvPlatformContextModule.java +9 -0
- package/cpp/MmkvHostObject.cpp +39 -41
- package/cpp/{Logger.h → MmkvLogger.h} +3 -3
- package/cpp/NativeMmkvModule.cpp +2 -2
- package/ios/AppleLogger.mm +3 -3
- package/ios/MmkvPlatformContextModule.mm +19 -1
- package/lib/commonjs/MMKV.js.map +1 -1
- package/lib/commonjs/NativeMmkvPlatformContext.js.map +1 -1
- package/lib/commonjs/createMMKV.js +17 -0
- package/lib/commonjs/createMMKV.js.map +1 -1
- package/lib/commonjs/hooks.js.map +1 -1
- package/lib/commonjs/index.js +19 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/MMKV.js.map +1 -1
- package/lib/module/NativeMmkvPlatformContext.js.map +1 -1
- package/lib/module/createMMKV.js +17 -0
- package/lib/module/createMMKV.js.map +1 -1
- package/lib/module/hooks.js.map +1 -1
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/MMKV.d.ts +0 -1
- package/lib/typescript/src/MMKV.d.ts.map +1 -1
- package/lib/typescript/src/NativeMmkv.d.ts +3 -3
- package/lib/typescript/src/NativeMmkvPlatformContext.d.ts +11 -0
- package/lib/typescript/src/NativeMmkvPlatformContext.d.ts.map +1 -1
- package/lib/typescript/src/Types.d.ts +4 -0
- package/lib/typescript/src/Types.d.ts.map +1 -1
- package/lib/typescript/src/createMMKV.d.ts +1 -1
- package/lib/typescript/src/createMMKV.d.ts.map +1 -1
- package/lib/typescript/src/createMMKV.web.d.ts +1 -1
- package/lib/typescript/src/createMMKV.web.d.ts.map +1 -1
- package/lib/typescript/src/hooks.d.ts +1 -1
- package/lib/typescript/src/hooks.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +8 -7
- package/react-native-mmkv.podspec +3 -0
- package/src/MMKV.ts +0 -1
- package/src/NativeMmkv.ts +3 -3
- package/src/NativeMmkvPlatformContext.ts +11 -0
- package/src/Types.ts +4 -0
- package/src/createMMKV.ts +20 -2
- package/src/createMMKV.web.ts +1 -1
- package/src/hooks.ts +1 -1
- package/src/index.ts +1 -1
- package/MMKV/LICENSE.TXT +0 -193
- package/MMKV/README.md +0 -354
- package/android/src/main/cpp/cpp-adapter.cpp +0 -7
package/MMKV/Core/MMKVPredef.h
CHANGED
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
#include <vector>
|
|
35
35
|
#include <unordered_map>
|
|
36
36
|
|
|
37
|
-
constexpr auto MMKV_VERSION = "v1.3.
|
|
37
|
+
constexpr auto MMKV_VERSION = "v1.3.7";
|
|
38
38
|
|
|
39
39
|
#ifdef DEBUG
|
|
40
40
|
# define MMKV_DEBUG
|
|
@@ -44,6 +44,10 @@ constexpr auto MMKV_VERSION = "v1.3.5";
|
|
|
44
44
|
# undef MMKV_DEBUG
|
|
45
45
|
#endif
|
|
46
46
|
|
|
47
|
+
#if __cplusplus>=202002L
|
|
48
|
+
# define MMKV_HAS_CPP20
|
|
49
|
+
#endif
|
|
50
|
+
|
|
47
51
|
#ifdef __ANDROID__
|
|
48
52
|
# ifdef FORCE_POSIX
|
|
49
53
|
# define MMKV_POSIX
|
|
@@ -195,9 +199,34 @@ using MMKVVector = std::vector<std::pair<NSString *, mmkv::MMBuffer>>;
|
|
|
195
199
|
using MMKVMap = std::unordered_map<NSString *, mmkv::KeyValueHolder, KeyHasher, KeyEqualer>;
|
|
196
200
|
using MMKVMapCrypt = std::unordered_map<NSString *, mmkv::KeyValueHolderCrypt, KeyHasher, KeyEqualer>;
|
|
197
201
|
#else
|
|
202
|
+
struct KeyHasher {
|
|
203
|
+
// enables heterogeneous lookup
|
|
204
|
+
using is_transparent = void;
|
|
205
|
+
|
|
206
|
+
std::size_t operator()(const std::string_view& str) const {
|
|
207
|
+
return std::hash<std::string_view>{}(str);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
std::size_t operator()(const std::string& str) const {
|
|
211
|
+
return std::hash<std::string>{}(str);
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
struct KeyEqualer {
|
|
216
|
+
// enables heterogeneous lookup
|
|
217
|
+
using is_transparent = void;
|
|
218
|
+
|
|
219
|
+
bool operator()(const std::string_view& lhs, const std::string_view& rhs) const {
|
|
220
|
+
return lhs == rhs;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
bool operator()(const std::string& lhs, const std::string& rhs) const {
|
|
224
|
+
return lhs == rhs;
|
|
225
|
+
}
|
|
226
|
+
};
|
|
198
227
|
using MMKVVector = std::vector<std::pair<std::string, mmkv::MMBuffer>>;
|
|
199
|
-
using MMKVMap = std::unordered_map<std::string, mmkv::KeyValueHolder>;
|
|
200
|
-
using MMKVMapCrypt = std::unordered_map<std::string, mmkv::KeyValueHolderCrypt>;
|
|
228
|
+
using MMKVMap = std::unordered_map<std::string, mmkv::KeyValueHolder, KeyHasher, KeyEqualer>;
|
|
229
|
+
using MMKVMapCrypt = std::unordered_map<std::string, mmkv::KeyValueHolderCrypt, KeyHasher, KeyEqualer>;
|
|
201
230
|
#endif // MMKV_APPLE
|
|
202
231
|
|
|
203
232
|
template <typename T>
|
|
@@ -217,6 +246,18 @@ constexpr size_t AES_KEY_BITSET_LEN = 128;
|
|
|
217
246
|
|
|
218
247
|
#endif //cplus-plus
|
|
219
248
|
|
|
249
|
+
#ifndef MMKV_WIN32
|
|
250
|
+
# ifndef likely
|
|
251
|
+
# define mmkv_unlikely(x) (__builtin_expect(bool(x), 0))
|
|
252
|
+
# define mmkv_likely(x) (__builtin_expect(bool(x), 1))
|
|
253
|
+
# endif
|
|
254
|
+
#else
|
|
255
|
+
# ifndef likely
|
|
256
|
+
# define mmkv_unlikely(x) (x)
|
|
257
|
+
# define mmkv_likely(x) (x)
|
|
258
|
+
# endif
|
|
259
|
+
#endif
|
|
260
|
+
|
|
220
261
|
#if defined(__arm__)
|
|
221
262
|
#if defined(__ARM_ARCH_7A__)
|
|
222
263
|
#if defined(__ARM_NEON__)
|
package/MMKV/Core/MMKV_IO.cpp
CHANGED
|
@@ -496,7 +496,7 @@ bool MMKV::writeActualSize(size_t size, uint32_t crcDigest, const void *iv, bool
|
|
|
496
496
|
needsFullWrite = true;
|
|
497
497
|
}
|
|
498
498
|
#ifndef MMKV_DISABLE_CRYPT
|
|
499
|
-
if (
|
|
499
|
+
if (mmkv_unlikely(iv)) {
|
|
500
500
|
memcpy(m_metaInfo->m_vector, iv, sizeof(m_metaInfo->m_vector));
|
|
501
501
|
if (m_metaInfo->m_version < MMKVVersionRandomIV) {
|
|
502
502
|
m_metaInfo->m_version = MMKVVersionRandomIV;
|
|
@@ -504,7 +504,7 @@ bool MMKV::writeActualSize(size_t size, uint32_t crcDigest, const void *iv, bool
|
|
|
504
504
|
needsFullWrite = true;
|
|
505
505
|
}
|
|
506
506
|
#endif
|
|
507
|
-
if (
|
|
507
|
+
if (mmkv_unlikely(increaseSequence)) {
|
|
508
508
|
m_metaInfo->m_sequence++;
|
|
509
509
|
m_metaInfo->m_lastConfirmedMetaInfo.lastActualSize = static_cast<uint32_t>(size);
|
|
510
510
|
m_metaInfo->m_lastConfirmedMetaInfo.lastCRCDigest = crcDigest;
|
|
@@ -526,7 +526,7 @@ bool MMKV::writeActualSize(size_t size, uint32_t crcDigest, const void *iv, bool
|
|
|
526
526
|
return false;
|
|
527
527
|
}
|
|
528
528
|
#endif
|
|
529
|
-
if (
|
|
529
|
+
if (mmkv_unlikely(needsFullWrite)) {
|
|
530
530
|
m_metaInfo->write(m_metaFile->getMemory());
|
|
531
531
|
} else {
|
|
532
532
|
m_metaInfo->writeCRCAndActualSizeOnly(m_metaFile->getMemory());
|
|
@@ -557,7 +557,7 @@ MMBuffer MMKV::getRawDataForKey(MMKVKey_t key) {
|
|
|
557
557
|
}
|
|
558
558
|
|
|
559
559
|
mmkv::MMBuffer MMKV::getDataForKey(MMKVKey_t key) {
|
|
560
|
-
if (
|
|
560
|
+
if (mmkv_unlikely(m_enableKeyExpire)) {
|
|
561
561
|
return getDataWithoutMTimeForKey(key);
|
|
562
562
|
}
|
|
563
563
|
return getRawDataForKey(key);
|
|
@@ -617,7 +617,7 @@ bool MMKV::setDataForKey(MMBuffer &&data, MMKVKey_t key, bool isDataHolder) {
|
|
|
617
617
|
} else {
|
|
618
618
|
kvHolder = KeyValueHolderCrypt(std::move(data));
|
|
619
619
|
}
|
|
620
|
-
if (
|
|
620
|
+
if (mmkv_likely(!m_enableKeyExpire)) {
|
|
621
621
|
itr->second = std::move(kvHolder);
|
|
622
622
|
} else {
|
|
623
623
|
itr = m_dicCrypt->find(key);
|
|
@@ -670,9 +670,9 @@ bool MMKV::setDataForKey(MMBuffer &&data, MMKVKey_t key, bool isDataHolder) {
|
|
|
670
670
|
return true;
|
|
671
671
|
}
|
|
672
672
|
} catch (std::exception &exception) {
|
|
673
|
-
|
|
673
|
+
MMKVWarning("compareBeforeSet exception: %s", exception.what());
|
|
674
674
|
} catch (...) {
|
|
675
|
-
|
|
675
|
+
MMKVWarning("compareBeforeSet fail");
|
|
676
676
|
}
|
|
677
677
|
} else {
|
|
678
678
|
if (oldValueData == data) {
|
|
@@ -683,7 +683,7 @@ bool MMKV::setDataForKey(MMBuffer &&data, MMKVKey_t key, bool isDataHolder) {
|
|
|
683
683
|
}
|
|
684
684
|
|
|
685
685
|
bool onlyOneKey = !m_isInterProcess && m_dic->size() == 1;
|
|
686
|
-
if (
|
|
686
|
+
if (mmkv_likely(!m_enableKeyExpire)) {
|
|
687
687
|
KVHolderRet_t ret;
|
|
688
688
|
if (onlyOneKey) {
|
|
689
689
|
ret = overrideDataWithKey(data, itr->second, isDataHolder);
|
|
@@ -732,6 +732,14 @@ bool MMKV::setDataForKey(MMBuffer &&data, MMKVKey_t key, bool isDataHolder) {
|
|
|
732
732
|
return true;
|
|
733
733
|
}
|
|
734
734
|
|
|
735
|
+
template <typename T>
|
|
736
|
+
static void eraseHelper(T& container, std::string_view key) {
|
|
737
|
+
auto itr = container.find(key);
|
|
738
|
+
if (itr != container.end()) {
|
|
739
|
+
container.erase(itr);
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
|
|
735
743
|
bool MMKV::removeDataForKey(MMKVKey_t key) {
|
|
736
744
|
if (isKeyEmpty(key)) {
|
|
737
745
|
return false;
|
|
@@ -745,7 +753,7 @@ bool MMKV::removeDataForKey(MMKVKey_t key) {
|
|
|
745
753
|
# ifdef MMKV_APPLE
|
|
746
754
|
auto ret = appendDataWithKey(nan, key, itr->second);
|
|
747
755
|
if (ret.first) {
|
|
748
|
-
if (
|
|
756
|
+
if (mmkv_unlikely(m_enableKeyExpire)) {
|
|
749
757
|
// filterExpiredKeys() may invalid itr
|
|
750
758
|
itr = m_dicCrypt->find(key);
|
|
751
759
|
if (itr == m_dicCrypt->end()) {
|
|
@@ -759,8 +767,8 @@ bool MMKV::removeDataForKey(MMKVKey_t key) {
|
|
|
759
767
|
# else
|
|
760
768
|
auto ret = appendDataWithKey(nan, key);
|
|
761
769
|
if (ret.first) {
|
|
762
|
-
if (
|
|
763
|
-
m_dicCrypt
|
|
770
|
+
if (mmkv_unlikely(m_enableKeyExpire)) {
|
|
771
|
+
eraseHelper(*m_dicCrypt, key);
|
|
764
772
|
} else {
|
|
765
773
|
m_dicCrypt->erase(itr);
|
|
766
774
|
}
|
|
@@ -775,10 +783,10 @@ bool MMKV::removeDataForKey(MMKVKey_t key) {
|
|
|
775
783
|
if (itr != m_dic->end()) {
|
|
776
784
|
m_hasFullWriteback = false;
|
|
777
785
|
static MMBuffer nan;
|
|
778
|
-
auto ret =
|
|
786
|
+
auto ret = mmkv_likely(!m_enableKeyExpire) ? appendDataWithKey(nan, itr->second) : appendDataWithKey(nan, key);
|
|
779
787
|
if (ret.first) {
|
|
780
788
|
#ifdef MMKV_APPLE
|
|
781
|
-
if (
|
|
789
|
+
if (mmkv_unlikely(m_enableKeyExpire)) {
|
|
782
790
|
// filterExpiredKeys() may invalid itr
|
|
783
791
|
itr = m_dic->find(key);
|
|
784
792
|
if (itr == m_dic->end()) {
|
|
@@ -789,9 +797,9 @@ bool MMKV::removeDataForKey(MMKVKey_t key) {
|
|
|
789
797
|
m_dic->erase(itr);
|
|
790
798
|
[oldKey release];
|
|
791
799
|
#else
|
|
792
|
-
if (
|
|
800
|
+
if (mmkv_unlikely(m_enableKeyExpire)) {
|
|
793
801
|
// filterExpiredKeys() may invalid itr
|
|
794
|
-
m_dic
|
|
802
|
+
eraseHelper(*m_dic, key);
|
|
795
803
|
} else {
|
|
796
804
|
m_dic->erase(itr);
|
|
797
805
|
}
|
|
@@ -939,7 +947,7 @@ KVHolderRet_t MMKV::doOverrideDataWithKey(const MMBuffer &data,
|
|
|
939
947
|
m_crypter->encrypt(ptr, ptr, m_actualSize);
|
|
940
948
|
}
|
|
941
949
|
#endif
|
|
942
|
-
|
|
950
|
+
recalculateCRCDigestOnly();
|
|
943
951
|
|
|
944
952
|
return make_pair(true, KeyValueHolder(originKeyLength, valueLength, offset));
|
|
945
953
|
}
|
|
@@ -1044,7 +1052,7 @@ bool MMKV::fullWriteback(AESCrypt *newCrypter, bool onlyWhileExpire) {
|
|
|
1044
1052
|
return false;
|
|
1045
1053
|
}
|
|
1046
1054
|
|
|
1047
|
-
if (
|
|
1055
|
+
if (mmkv_unlikely(m_enableKeyExpire)) {
|
|
1048
1056
|
auto expiredCount = filterExpiredKeys();
|
|
1049
1057
|
if (onlyWhileExpire && expiredCount == 0) {
|
|
1050
1058
|
return true;
|
|
@@ -1270,9 +1278,9 @@ bool MMKV::doFullWriteBack(pair<MMBuffer, size_t> prepared, AESCrypt *newCrypter
|
|
|
1270
1278
|
|
|
1271
1279
|
m_actualSize = totalSize;
|
|
1272
1280
|
if (encrypter) {
|
|
1273
|
-
|
|
1281
|
+
recalculateCRCDigestWithIV(newIV);
|
|
1274
1282
|
} else {
|
|
1275
|
-
|
|
1283
|
+
recalculateCRCDigestWithIV(nullptr);
|
|
1276
1284
|
}
|
|
1277
1285
|
m_hasFullWriteback = true;
|
|
1278
1286
|
// make sure lastConfirmedMetaInfo is saved if needed
|
|
@@ -1305,7 +1313,7 @@ bool MMKV::doFullWriteBack(pair<MMBuffer, size_t> prepared, AESCrypt *, bool nee
|
|
|
1305
1313
|
}
|
|
1306
1314
|
|
|
1307
1315
|
m_actualSize = totalSize;
|
|
1308
|
-
|
|
1316
|
+
recalculateCRCDigestWithIV(nullptr);
|
|
1309
1317
|
m_hasFullWriteback = true;
|
|
1310
1318
|
// make sure lastConfirmedMetaInfo is saved if needed
|
|
1311
1319
|
if (needSync) {
|
|
@@ -1751,7 +1759,7 @@ mmkv::MMBuffer MMKV::getDataWithoutMTimeForKey(MMKVKey_t key) {
|
|
|
1751
1759
|
#ifdef MMKV_APPLE
|
|
1752
1760
|
MMKVInfo("deleting expired key [%@] in mmkv [%s], due date %u", key, m_mmapID.c_str(), time);
|
|
1753
1761
|
#else
|
|
1754
|
-
MMKVInfo("deleting expired key [%s] in mmkv [%s], due date %u", key.
|
|
1762
|
+
MMKVInfo("deleting expired key [%s] in mmkv [%s], due date %u", key.data(), m_mmapID.c_str(), time);
|
|
1755
1763
|
#endif
|
|
1756
1764
|
removeValueForKey(key);
|
|
1757
1765
|
return MMBuffer();
|
package/MMKV/Core/MMKV_OSX.cpp
CHANGED
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
# include <sys/utsname.h>
|
|
36
36
|
# include <sys/sysctl.h>
|
|
37
37
|
# include "MMKV_OSX.h"
|
|
38
|
+
# include "MMKVLog.h"
|
|
38
39
|
|
|
39
40
|
# ifdef MMKV_IOS
|
|
40
41
|
# include <sys/mman.h>
|
|
@@ -139,7 +140,7 @@ bool MMKV::set(NSObject<NSCoding> *__unsafe_unretained obj, MMKVKey_t key, uint3
|
|
|
139
140
|
if (tmpData) {
|
|
140
141
|
// delay write the size needed for encoding tmpData
|
|
141
142
|
// avoid memory copying
|
|
142
|
-
if (
|
|
143
|
+
if (mmkv_likely(!m_enableKeyExpire)) {
|
|
143
144
|
return setDataForKey(MMBuffer(tmpData, MMBufferNoCopy), key, true);
|
|
144
145
|
} else {
|
|
145
146
|
MMBuffer data(tmpData, MMBufferNoCopy);
|
|
@@ -167,7 +168,7 @@ bool MMKV::set(NSObject<NSCoding> *__unsafe_unretained obj, MMKVKey_t key, uint3
|
|
|
167
168
|
return false;
|
|
168
169
|
}
|
|
169
170
|
if (archived.length > 0) {
|
|
170
|
-
if (
|
|
171
|
+
if (mmkv_likely(!m_enableKeyExpire)) {
|
|
171
172
|
return setDataForKey(MMBuffer(archived, MMBufferNoCopy), key);
|
|
172
173
|
} else {
|
|
173
174
|
MMBuffer data(archived, MMBufferNoCopy);
|
|
@@ -295,7 +296,7 @@ NSArray *MMKV::allKeys(bool filterExpire) {
|
|
|
295
296
|
SCOPED_LOCK(m_lock);
|
|
296
297
|
checkLoadData();
|
|
297
298
|
|
|
298
|
-
if (
|
|
299
|
+
if (mmkv_unlikely(filterExpire && m_enableKeyExpire)) {
|
|
299
300
|
SCOPED_LOCK(m_exclusiveProcessLock);
|
|
300
301
|
fullWriteback(nullptr, true);
|
|
301
302
|
}
|
|
@@ -135,32 +135,46 @@ typedef size_t (*AShmem_getSize_t)(int fd);
|
|
|
135
135
|
#endif
|
|
136
136
|
|
|
137
137
|
int ASharedMemory_create(const char *name, size_t size) {
|
|
138
|
-
int fd = -1;
|
|
139
138
|
#ifndef MMKV_OHOS
|
|
140
|
-
if (g_android_api >= __ANDROID_API_O__) {
|
|
139
|
+
if (g_android_api >= __ANDROID_API_O__ || g_android_api >= __ANDROID_API_M__) {
|
|
141
140
|
static auto handle = loadLibrary();
|
|
142
141
|
static AShmem_create_t funcPtr =
|
|
143
142
|
(handle != nullptr) ? reinterpret_cast<AShmem_create_t>(dlsym(handle, "ASharedMemory_create")) : nullptr;
|
|
144
143
|
if (funcPtr) {
|
|
145
|
-
fd = funcPtr(name, size);
|
|
144
|
+
int fd = funcPtr(name, size);
|
|
146
145
|
if (fd < 0) {
|
|
147
146
|
MMKVError("fail to ASharedMemory_create %s with size %zu, errno:%s", name, size, strerror(errno));
|
|
147
|
+
} else {
|
|
148
|
+
MMKVInfo("ASharedMemory_create %s with size %zu, fd:%d", name, size, fd);
|
|
149
|
+
return fd;
|
|
148
150
|
}
|
|
149
|
-
} else {
|
|
151
|
+
} else if (g_android_api >= __ANDROID_API_O__) {
|
|
150
152
|
MMKVWarning("fail to locate ASharedMemory_create() from loading libandroid.so");
|
|
151
153
|
}
|
|
154
|
+
|
|
155
|
+
static AShmem_create_t regionFuncPtr =
|
|
156
|
+
(handle != nullptr) ? reinterpret_cast<AShmem_create_t>(dlsym(handle, "ashmem_create_region")) : nullptr;
|
|
157
|
+
if (regionFuncPtr) {
|
|
158
|
+
int fd = regionFuncPtr(name, size);
|
|
159
|
+
if (fd < 0) {
|
|
160
|
+
MMKVError("fail to ashmem_create_region %s with size %zu, errno:%s", name, size, strerror(errno));
|
|
161
|
+
} else {
|
|
162
|
+
MMKVInfo("ashmem_create_region %s with size %zu, fd:%d", name, size, fd);
|
|
163
|
+
return fd;
|
|
164
|
+
}
|
|
165
|
+
} else {
|
|
166
|
+
MMKVWarning("fail to locate ashmem_create_region() from loading libandroid.so");
|
|
167
|
+
}
|
|
152
168
|
}
|
|
153
169
|
#endif
|
|
170
|
+
int fd = open(ASHMEM_NAME_DEF, O_RDWR | O_CLOEXEC);
|
|
154
171
|
if (fd < 0) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
} else if (ioctl(fd, ASHMEM_SET_SIZE, size) != 0) {
|
|
162
|
-
MMKVError("fail to set ashmem:%s, size %zu, %s", name, size, strerror(errno));
|
|
163
|
-
}
|
|
172
|
+
MMKVError("fail to open ashmem:%s, %s", name, strerror(errno));
|
|
173
|
+
} else {
|
|
174
|
+
if (ioctl(fd, ASHMEM_SET_NAME, name) != 0) {
|
|
175
|
+
MMKVError("fail to set ashmem name:%s, %s", name, strerror(errno));
|
|
176
|
+
} else if (ioctl(fd, ASHMEM_SET_SIZE, size) != 0) {
|
|
177
|
+
MMKVError("fail to set ashmem:%s, size %zu, %s", name, size, strerror(errno));
|
|
164
178
|
}
|
|
165
179
|
}
|
|
166
180
|
return fd;
|