Skip to content

Commit a0f98a4

Browse files
authored
Merge pull request #2684 from AllenInstitute/feature/2684-prepend-module-name-functions
PrependModuleNameIfStatic_TS: Add it and use it
2 parents 5ea9cfd + 8a94b2f commit a0f98a4

File tree

3 files changed

+98
-6
lines changed

3 files changed

+98
-6
lines changed

Packages/MIES/MIES_Debugging.ipf

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,16 @@ static Function FindFirstOutsideCaller(string &func, string &line, string &file)
2222

2323
for(i = numCallers - 2; i >= 0; i -= 1)
2424
caller = StringFromList(i, stacktrace)
25-
func = StringFromList(0, caller, ",")
26-
file = StringFromList(1, caller, ",")
27-
line = StringFromList(2, caller, ",")
25+
26+
file = StringFromList(1, caller, ",")
2827

2928
if(cmpstr("MIES_DEBUGGING.ipf", file))
29+
30+
func = StringFromList(0, caller, ",")
31+
line = StringFromList(2, caller, ",")
32+
33+
func = PrependModuleNameIfStatic_TS(func, file)
34+
3035
return NaN
3136
endif
3237
endfor

Packages/MIES/MIES_Utilities_ProgramFlow.ipf

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,41 @@ Function DoAbortNow(string msg)
8383
Abort
8484
End
8585

86+
#if IgorVersion() < 10
87+
88+
/// @brief Prepend the regular module name (if available) for static functions to the function name
89+
///
90+
/// Due to this feature being IP10 only we always return just the function name.
91+
threadsafe Function/S PrependModuleNameIfStatic_TS(string func, string procWin)
92+
93+
return func
94+
End
95+
96+
#else
97+
98+
/// @brief Prepend the regular module name (if available) for static functions to the function name
99+
threadsafe Function/S PrependModuleNameIfStatic_TS(string func, string procWin)
100+
101+
string info, module
102+
103+
info = FunctionInfo(func, procWin)
104+
105+
if(!cmpstr(StringByKey("SPECIAL", info), "static"))
106+
module = StringByKey("MODULE", info)
107+
108+
if(IsEmpty(module))
109+
// not in a regular module
110+
return func
111+
endif
112+
113+
return module + "#" + func
114+
endif
115+
116+
return func
117+
End
118+
119+
#endif
120+
86121
/// @brief Return a nicely formatted multiline stacktrace
87122
threadsafe Function/S GetStackTrace([string prefix])
88123

@@ -110,9 +145,13 @@ threadsafe Function/S GetStackTrace([string prefix])
110145

111146
for(i = 0; i < (numCallers - 2); i += 1)
112147
entry = StringFromList(i, stacktrace)
113-
func = StringFromList(0, entry, ",")
114-
file = StringFromList(1, entry, ",")
115-
line = StringFromList(2, entry, ",")
148+
149+
func = StringFromList(0, entry, ",")
150+
file = StringFromList(1, entry, ",")
151+
line = StringFromList(2, entry, ",")
152+
153+
func = PrependModuleNameIfStatic_TS(func, file)
154+
116155
sprintf str, "%s%s(...)#L%s [%s]\r", prefix, func, line, file
117156
output += str
118157
endfor

Packages/tests/Basic/UTF_Utils_ProgramFlow.ipf

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,51 @@ Function RunningInMainThread_Main()
167167
End
168168

169169
/// @}
170+
171+
/// PrependModuleNameIfStatic_TS
172+
/// @{
173+
174+
Function PMNW_Helper_IGNORE()
175+
End
176+
177+
static Function PMNW_Helper_static_IGNORE()
178+
End
179+
180+
threadsafe static Function PMNW_Helper_static_TS_IGNORE()
181+
End
182+
183+
threadsafe Function PMNW_Helper_TS_IGNORE()
184+
End
185+
186+
Function PMNWorks()
187+
188+
string module, func, funcWithMod
189+
190+
module = "UTILSTEST_PROGRAMFLOW"
191+
192+
func = "PMNW_Helper_IGNORE"
193+
funcWithMod = func
194+
CHECK_EQUAL_STR(PrependModuleNameIfStatic_TS(func, "UTF_Utils_ProgramFlow.ipf"), func)
195+
196+
func = "PMNW_Helper_TS_IGNORE"
197+
funcWithMod = func
198+
CHECK_EQUAL_STR(PrependModuleNameIfStatic_TS(func, "UTF_Utils_ProgramFlow.ipf"), funcWithMod)
199+
200+
func = "PMNW_Helper_static_IGNORE"
201+
#if IgorVersion() >= 10
202+
funcWithMod = module + "#" + func
203+
#else
204+
funcWithMod = func
205+
#endif
206+
CHECK_EQUAL_STR(PrependModuleNameIfStatic_TS(func, "UTF_Utils_ProgramFlow.ipf"), funcWithMod)
207+
208+
func = "PMNW_Helper_static_TS_IGNORE"
209+
#if IgorVersion() >= 10
210+
funcWithMod = module + "#" + func
211+
#else
212+
funcWithMod = func
213+
#endif
214+
CHECK_EQUAL_STR(PrependModuleNameIfStatic_TS(func, "UTF_Utils_ProgramFlow.ipf"), funcWithMod)
215+
End
216+
217+
/// @}

0 commit comments

Comments
 (0)