Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复 Xcode16 编译运行 iOS18 sqlite3_finalize 闪退问题 #166

Open
li6185377 opened this issue Jul 16, 2024 · 12 comments
Open

修复 Xcode16 编译运行 iOS18 sqlite3_finalize 闪退问题 #166

li6185377 opened this issue Jul 16, 2024 · 12 comments

Comments

@li6185377
Copy link

li6185377 commented Jul 16, 2024

修复Xcode16编译引起的闪退,在 iOS18 中,需要提前对 sqlite3_stmt 执行 sqlite3_finalize

@implementation YYKVStorage

- (BOOL)_dbClose {
   ...
// 原代码
    if (_dbStmtCache) CFRelease(_dbStmtCache);

// 替换为
    if (_dbStmtCache) {              
        CFIndex size = CFDictionaryGetCount(_dbStmtCache);
        CFTypeRef *valuesRef = (CFTypeRef *)malloc(size * sizeof(CFTypeRef));
        CFDictionaryGetKeysAndValues(_dbStmtCache, NULL, (const void **)valuesRef);
        const sqlite3_stmt **stmts = (const sqlite3_stmt **)valuesRef;
        for (CFIndex i = 0; i < size; i ++) {
            sqlite3_stmt *stmt = (sqlite3_stmt *)stmts[i];
            sqlite3_finalize(stmt);
        }
        free(valuesRef);
        CFRelease(_dbStmtCache);
    }
    ...
}

@end

建议改用 CFDictionaryApplyFunction 更加优雅: #163

该 pull request 还有对 WAL 膨胀的治理。

@zhenghaonagehao
Copy link

觉着这个问题作者会修复么?

@faimin
Copy link

faimin commented Sep 12, 2024

觉着这个问题作者会修复么?

@zhenghaonagehao li6185377老哥把解决办法贴在这里的初衷也许并不是奢望作者及时的进行修复,而只是给遇到同样问题的朋友们提供一种解决方案,反哺开源社区~

@kedu
Copy link

kedu commented Sep 18, 2024

能列全一下代码吗?不知道替换哪些代码

@miaoruiyuan
Copy link

能列全一下代码吗?不知道替换哪些代码
YYKVStorage.m 104 line

@kedu
Copy link

kedu commented Sep 19, 2024

我这104行是这 _dbOpenErrorCount = 0; ,肯定不对

@li6185377
Copy link
Author

li6185377 commented Sep 19, 2024

我这104行是这 _dbOpenErrorCount = 0; ,肯定不对

YYKVStorage.m

// 原代码
    if (_dbStmtCache) CFRelease(_dbStmtCache);

// 替换为
    if (_dbStmtCache) {              
        CFIndex size = CFDictionaryGetCount(_dbStmtCache);
        CFTypeRef *valuesRef = (CFTypeRef *)malloc(size * sizeof(CFTypeRef));
        CFDictionaryGetKeysAndValues(_dbStmtCache, NULL, (const void **)valuesRef);
        const sqlite3_stmt **stmts = (const sqlite3_stmt **)valuesRef;
        for (CFIndex i = 0; i < size; i ++) {
            sqlite3_stmt *stmt = stmts[i];
            sqlite3_finalize(stmt);
        }
        free(valuesRef);
        CFRelease(_dbStmtCache);
    }

@kedu
Copy link

kedu commented Sep 19, 2024

好的,感谢

@LoveYao
Copy link

LoveYao commented Sep 23, 2024

感谢大佬

@Rogue24
Copy link

Rogue24 commented Sep 23, 2024

@li6185377 大佬,替换后会有警告 “Initializing 'sqlite3_stmt *' (aka 'struct sqlite3_stmt *') with an expression of type 'const sqlite3_stmt *' (aka 'const struct sqlite3_stmt *') discards qualifiers”,会有影响吗?

@huamouChen
Copy link

@li6185377 大佬,替换后会有警告 “Initializing 'sqlite3_stmt *' (aka 'struct sqlite3_stmt *') with an expression of type 'const sqlite3_stmt *' (aka 'const struct sqlite3_stmt *') discards qualifiers”,会有影响吗?

sqlite3_stmt *stmt = (sqlite3_stmt *)stmts[i];

@Ye-YiChen
Copy link

Ye-YiChen commented Nov 8, 2024

这个有办法可以规避吗?除了改代码以外。

@ptlCoder
Copy link

pod 导入的 怎么整?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants