From 591812fd8c7d5ae2ead215135753b868eb039aa0 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Fri, 9 Feb 2018 03:34:50 +0800 Subject: [PATCH] src: do not redefine private for GenDebugSymbols Redefining private breaks any private inheritance in the included files. We can simply declare GenDebugSymbols() as friends in related classes to gain the access that we need. Backport-PR-URL: https://github.com/nodejs/node/pull/19176 PR-URL: https://github.com/nodejs/node/pull/18653 Reviewed-By: Anna Henningsen Reviewed-By: Ben Noordhuis Reviewed-By: Colin Ihrig Reviewed-By: James M Snell --- src/base-object.h | 1 + src/env.h | 1 + src/handle_wrap.h | 2 ++ src/node_postmortem_metadata.cc | 54 --------------------------------- src/req-wrap.h | 1 + src/util.h | 2 ++ 6 files changed, 7 insertions(+), 54 deletions(-) diff --git a/src/base-object.h b/src/base-object.h index 5852f764066fbc..965683d029e43e 100644 --- a/src/base-object.h +++ b/src/base-object.h @@ -70,6 +70,7 @@ class BaseObject { // offsets and generate debug symbols for BaseObject, which assumes that the // position of members in memory are predictable. For more information please // refer to `doc/guides/node-postmortem-support.md` + friend int GenDebugSymbols(); v8::Persistent persistent_handle_; Environment* env_; }; diff --git a/src/env.h b/src/env.h index a0b28c8724a9b0..9568b1545ba1d3 100644 --- a/src/env.h +++ b/src/env.h @@ -738,6 +738,7 @@ class Environment { // symbols for Environment, which assumes that the position of members in // memory are predictable. For more information please refer to // `doc/guides/node-postmortem-support.md` + friend int GenDebugSymbols(); HandleWrapQueue handle_wrap_queue_; ReqWrapQueue req_wrap_queue_; ListHead&); static void OnClose(uv_handle_t* handle); + // handle_wrap_queue_ needs to be at a fixed offset from the start of the // class because it is used by src/node_postmortem_metadata.cc to calculate // offsets and generate debug symbols for HandleWrap, which assumes that the // position of members in memory are predictable. For more information please // refer to `doc/guides/node-postmortem-support.md` + friend int GenDebugSymbols(); ListNode handle_wrap_queue_; enum { kInitialized, kClosing, kClosingWithCallback, kClosed } state_; uv_handle_t* const handle_; diff --git a/src/node_postmortem_metadata.cc b/src/node_postmortem_metadata.cc index d90ceb04600d26..5d7a8c88ecb2c7 100644 --- a/src/node_postmortem_metadata.cc +++ b/src/node_postmortem_metadata.cc @@ -1,57 +1,3 @@ -// Need to import standard headers before redefining private, otherwise it -// won't compile. -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace node { -// Forward declaration needed before redefining private. -int GenDebugSymbols(); -} // namespace node - - -#define private friend int GenDebugSymbols(); private - #include "env.h" #include "base-object-inl.h" #include "handle_wrap.h" diff --git a/src/req-wrap.h b/src/req-wrap.h index 05bc558570abf1..ddd0840aad2ab6 100644 --- a/src/req-wrap.h +++ b/src/req-wrap.h @@ -22,6 +22,7 @@ class ReqWrap : public AsyncWrap { private: friend class Environment; + friend int GenDebugSymbols(); ListNode req_wrap_queue_; protected: diff --git a/src/util.h b/src/util.h index 1272de1893294c..0ca3d8ea0efb4b 100644 --- a/src/util.h +++ b/src/util.h @@ -159,6 +159,7 @@ class ListNode { private: template (U::*M)> friend class ListHead; + friend int GenDebugSymbols(); ListNode* prev_; ListNode* next_; DISALLOW_COPY_AND_ASSIGN(ListNode); @@ -190,6 +191,7 @@ class ListHead { inline Iterator end() const; private: + friend int GenDebugSymbols(); ListNode head_; DISALLOW_COPY_AND_ASSIGN(ListHead); };