react-native-mmkv-dz 2.5.1

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.
Files changed (138) hide show
  1. package/LICENSE +219 -0
  2. package/MMKV/CHANGELOG.md +553 -0
  3. package/MMKV/Core/CMakeLists.txt +153 -0
  4. package/MMKV/Core/CodedInputData.cpp +228 -0
  5. package/MMKV/Core/CodedInputData.h +83 -0
  6. package/MMKV/Core/CodedInputDataCrypt.cpp +280 -0
  7. package/MMKV/Core/CodedInputDataCrypt.h +87 -0
  8. package/MMKV/Core/CodedInputDataCrypt_OSX.cpp +62 -0
  9. package/MMKV/Core/CodedInputData_OSX.cpp +92 -0
  10. package/MMKV/Core/CodedOutputData.cpp +174 -0
  11. package/MMKV/Core/CodedOutputData.h +82 -0
  12. package/MMKV/Core/Core.xcodeproj/project.pbxproj +702 -0
  13. package/MMKV/Core/Core.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  14. package/MMKV/Core/Core.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  15. package/MMKV/Core/Core.xcodeproj/xcshareddata/xcschemes/Core.xcscheme +67 -0
  16. package/MMKV/Core/Core.xcodeproj/xcshareddata/xcschemes/MMKVWatchCore.xcscheme +67 -0
  17. package/MMKV/Core/InterProcessLock.cpp +186 -0
  18. package/MMKV/Core/InterProcessLock.h +119 -0
  19. package/MMKV/Core/InterProcessLock_Android.cpp +103 -0
  20. package/MMKV/Core/InterProcessLock_Win32.cpp +108 -0
  21. package/MMKV/Core/KeyValueHolder.cpp +236 -0
  22. package/MMKV/Core/KeyValueHolder.h +118 -0
  23. package/MMKV/Core/MMBuffer.cpp +185 -0
  24. package/MMKV/Core/MMBuffer.h +107 -0
  25. package/MMKV/Core/MMKV.cpp +1418 -0
  26. package/MMKV/Core/MMKV.h +386 -0
  27. package/MMKV/Core/MMKVLog.cpp +127 -0
  28. package/MMKV/Core/MMKVLog.h +86 -0
  29. package/MMKV/Core/MMKVLog_Android.cpp +79 -0
  30. package/MMKV/Core/MMKVMetaInfo.hpp +81 -0
  31. package/MMKV/Core/MMKVPredef.h +245 -0
  32. package/MMKV/Core/MMKV_Android.cpp +259 -0
  33. package/MMKV/Core/MMKV_IO.cpp +1119 -0
  34. package/MMKV/Core/MMKV_IO.h +57 -0
  35. package/MMKV/Core/MMKV_OSX.cpp +347 -0
  36. package/MMKV/Core/MMKV_OSX.h +51 -0
  37. package/MMKV/Core/MemoryFile.cpp +537 -0
  38. package/MMKV/Core/MemoryFile.h +182 -0
  39. package/MMKV/Core/MemoryFile_Android.cpp +211 -0
  40. package/MMKV/Core/MemoryFile_Linux.cpp +120 -0
  41. package/MMKV/Core/MemoryFile_OSX.cpp +142 -0
  42. package/MMKV/Core/MemoryFile_Win32.cpp +536 -0
  43. package/MMKV/Core/MiniPBCoder.cpp +366 -0
  44. package/MMKV/Core/MiniPBCoder.h +129 -0
  45. package/MMKV/Core/MiniPBCoder_OSX.cpp +228 -0
  46. package/MMKV/Core/PBEncodeItem.hpp +86 -0
  47. package/MMKV/Core/PBUtility.cpp +61 -0
  48. package/MMKV/Core/PBUtility.h +153 -0
  49. package/MMKV/Core/ScopedLock.hpp +69 -0
  50. package/MMKV/Core/ThreadLock.cpp +68 -0
  51. package/MMKV/Core/ThreadLock.h +78 -0
  52. package/MMKV/Core/ThreadLock_Win32.cpp +89 -0
  53. package/MMKV/Core/aes/AESCrypt.cpp +256 -0
  54. package/MMKV/Core/aes/AESCrypt.h +107 -0
  55. package/MMKV/Core/aes/openssl/openssl_aes-armv4.S +1231 -0
  56. package/MMKV/Core/aes/openssl/openssl_aes.h +118 -0
  57. package/MMKV/Core/aes/openssl/openssl_aes_core.cpp +1044 -0
  58. package/MMKV/Core/aes/openssl/openssl_aes_locl.h +38 -0
  59. package/MMKV/Core/aes/openssl/openssl_aesv8-armx.S +308 -0
  60. package/MMKV/Core/aes/openssl/openssl_arm_arch.h +84 -0
  61. package/MMKV/Core/aes/openssl/openssl_cfb128.cpp +97 -0
  62. package/MMKV/Core/aes/openssl/openssl_md32_common.h +254 -0
  63. package/MMKV/Core/aes/openssl/openssl_md5.h +49 -0
  64. package/MMKV/Core/aes/openssl/openssl_md5_dgst.cpp +166 -0
  65. package/MMKV/Core/aes/openssl/openssl_md5_locl.h +75 -0
  66. package/MMKV/Core/aes/openssl/openssl_md5_one.cpp +30 -0
  67. package/MMKV/Core/aes/openssl/openssl_opensslconf.h +271 -0
  68. package/MMKV/Core/core.vcxproj +186 -0
  69. package/MMKV/Core/core.vcxproj.filters +150 -0
  70. package/MMKV/Core/crc32/Checksum.h +67 -0
  71. package/MMKV/Core/crc32/crc32_armv8.cpp +132 -0
  72. package/MMKV/Core/crc32/zlib/crc32.cpp +55 -0
  73. package/MMKV/Core/crc32/zlib/crc32.h +48 -0
  74. package/MMKV/Core/crc32/zlib/zconf.h +380 -0
  75. package/MMKV/Core/crc32/zlib/zutil.h +25 -0
  76. package/MMKV/LICENSE.TXT +193 -0
  77. package/MMKV/README.md +288 -0
  78. package/README.md +221 -0
  79. package/android/CMakeLists.txt +71 -0
  80. package/android/build.gradle +371 -0
  81. package/android/gradle.properties +4 -0
  82. package/android/src/main/AndroidManifest.xml +4 -0
  83. package/android/src/main/cpp/MmkvHostObject.cpp +302 -0
  84. package/android/src/main/cpp/MmkvHostObject.h +26 -0
  85. package/android/src/main/cpp/cpp-adapter.cpp +65 -0
  86. package/android/src/main/java/com/reactnativemmkv/MmkvModule.java +49 -0
  87. package/android/src/main/java/com/reactnativemmkv/MmkvPackage.java +26 -0
  88. package/cpp/TypedArray.cpp +341 -0
  89. package/cpp/TypedArray.h +175 -0
  90. package/ios/JSIUtils.h +50 -0
  91. package/ios/JSIUtils.mm +194 -0
  92. package/ios/Mmkv.xcodeproj/project.pbxproj +291 -0
  93. package/ios/MmkvHostObject.h +27 -0
  94. package/ios/MmkvHostObject.mm +299 -0
  95. package/ios/MmkvModule.h +5 -0
  96. package/ios/MmkvModule.mm +73 -0
  97. package/lib/commonjs/MMKV.js +146 -0
  98. package/lib/commonjs/MMKV.js.map +1 -0
  99. package/lib/commonjs/PlatformChecker.js +16 -0
  100. package/lib/commonjs/PlatformChecker.js.map +1 -0
  101. package/lib/commonjs/createMMKV.js +66 -0
  102. package/lib/commonjs/createMMKV.js.map +1 -0
  103. package/lib/commonjs/createMMKV.mock.js +40 -0
  104. package/lib/commonjs/createMMKV.mock.js.map +1 -0
  105. package/lib/commonjs/createMMKV.web.js +77 -0
  106. package/lib/commonjs/createMMKV.web.js.map +1 -0
  107. package/lib/commonjs/createTextEncoder.js +24 -0
  108. package/lib/commonjs/createTextEncoder.js.map +1 -0
  109. package/lib/commonjs/hooks.js +200 -0
  110. package/lib/commonjs/hooks.js.map +1 -0
  111. package/lib/commonjs/index.js +32 -0
  112. package/lib/commonjs/index.js.map +1 -0
  113. package/lib/module/MMKV.js +134 -0
  114. package/lib/module/MMKV.js.map +1 -0
  115. package/lib/module/PlatformChecker.js +9 -0
  116. package/lib/module/PlatformChecker.js.map +1 -0
  117. package/lib/module/createMMKV.js +55 -0
  118. package/lib/module/createMMKV.js.map +1 -0
  119. package/lib/module/createMMKV.mock.js +31 -0
  120. package/lib/module/createMMKV.mock.js.map +1 -0
  121. package/lib/module/createMMKV.web.js +67 -0
  122. package/lib/module/createMMKV.web.js.map +1 -0
  123. package/lib/module/createTextEncoder.js +17 -0
  124. package/lib/module/createTextEncoder.js.map +1 -0
  125. package/lib/module/hooks.js +181 -0
  126. package/lib/module/hooks.js.map +1 -0
  127. package/lib/module/index.js +3 -0
  128. package/lib/module/index.js.map +1 -0
  129. package/lib/typescript/MMKV.d.ts +137 -0
  130. package/lib/typescript/PlatformChecker.d.ts +1 -0
  131. package/lib/typescript/createMMKV.d.ts +6 -0
  132. package/lib/typescript/createMMKV.mock.d.ts +2 -0
  133. package/lib/typescript/createMMKV.web.d.ts +2 -0
  134. package/lib/typescript/createTextEncoder.d.ts +1 -0
  135. package/lib/typescript/hooks.d.ts +81 -0
  136. package/lib/typescript/index.d.ts +2 -0
  137. package/package.json +168 -0
  138. package/react-native-mmkv.podspec +32 -0
