Remove empty from slow runtime tests
[hiphop-php.git] / hphp / runtime / base / member-reflection.cpp
blobbf813c3e69284cf4390d1aef7104ec6ca5515037
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
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"
23 #include <cstdio>
24 #include <dlfcn.h>
25 #include <string>
26 #include <unordered_map>
28 namespace HPHP {
30 ///////////////////////////////////////////////////////////////////////////////
32 std::unordered_map<std::string, const char*(*)(const void*, const void*)> const*
33 g_member_reflection_vtable = nullptr;
35 #define X(name) \
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); \
42 HPHP_REFLECTABLES
43 #undef X
46 bool init_member_reflection(const std::string& extractPath,
47 const std::string& fallbackPath,
48 bool trust) {
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;
55 embedded_data desc;
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");
60 return false;
63 auto const handle = dlopen_embedded_data(
64 desc,
65 extractPath,
66 fallbackPath,
67 buildId().toString(),
68 trust
70 if (!handle) {
71 Logger::Warning("init_member_reflection: "
72 "Failed to dlopen embedded data");
73 return false;
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());
82 return false;
85 return true;
88 #define X(name)
90 #undef X
92 ///////////////////////////////////////////////////////////////////////////////