From 930a41093d226616931d6b88f34ecc3c96773b33 Mon Sep 17 00:00:00 2001 From: "Pascal J. Bourguignon" Date: Thu, 10 Aug 2023 12:44:31 +0200 Subject: [PATCH] Removed including standard libraries from mock sources. --- lib/cmock_file_writer.rb | 2 ++ lib/cmock_generator.rb | 9 +++------ lib/cmock_generator_utils.rb | 2 +- src/cmock.c | 8 ++++++++ src/cmock.h | 1 + 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/cmock_file_writer.rb b/lib/cmock_file_writer.rb index f30c44b2..d7849d08 100644 --- a/lib/cmock_file_writer.rb +++ b/lib/cmock_file_writer.rb @@ -22,6 +22,8 @@ def create_file(filename, subdir) full_file_name_temp = "#{@config.mock_path}/#{subdir + '/' if subdir}#{filename}.new" full_file_name_done = "#{@config.mock_path}/#{subdir + '/' if subdir}#{filename}" + $stderr.puts "Creating #{full_file_name_done.inspect}" unless (@config.verbosity < 2) + File.open(full_file_name_temp, 'w') do |file| yield(file, filename) end diff --git a/lib/cmock_generator.rb b/lib/cmock_generator.rb index a1c2f28c..6591aa6a 100644 --- a/lib/cmock_generator.rb +++ b/lib/cmock_generator.rb @@ -129,6 +129,8 @@ def create_using_statement(file, function) def create_mock_header_file(mock_project) if @include_inline == :include @file_writer.create_file(mock_project[:module_name] + (mock_project[:module_ext]), mock_project[:folder]) do |file, _filename| + file << "/* Source File: #{mock_project[:source]} */\n" + file << "/* Normalized source (without inlines). */\n" file << mock_project[:parsed_stuff][:normalized_source] end end @@ -240,11 +242,6 @@ def create_mock_header_footer(header) def create_source_header_section(file, filename, mock_project) header_file = (mock_project[:folder] || '') + filename.gsub('.c', mock_project[:module_ext]) file << "/* AUTOGENERATED FILE. DO NOT EDIT. */\n" unless mock_project[:parsed_stuff][:functions].empty? - file << "#include \n" - file << "#include \n" - unless @exclude_setjmp_h - file << "#include \n" - end file << "#include \"cmock.h\"\n" @includes_c_pre_header.each { |inc| file << "#include #{inc}\n" } file << "#include \"#{header_file}\"\n" @@ -314,7 +311,7 @@ def create_mock_init_function(file, mock_project) def create_mock_destroy_function(file, mock_project) file << "void #{mock_project[:clean_name]}_Destroy(void)\n{\n" file << " CMock_Guts_MemFreeAll();\n" - file << " memset(&Mock, 0, sizeof(Mock));\n" + file << " CMock_memset(&Mock, 0, sizeof(Mock));\n" file << mock_project[:parsed_stuff][:functions].collect { |function| @plugins.run(:mock_destroy, function) }.join unless @fail_on_unexpected_calls diff --git a/lib/cmock_generator_utils.rb b/lib/cmock_generator_utils.rb index ecbc37e5..3d7c2378 100644 --- a/lib/cmock_generator_utils.rb +++ b/lib/cmock_generator_utils.rb @@ -51,7 +51,7 @@ def code_add_base_expectation(func_name, global_ordering_supported = true) lines = " CMOCK_MEM_INDEX_TYPE cmock_guts_index = CMock_Guts_MemNew(sizeof(CMOCK_#{func_name}_CALL_INSTANCE));\n" lines << " CMOCK_#{func_name}_CALL_INSTANCE* cmock_call_instance = (CMOCK_#{func_name}_CALL_INSTANCE*)CMock_Guts_GetAddressFor(cmock_guts_index);\n" lines << " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringOutOfMemory);\n" - lines << " memset(cmock_call_instance, 0, sizeof(*cmock_call_instance));\n" + lines << " CMock_memset(cmock_call_instance, 0, sizeof(*cmock_call_instance));\n" lines << " Mock.#{func_name}_CallInstance = CMock_Guts_MemChain(Mock.#{func_name}_CallInstance, cmock_guts_index);\n" lines << " Mock.#{func_name}_IgnoreBool = (char)0;\n" if @ignore || @ignore_stateless lines << " cmock_call_instance->LineNumber = cmock_line;\n" diff --git a/src/cmock.c b/src/cmock.c index e6a11971..b3086d26 100644 --- a/src/cmock.c +++ b/src/cmock.c @@ -229,3 +229,11 @@ void CMock_Guts_MemFreeFinal(void) #endif } +void CMock_memset(void* ptr, int value, size_t num) +{ + size_t i; + for (i = 0; i < num; i++) + { + ((char*)ptr)[i] = (char)value; + } +} diff --git a/src/cmock.h b/src/cmock.h index 45bab182..e674b457 100644 --- a/src/cmock.h +++ b/src/cmock.h @@ -43,5 +43,6 @@ CMOCK_MEM_INDEX_TYPE CMock_Guts_MemBytesFree(void) CMOCK_FUNCTION_ATTR(pure); CMOCK_MEM_INDEX_TYPE CMock_Guts_MemBytesUsed(void) CMOCK_FUNCTION_ATTR(pure); void CMock_Guts_MemFreeAll(void); void CMock_Guts_MemFreeFinal(void); +void CMock_memset(void* ptr, int value, size_t num); #endif /* end of CMOCK_FRAMEWORK_H */