hiphop 2.1 开发问题总结 原创-胡志广
1.??Hhvm2.1?生成扩展文件方式
Hhvm2.1?的结构化变化比较大,idl的目录放到了$HPHP_HOME/hphp/system/idl下,并且他的格式已经换成了xxx.idl.json
生成*.h和*.cpp的模式为:
php$HPHP_HOME/hphp/system/idl/idl.php cpp xxx.idl.json $HPHP_HOME/hphp/runtime/ext/ext_xxx.h$HPHP_HOME/hphp/runtime/ext/ext_xxx.cpp
参数的意思:
(1)????模式,cpp ,也有其他的如inc,test?等
(2)????Idl文件,如hello.idl.json
(3)????输出头文件的位置,如$HPHP_HOME/hphp/runtime/ext/ext_hello.h
(4)????输出实现的位置,如$HPHP_HOME/hphp/runtime/ext/ext_hello.cpp
?
例:
有一个新的扩展名字为hello.idl.json
php $HPHP_HOME/hphp/system/idl/idl.phpcpp hello.idl.json $HPHP_HOME/hphp/runtime/ext/ext_hello.h$HPHP_HOME/hphp/runtime/ext/ext_hello.cpp
?
2.??error: 'c_TestClass' was notdeclared in this scope/export/dev_hphp2.0/hiphop-php_hzg/hphp/runtime/ext_hhvm/ext_hhvm_infotabs.cpp:At global scope:
/export/dev_hphp2.0/hiphop-php_hzg/hphp/runtime/ext_hhvm/ext_hhvm_infotabs.cpp:6118:49:error: 'c_TestClass' was not declared in this scope
/export/dev_hphp2.0/hiphop-php_hzg/hphp/runtime/ext_hhvm/ext_hhvm_infotabs.cpp:6118:125:error: 'c_TestClass' has not been declared
报了上面的错误是因为在ext.h中没有加入新的扩展的头文件,我们只需要把新的扩展的头文件加入进去即可:
#include"hphp/runtime/ext/ext_testclass.h"
?
?
在实现类中需要实现构造函数:
c_TestClass::c_TestClass(Class*cls):ExtObjectData(cls){
?
}
c_TestClass::~c_TestClass(){
?
}
?
当报下面的错误时:
(1)这个是参数的问题
/export/dev_hphp2.0/hiphop-php_hzg/hphp/runtime/ext/ext_testclass.cpp:7:57:error: default argument given for parameter 1 of'HPHP::c_TestClass::c_TestClass(HPHP::Class*)'
(2)这个是由于c_TestClass(Class* cls):ExtObjectData(cb)变量不一致造成的,比如前面是cls我后面定义的是cb
/export/dev_hphp2.0/hiphop-php_hzg/hphp/runtime/ext/ext_testclass.cpp:7:52:error: 'cb' was not declared in this scope
?
正常的实现是:
c_TestClass::c_TestClass(Class*cls):ExtObjectData(cls){
?
?
?
3.??undefined reference to`HPHP::c_ICE::~c_ICE()'错误解决../../bin/libext_hhvm.a(ext_ice.cpp.ext_hhvm.cpp.o):(.rodata._ZTVN4HPHP5c_ICEE[vtablefor HPHP::c_ICE]+0x10): undefined reference to `HPHP::c_ICE::~c_ICE()'
../../bin/libext_hhvm.a(ext_ice.cpp.ext_hhvm.cpp.o):(.rodata._ZTVN4HPHP5c_ICEE[vtablefor HPHP::c_ICE]+0x18): undefined reference to `HPHP::c_ICE::~c_ICE()'
../../bin/libext_hhvm.a(ext_ice.cpp.ext_hhvm.cpp.o):(.rodata._ZTVN4HPHP7c_ProxyE[vtablefor HPHP::c_Proxy]+0x10): undefined reference to `HPHP::c_Proxy::~c_Proxy()'
../../bin/libext_hhvm.a(ext_ice.cpp.ext_hhvm.cpp.o):(.rodata._ZTVN4HPHP7c_ProxyE[vtablefor HPHP::c_Proxy]+0x18): undefined reference to `HPHP::c_Proxy::~c_Proxy()'
../../bin/libext_hhvm.a(ext_ice.cpp.ext_hhvm.cpp.o):(.rodata._ZTVN4HPHP14c_IcePHP_classE[vtablefor HPHP::c_IcePHP_class]+0x10): undefined reference to`HPHP::c_IcePHP_class::~c_IcePHP_class()'
../../bin/libext_hhvm.a(ext_ice.cpp.ext_hhvm.cpp.o):(.rodata._ZTVN4HPHP14c_IcePHP_classE[vtablefor HPHP::c_IcePHP_class]+0x18): undefined reference to`HPHP::c_IcePHP_class::~c_IcePHP_class()'
../../bin/libext_hhvm.a(ext_ice.cpp.ext_hhvm.cpp.o):(.rodata._ZTVN4HPHP10c_TypeInfoE[vtablefor HPHP::c_TypeInfo]+0x10): undefined reference to`HPHP::c_TypeInfo::~c_TypeInfo()'
../../bin/libext_hhvm.a(ext_ice.cpp.ext_hhvm.cpp.o):(.rodata._ZTVN4HPHP10c_TypeInfoE[vtablefor HPHP::c_TypeInfo]+0x18): undefined reference to`HPHP::c_TypeInfo::~c_TypeInfo()'
?
当报这个错误的时候,是由于新添加的扩展没有对类进行实现,添加实现即可:
?
在实现类中需要实现构造函数:
c_TestClass::c_TestClass(Class*cls):ExtObjectData(cls){
?
}
c_TestClass::~c_TestClass(){
?
}
?
4.??Idl.json定义args的value不能是””和非字符串;
而且必须是定义非空的只能小于等于2个;
定义String空:null_string;
定义Variant,StringMap?空:null_variant;
定义Object空:null_object;
其他的参照hphp/runtime/base/types.h
?
?
5.??Hhvm创建线程失败解决pthread_attr_t attr;
如果设置attr.stacksize=1.1M,则创建成功;
如果设置:
attr.stacksize=2B,则创建失败;
这是为什么呢?
这是由于1M是一个临界值,创建线程时需要是1M+nkb,也就是需要大于1M才可以;
如果我们需要突破这个限制,那么改如下代码:
由于src/util/ringbuffer.cpp 中设置了线程栈的大小:
static const int kMaxRBBytes = 1 << 20; // 1MB
这里改成小于1M即可;
static const int kMaxRBBytes = 1 << 19; // 512KB
?
这个改成512KB后,就可以支持attr.stacksize=512K+nkb了,但是小于512KB,还是会失败;
所以如果我们要设置线程栈小于1M时,这里我们可以自己控制,比如我们设置了100K,那么相对kMaxRBBytes变量就要设置为小于100K的临界值即可;
?
该问题是百度张慕华解决的,我这里借鉴;
?
解决方式见:
?
https://github.com/facebook/hiphop-php/issues/1015