php模块的编写有个线程安全问题,有可能你的模块能很好的运行,但是如果加了线程安全的时候,你有可能会得到如下错误:
error: `tsrm_ls' undeclared (first use in this function)
这种原因官方有2种解决办法(在ext/xsl/php_xsl.h文件中有说明):
1) Add TSRM_FETCH(); calls to the functions where the tsrm_ls function is needed. This should be added as the first statement after variable declarations.
2) Change the functions to include the magick TSRM_CC/TSRM_DC parameters.This will cause the tsrm_ls symbol to be passed when the function is called. This method might be time consuming depending on the number of functions and function calls in the code.
在TSRM/TSRM.h文件中有如下定义:#define TSRMLS_FETCH() void ***tsrm_ls = (void ***) ts_resource_ex(0, NULL)
#define TSRMLS_FETCH_FROM_CTX(ctx) void ***tsrm_ls = (void ***) ctx
#define TSRMLS_SET_CTX(ctx) ctx = (void ***) tsrm_ls
#define TSRMG(id, type, element) (((type) (*((void ***) tsrm_ls))[TSRM_UNSHUFFLE_RSRC_ID(id)])->element)
#define TSRMLS_D void ***tsrm_ls
#define TSRMLS_DC , TSRMLS_D
#define TSRMLS_C tsrm_ls
#define TSRMLS_CC , TSRMLS_C
我推荐用第二种,使用方法很简单:
1.在方法定义时加上TSRMLS_D(如果方法没有参数用这个)或者TSRMLS_DC(有1个以上的参数)
2.在方法调用时用TSRMLS_C(如果方法没有参数用这个)或者TSRMLS_CC(有1个以上的参数)
我这样理解D,C的含义(没去看源代码,瞎猜的):
第一个后缀字母D表示定义,即D=Define,第一个后缀字母C表示调用,即C=Call,而第二个后缀字母C是不是表示逗号呢? C=Comma (逗号)
TSRMLS_D就是定义了,所以是 void ***tsrm_ls
TSRMLS_DC是带逗号的定义,所以是 , void ***tsrm_ls
TSRMLS_C是调用,即tsrm_ls
TSRMLS_CC是调用并带逗号,即 ,tsrm_ls
类别:技术文章 | 阅读:316402 | 评论:0 |
标签:php zend