Skip to content

Commit

Permalink
Solving issues with py dict.
Browse files Browse the repository at this point in the history
  • Loading branch information
viferga committed Nov 5, 2024
1 parent b948b0c commit 24dfb25
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
6 changes: 2 additions & 4 deletions cmake/CompileOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,10 @@ elseif(OPTION_BUILD_ADDRESS_SANITIZER AND (CMAKE_BUILD_TYPE STREQUAL "Debug" OR
set(TESTS_SANITIZER_ENVIRONMENT_VARIABLES
"LSAN_OPTIONS=verbosity=1:log_threads=1:print_suppressions=false:suppressions=${CMAKE_SOURCE_DIR}/source/tests/sanitizer/lsan.supp"

# Specify use_sigaltstack=0 as CoreCLR uses own alternate stack for signal handlers (https://github.com/swgillespie/coreclr/commit/bec020aa466d08e49e007d0011b0e79f8f7c7a62)
# "ASAN_OPTIONS=use_sigaltstack=0:symbolize=1:alloc_dealloc_mismatch=0:strict_string_checks=1:detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1:fast_unwind_on_malloc=0"

# Specify handle_segv=0 and detect_leaks=0 for the JVM (https://blog.gypsyengineer.com/en/security/running-java-with-addresssanitizer.html)
# "ASAN_OPTIONS=detect_leaks=0:handle_segv=0:symbolize=1:alloc_dealloc_mismatch=0:strict_string_checks=1:detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1:fast_unwind_on_malloc=0"
# "ASAN_OPTIONS=handle_segv=0:symbolize=1:alloc_dealloc_mismatch=0:strict_string_checks=1:detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1:fast_unwind_on_malloc=0"

# Specify use_sigaltstack=0 as CoreCLR uses own alternate stack for signal handlers (https://github.com/swgillespie/coreclr/commit/bec020aa466d08e49e007d0011b0e79f8f7c7a62)
"ASAN_OPTIONS=use_sigaltstack=0:symbolize=1:alloc_dealloc_mismatch=0:strict_string_checks=1:detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1:fast_unwind_on_malloc=0"
)
set(SANITIZER_COMPILE_DEFINITIONS
Expand Down
9 changes: 7 additions & 2 deletions cmake/FindNodeJS.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -559,12 +559,17 @@ if(NOT NodeJS_LIBRARY)

set(BUILD_DEBUG)
set(BUILD_DEBUG_ASAN)
set(BUILD_DEBUG_ASAN_OPTIONS)

if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
set(BUILD_DEBUG --debug)

if(OPTION_BUILD_ADDRESS_SANITIZER)
set(BUILD_DEBUG_ASAN --enable-asan)

if("${NodeJS_VERSION_MAJOR}" GREATER_EQUAL "20")
set(BUILD_DEBUG_ASAN_OPTIONS ${CMAKE_COMMAND} -E env ASAN_OPTIONS=detect_container_overflow=0)
endif()
endif()
endif()

Expand All @@ -585,12 +590,12 @@ if(NOT NodeJS_LIBRARY)
if(N GREATER 1)
execute_process(
WORKING_DIRECTORY "${NodeJS_OUTPUT_PATH}"
COMMAND make -j${N} -C ${NodeJS_OUTPUT_PATH}/out BUILDTYPE=${CMAKE_BUILD_TYPE} V=1
COMMAND ${BUILD_DEBUG_ASAN_OPTIONS} make -j${N} -C ${NodeJS_OUTPUT_PATH}/out BUILDTYPE=${CMAKE_BUILD_TYPE} V=1
)
else()
execute_process(
WORKING_DIRECTORY "${NodeJS_OUTPUT_PATH}"
COMMAND make -C ${NodeJS_OUTPUT_PATH}/out BUILDTYPE=${CMAKE_BUILD_TYPE} V=1
COMMAND ${BUILD_DEBUG_ASAN_OPTIONS} make -C ${NodeJS_OUTPUT_PATH}/out BUILDTYPE=${CMAKE_BUILD_TYPE} V=1
)
endif()
endif()
Expand Down
2 changes: 0 additions & 2 deletions source/loaders/py_loader/include/py_loader/py_loader_dict.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@

#include <py_loader/py_loader_api.h>

#include <loader/loader_impl_interface.h>

#include <Python.h>

#ifdef __cplusplus
Expand Down
8 changes: 5 additions & 3 deletions source/loaders/py_loader/source/py_loader_dict.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include <py_loader/py_loader_dict.h>
#include <py_loader/py_loader_threading.h>

#include <metacall/metacall_value.h>

#include <Python.h>

#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 13
Expand All @@ -33,7 +35,7 @@
struct py_loader_impl_dict_obj
{
PyDictObject dict;
value v;
void *v;
PyObject *parent;
};

Expand Down Expand Up @@ -130,13 +132,13 @@ int py_loader_impl_dict_init(struct py_loader_impl_dict_obj *self, PyObject *arg

void py_loader_impl_dict_dealloc(struct py_loader_impl_dict_obj *self)
{
value_type_destroy(self->v);
metacall_value_destroy(self->v);
Py_DECREF(self->parent); /* TODO: Review if this is correct or this line is unnecessary */

PyDict_Type.tp_dealloc((PyObject *)self);
}

int py_loader_impl_dict_type_init()
int py_loader_impl_dict_type_init(void)
{
/* py_loader_impl_dict_type is derived from PyDict_Type */
py_loader_impl_dict_type.tp_base = &PyDict_Type;
Expand Down

0 comments on commit 24dfb25

Please sign in to comment.