Skip to content

Commit

Permalink
Removed including standard libraries from mock sources.
Browse files Browse the repository at this point in the history
  • Loading branch information
informatimago committed Nov 16, 2023
1 parent 6820d34 commit 930a410
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
2 changes: 2 additions & 0 deletions lib/cmock_file_writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 3 additions & 6 deletions lib/cmock_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <string.h>\n"
file << "#include <stdlib.h>\n"
unless @exclude_setjmp_h
file << "#include <setjmp.h>\n"
end
file << "#include \"cmock.h\"\n"
@includes_c_pre_header.each { |inc| file << "#include #{inc}\n" }
file << "#include \"#{header_file}\"\n"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/cmock_generator_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 8 additions & 0 deletions src/cmock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
1 change: 1 addition & 0 deletions src/cmock.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

0 comments on commit 930a410

Please sign in to comment.