Skip to content

Commit

Permalink
use <csignal>
Browse files Browse the repository at this point in the history
  • Loading branch information
archibate committed Aug 2, 2021
1 parent 43d3edf commit ee327ad
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 24 deletions.
18 changes: 14 additions & 4 deletions zeno/utils/SignalHooks.cpp
Original file line number Diff line number Diff line change
@@ -1,10 1,10 @@
#include <zeno/zeno.h>
#include <zeno/utils/zlog.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <cstdio>
#include <cstdlib>
#include <csignal>
#ifdef __linux__
#include <string.h>
#include <unistd.h>
#endif

Expand Down Expand Up @@ -32,7 32,15 @@ void trigger_gdb() {

#ifdef ZENO_FAULTHANDLER
static void signal_handler(int signo) {
#ifdef __linux__
zlog::error("recieved signal {}: {}", signo, strsignal(signo));
#else
const char *signame = "SIG-unknown";
if (signo == SIGSEGV) signame = "SIGSEGV";
if (signo == SIGFPE) signame = "SIGFPE";
if (signo == SIGILL) signame = "SIGILL";
zlog::error("recieved signal {}: {}", signo, signame);
#endif
print_traceback();
trigger_gdb();
exit(-signo);
Expand All @@ -45,7 53,9 @@ static int registerMyHandlers() {
signal(SIGSEGV, signal_handler);
signal(SIGFPE, signal_handler);
signal(SIGILL, signal_handler);
#ifdef __linux__
signal(SIGBUS, signal_handler);
#endif
return 1;
}

Expand Down
17 changes: 8 additions & 9 deletions zeno/utils/StackTraceback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 20,7 @@
#include <execinfo.h>
#include <cxxabi.h>
#endif
#ifdef _WIN64
#include <intrin.h>
#include <dbghelp.h>

#ifdef _WIN32
#include <windows.h>
// Never directly include <windows.h>. That will bring you evil max/min macros.
#if defined(min)
Expand All @@ -32,6 29,8 @@
#if defined(max)
#undef max
#endif
#include <intrin.h>
#include <dbghelp.h>

#pragma comment(lib, "dbghelp.lib")
// https://gist.github.com/rioki/85ca8295d51a5e0b7c56e5005b0ba8b4
Expand Down Expand Up @@ -91,7 90,7 @@ struct StackFrame {
};

inline std::vector<StackFrame> stack_trace() {
#if _WIN64
#if _WIN32
DWORD machine = IMAGE_FILE_MACHINE_AMD64;
#else
DWORD machine = IMAGE_FILE_MACHINE_I386;
Expand All @@ -110,7 109,7 @@ inline std::vector<StackFrame> stack_trace() {
context.ContextFlags = CONTEXT_FULL;
RtlCaptureContext(&context);

#if _WIN64
#if _WIN32
STACKFRAME frame = {};
frame.AddrPC.Offset = context.Rip;
frame.AddrPC.Mode = AddrModeFlat;
Expand All @@ -136,7 135,7 @@ inline std::vector<StackFrame> stack_trace() {
StackFrame f = {};
f.address = frame.AddrPC.Offset;

#if _WIN64
#if _WIN32
DWORD64 moduleBase = 0;
#else
DWORD moduleBase = 0;
Expand All @@ -151,7 150,7 @@ inline std::vector<StackFrame> stack_trace() {
} else {
f.module = "Unknown Module";
}
#if _WIN64
#if _WIN32
DWORD64 offset = 0;
#else
DWORD offset = 0;
Expand Down Expand Up @@ -294,7 293,7 @@ void print_traceback() {
"========================================================================"
"==================\n");
printf("\n");
#elif defined(_WIN64)
#elif defined(_WIN32)
// Windows
fmt::print(fg(fmt::color::magenta), "************************\n");
fmt::print(fg(fmt::color::magenta), "* Zeno Stack Traceback *\n");
Expand Down
25 changes: 14 additions & 11 deletions zenqt/system/dll.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 2,36 @@

from .utils import rel2abs, os_name

'''
lib_dir = rel2abs(__file__, '..', 'lib')

#'''
if os_name == 'win32':
dllpath = rel2abs(__file__, 'lib')
os.environ['PATH'] = os.pathsep dllpath
os.environ['PATH'] = os.pathsep lib_dir
ctypes.cdll.LoadLibrary('zeno.dll')
elif os_name == 'darwin':
ctypes.cdll.LoadLibrary(rel2abs(__file__, 'lib', 'libzeno.dylib'))
ctypes.cdll.LoadLibrary(os.path.join(lib_dir, 'libzeno.dylib'))
else:
ctypes.cdll.LoadLibrary(rel2abs(__file__, 'lib', 'libzeno.so'))
'''
ctypes.cdll.LoadLibrary(os.path.join(lib_dir, 'libzeno.so'))
#'''

from . import pyzeno as core

def loadAutoloads():
dir = rel2abs(__file__, 'lib')
print('loading addons from', dir)
if not os.path.isdir(dir):
print('loading addons from', lib_dir)
if not os.path.isdir(lib_dir):
return

paths = []
for name in os.listdir(dir):
path = os.path.join(dir, name)
for name in os.listdir(lib_dir):
path = os.path.join(lib_dir, name)
if os.path.islink(path):
continue
if os_name == 'win32':
if name.endswith('.dll'):
paths.append(name)
elif os_name == 'darwin':
if name.endswith('.dylib'):
paths.append(name)
else:
if 'so' in name.split(os.extsep):
paths.append(path)
Expand Down

0 comments on commit ee327ad

Please sign in to comment.