2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 | Copyright (c) 1997-2010 The PHP Group |
7 +----------------------------------------------------------------------+
8 | This source file is subject to version 3.01 of the PHP license, |
9 | that is bundled with this package in the file LICENSE, and is |
10 | available through the world-wide-web at the following url: |
11 | http://www.php.net/license/3_01.txt |
12 | If you did not receive a copy of the PHP license and are unable to |
13 | obtain it through the world-wide-web, please send a note to |
14 | license@php.net so we can mail you a copy immediately. |
15 +----------------------------------------------------------------------+
17 #include "hphp/runtime/ext/extension.h"
18 #include "hphp/runtime/ext/extension-registry.h"
22 #include "hphp/util/exception.h"
23 #include "hphp/util/assertions.h"
24 #include "hphp/runtime/ext/apache/ext_apache.h"
25 #include "hphp/runtime/ext/apc/ext_apc.h"
26 #include "hphp/runtime/ext/string/ext_string.h"
27 #include "hphp/runtime/base/program-functions.h"
28 #include "hphp/runtime/base/config.h"
29 #include "hphp/runtime/vm/runtime.h"
30 #include "hphp/runtime/vm/unit.h"
31 #include "hphp/system/systemlib.h"
37 ///////////////////////////////////////////////////////////////////////////////
38 // Global systemlib extensions implemented entirely in PHP
40 IMPLEMENT_DEFAULT_EXTENSION_VERSION(redis
, NO_EXTENSION_VERSION_YET
);
42 ///////////////////////////////////////////////////////////////////////////////
44 Extension::Extension(const char* name
, const char* version
/* = "" */)
46 , m_version(version
? version
: "") {
47 ExtensionRegistry::registerExtension(this);
50 const static std::string
51 s_systemlibPhpName("systemlib.php"),
52 s_systemlibHhasName("systemlib.hhas.");
54 bool Extension::IsSystemlibPath(const std::string
& name
) {
55 return !name
.compare(0, 2, "/:");
58 void Extension::CompileSystemlib(const std::string
&slib
,
59 const std::string
&name
) {
60 // TODO (t3443556) Bytecode repo compilation expects that any errors
61 // encountered during systemlib compilation have valid filename pointers
62 // which won't be the case for now unless these pointers are long-lived.
63 auto const moduleName
= makeStaticString("/:" + name
);
64 auto const unit
= compile_systemlib_string(slib
.c_str(), slib
.size(),
66 always_assert_flog(unit
, "No unit created for systemlib `{}'", moduleName
);
68 const StringData
* msg
;
70 if (unit
->compileTimeFatal(msg
, line
) ||
71 unit
->parseFatal(msg
, line
)) {
72 std::fprintf(stderr
, "Systemlib `%s' contains a fataling unit: %s, %d\n",
80 SystemLib::addPersistentUnit(unit
);
84 * Loads a named systemlib section from the main binary (or DSO)
85 * using the label "ext.{hash(name)}"
87 * If {name} is not passed, then {m_name} is assumed.
89 void Extension::loadSystemlib(const std::string
& name
) {
90 std::string n
= name
.empty() ?
91 std::string(m_name
.data(), m_name
.size()) : name
;
93 std::string
section("ext_");
95 std::string
section("ext.");
97 section
+= HHVM_FN(md5
)(n
, false).substr(0, 12).data();
99 std::string slib
= get_systemlib(&hhas
, section
, m_dsoName
);
101 std::string phpname
= s_systemlibPhpName
+ n
;
102 CompileSystemlib(slib
, phpname
);
105 std::string hhasname
= s_systemlibHhasName
+ n
;
106 CompileSystemlib(hhas
, hhasname
);
110 /////////////////////////////////////////////////////////////////////////////