Skip to content

Commit 19c762e

Browse files
committed
Removed including standard libraries from mock sources.
1 parent ed29ce3 commit 19c762e

5 files changed

+15
-7
lines changed

lib/cmock_file_writer.rb

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ def create_file(filename, subdir)
2222

2323
full_file_name_temp = "#{@config.mock_path}/#{subdir + '/' if subdir}#{filename}.new"
2424
full_file_name_done = "#{@config.mock_path}/#{subdir + '/' if subdir}#{filename}"
25+
$stderr.puts "Creating #{full_file_name_done.inspect}" unless (@config.verbosity < 2)
26+
2527
File.open(full_file_name_temp, 'w') do |file|
2628
yield(file, filename)
2729
end

lib/cmock_generator.rb

+3-6
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ def create_using_statement(file, function)
100100
def create_mock_header_file(mock_project)
101101
if @include_inline == :include
102102
@file_writer.create_file(mock_project[:module_name] + (mock_project[:module_ext]), mock_project[:folder]) do |file, _filename|
103+
file << "/* Source File: #{mock_project[:source]} */\n"
104+
file << "/* Normalized source (without inlines). */\n"
103105
file << mock_project[:parsed_stuff][:normalized_source]
104106
end
105107
end
@@ -209,11 +211,6 @@ def create_mock_header_footer(header)
209211
def create_source_header_section(file, filename, mock_project)
210212
header_file = (mock_project[:folder] || '') + filename.gsub('.c', mock_project[:module_ext])
211213
file << "/* AUTOGENERATED FILE. DO NOT EDIT. */\n" unless mock_project[:parsed_stuff][:functions].empty?
212-
file << "#include <string.h>\n"
213-
file << "#include <stdlib.h>\n"
214-
unless @exclude_setjmp_h
215-
file << "#include <setjmp.h>\n"
216-
end
217214
file << "#include \"cmock.h\"\n"
218215
@includes_c_pre_header.each { |inc| file << "#include #{inc}\n" }
219216
file << "#include \"#{header_file}\"\n"
@@ -283,7 +280,7 @@ def create_mock_init_function(file, mock_project)
283280
def create_mock_destroy_function(file, mock_project)
284281
file << "void #{mock_project[:clean_name]}_Destroy(void)\n{\n"
285282
file << " CMock_Guts_MemFreeAll();\n"
286-
file << " memset(&Mock, 0, sizeof(Mock));\n"
283+
file << " CMock_memset(&Mock, 0, sizeof(Mock));\n"
287284
file << mock_project[:parsed_stuff][:functions].collect { |function| @plugins.run(:mock_destroy, function) }.join
288285

289286
unless @fail_on_unexpected_calls

lib/cmock_generator_utils.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def code_add_base_expectation(func_name, global_ordering_supported = true)
5151
lines = " CMOCK_MEM_INDEX_TYPE cmock_guts_index = CMock_Guts_MemNew(sizeof(CMOCK_#{func_name}_CALL_INSTANCE));\n"
5252
lines << " CMOCK_#{func_name}_CALL_INSTANCE* cmock_call_instance = (CMOCK_#{func_name}_CALL_INSTANCE*)CMock_Guts_GetAddressFor(cmock_guts_index);\n"
5353
lines << " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringOutOfMemory);\n"
54-
lines << " memset(cmock_call_instance, 0, sizeof(*cmock_call_instance));\n"
54+
lines << " CMock_memset(cmock_call_instance, 0, sizeof(*cmock_call_instance));\n"
5555
lines << " Mock.#{func_name}_CallInstance = CMock_Guts_MemChain(Mock.#{func_name}_CallInstance, cmock_guts_index);\n"
5656
lines << " Mock.#{func_name}_IgnoreBool = (char)0;\n" if @ignore || @ignore_stateless
5757
lines << " cmock_call_instance->LineNumber = cmock_line;\n"

src/cmock.c

+8
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,11 @@ void CMock_Guts_MemFreeFinal(void)
229229
#endif
230230
}
231231

232+
void CMock_memset(void* ptr, int value, size_t num)
233+
{
234+
size_t i;
235+
for (i = 0; i < num; i++)
236+
{
237+
((char*)ptr)[i] = (char)value;
238+
}
239+
}

src/cmock.h

+1
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,6 @@ CMOCK_MEM_INDEX_TYPE CMock_Guts_MemBytesFree(void) CMOCK_FUNCTION_ATTR(pure);
4343
CMOCK_MEM_INDEX_TYPE CMock_Guts_MemBytesUsed(void) CMOCK_FUNCTION_ATTR(pure);
4444
void CMock_Guts_MemFreeAll(void);
4545
void CMock_Guts_MemFreeFinal(void);
46+
void CMock_memset(void* ptr, int value, size_t num);
4647

4748
#endif /* end of CMOCK_FRAMEWORK_H */

0 commit comments

Comments
 (0)