parlib: Fix "can't print 'ret'" bug
Thanks to nasty macros, if you tried to do something like:
int ret = 3;
printf("Return value is %d\n", ret);
You'd get "Return value is 0". The problem was that the 'ret' variable
inside the macro would be the one printed, not the one passed in.
Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
diff --git a/user/parlib/include/parlib/stdio.h b/user/parlib/include/parlib/stdio.h
index ac5e517..4b9467f 100644
--- a/user/parlib/include/parlib/stdio.h
+++ b/user/parlib/include/parlib/stdio.h
@@ -75,35 +75,36 @@
#define vfprintf(f_stream, fmt, ...) \
({ \
- int ret; \
+ int __parlib_safe_print_ret; \
\
if (__safe_to_printf()) \
- ret = vfprintf(f_stream, fmt, __VA_ARGS__); \
+ __parlib_safe_print_ret = vfprintf(f_stream, fmt, __VA_ARGS__); \
else \
- ret = __vc_ctx_vfprintf(f_stream, fmt, __VA_ARGS__); \
- ret; \
+ __parlib_safe_print_ret = __vc_ctx_vfprintf(f_stream, fmt, \
+ __VA_ARGS__); \
+ __parlib_safe_print_ret; \
})
#define fprintf(f_stream, ...) \
({ \
- int ret; \
+ int __parlib_safe_print_ret; \
\
if (__safe_to_printf()) \
- ret = fprintf(f_stream, __VA_ARGS__); \
+ __parlib_safe_print_ret = fprintf(f_stream, __VA_ARGS__); \
else \
- ret = __vc_ctx_fprintf(f_stream, __VA_ARGS__); \
- ret; \
+ __parlib_safe_print_ret = __vc_ctx_fprintf(f_stream, __VA_ARGS__); \
+ __parlib_safe_print_ret; \
})
#define printf(...) \
({ \
- int ret; \
+ int __parlib_safe_print_ret; \
\
if (__safe_to_printf()) \
- ret = printf(__VA_ARGS__); \
+ __parlib_safe_print_ret = printf(__VA_ARGS__); \
else \
- ret = __vc_ctx_fprintf(stdout, __VA_ARGS__); \
- ret; \
+ __parlib_safe_print_ret = __vc_ctx_fprintf(stdout, __VA_ARGS__); \
+ __parlib_safe_print_ret; \
})
#define I_AM_HERE __vc_ctx_fprintf(stderr, \