Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

Commit

Permalink
Refactoring code of 2.1.3 #1 (#15262)
Browse files Browse the repository at this point in the history
Refactoring code of 2.1.3 towards 2.1.4 #1
  • Loading branch information
pixiuPL authored Jan 15, 2018
1 parent 6250e77 commit 970edb9
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 71 deletions.
24 changes: 7 additions & 17 deletions deploy/brandelf.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@
*/

#include <sys/cdefs.h>
//NOTE: commented out to make it compile on linux
// __FBSDID("$FreeBSD: src/usr.bin/brandelf/brandelf.c,v 1.25.22.2 2012/03/16 03:22:37 eadler Exp $");

#include <sys/types.h>
//NOTE: changed path to make it compile on linux
#include <elf.h>
#include <sys/errno.h>
#include <err.h>
Expand All @@ -51,18 +47,16 @@ struct ELFtypes {
const char *str;
int value;
};
/* XXX - any more types? */

static struct ELFtypes elftypes[] = {
{ "FreeBSD", ELFOSABI_FREEBSD },
{ "Linux", ELFOSABI_LINUX },
{ "Solaris", ELFOSABI_SOLARIS },
{ "SVR4", ELFOSABI_SYSV }
};

int
main(int argc, char **argv)
int main(int argc, char **argv)
{

const char *strtype = "FreeBSD";
int type = ELFOSABI_FREEBSD;
int retval = 0;
Expand All @@ -86,7 +80,7 @@ main(int argc, char **argv)
listed = 1;
break;
case 'v':
/* does nothing */
/* do nothing */
break;
case 't':
if (force)
Expand Down Expand Up @@ -163,16 +157,14 @@ main(int argc, char **argv)
return retval;
}

static void
usage(void)
static void usage(void)
{
(void)fprintf(stderr,
"usage: brandelf [-lv] [-f ELF_ABI_number] [-t string] file ...\n");
exit(1);
}

static const char *
iselftype(int etype)
static const char * iselftype(int etype)
{
size_t elfwalk;

Expand All @@ -184,8 +176,7 @@ iselftype(int etype)
return 0;
}

static int
elftype(const char *elfstrtype)
static int elftype(const char *elfstrtype)
{
size_t elfwalk;

Expand All @@ -197,8 +188,7 @@ elftype(const char *elfstrtype)
return -1;
}

