sqlite3源代码中sqlite3结构的混乱

Alf*_*ong 1 c database sqlite

在函数中

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 );
     ...
}
Run Code Online (Sandbox Code Playgroud)

我知道 sqlite3 只是一个声明为的假结构

 typedef struct sqlite3 sqlite3;
Run Code Online (Sandbox Code Playgroud)

没有任何身体。我知道sqlite3 *通常会被投射到 a Vdbe*

但这里,db是 类型的sqlite3*,怎么可能db->malloFailed存在呢?为什么编译器不抱怨?

也有类似的情况sqlite3_stmt

typedef struct sqlite3_stmt sqlite3_stmt;
Run Code Online (Sandbox Code Playgroud)

没有身体。我猜sqlite3_stmt是一个解析SQL语句的语法树。我想看看它的结构。然而,该类型使用这种奇怪的模式隐藏得很深,我看不到它是什么。

即使Vdbe是同样的情况...

typedef struct Vdbe Vdbe;
Run Code Online (Sandbox Code Playgroud)

到底哪里才是真正的struct

CL.*_*CL. 5

sqlite3不是一个结构;该sqlite.h文件只是没有定义其主体。

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

/*
** 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 */
  ...
Run Code Online (Sandbox Code Playgroud)