Skip to content

Commit

Permalink
Allow NDI classes to set arbitrary ObjectData attributes
Browse files Browse the repository at this point in the history
Summary: This will be used by ext/asio HNI conversion for IsWaitHandle

Reviewed By: @ptarjan

Differential Revision: D1458681
  • Loading branch information
sgolemon authored and facebook-github-bot committed Aug 10, 2014
1 parent 278c7ad commit 2060b3a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion hphp/runtime/vm/native-data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ void registerNativeDataInfo(const StringData* name,
assert(s_nativedatainfo.find(name) == s_nativedatainfo.end());
NativeDataInfo info;
info.sz = sz;
info.odattrs = ObjectData::Attribute::HasNativeData;
info.init = init;
info.copy = copy;
info.destroy = destroy;
Expand Down Expand Up @@ -130,7 +131,7 @@ ObjectData* nativeDataInstanceCtor(Class* cls) {

void *ptr = MM().objMallocLogged(size);
auto obj = new (static_cast<char*>(ptr) + nativeDataSize) ObjectData(cls);
obj->setAttribute(ObjectData::Attribute::HasNativeData);
obj->setAttribute(static_cast<ObjectData::Attribute>(ndi->odattrs));
if (ndi->init) {
ndi->init(obj);
}
Expand Down
8 changes: 7 additions & 1 deletion hphp/runtime/vm/native-data.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,15 @@ struct NativeDataInfo {
typedef void (*SweepFunc)(ObjectData *sweep);

size_t sz;
uint16_t odattrs;
InitFunc init; // new Object
CopyFunc copy; // clone $obj
DestroyFunc destroy; // unset($obj)
SweepFunc sweep; // sweep $obj

void setObjectDataAttribute(uint16_t attr) {
odattrs |= attr;
}
};

NativeDataInfo* getNativeDataInfo(const StringData* name);
Expand Down Expand Up @@ -97,7 +102,8 @@ enum NDIFlags {
};

template<class T>
void registerNativeDataInfo(const StringData* name, int64_t flags = 0) {
void registerNativeDataInfo(const StringData* name,
int64_t flags = 0) {
registerNativeDataInfo(name, sizeof(T),
&nativeDataInfoInit<T>,
(flags & NDIFlags::NO_COPY)
Expand Down

0 comments on commit 2060b3a

Please sign in to comment.