static void
printelftypes(void)
static void printelftypes(void)
{
size_t elfwalk;

Expand Down
3 changes: 1 addition & 2 deletions src/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Copyright (C) 2011 James Roe <[email protected]>
Copyright (C) 2011 execjosh, http://execjosh.blogspot.com
Copyright (C) 2012 James M. Greene <[email protected]>
Copyright (c) 2018 pixiuPL
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -94,7 +95,6 @@ phantom.defaultErrorHandler = function (message, stack) {
};

phantom.onError = phantom.defaultErrorHandler;

phantom.callback = function (callback) {
var ret = phantom.createCallback();
ret.called.connect(function (args) {
Expand Down Expand Up @@ -310,7 +310,6 @@ phantom.callback = function (callback) {
}
cache[filename] = module;
module._load();

return module.exports;
};

Expand Down
3 changes: 2 additions & 1 deletion src/callback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@
*/

#include <QDebug>

#include "callback.h"

Callback::Callback(QObject* parent)
: QObject(parent)
{
// No action here?
// TODO Implement some type of action
}

QVariant Callback::call(const QVariantList& arguments)
Expand Down
3 changes: 0 additions & 3 deletions src/callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,11 @@
class Callback : public QObject
{
Q_OBJECT

Q_PROPERTY(QVariant returnValue READ returnValue WRITE setReturnValue)

public:
Callback(QObject* parent);

QVariant call(const QVariantList& arguments);

QVariant returnValue() const;
void setReturnValue(const QVariant& returnValue);

Expand Down
18 changes: 3 additions & 15 deletions src/childprocess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@
// ChildProcessContext
//

ChildProcessContext::ChildProcessContext(QObject* parent)
: QObject(parent)
, m_proc(this)
ChildProcessContext::ChildProcessContext(QObject* parent) : QObject(parent), m_proc(this)
{
connect(&m_proc, SIGNAL(readyReadStandardOutput()), this, SLOT(_readyReadStandardOutput()));
connect(&m_proc, SIGNAL(readyReadStandardError()), this, SLOT(_readyReadStandardError()));
Expand All @@ -44,23 +42,17 @@ ChildProcessContext::ChildProcessContext(QObject* parent)
}

ChildProcessContext::~ChildProcessContext() = default;

// public:

qint64 ChildProcessContext::pid() const
{
Q_PID pid = m_proc.pid();

#if !defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
return pid;
#else
// TODO Investigate...
return pid->dwProcessId;
#endif
}

void ChildProcessContext::kill(const QString& signal)
{
// TODO: it would be nice to be able to handle more signals
if ("SIGKILL" == signal) {
m_proc.kill();
} else {
Expand All @@ -80,8 +72,7 @@ void ChildProcessContext::_setEncoding(const QString& encoding)
bool ChildProcessContext::_start(const QString& cmd, const QStringList& args)
{
m_proc.start(cmd, args);
// TODO: Is there a better way to do this???
return m_proc.waitForStarted(1000);
return m_proc.waitForStarted(1000);
}

qint64 ChildProcessContext::_write(const QString &chunk, const QString &encoding)
Expand All @@ -100,7 +91,6 @@ qint64 ChildProcessContext::_write(const QString &chunk, const QString &encoding
}

qint64 bytesWritten = m_proc.write(codec->fromUnicode(chunk));

return bytesWritten;
}

Expand All @@ -126,14 +116,12 @@ void ChildProcessContext::_readyReadStandardError()
void ChildProcessContext::_finished(const int exitCode, const QProcess::ExitStatus exitStatus)
{
Q_UNUSED(exitStatus)

emit exit(exitCode);
}

void ChildProcessContext::_error(const QProcess::ProcessError error)
{
Q_UNUSED(error)

emit exit(m_proc.exitCode());
}

Expand Down
10 changes: 2 additions & 8 deletions src/childprocess.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,25 @@

#include <QObject>
#include <QProcess>

#ifdef Q_OS_WIN
#include <QtCore/qt_windows.h>
#endif

#include "encoding.h"

/**
* This class wraps a QProcess and facilitates emulation of node.js's ChildProcess
*/
class ChildProcessContext : public QObject
{
Q_OBJECT
Q_PROPERTY(qint64 pid READ pid)
Q_OBJECT;
Q_PROPERTY(qint64 pid READ pid);

public:
explicit ChildProcessContext(QObject* parent = Q_NULLPTR);
virtual ~ChildProcessContext();

qint64 pid() const;
Q_INVOKABLE void kill(const QString& signal = "SIGTERM");

Q_INVOKABLE void _setEncoding(const QString& encoding);
Q_INVOKABLE bool _start(const QString& cmd, const QStringList& args);

Q_INVOKABLE qint64 _write(const QString &chunk, const QString &encoding);
Q_INVOKABLE void _close();

Expand Down
28 changes: 5 additions & 23 deletions src/crashdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,20 @@
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>

#include <QtGlobal>

#if defined(Q_OS_WIN)
#include <windows.h>
#else
#include <sys/resource.h>
#include <string.h>
#endif

#include "crashdump.h"

void
print_crash_message()
void print_crash_message()
{
fputs("PhantomJS has crashed. Please read the bug reporting guide at\n"
"<http://phantomjs.org/bug-reporting.html> and file a bug report.\n",
stderr);
fflush(stderr);
}

#if defined(Q_OS_WIN)

static LONG WINAPI unhandled_exception_filter(LPEXCEPTION_POINTERS ptrs)
{
fprintf(stderr, "Fatal Windows exception, code 0x%08x.\n",
Expand All @@ -63,13 +54,7 @@ static LONG WINAPI unhandled_exception_filter(LPEXCEPTION_POINTERS ptrs)
return EXCEPTION_EXECUTE_HANDLER;
}

#if _MSC_VER >= 1400
static void
invalid_parameter_handler(const wchar_t* expression,
const wchar_t* function,
const wchar_t* file,
unsigned int line,
uintptr_t /*reserved*/)
static void invalid_parameter_handler(const wchar_t* expression, const wchar_t* function, const wchar_t* file, unsigned int line, uintptr_t )
{
// The parameters all have the value NULL unless a debug version of the CRT library is used
// https://msdn.microsoft.com/en-us/library/a9yf33zb(v=VS.80).aspx
Expand Down Expand Up @@ -135,17 +120,15 @@ init_crash_handler_os()

#else // not Windows; Unix assumed

static void
handle_fatal_signal(int signo)
static void handle_fatal_signal(int signo)
{
// It would be nice to print the offending signal name here, but
// strsignal() isn't reliably available. Instead we let the shell do it.
print_crash_message();
raise(signo);
}

static void
init_crash_handler_os()
static void init_crash_handler_os()
{
const char* offender;

Expand Down Expand Up @@ -196,8 +179,7 @@ init_crash_handler_os()

#endif // not Windows

void
init_crash_handler()
void init_crash_handler()
{
// Qt, QtWebkit, and PhantomJS mostly don't make use of C++ exceptions,
// so in the rare cases where an exception does get thrown, it will
Expand Down
3 changes: 1 addition & 2 deletions src/crashdump.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef CRASHDUMP_H

This comment has been minimized.

Copy link
@annulen

annulen Jan 24, 2018

Dude, do you even know what "include guard" is?

#define CRASHDUMP_H

extern void print_crash_message();
extern void init_crash_handler();

#endif // CRASHDUMP_H

0 comments on commit 970edb9

Please sign in to comment.