diff --git a/CMakeLists.txt b/CMakeLists.txt index 10dd5f17..2e2bfb9a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS 1) include_directories("include/") include_directories("vendor/") + # CMark link_directories("vendor/cmark") @@ -30,8 +31,8 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") ######################## # Add back: fsanitize=leak - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fasynchronous-unwind-tables -ggdb3 -Wall -fsanitize=leak -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer -flto=auto") - set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fsanitize=leak -fsanitize=address -fsanitize=undefined -no-pie -Wall -fno-omit-frame-pointer") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address,leak,undefined -fno-omit-frame-pointer -fasynchronous-unwind-tables -no-pie -ggdb3 -Wall -flto=auto") + set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fsanitize=address,leak,undefined -fno-omit-frame-pointer -no-pie -Wall -fno-omit-frame-pointer") ######################## # RELEASE # @@ -57,10 +58,17 @@ else () # Executable add_executable(fan ${SRC_FILES}) + # Link libasan only for debug builds +# if(CMAKE_BUILD_TYPE MATCHES Debug) +# target_link_libraries(fan PRIVATE asan) +# endif() + # Final Build target_link_libraries(fan-dev PRIVATE ${CMAKE_CXX_STANDARD_LIBRARIES} pthread ${CURL_LIBRARIES} cmark) #leveldb target_link_libraries(fan PRIVATE ${CMAKE_CXX_STANDARD_LIBRARIES} fan-dev) + + endif() # Static Lib diff --git a/src/vm/std/os.cpp b/src/vm/std/os.cpp index 9cdba183..12595a3a 100644 --- a/src/vm/std/os.cpp +++ b/src/vm/std/os.cpp @@ -25,7 +25,7 @@ void lib::os::getEnv(WrenVM* vm) { const char* key = wrenGetSlotString(vm, 1); auto val = std::getenv(key); wrenEnsureSlots(vm, 1); - if (val == NULL) { + if (val == nullptr) { wrenSetSlotNull(vm, 0); } else { wrenSetSlotString(vm, 0, val); @@ -103,7 +103,7 @@ double getParentProcessId() { return 0; // Parent process not found. #else pid_t ppid = getppid(); - double dPpid = static_cast(ppid); + auto dPpid = static_cast(ppid); return dPpid; #endif } @@ -155,7 +155,7 @@ constexpr std::string_view vm::getPlatformArchitecture() { void lib::os::runtimeOS(WrenVM* vm) { wrenEnsureSlots(vm, 1); auto os = vm::getOperatingSystem(); - if (os != "uknown") { + if (os != "unknown") { wrenSetSlotString(vm, 0, os.data()); } else { wrenSetSlotNull(vm, 0); @@ -183,7 +183,7 @@ void lib::os::processExec(WrenVM* vm) { for (int i = 0; i < argsLen; i++) { wrenGetListElement(vm, 2, i, 4); auto arg = wrenGetSlotString(vm, 4); - args.push_back(arg); + args.emplace_back(arg); } std::string parsedArgs = boost::algorithm::join(args, " "); diff --git a/tests/std/exec.fan b/tests/std/exec.fan new file mode 100644 index 00000000..e658b1f9 --- /dev/null +++ b/tests/std/exec.fan @@ -0,0 +1,5 @@ +import "std/os" for Process + +var out = Process.exec("eval", ["echo", "-n", "hi, there", "|", "sha256sum"]) + +System.print(out) \ No newline at end of file diff --git a/valgrind.sh b/valgrind.sh index d81d2271..1159b1a9 100755 --- a/valgrind.sh +++ b/valgrind.sh @@ -3,16 +3,18 @@ # Check for the existence of the fan executable in different directories if [[ -x "./build/debug/fan" ]]; then FAN_EXEC="./build/debug/fan" -elif [[ -x "./build/release/fan" ]]; then - FAN_EXEC="./build/release/fan" +#elif [[ -x "./build/release/fan" ]]; then +# FAN_EXEC="./build/release/fan" else FAN_EXEC="./build/fan" fi +export LD_PRELOAD="/usr/lib/x86_64-linux-gnu/libasan.so.6:$LD_PRELOAD" + FAN_LIB=./lang valgrind --leak-check=full \ --show-leak-kinds=all \ --track-origins=yes \ --verbose \ --leak-check=full \ --log-file=build/valgrind-out.txt \ - $(FAN_EXEC) $@ + $FAN_EXEC $@