@@ -0,0 +1,57 @@
1
+ /*
2
+ * Tencent is pleased to support the open source community by making
3
+ * MMKV available.
4
+ *
5
+ * Copyright (C) 2020 THL A29 Limited, a Tencent company.
6
+ * All rights reserved.
7
+ *
8
+ * Licensed under the BSD 3-Clause License (the "License"); you may not use
9
+ * this file except in compliance with the License. You may obtain a copy of
10
+ * the License at
11
+ *
12
+ * https://opensource.org/licenses/BSD-3-Clause
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ #ifndef MMKV_IO_h
22
+ #define MMKV_IO_h
23
+ #ifdef __cplusplus
24
+
25
+ #include "MMKV.h"
26
+
27
+ MMKV_NAMESPACE_BEGIN
28
+
29
+ std::string mmapedKVKey(const std::string &mmapID, const MMKVPath_t *rootPath = nullptr);
30
+ MMKVPath_t mappedKVPathWithID(const std::string &mmapID, MMKVMode mode, const MMKVPath_t *rootPath);
31
+ MMKVPath_t crcPathWithID(const std::string &mmapID, MMKVMode mode, const MMKVPath_t *rootPath);
32
+
33
+ MMKVRecoverStrategic onMMKVCRCCheckFail(const std::string &mmapID);
34
+ MMKVRecoverStrategic onMMKVFileLengthError(const std::string &mmapID);
35
+
36
+ template <typename T>
37
+ void clearDictionary(T *dic) {
38
+ if (!dic) {
39
+ return;
40
+ }
41
+ #ifdef MMKV_APPLE
42
+ for (auto &pair : *dic) {
43
+ [pair.first release];
44
+ }
45
+ #endif
46
+ dic->clear();
47
+ }
48
+
49
+ enum : bool {
50
+ KeepSequence = false,
51
+ IncreaseSequence = true,
52
+ };
53
+
54
+ MMKV_NAMESPACE_END
55
+
56
+ #endif
57
+ #endif /* MMKV_IO_h */
@@ -0,0 +1,347 @@
1
+ /*
2
+ * Tencent is pleased to support the open source community by making
3
+ * MMKV available.
4
+ *
5
+ * Copyright (C) 2019 THL A29 Limited, a Tencent company.
6
+ * All rights reserved.
7
+ *
8
+ * Licensed under the BSD 3-Clause License (the "License"); you may not use
9
+ * this file except in compliance with the License. You may obtain a copy of
10
+ * the License at
11
+ *
12
+ * https://opensource.org/licenses/BSD-3-Clause
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ #include "MMKVPredef.h"
22
+
23
+ #ifdef MMKV_APPLE
24
+
25
+ # include "CodedInputData.h"
26
+ # include "CodedOutputData.h"
27
+ # include "InterProcessLock.h"
28
+ # include "MMKV.h"
29
+ # include "MemoryFile.h"
30
+ # include "MiniPBCoder.h"
31
+ # include "PBUtility.h"
32
+ # include "ScopedLock.hpp"
33
+ # include "ThreadLock.h"
34
+ # include "aes/AESCrypt.h"
35
+ # include <sys/utsname.h>
36
+
37
+ # ifdef MMKV_IOS
38
+ # include "MMKV_OSX.h"
39
+ # include <sys/mman.h>
40
+ # endif
41
+
42
+ # ifdef __aarch64__
43
+ # include "Checksum.h"
44
+ # endif
45
+
46
+ # if __has_feature(objc_arc)
47
+ # error This file must be compiled with MRC. Use -fno-objc-arc flag.
48
+ # endif
49
+
50
+ using namespace std;
51
+ using namespace mmkv;
52
+
53
+ extern ThreadLock *g_instanceLock;
54
+ extern MMKVPath_t g_rootDir;
55
+
56
+ enum { UnKnown = 0, PowerMac = 1, Mac, iPhone, iPod, iPad, AppleTV, AppleWatch };
57
+ static void GetAppleMachineInfo(int &device, int &version);
58
+
59
+ MMKV_NAMESPACE_BEGIN
60
+
61
+ # ifdef MMKV_IOS
62
+ MLockPtr::MLockPtr(void *ptr, size_t size) : m_lockDownSize(0), m_lockedPtr(nullptr) {
63
+ if (!ptr || size == 0) {
64
+ return;
65
+ }
66
+ // calc ptr to mlock()
67
+ auto writePtr = (size_t) ptr;
68
+ auto lockPtr = (writePtr / DEFAULT_MMAP_SIZE) * DEFAULT_MMAP_SIZE;
69
+ auto lockDownSize = writePtr - lockPtr + size;
70
+ if (mlock((void *) lockPtr, lockDownSize) == 0) {
71
+ m_lockedPtr = (uint8_t *) lockPtr;
72
+ m_lockDownSize = lockDownSize;
73
+ } else {
74
+ MMKVError("fail to mlock [%p], %s", m_lockedPtr, strerror(errno));
75
+ // just fail on this condition, otherwise app will crash anyway
76
+ }
77
+ }
78
+
79
+ MLockPtr::MLockPtr(MLockPtr &&other) : m_lockDownSize(other.m_lockDownSize), m_lockedPtr(other.m_lockedPtr) {
80
+ other.m_lockedPtr = nullptr;
81
+ }
82
+
83
+ MLockPtr::~MLockPtr() {
84
+ if (m_lockedPtr) {
85
+ munlock(m_lockedPtr, m_lockDownSize);
86
+ }
87
+ }
88
+
89
+ # endif
90
+
91
+ extern ThreadOnceToken_t once_control;
92
+ extern void initialize();
93
+
94
+ void MMKV::minimalInit(MMKVPath_t defaultRootDir) {
95
+ ThreadLock::ThreadOnce(&once_control, initialize);
96
+
97
+ // crc32 instruction requires A10 chip, aka iPhone 7 or iPad 6th generation
98
+ int device = 0, version = 0;
99
+ GetAppleMachineInfo(device, version);
100
+ MMKVInfo("Apple Device:%d, version:%d", device, version);
101
+
102
+ g_rootDir = defaultRootDir;
103
+ mkPath(g_rootDir);
104
+
105
+ MMKVInfo("default root dir: " MMKV_PATH_FORMAT, g_rootDir.c_str());
106
+ }
107
+
108
+ # ifdef MMKV_IOS
109
+
110
+ static bool g_isInBackground = false;
111
+
112
+ void MMKV::setIsInBackground(bool isInBackground) {
113
+ SCOPED_LOCK(g_instanceLock);
114
+
115
+ g_isInBackground = isInBackground;
116
+ MMKVInfo("g_isInBackground:%d", g_isInBackground);
117
+ }
118
+
119
+ bool MMKV::isInBackground() {
120
+ SCOPED_LOCK(g_instanceLock);
121
+
122
+ return g_isInBackground;
123
+ }
124
+
125
+ pair<bool, MLockPtr> guardForBackgroundWriting(void *ptr, size_t size) {
126
+ if (g_isInBackground) {
127
+ MLockPtr mlockPtr(ptr, size);
128
+ return make_pair(mlockPtr.isLocked(), move(mlockPtr));
129
+ } else {
130
+ return make_pair(true, MLockPtr(nullptr, 0));
131
+ }
132
+ }
133
+
134
+ # endif // MMKV_IOS
135
+
136
+ bool MMKV::set(NSObject<NSCoding> *__unsafe_unretained obj, MMKVKey_t key) {
137
+ if (isKeyEmpty(key)) {
138
+ return false;
139
+ }
140
+ if (!obj) {
141
+ removeValueForKey(key);
142
+ return true;
143
+ }
144
+
145
+ NSData *tmpData = nil;
146
+ if ([obj isKindOfClass:NSString.class]) {
147
+ auto str = (NSString *) obj;
148
+ tmpData = [str dataUsingEncoding:NSUTF8StringEncoding];
149
+ } else if ([obj isKindOfClass:NSData.class]) {
150
+ tmpData = (NSData *) obj;
151
+ }
152
+ if (tmpData) {
153
+ // delay write the size needed for encoding tmpData
154
+ // avoid memory copying
155
+ return setDataForKey(MMBuffer(tmpData, MMBufferNoCopy), key, true);
156
+ } else if ([obj isKindOfClass:NSDate.class]) {
157
+ NSDate *oDate = (NSDate *) obj;
158
+ double time = oDate.timeIntervalSince1970;
159
+ return set(time, key);
160
+ } else {
161
+ /*if ([object conformsToProtocol:@protocol(NSCoding)])*/ {
162
+ auto tmp = [NSKeyedArchiver archivedDataWithRootObject:obj];
163
+ if (tmp.length > 0) {
164
+ return setDataForKey(MMBuffer(tmp, MMBufferNoCopy), key);
165
+ }
166
+ }
167
+ }
168
+ return false;
169
+ }
170
+
171
+ NSObject *MMKV::getObject(MMKVKey_t key, Class cls) {
172
+ if (isKeyEmpty(key) || !cls) {
173
+ return nil;
174
+ }
175
+ SCOPED_LOCK(m_lock);
176
+ auto data = getDataForKey(key);
177
+ if (data.length() > 0) {
178
+ if (MiniPBCoder::isCompatibleClass(cls)) {
179
+ try {
180
+ auto result = MiniPBCoder::decodeObject(data, cls);
181
+ return result;
182
+ } catch (std::exception &exception) {
183
+ MMKVError("%s", exception.what());
184
+ }
185
+ } else {
186
+ if ([cls conformsToProtocol:@protocol(NSCoding)]) {
187
+ auto tmp = [NSData dataWithBytesNoCopy:data.getPtr() length:data.length() freeWhenDone:NO];
188
+ return [NSKeyedUnarchiver unarchiveObjectWithData:tmp];
189
+ }
190
+ }
191
+ }
192
+ return nil;
193
+ }
194
+
195
+ # ifndef MMKV_DISABLE_CRYPT
196
+
197
+ constexpr uint32_t Fixed32Size = pbFixed32Size();
198
+
199
+ pair<bool, KeyValueHolder>
200
+ MMKV::appendDataWithKey(const MMBuffer &data, MMKVKey_t key, const KeyValueHolderCrypt &kvHolder, bool isDataHolder) {
201
+ if (kvHolder.type != KeyValueHolderType_Offset) {
202
+ return appendDataWithKey(data, key, isDataHolder);
203
+ }
204
+ SCOPED_LOCK(m_exclusiveProcessLock);
205
+
206
+ uint32_t keyLength = kvHolder.keySize;
207
+ // size needed to encode the key
208
+ size_t rawKeySize = keyLength + pbRawVarint32Size(keyLength);
209
+
210
+ auto basePtr = (uint8_t *) m_file->getMemory() + Fixed32Size;
211
+ MMBuffer keyData(rawKeySize);
212
+ AESCrypt decrypter = m_crypter->cloneWithStatus(kvHolder.cryptStatus);
213
+ decrypter.decrypt(basePtr + kvHolder.offset, keyData.getPtr(), rawKeySize);
214
+
215
+ return doAppendDataWithKey(data, keyData, isDataHolder, keyLength);
216
+ }
217
+ # endif
218
+
219
+ NSArray *MMKV::allKeys() {
220
+ SCOPED_LOCK(m_lock);
221
+ checkLoadData();
222
+
223
+ NSMutableArray *keys = [NSMutableArray array];
224
+ if (m_crypter) {
225
+ for (const auto &pair : *m_dicCrypt) {
226
+ [keys addObject:pair.first];
227
+ }
228
+ } else {
229
+ for (const auto &pair : *m_dic) {
230
+ [keys addObject:pair.first];
231
+ }
232
+ }
233
+ return keys;
234
+ }
235
+
236
+ void MMKV::removeValuesForKeys(NSArray *arrKeys) {
237
+ if (arrKeys.count == 0) {
238
+ return;
239
+ }
240
+ if (arrKeys.count == 1) {
241
+ return removeValueForKey(arrKeys[0]);
242
+ }
243
+
244
+ SCOPED_LOCK(m_lock);
245
+ SCOPED_LOCK(m_exclusiveProcessLock);
246
+ checkLoadData();
247
+
248
+ size_t deleteCount = 0;
249
+ if (m_crypter) {
250
+ for (NSString *key in arrKeys) {
251
+ auto itr = m_dicCrypt->find(key);
252
+ if (itr != m_dicCrypt->end()) {
253
+ auto oldKey = itr->first;
254
+ m_dicCrypt->erase(itr);
255
+ [oldKey release];
256
+ deleteCount++;
257
+ }
258
+ }
259
+ } else {
260
+ for (NSString *key in arrKeys) {
261
+ auto itr = m_dic->find(key);
262
+ if (itr != m_dic->end()) {
263
+ auto oldKey = itr->first;
264
+ m_dic->erase(itr);
265
+ [oldKey release];
266
+ deleteCount++;
267
+ }
268
+ }
269
+ }
270
+ if (deleteCount > 0) {
271
+ m_hasFullWriteback = false;
272
+
273
+ fullWriteback();
274
+ }
275
+ }
276
+
277
+ void MMKV::enumerateKeys(EnumerateBlock block) {
278
+ if (block == nil) {
279
+ return;
280
+ }
281
+ SCOPED_LOCK(m_lock);
282
+ checkLoadData();
283
+
284
+ MMKVInfo("enumerate [%s] begin", m_mmapID.c_str());
285
+ if (m_crypter) {
286
+ for (const auto &pair : *m_dicCrypt) {
287
+ BOOL stop = NO;
288
+ block(pair.first, &stop);
289
+ if (stop) {
290
+ break;
291
+ }
292
+ }
293
+ } else {
294
+ for (const auto &pair : *m_dic) {
295
+ BOOL stop = NO;
296
+ block(pair.first, &stop);
297
+ if (stop) {
298
+ break;
299
+ }
300
+ }
301
+ }
302
+ MMKVInfo("enumerate [%s] finish", m_mmapID.c_str());
303
+ }
304
+
305
+ MMKV_NAMESPACE_END
306
+
307
+ # include <sys/sysctl.h>
308
+
309
+ static void GetAppleMachineInfo(int &device, int &version) {
310
+ device = UnKnown;
311
+ version = 0;
312
+
313
+ # if 0
314
+ struct utsname systemInfo = {};
315
+ uname(&systemInfo);
316
+ std::string machine(systemInfo.machine);
317
+ # else
318
+ size_t size;
319
+ sysctlbyname("hw.machine", nullptr, &size, nullptr, 0);
320
+ char *answer = (char *) malloc(size);
321
+ sysctlbyname("hw.machine", answer, &size, nullptr, 0);
322
+ std::string machine(answer);
323
+ free(answer);
324
+ # endif
325
+
326
+ if (machine.find("PowerMac") != std::string::npos || machine.find("Power Macintosh") != std::string::npos) {
327
+ device = PowerMac;
328
+ } else if (machine.find("Mac") != std::string::npos || machine.find("Macintosh") != std::string::npos) {
329
+ device = Mac;
330
+ } else if (machine.find("iPhone") != std::string::npos) {
331
+ device = iPhone;
332
+ } else if (machine.find("iPod") != std::string::npos) {
333
+ device = iPod;
334
+ } else if (machine.find("iPad") != std::string::npos) {
335
+ device = iPad;
336
+ } else if (machine.find("AppleTV") != std::string::npos) {
337
+ device = AppleTV;
338
+ } else if (machine.find("AppleWatch") != std::string::npos) {
339
+ device = AppleWatch;
340
+ }
341
+ auto pos = machine.find_first_of("0123456789");
342
+ if (pos != std::string::npos) {
343
+ version = std::atoi(machine.substr(pos).c_str());
344
+ }
345
+ }
346
+
347
+ #endif // MMKV_APPLE
@@ -0,0 +1,51 @@
1
+ /*
2
+ * Tencent is pleased to support the open source community by making
3
+ * MMKV available.
4
+ *
5
+ * Copyright (C) 2019 THL A29 Limited, a Tencent company.
6
+ * All rights reserved.
7
+ *
8
+ * Licensed under the BSD 3-Clause License (the "License"); you may not use
9
+ * this file except in compliance with the License. You may obtain a copy of
10
+ * the License at
11
+ *
12
+ * https://opensource.org/licenses/BSD-3-Clause
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ #pragma once
22
+ #include "MMKVPredef.h"
23
+
24
+ #if defined(MMKV_IOS) && defined(__cplusplus)
25
+
26
+ MMKV_NAMESPACE_BEGIN
27
+
28
+ class MLockPtr {
29
+ size_t m_lockDownSize;
30
+ uint8_t *m_lockedPtr;
31
+
32
+ public:
33
+ MLockPtr(void *ptr, size_t size);
34
+ MLockPtr(MLockPtr &&other);
35
+
36
+ ~MLockPtr();
37
+
38
+ bool isLocked() const {
39
+ return (m_lockedPtr != nullptr);
40
+ }
41
+
42
+ // just forbid it for possibly misuse
43
+ explicit MLockPtr(const MLockPtr &other) = delete;
44
+ MLockPtr &operator=(const MLockPtr &other) = delete;
45
+ };
46
+
47
+ std::pair<bool, MLockPtr> guardForBackgroundWriting(void *ptr, size_t size);
48
+
49
+ MMKV_NAMESPACE_END
50
+
51
+ #endif