diff eval.h @ 11801:026edf66e3a9 libavcodec

Make ff_parse_expr() and ff_parse_and_eval_expr() return an int containing an error code. Allow these functions to convey the reason of the failure to the calling function, failure which is not always due to a parsing error but it may depend for example on a memory problem. Also fix several potential memleaks.
author stefano
date Tue, 01 Jun 2010 08:07:07 +0000
parents d7a5fc4b7aee
children 5880d90f2b99
line wrap: on
line diff
--- a/eval.h	Mon May 31 22:01:31 2010 +0000
+++ b/eval.h	Tue Jun 01 08:07:07 2010 +0000
@@ -32,6 +32,8 @@
  * Parses and evaluates an expression.
  * Note, this is significantly slower than ff_eval_expr().
  *
+ * @param res a pointer to a double where is put the result value of
+ * the expression, or NAN in case of error
  * @param s expression as a zero terminated string for example "1+2^3+5*5+sin(2/3)"
  * @param const_name NULL terminated array of zero terminated strings of constant identifers for example {"PI", "E", 0}
  * @param const_value a zero terminated array of values for the identifers from const_name
@@ -41,9 +43,10 @@
  * @param func2 NULL terminated array of function pointers for functions which take 2 arguments
  * @param opaque a pointer which will be passed to all functions from func1 and func2
  * @param log_ctx parent logging context
- * @return the value of the expression
+ * @return 0 in case of success, a negative value corresponding to an
+ * AVERROR code otherwise
  */
-double ff_parse_and_eval_expr(const char *s,
+int ff_parse_and_eval_expr(double *res, const char *s,
                               const char * const *const_name, const double *const_value,
                               const char * const *func1_name, double (* const *func1)(void *, double),
                               const char * const *func2_name, double (* const *func2)(void *, double, double),
@@ -52,6 +55,10 @@
 /**
  * Parses an expression.
  *
+ * @param expr a pointer where is put an AVExpr containing the parsed
+ * value in case of successfull parsing, or NULL otherwise.
+ * The pointed to AVExpr must be freed with ff_free_expr() by the user
+ * when it is not needed anymore.
  * @param s expression as a zero terminated string for example "1+2^3+5*5+sin(2/3)"
  * @param const_name NULL terminated array of zero terminated strings of constant identifers for example {"PI", "E", 0}
  * @param func1_name NULL terminated array of zero terminated strings of func1 identifers
@@ -59,10 +66,10 @@
  * @param func2_name NULL terminated array of zero terminated strings of func2 identifers
  * @param func2 NULL terminated array of function pointers for functions which take 2 arguments
  * @param log_ctx parent logging context
- * @return AVExpr which must be freed with ff_free_expr() by the user when it is not needed anymore
- *         NULL if anything went wrong
+ * @return 0 in case of success, a negative value corresponding to an
+ * AVERROR code otherwise
  */
-AVExpr *ff_parse_expr(const char *s,
+int ff_parse_expr(AVExpr **expr, const char *s,
                       const char * const *const_name,
                       const char * const *func1_name, double (* const *func1)(void *, double),
                       const char * const *func2_name, double (* const *func2)(void *, double, double),