Add <<__NativeData("Type")>> registry for over-allocating ObjectData
Allows storing arbitrary data in an ObjectData structure
from extension code.
Allocates extra space (as requested by Native::registerNativeDataInfo())
in the ObjectData sturcture (prior to the formal struct) and calls
Init, Clone, and Destroy functions (as registered).
Standard class implementation implement these via their empty constructor,
copy constructor, and destructor respectively.
For example:
ext_foo.php
<?hh
<<__NativeData("MyClass")>>
class MyClass {
/* blah blah blah */
}
ext_foo.cpp
struct MyClass : Native::NativeData {
public:
// Called by `$x = new MyClass;` or `$x = clone $MyClassInstance;`
// to initialize the C++ object
MyClass() {}
// Called by `$x = clone $MyClassInstance`
// to copy from an existing C++ object
MyClass& operator=(const MyClass& src) {
if (src.m_foo) {
m_foo = newFoo(src.m_foo);
}
return *this;
}
// Called when object goes out of scope or request end
~MyClass() {
if (m_foo) {
delete m_foo;
}
}
// etc...
private:
Foo *m_foo = nullptr;
}
Further down in the Extension structure:
void moduleInit() override {
Native::registerNativeDataInfo<MyClass>(s_MyClass.get());
}
Reviewed By: @jdelong
Differential Revision:
D1171055