Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: extract common macro to util.h #27512

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions src/env-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,6 @@

#include <utility>

#ifdef _WIN32
/* MAX_PATH is in characters, not bytes. Make sure we have enough headroom. */
#define CWD_BUFSIZE (MAX_PATH * 4)
#else
#include <climits> // PATH_MAX on Solaris.
#define CWD_BUFSIZE (PATH_MAX)
#endif

namespace node {

inline v8::Isolate* IsolateData::isolate() const {
Expand Down
15 changes: 3 additions & 12 deletions src/inspector_profiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "node_file.h"
#include "node_internals.h"
#include "v8-inspector.h"
#include "util.h"

namespace node {
namespace profiler {
Expand All @@ -23,16 +24,6 @@ using v8::Value;

using v8_inspector::StringView;

#ifdef _WIN32
const char* const kPathSeparator = "\\/";
/* MAX_PATH is in characters, not bytes. Make sure we have enough headroom. */
#define CWD_BUFSIZE (MAX_PATH * 4)
#else
#include <climits> // PATH_MAX on Solaris.
const char* const kPathSeparator = "/";
#define CWD_BUFSIZE (PATH_MAX)
#endif

V8ProfilerConnection::V8ProfilerConnection(Environment* env)
: session_(env->inspector_agent()->Connect(
std::make_unique<V8ProfilerConnection::V8ProfilerSessionDelegate>(
Expand Down Expand Up @@ -284,8 +275,8 @@ void EndStartedProfilers(Environment* env) {
}

std::string GetCwd() {
char cwd[CWD_BUFSIZE];
size_t size = CWD_BUFSIZE;
char cwd[PATH_MAX_BYTES];
size_t size = PATH_MAX_BYTES;
int err = uv_cwd(cwd, &size);
// This can fail if the cwd is deleted.
// TODO(joyeecheung): store this in the Environment during Environment
Expand Down
11 changes: 2 additions & 9 deletions src/node_process_methods.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,6 @@ Mutex umask_mutex;
// used in Hrtime() and Uptime() below
#define NANOS_PER_SEC 1000000000

#ifdef _WIN32
/* MAX_PATH is in characters, not bytes. Make sure we have enough headroom. */
#define CHDIR_BUFSIZE (MAX_PATH * 4)
#else
#define CHDIR_BUFSIZE (PATH_MAX)
#endif

static void Abort(const FunctionCallbackInfo<Value>& args) {
Abort();
}
Expand All @@ -81,7 +74,7 @@ static void Chdir(const FunctionCallbackInfo<Value>& args) {
if (err) {
// Also include the original working directory, since that will usually
// be helpful information when debugging a `chdir()` failure.
char buf[CHDIR_BUFSIZE];
char buf[PATH_MAX_BYTES];
size_t cwd_len = sizeof(buf);
uv_cwd(buf, &cwd_len);
return env->ThrowUVException(err, "chdir", nullptr, buf, *path);
Expand Down Expand Up @@ -119,7 +112,7 @@ static void CPUUsage(const FunctionCallbackInfo<Value>& args) {
static void Cwd(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
CHECK(env->has_run_bootstrapping_code());
char buf[CHDIR_BUFSIZE];
char buf[PATH_MAX_BYTES];
size_t cwd_len = sizeof(buf);
int err = uv_cwd(buf, &cwd_len);
if (err)
Expand Down
12 changes: 2 additions & 10 deletions src/node_report.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

#include "node_report.h"
#include "debug_utils.h"
#include "node_internals.h"
gengjiawen marked this conversation as resolved.
Show resolved Hide resolved
#include "node_metadata.h"
#include "util.h"

#ifdef _WIN32
#include <Windows.h>
Expand All @@ -17,14 +17,6 @@
#include <cwctype>
#include <fstream>
#include <iomanip>
#include <climits> // PATH_MAX

#ifdef _WIN32
/* MAX_PATH is in characters, not bytes. Make sure we have enough headroom. */
#define PATH_MAX_BYTES (MAX_PATH * 4)
#else
#define PATH_MAX_BYTES (PATH_MAX)
#endif

#ifndef _WIN32
extern char** environ;
Expand Down Expand Up @@ -110,7 +102,7 @@ std::string TriggerNodeReport(Isolate* isolate,
// Regular file. Append filename to directory path if one was specified
if (env != nullptr && options->report_directory.length() > 0) {
std::string pathname = options->report_directory;
pathname += PATHSEP;
pathname += node::kPathSeparator;
pathname += filename;
outfile.open(pathname, std::ios::out | std::ios::binary);
} else {
Expand Down
7 changes: 1 addition & 6 deletions src/node_report.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "node_buffer.h"
#include "uv.h"
#include "v8.h"
#include "util.h"

#ifndef _WIN32
#include <sys/types.h>
Expand All @@ -26,12 +27,6 @@

namespace report {

#ifdef _WIN32
#define PATHSEP "\\"
#else // UNIX, OSX
#define PATHSEP "/"
#endif
gengjiawen marked this conversation as resolved.
Show resolved Hide resolved

// Function declarations - functions in src/node_report.cc
std::string TriggerNodeReport(v8::Isolate* isolate,
node::Environment* env,
Expand Down
11 changes: 11 additions & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "v8.h"

#include <cassert>
#include <climits> // PATH_MAX
#include <csignal>
#include <cstddef>
#include <cstdio>
Expand All @@ -43,6 +44,16 @@

namespace node {

// Maybe remove kPathSeparator when cpp17 is ready
#ifdef _WIN32
constexpr char kPathSeparator = '\\';
/* MAX_PATH is in characters, not bytes. Make sure we have enough headroom. */
#define PATH_MAX_BYTES (MAX_PATH * 4)
#else
constexpr char kPathSeparator = '/';
#define PATH_MAX_BYTES (PATH_MAX)
#endif

// These should be used in our code as opposed to the native
// versions as they abstract out some platform and or
// compiler version specific functionality
Expand Down