diff --git a/binarycpython/utils/grid.py b/binarycpython/utils/grid.py index 8d212b5b608ebb19c2ff949c52952b21de1311de..5a12082ba9a9a2bfeb27809aaf34f5d1e1907c75 100644 --- a/binarycpython/utils/grid.py +++ b/binarycpython/utils/grid.py @@ -677,51 +677,61 @@ class Population: """ Function/routine to set all the custom logging so that the function memory pointer is known to the grid. + + When the memory adress is loaded and """ - # C_logging_code gets priority of C_autogen_code - verbose_print( - "Creating and loading custom logging functionality", - self.grid_options["verbosity"], - 1, - ) - if self.grid_options["C_logging_code"]: - # Generate entire shared lib code around logging lines - custom_logging_code = binary_c_log_code( - self.grid_options["C_logging_code"], - verbosity=self.grid_options["verbosity"]-(_CUSTOM_LOGGING_VERBOSITY_LEVEL-1), + # Only if the values are the 'default' unset values + if (self.grid_options["custom_logging_func_memaddr"] == -1 and self.grid_options["_custom_logging_shared_library_file"] is None): + verbose_print( + "Creating and loading custom logging functionality", + self.grid_options["verbosity"], + 1, ) + # C_logging_code gets priority of C_autogen_code + if self.grid_options["C_logging_code"]: + # Generate entire shared lib code around logging lines + custom_logging_code = binary_c_log_code( + self.grid_options["C_logging_code"], + verbosity=self.grid_options["verbosity"]-(_CUSTOM_LOGGING_VERBOSITY_LEVEL-1), + ) - # Load memory address - ( - self.grid_options["custom_logging_func_memaddr"], - self.grid_options["_custom_logging_shared_library_file"], - ) = create_and_load_logging_function( - custom_logging_code, - verbosity=self.grid_options["verbosity"]-(_CUSTOM_LOGGING_VERBOSITY_LEVEL-1), - custom_tmp_dir=self.grid_options["tmp_dir"], - ) + # Load memory address + ( + self.grid_options["custom_logging_func_memaddr"], + self.grid_options["_custom_logging_shared_library_file"], + ) = create_and_load_logging_function( + custom_logging_code, + verbosity=self.grid_options["verbosity"]-(_CUSTOM_LOGGING_VERBOSITY_LEVEL-1), + custom_tmp_dir=self.grid_options["tmp_dir"], + ) - elif self.grid_options["C_auto_logging"]: - # Generate real logging code - logging_line = autogen_C_logging_code( - self.grid_options["C_auto_logging"], - verbosity=self.grid_options["verbosity"]-(_CUSTOM_LOGGING_VERBOSITY_LEVEL-1), - ) + elif self.grid_options["C_auto_logging"]: + # Generate real logging code + logging_line = autogen_C_logging_code( + self.grid_options["C_auto_logging"], + verbosity=self.grid_options["verbosity"]-(_CUSTOM_LOGGING_VERBOSITY_LEVEL-1), + ) - # Generate entire shared lib code around logging lines - custom_logging_code = binary_c_log_code( - logging_line, verbosity=self.grid_options["verbosity"]-(_CUSTOM_LOGGING_VERBOSITY_LEVEL-1) - ) + # Generate entire shared lib code around logging lines + custom_logging_code = binary_c_log_code( + logging_line, verbosity=self.grid_options["verbosity"]-(_CUSTOM_LOGGING_VERBOSITY_LEVEL-1) + ) - # Load memory address - ( - self.grid_options["custom_logging_func_memaddr"], - self.grid_options["_custom_logging_shared_library_file"], - ) = create_and_load_logging_function( - custom_logging_code, - verbosity=self.grid_options["verbosity"]-(_CUSTOM_LOGGING_VERBOSITY_LEVEL-1), - custom_tmp_dir=self.grid_options["tmp_dir"], + # Load memory address + ( + self.grid_options["custom_logging_func_memaddr"], + self.grid_options["_custom_logging_shared_library_file"], + ) = create_and_load_logging_function( + custom_logging_code, + verbosity=self.grid_options["verbosity"]-(_CUSTOM_LOGGING_VERBOSITY_LEVEL-1), + custom_tmp_dir=self.grid_options["tmp_dir"], + ) + else: + verbose_print( + "Custom logging library already loaded. Not setting them again.", + self.grid_options["verbosity"], + 1, ) ################################################### @@ -3125,10 +3135,10 @@ class Population: 1, ) - # TODO: Unset custom logging code + # TODO: Explicitly unload the library - # TODO: Unset function memory address - # print(self.grid_options["custom_logging_func_memaddr"]) + # Reset the memory adress location + self.grid_options["custom_logging_func_memaddr"] = -1 # remove shared library files if self.grid_options["_custom_logging_shared_library_file"]: @@ -3136,6 +3146,7 @@ class Population: self.grid_options["_custom_logging_shared_library_file"], self.grid_options["verbosity"], ) + self.grid_options["_custom_logging_shared_library_file"] = None if evol_type == "population": verbose_print(