-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathext_igbinary.cpp
79 lines (63 loc) · 2.13 KB
/
ext_igbinary.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
+----------------------------------------------------------------------+
| See COPYING file for further copyright information |
+----------------------------------------------------------------------+
| Author of hhvm fork: Tyson Andre <[email protected]> |
| Author of original igbinary: Oleg Grenrus <[email protected]>|
| See CREDITS for contributors |
+----------------------------------------------------------------------+
*/
/* Same as equivalent php version? */
#define IGBINARY_HHVM_VERSION "1.2.5-dev"
#include "ext_igbinary.hpp"
#include "hphp/runtime/ext/extension.h"
#include "hphp/runtime/ext/extension-registry.h"
namespace HPHP {
Variant HHVM_FUNCTION(igbinary_serialize, const Variant &var) {
return igbinary_serialize(var);
}
Variant HHVM_FUNCTION(igbinary_unserialize, const String &serialized) {
if (serialized.size() <= 0) {
return init_null();
}
Variant result;
// try {
igbinary_unserialize(reinterpret_cast<const uint8_t*>(serialized.data()), serialized.size(), result);
return result;
// } catch (Exception &e) {
// raise_warning(e.getMessage());
// return init_null();
// }
}
struct Igbinary {
public:
bool compact_strings{true};
};
const StaticString s_igbinary_ext_name("igbinary");
IMPLEMENT_THREAD_LOCAL_NO_CHECK(Igbinary, s_igbinary);
bool igbinary_should_compact_strings() {
return s_igbinary->compact_strings;
}
static class IgbinaryExtension : public Extension {
public:
IgbinaryExtension() : Extension("igbinary", IGBINARY_HHVM_VERSION) {}
void moduleInit() override {
HHVM_FE(igbinary_serialize);
HHVM_FE(igbinary_unserialize);
loadSystemlib();
}
void threadInit() override {
assert(s_igbinary.isNull());
s_igbinary.getCheck();
Extension* ext = ExtensionRegistry::get(s_igbinary_ext_name);
assert(ext);
IniSetting::Bind(ext, IniSetting::PHP_INI_ALL,
"igbinary.compact_strings", "1",
&s_igbinary->compact_strings);
}
void threadShutdown() override {
s_igbinary.destroy();
}
} s_igbinary_extension;
HHVM_GET_MODULE(igbinary);
} // namespace HPHP