+
+
+/* handle the exit code of a module function call.
+ * (used internally in do_action())
+ * @param h - script handle (h->last_retcode and h->run_flags will be set).
+ * @param ret - module function (v0 or v2) retcode
+ * Side-effects: sets _last_returned_code
+ */
+#define MODF_HANDLE_RETCODE(h, ret) \
+ do { \
+ /* if (unlikely((ret)==0)) (h)->run_flags|=EXIT_R_F; */ \
+ (h)->run_flags |= EXIT_R_F & (((ret) != 0) -1); \
+ (h)->last_retcode=(ret); \
+ _last_returned_code = (h)->last_retcode; \
+ } while(0)
+
+
+
+/* frees parameters converted using MODF_RVE_PARAM_CONVERT() from dst.
+ * (used internally in do_action())
+ * Assumes src is unchanged.
+ * Side-effects: clobbers i (int).
+ */
+#define MODF_RVE_PARAM_FREE(src, dst) \
+ for (i=0; i < (dst)[1].u.number; i++) { \
+ if ((src)[i+2].type == RVE_ST && (dst)[i+2].u.string) { \
+ pkg_free((dst)[i+2].u.string); \
+ (dst)[i+2].u.string = 0; \
+ } \
+ }
+
+
+/* fills dst from src, converting RVE_ST params to STRING_ST.
+ * (used internally in do_action())
+ * @param src - source action_u_t array, as in the action structure
+ * @param dst - destination action_u_t array, will be filled from src.
+ * WARNING: dst must be cleaned when done, use MODULE_RVE_PARAM_FREE()
+ * Side-effects: clobbers i (int), s (str), rv (rvalue*), might jump to error.
+ */
+#define MODF_RVE_PARAM_CONVERT(h, msg, src, dst) \
+ do { \
+ (dst)[1]=(src)[1]; \
+ for (i=0; i < (src)[1].u.number; i++) { \
+ if ((src)[2+i].type == RVE_ST) { \
+ rv=rval_expr_eval((h), (msg), (src)[i+2].u.data); \
+ if (unlikely(rv == 0 || \
+ rval_get_str((h), (msg), &s, rv, 0) < 0)) { \
+ rval_destroy(rv); \
+ ERR("failed to convert RVE to string\n"); \
+ (dst)[1].u.number = i; \
+ MODF_RVE_PARAM_FREE(src, dst); \
+ goto error; \
+ } \
+ (dst)[i+2].type = STRING_ST; \
+ (dst)[i+2].u.string = s.s; \
+ (dst)[i+2].u.str.len = s.len; \
+ rval_destroy(rv); \
+ } else \
+ (dst)[i+2]=(src)[i+2]; \
+ } \
+ } while(0)
+
+
+
+/* call a module function with normal STRING_ST params.
+ * (used internally in do_action())
+ * @param f_type - cmd_function type
+ * @param h
+ * @param msg
+ * @param src - source action_u_t array (e.g. action->val)
+ * @param params... - variable list of parameters, passed to the module
+ * function
+ * Side-effects: sets ret, clobbers i (int), s (str), rv (rvalue*), f,
+ * might jump to error.
+ *
+ */
+#ifdef __SUNPRO_C
+#define MODF_CALL(f_type, h, msg, src, ...) \
+ do { \
+ f=((union cmd_export_u*)(src)[0].u.data)->c.function; \
+ ret=((f_type)f)((msg), __VAR_ARGS__); \
+ MODF_HANDLE_RETCODE(h, ret); \
+ } while (0)
+#else /* ! __SUNPRO_C (gcc, icc a.s.o) */
+#define MODF_CALL(f_type, h, msg, src, params...) \
+ do { \
+ f=((union cmd_export_u*)(src)[0].u.data)->c.function; \
+ ret=((f_type)f)((msg), ## params ); \
+ MODF_HANDLE_RETCODE(h, ret); \
+ } while (0)
+#endif /* __SUNPRO_C */
+
+
+
+/* call a module function with possible RVE params.
+ * (used internally in do_action())
+ * @param f_type - cmd_function type
+ * @param h
+ * @param msg
+ * @param src - source action_u_t array (e.g. action->val)
+ * @param dst - temporary action_u_t array used for conversions. It can be
+ * used for the function parameters. It's contents it's not
+ * valid after the call.
+ * @param params... - variable list of parameters, passed to the module
+ * function
+ * Side-effects: sets ret, clobbers i (int), s (str), rv (rvalue*), f, dst,
+ * might jump to error.
+ *
+ */
+#ifdef __SUNPRO_C
+#define MODF_RVE_CALL(f_type, h, msg, src, dst, ...) \
+ do { \
+ f=((union cmd_export_u*)(src)[0].u.data)->c.function; \
+ MODF_RVE_PARAM_CONVERT(h, msg, src, dst); \
+ ret=((f_type)f)((msg), __VAR_ARGS__); \
+ MODF_HANDLE_RETCODE(h, ret); \
+ /* free strings allocated by us */ \
+ MODF_RVE_PARAM_FREE(src, dst); \
+ } while (0)
+#else /* ! __SUNPRO_C (gcc, icc a.s.o) */
+#define MODF_RVE_CALL(f_type, h, msg, src, dst, params...) \
+ do { \
+ f=((union cmd_export_u*)(src)[0].u.data)->c.function; \
+ MODF_RVE_PARAM_CONVERT(h, msg, src, dst); \
+ ret=((f_type)f)((msg), ## params ); \
+ MODF_HANDLE_RETCODE(h, ret); \
+ /* free strings allocated by us */ \
+ MODF_RVE_PARAM_FREE(src, dst); \
+ } while (0)
+#endif /* __SUNPRO_C */
+
+