2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #include "hphp/runtime/base/member-reflection.h"
19 #include "hphp/util/build-info.h"
20 #include "hphp/util/embedded-data.h"
21 #include "hphp/util/logger.h"
26 #include <unordered_map>
30 ///////////////////////////////////////////////////////////////////////////////
32 std::unordered_map
<std::string
, const char*(*)(const void*, const void*)> const*
33 g_member_reflection_vtable
= nullptr;
36 const char* nameof_member(const HPHP::name* base, const void* internal) { \
37 if (!g_member_reflection_vtable) return nullptr; \
38 auto it = g_member_reflection_vtable->find("HPHP::"#name); \
39 if (it == std::end(*g_member_reflection_vtable)) return nullptr; \
40 return it->second(base, internal); \
46 bool init_member_reflection(const std::string
& extractPath
,
47 const std::string
& fallbackPath
,
49 g_member_reflection_vtable
=
50 reinterpret_cast<decltype(g_member_reflection_vtable
)>(
51 dlsym(RTLD_DEFAULT
, detail::kMemberReflectionTableName
)
53 if (g_member_reflection_vtable
) return true;
56 if (!get_embedded_data("member_reflection", &desc
)) {
57 // We might not be embedding the shared object, depending on platform, so
58 // don't cry too loudly if we don't find it.
59 Logger::Verbose("init_member_reflection: Unable to find embedded data");
63 auto const handle
= dlopen_embedded_data(
71 Logger::Warning("init_member_reflection: "
72 "Failed to dlopen embedded data");
76 g_member_reflection_vtable
=
77 reinterpret_cast<decltype(g_member_reflection_vtable
)>(
78 dlsym(handle
, detail::kMemberReflectionTableName
)
80 if (!g_member_reflection_vtable
) {
81 Logger::Warning("init_member_reflection: dlsym failed: %s", dlerror());
92 ///////////////////////////////////////////////////////////////////////////////