Mercurial > libavcodec.hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
11800:966aa6b53dcf | 11801:026edf66e3a9 |
---|---|
30 | 30 |
31 /** | 31 /** |
32 * Parses and evaluates an expression. | 32 * Parses and evaluates an expression. |
33 * Note, this is significantly slower than ff_eval_expr(). | 33 * Note, this is significantly slower than ff_eval_expr(). |
34 * | 34 * |
35 * @param res a pointer to a double where is put the result value of | |
36 * the expression, or NAN in case of error | |
35 * @param s expression as a zero terminated string for example "1+2^3+5*5+sin(2/3)" | 37 * @param s expression as a zero terminated string for example "1+2^3+5*5+sin(2/3)" |
36 * @param const_name NULL terminated array of zero terminated strings of constant identifers for example {"PI", "E", 0} | 38 * @param const_name NULL terminated array of zero terminated strings of constant identifers for example {"PI", "E", 0} |
37 * @param const_value a zero terminated array of values for the identifers from const_name | 39 * @param const_value a zero terminated array of values for the identifers from const_name |
38 * @param func1_name NULL terminated array of zero terminated strings of func1 identifers | 40 * @param func1_name NULL terminated array of zero terminated strings of func1 identifers |
39 * @param func1 NULL terminated array of function pointers for functions which take 1 argument | 41 * @param func1 NULL terminated array of function pointers for functions which take 1 argument |
40 * @param func2_name NULL terminated array of zero terminated strings of func2 identifers | 42 * @param func2_name NULL terminated array of zero terminated strings of func2 identifers |
41 * @param func2 NULL terminated array of function pointers for functions which take 2 arguments | 43 * @param func2 NULL terminated array of function pointers for functions which take 2 arguments |
42 * @param opaque a pointer which will be passed to all functions from func1 and func2 | 44 * @param opaque a pointer which will be passed to all functions from func1 and func2 |
43 * @param log_ctx parent logging context | 45 * @param log_ctx parent logging context |
44 * @return the value of the expression | 46 * @return 0 in case of success, a negative value corresponding to an |
47 * AVERROR code otherwise | |
45 */ | 48 */ |
46 double ff_parse_and_eval_expr(const char *s, | 49 int ff_parse_and_eval_expr(double *res, const char *s, |
47 const char * const *const_name, const double *const_value, | 50 const char * const *const_name, const double *const_value, |
48 const char * const *func1_name, double (* const *func1)(void *, double), | 51 const char * const *func1_name, double (* const *func1)(void *, double), |
49 const char * const *func2_name, double (* const *func2)(void *, double, double), | 52 const char * const *func2_name, double (* const *func2)(void *, double, double), |
50 void *opaque, int log_offset, void *log_ctx); | 53 void *opaque, int log_offset, void *log_ctx); |
51 | 54 |
52 /** | 55 /** |
53 * Parses an expression. | 56 * Parses an expression. |
54 * | 57 * |
58 * @param expr a pointer where is put an AVExpr containing the parsed | |
59 * value in case of successfull parsing, or NULL otherwise. | |
60 * The pointed to AVExpr must be freed with ff_free_expr() by the user | |
61 * when it is not needed anymore. | |
55 * @param s expression as a zero terminated string for example "1+2^3+5*5+sin(2/3)" | 62 * @param s expression as a zero terminated string for example "1+2^3+5*5+sin(2/3)" |
56 * @param const_name NULL terminated array of zero terminated strings of constant identifers for example {"PI", "E", 0} | 63 * @param const_name NULL terminated array of zero terminated strings of constant identifers for example {"PI", "E", 0} |
57 * @param func1_name NULL terminated array of zero terminated strings of func1 identifers | 64 * @param func1_name NULL terminated array of zero terminated strings of func1 identifers |
58 * @param func1 NULL terminated array of function pointers for functions which take 1 argument | 65 * @param func1 NULL terminated array of function pointers for functions which take 1 argument |
59 * @param func2_name NULL terminated array of zero terminated strings of func2 identifers | 66 * @param func2_name NULL terminated array of zero terminated strings of func2 identifers |
60 * @param func2 NULL terminated array of function pointers for functions which take 2 arguments | 67 * @param func2 NULL terminated array of function pointers for functions which take 2 arguments |
61 * @param log_ctx parent logging context | 68 * @param log_ctx parent logging context |
62 * @return AVExpr which must be freed with ff_free_expr() by the user when it is not needed anymore | 69 * @return 0 in case of success, a negative value corresponding to an |
63 * NULL if anything went wrong | 70 * AVERROR code otherwise |
64 */ | 71 */ |
65 AVExpr *ff_parse_expr(const char *s, | 72 int ff_parse_expr(AVExpr **expr, const char *s, |
66 const char * const *const_name, | 73 const char * const *const_name, |
67 const char * const *func1_name, double (* const *func1)(void *, double), | 74 const char * const *func1_name, double (* const *func1)(void *, double), |
68 const char * const *func2_name, double (* const *func2)(void *, double, double), | 75 const char * const *func2_name, double (* const *func2)(void *, double, double), |
69 int log_offset, void *log_ctx); | 76 int log_offset, void *log_ctx); |
70 | 77 |