首先,是整数类型:
src/core/ngx_config.h
<code><span>typedef</span> intptr_t ngx_int_t; <span>typedef</span> uintptr_t ngx_uint_t; <span>typedef</span> intptr_t ngx_flag_t;</code>
即整数、无符号整数和bool。intptr_t 等三种类型定义如下:
/usr/local/include/stdint.h
<code><span>/* Types for `void *' pointers. */</span><span>#if __WORDSIZE == 64</span><span># ifndef __intptr_t_defined</span> typedef <span>long</span><span>int</span> intptr_t; <span># define __intptr_t_defined</span><span># endif</span> typedef unsigned <span>long</span><span>int</span> uintptr_t; <span>#else</span><span># ifndef __intptr_t_defined</span> typedef <span>int</span> intptr_t; <span># define __intptr_t_defined</span><span># endif</span> typedef unsigned <span>int</span> uintptr_t; <span>#endif</span></code>
即:64系统则使用长整形(8字节),否则使用整形(4字节)。
然后是字符串型:
/src/core/ngx_string.h
<code><span>typedef</span> struct { size_t len; u_char *<span><span>data</span>;</span> } ngx_str_t; </code>
接着,定义了一堆字符串相关的函数,类似于对应于ngx_str_t的成员函数吧。
函数 | 描述 |
---|---|
ngx_string(str) | 构造函数,str指向\0结尾的字符串 |
ngx_null_string | 空构造函数 |
ngx_str_set(str, text) | text指向\0结尾的字符串,将它set给ngx_str_t对象str |
ngx_strncmp | 封装strncmp |
ngx_strcmp | 封装strcmp |
… | … |
此外,顺便定义了其他几个类型:
<code><span>typedef</span><span>struct</span> { ngx_str_t key; ngx_str_t value; } ngx_keyval_t; <span>typedef</span><span>struct</span> { <span>// 位域用来标示类型等元信息</span><span>unsigned</span> len:<span>28</span>; <span>unsigned</span> valid:<span>1</span>; <span>unsigned</span> no_cacheable:<span>1</span>; <span>unsigned</span> not_found:<span>1</span>; <span>unsigned</span> escape:<span>1</span>; u_char *data; } ngx_variable_value_t; <span>typedef</span><span>struct</span> { ngx_rbtree_node_t node; ngx_str_t str; } ngx_str_node_t;</code>
定义了自己的错误类型:(原因是系统的strerror和strerror_r函数不是信号安全的,因此作者将错误码对应的错误msg拷贝了一遍,自己维护,自己的函数写的很简单,是信号安全的)
src/os/unix/ngx_errno.h
<code><span>typedef</span><span>int</span> ngx_err_t; <span>// 根据错误号err,将对应的描述信息拷贝到errstr,最多拷贝size字节</span> u_char *ngx_strerror(ngx_err_t err, u_char *errstr, size_t size); ngx_int_t ngx_strerror_init(<span>void</span>);</code>
系统的errno.h中定义了错误号,多层include后最终错误号定义于/usr/include/asm-generic/errno.h中。
而strerror和strerror_r函数声明于string.h
版权声明:本文为博主原创文章,未经博主允许不得转载。
以上就介绍了基本数据结构,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。