Fix const pointer handling in return values

This commit is contained in:
Mark VanderVoord
2026-06-16 15:37:14 -04:00
parent 29ef16e54b
commit 3d4ddfdc4c
3 changed files with 16 additions and 8 deletions
+13 -6
View File
@@ -296,11 +296,20 @@ class CMockGenerator
file << "}\n\n"
end
def function_return_type(function)
# When const_ptr? is true, the "const" in :modifier belongs after the asterisk (e.g. "int* const"),
# not as a prefix (which would incorrectly produce "const int*").
ret = if function[:return][:const_ptr?]
"#{function[:return][:type]} const"
else
(function[:modifier].empty? ? '' : "#{function[:modifier]} ") + function[:return][:type]
end
ret + (function[:c_calling_convention] ? " #{function[:c_calling_convention]}" : '')
end
def create_mock_implementation(file, function)
# prepare return value and arguments
function_mod_and_rettype = (function[:modifier].empty? ? '' : "#{function[:modifier]} ") +
(function[:return][:type]) +
(function[:c_calling_convention] ? " #{function[:c_calling_convention]}" : '')
function_mod_and_rettype = function_return_type(function)
args_string = function[:args_string]
args_string += ", #{function[:var_arg]}" unless function[:var_arg].nil?
@@ -359,9 +368,7 @@ class CMockGenerator
def create_function_skeleton(file, function, existing)
# prepare return value and arguments
function_mod_and_rettype = (function[:modifier].empty? ? '' : "#{function[:modifier]} ") +
(function[:return][:type]) +
(function[:c_calling_convention] ? " #{function[:c_calling_convention]}" : '')
function_mod_and_rettype = function_return_type(function)
args_string = function[:args_string]
args_string += ", #{function[:var_arg]}" unless function[:var_arg].nil?
+2 -1
View File
@@ -567,9 +567,10 @@ class CMockHeaderParser
rettype = parsed[:type]
rettype = 'void' if @local_as_void.include?(rettype.strip)
retstr = parsed[:const_ptr?] ? "#{rettype} const" : rettype
decl[:return] = { :type => rettype,
:name => 'cmock_to_return',
:str => "#{rettype} cmock_to_return",
:str => "#{retstr} cmock_to_return",
:void? => (rettype == 'void'),
:ptr? => parsed[:ptr?] || false,
:const? => parsed[:const?] || false,
+1 -1
View File
@@ -1038,7 +1038,7 @@ describe CMockHeaderParser, "Verify CMockHeaderParser Module" do
:ptr? => true,
:const? => false,
:const_ptr? => true,
:str => "int* cmock_to_return",
:str => "int* const cmock_to_return",
:void? => false
},
:modifier=>"const",