在sqlite3源代码中对sqlite3 struct的混淆 [英] Confusion on sqlite3 struct in sqlite3 source code

查看:247
本文介绍了在sqlite3源代码中对sqlite3 struct的混淆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在函数

static int sqlite3Prepare(
    sqlite3 *db,              /* Database handle. */
    const char *zSql,         /* UTF-8 encoded SQL statement. */
    int nBytes,               /* Length of zSql in bytes. */
    int saveSqlFlag,          /* True to copy SQL text into the sqlite3_stmt */
    Vdbe *pReprepare,         /* VM being reprepared */
    sqlite3_stmt **ppStmt,    /* OUT: A pointer to the prepared statement */
    const char **pzTail       /* OUT: End of parsed string */
    ) {
     ...
     pParse = sqlite3StackAllocZero(db, sizeof(*pParse));
     ...
     assert( !db->mallocFailed );
     ...
}

我知道sqlite3只是一个假的struct as

I know sqlite3 is just a fake struct declared as

 typedef struct sqlite3 sqlite3;

没有任何正文。我知道 sqlite3 * 通常被转换为 Vdbe *

without any body. I know sqlite3 * is usually is cast to a Vdbe*.

但是, db sqlite3 * 的类型, db-> malloFailed 存在?为什么编译器不报错?

But here, db is of the type of sqlite3*, how can db->malloFailed exist? Why doesn't the compiler complain?

有类似的情况, sqlite3_stmt

typedef struct sqlite3_stmt sqlite3_stmt;

。我猜 sqlite3_stmt 是解析的SQL语句的语法树。我想看看它的结构。但是,这种类型被深深地使用这个奇怪的模式,我看不到它是什么。

with no body. I guess sqlite3_stmt is a syntax tree of parsed SQL statements. I would like to see the structure of it. However, the type is hidden so deeply using this weird pattern that I can't see what it is.

偶尔 Vdbe 是同样的情况...

Even Vdbe is the same situation...

typedef struct Vdbe Vdbe;

实际上是真实的 struct

推荐答案

sqlite3 struct; sqlite.h 文件只是没有定义它的正文。

sqlite3 is not a fake struct; the sqlite.h file just does not define its body.

它的定义在 sqliteInt.h 文件(它也是 sqlite3.c 合并的一部分):

Its definition is in the sqliteInt.h file (which is also part of the sqlite3.c amalgamation):

/*
** Each database connection is an instance of the following structure.
*/
struct sqlite3 {
  sqlite3_vfs *pVfs;            /* OS Interface */
  struct Vdbe *pVdbe;           /* List of active virtual machines */
  CollSeq *pDfltColl;           /* The default collating sequence (BINARY) */
  ...
  u8 mallocFailed;              /* True if we have seen a malloc failure */
  ...

这篇关于在sqlite3源代码中对sqlite3 struct的混淆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