introduce visitor for parsing suffixed integer
cover introduce visitor for parsing suffixed integer
Igor Mammedov (2):
qapi: add visitor for parsing int[KMGT] input string
target-i386: use visit_type_unit_suffixed_int() to parse tsc_freq
property value
qapi/qapi-dealloc-visitor.c | 7 +++++++ qapi/qapi-visit-core.c | 13 +++++++++++++ qapi/qapi-visit-core.h | 8 ++++++++ qapi/string-input-visitor.c | 22 ++++++++++++++++++++++ target-i386/cpu.c | 2 +- 5 files changed, 51 insertions(+), 1 deletion(-)
Signature · 1 line
1.7.11.7
PATCH 1/2 qapi: add visitor for parsing int[KMGT] input string
Caller of visit_type_unit_suffixed_int() will have to specify value of 'K' suffix via unit argument.
For Kbytes it's 1024, for Khz it's 1000.
---
v2:
- convert type_freq to type_unit_suffixed_int.
- provide qapi_dealloc_type_unit_suffixed_int() impl.
--- qapi/qapi-dealloc-visitor.c | 7 +++++++ qapi/qapi-visit-core.c | 13 +++++++++++++ qapi/qapi-visit-core.h | 8 ++++++++ qapi/string-input-visitor.c | 22 ++++++++++++++++++++++ 4 files changed, 50 insertions(+)
qapi/qapi-dealloc-visitor.c +7 -0
@@ -143,6 +143,12 @@ static void qapi_dealloc_type_enum(Visitor *v, int *obj, const char *strings[], { } +static void qapi_dealloc_type_unit_suffixed_int (Visitor *v,int64_t *obj, +const char *name, +const int unit,Error **errp) +{ +} +Visitor *qapi_dealloc_get_visitor (QapiDeallocVisitor *v) {return &v->visitor;
@@ -170,6 +176,7 @@ QapiDeallocVisitor *qapi_dealloc_visitor_new(void) v->visitor.type_str = qapi_dealloc_type_str; v->visitor.type_number = qapi_dealloc_type_number; v->visitor.type_size = qapi_dealloc_type_size; + v->visitor.type_unit_suffixed_int = qapi_dealloc_type_unit_suffixed_int;QTAILQ_INIT (&v->stack);
qapi/qapi-visit-core.c +13 -0
@@ -311,3 +311,16 @@ void input_type_enum(Visitor *v, int *obj, const char *strings[],g_free (enum_str); *obj = value; } + +void visit_type_unit_suffixed_int (Visitor *v,int64_t *obj,const char *name, +const int unit,Error **errp) +{ +if (!error_is_set (errp)) { +return ; + } +if (v->type_unit_suffixed_int) { + v->type_unit_suffixed_int (v, obj, name, unit, errp); + }else { +visit_type_int64 (v, obj, name, errp); + } +}
qapi/qapi-visit-core.h +8 -0
@@ -62,6 +62,12 @@ struct Visitorvoid (*type_int64)(Visitor *v,int64_t *obj,const char *name,Error **errp);/* visit_type_size() falls back to (*type_uint64)() if type_size is unset */ void (*type_size)(Visitor *v,uint64_t *obj,const char *name,Error **errp); +/* +* visit_unit_suffixed_int() falls back to (*type_int64)() +* if type_unit_suffixed_int is unset +*/ +void (*type_unit_suffixed_int)(Visitor *v,int64_t *obj,const char *name, +const int unit,Error **errp); }; void visit_start_handle(Visitor *v, void **obj, const char *kind,
@@ -91,5 +97,7 @@ void visit_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp);void visit_type_bool (Visitor *v,bool *obj,const char *name,Error **errp);void visit_type_str (Visitor *v,char **obj,const char *name,Error **errp);void visit_type_number (Visitor *v,double *obj,const char *name,Error **errp); +void visit_type_unit_suffixed_int (Visitor *v,int64_t *obj,const char *name, +const int unit,Error **errp);#endif
qapi/string-input-visitor.c +22 -0
@@ -110,6 +110,27 @@ static void parse_start_optional(Visitor *v, bool *present, *present = true; } +static void parse_type_unit_suffixed_int (Visitor *v,int64_t *obj, +const char *name,const int unit, +Error **errp) +{ +StringInputVisitor *siv =DO_UPCAST (StringInputVisitor, visitor, v); +char *endp = (char *) siv->string; +long long val =0 ; + +if (siv->string) { + val =strtosz_suffix_unit (siv->string, &endp, +STRTOSZ_DEFSUFFIX_B , unit); + } +if (!siv->string || val ==-1 || *endp) { +error_set (errp,QERR_INVALID_PARAMETER_VALUE , name, +"a value representable as a non-negative int64" ); +return ; + } + + *obj = val; +} +Visitor *string_input_get_visitor (StringInputVisitor *v) {return &v->visitor;
@@ -132,6 +153,7 @@ StringInputVisitor *string_input_visitor_new(const char *str) v->visitor.type_str = parse_type_str; v->visitor.type_number = parse_type_number; v->visitor.start_optional = parse_start_optional; + v->visitor.type_unit_suffixed_int = parse_type_unit_suffixed_int; v->string = str;return v;
Signature · 1 line
1.7.11.7
Re: [Qemu-devel] [PATCH 1/2] qapi: add visitor for parsing int[KMGT] input string
Quoted 5 lines · Igor Mammedov
Caller of
visit_type_unit_suffixed_int()will have to specify value of 'K' suffix via unit argument.
For Kbytes it's 1024, for Khz it's 1000.Signed-off-by Igor Mammedov <[email protected]>
Quoted 125 lines
---
v2:
- converttype_freqtotype_unit_suffixed_int.
- provideqapi_dealloc_type_unit_suffixed_int()impl.--- qapi/qapi-dealloc-visitor.c | 7 +++++++ qapi/qapi-visit-core.c | 13 +++++++++++++ qapi/qapi-visit-core.h | 8 ++++++++ qapi/string-input-visitor.c | 22 ++++++++++++++++++++++ 4 files changed, 50 insertions(+)qapi/qapi-dealloc-visitor.c +7
-0@@ -143,6 +143,12 @@ static void qapi_dealloc_type_enum(Visitor *v, int *obj, const char *strings[], { } +static void qapi_dealloc_type_unit_suffixed_int (Visitor *v,int64_t *obj, +const char *name, +const int unit,Error **errp) +{ +} +Visitor *qapi_dealloc_get_visitor (QapiDeallocVisitor *v) {return &v->visitor;@@ -170,6 +176,7 @@ QapiDeallocVisitor *qapi_dealloc_visitor_new(void) v->visitor.type_str = qapi_dealloc_type_str; v->visitor.type_number = qapi_dealloc_type_number; v->visitor.type_size = qapi_dealloc_type_size; + v->visitor.type_unit_suffixed_int = qapi_dealloc_type_unit_suffixed_int;QTAILQ_INIT (&v->stack);qapi/qapi-visit-core.c +13
-0@@ -311,3 +311,16 @@ void input_type_enum(Visitor *v, int *obj, const char *strings[],g_free (enum_str); *obj = value; } + +void visit_type_unit_suffixed_int (Visitor *v,int64_t *obj,const char *name, +const int unit,Error **errp) +{ +if (!error_is_set (errp)) { +return ; + } +if (v->type_unit_suffixed_int) { + v->type_unit_suffixed_int (v, obj, name, unit, errp); + }else { +visit_type_int64 (v, obj, name, errp); + } +}qapi/qapi-visit-core.h +8
-0@@ -62,6 +62,12 @@ struct Visitorvoid (*type_int64)(Visitor *v,int64_t *obj,const char *name,Error **errp);/* visit_type_size() falls back to (*type_uint64)() if type_size is unset */ void (*type_size)(Visitor *v,uint64_t *obj,const char *name,Error **errp); +/* +* visit_unit_suffixed_int() falls back to (*type_int64)() +* if type_unit_suffixed_int is unset +*/ +void (*type_unit_suffixed_int)(Visitor *v,int64_t *obj,const char *name, +const int unit,Error **errp); }; void visit_start_handle(Visitor *v, void **obj, const char *kind,@@ -91,5 +97,7 @@ void visit_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp);void visit_type_bool (Visitor *v,bool *obj,const char *name,Error **errp);void visit_type_str (Visitor *v,char **obj,const char *name,Error **errp);void visit_type_number (Visitor *v,double *obj,const char *name,Error **errp); +void visit_type_unit_suffixed_int (Visitor *v,int64_t *obj,const char *name, +const int unit,Error **errp);#endif qapi/string-input-visitor.c +22
-0@@ -110,6 +110,27 @@ static void parse_start_optional(Visitor *v, bool *present, *present = true; } +static void parse_type_unit_suffixed_int (Visitor *v,int64_t *obj, +const char *name,const int unit, +Error **errp) +{ +StringInputVisitor *siv =DO_UPCAST (StringInputVisitor, visitor, v); +char *endp = (char *) siv->string; +long long val =0 ; + +if (siv->string) { + val =strtosz_suffix_unit (siv->string, &endp, +STRTOSZ_DEFSUFFIX_B , unit); + } +if (!siv->string || val ==-1 || *endp) { +error_set (errp,QERR_INVALID_PARAMETER_VALUE , name, +"a value representable as a non-negative int64" ); +return ; + } + + *obj = val; +} +Visitor *string_input_get_visitor (StringInputVisitor *v) {return &v->visitor;@@ -132,6 +153,7 @@ StringInputVisitor *string_input_visitor_new(const char *str) v->visitor.type_str = parse_type_str; v->visitor.type_number = parse_type_number; v->visitor.start_optional = parse_start_optional; + v->visitor.type_unit_suffixed_int = parse_type_unit_suffixed_int; v->string = str;return v;Signature · 1 line
1.7.11.7
Re: [Qemu-devel] [PATCH 1/2] qapi: add visitor for parsing int[KMGT] input string
In reply to Igor MammedovQuoted 97 lines · Igor Mammedov
Caller of
visit_type_unit_suffixed_int()will have to specify value of 'K' suffix via unit argument.
For Kbytes it's 1024, for Khz it's 1000.Signed-off-by Igor Mammedov <[email protected]>---
v2:
- converttype_freqtotype_unit_suffixed_int.
- provideqapi_dealloc_type_unit_suffixed_int()impl.--- qapi/qapi-dealloc-visitor.c | 7 +++++++ qapi/qapi-visit-core.c | 13 +++++++++++++ qapi/qapi-visit-core.h | 8 ++++++++ qapi/string-input-visitor.c | 22 ++++++++++++++++++++++ 4 files changed, 50 insertions(+)qapi/qapi-dealloc-visitor.c +7
-0@@ -143,6 +143,12 @@ static void qapi_dealloc_type_enum(Visitor *v, int *obj, const char *strings[], { } +static void qapi_dealloc_type_unit_suffixed_int (Visitor *v,int64_t *obj, +const char *name, +const int unit,Error **errp) +{ +} +Visitor *qapi_dealloc_get_visitor (QapiDeallocVisitor *v) {return &v->visitor;@@ -170,6 +176,7 @@ QapiDeallocVisitor *qapi_dealloc_visitor_new(void) v->visitor.type_str = qapi_dealloc_type_str; v->visitor.type_number = qapi_dealloc_type_number; v->visitor.type_size = qapi_dealloc_type_size; + v->visitor.type_unit_suffixed_int = qapi_dealloc_type_unit_suffixed_int;QTAILQ_INIT (&v->stack);qapi/qapi-visit-core.c +13
-0@@ -311,3 +311,16 @@ void input_type_enum(Visitor *v, int *obj, const char *strings[],g_free (enum_str); *obj = value; } + +void visit_type_unit_suffixed_int (Visitor *v,int64_t *obj,const char *name, +const int unit,Error **errp) +{ +if (!error_is_set (errp)) { +return ; + } +if (v->type_unit_suffixed_int) { + v->type_unit_suffixed_int (v, obj, name, unit, errp); + }else { +visit_type_int64 (v, obj, name, errp); + } +}qapi/qapi-visit-core.h +8
-0@@ -62,6 +62,12 @@ struct Visitorvoid (*type_int64)(Visitor *v,int64_t *obj,const char *name,Error **errp);/* visit_type_size() falls back to (*type_uint64)() if type_size is unset */ void (*type_size)(Visitor *v,uint64_t *obj,const char *name,Error **errp); +/* +* visit_unit_suffixed_int() falls back to (*type_int64)() +* if type_unit_suffixed_int is unset +*/ +void (*type_unit_suffixed_int)(Visitor *v,int64_t *obj,const char *name, +const int unit,Error **errp); }; void visit_start_handle(Visitor *v, void **obj, const char *kind,@@ -91,5 +97,7 @@ void visit_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp);void visit_type_bool (Visitor *v,bool *obj,const char *name,Error **errp);void visit_type_str (Visitor *v,char **obj,const char *name,Error **errp);void visit_type_number (Visitor *v,double *obj,const char *name,Error **errp); +void visit_type_unit_suffixed_int (Visitor *v,int64_t *obj,const char *name, +const int unit,Error **errp);#endif qapi/string-input-visitor.c +2
-0@@ -110,6 +110,27 @@ static void parse_start_optional(Visitor *v, bool *present, *present = true; } +static void parse_type_unit_suffixed_int(Visitor *v, int64_t *obj, + const char *name, const int unit,
qapi/string-input-visitor.c static void parse_start_optional(Visitor *v, bool *present, · line 124
Quoted 10 lines
qapi/string-input-visitor.c +10
-0+ Error **errp) +{ +StringInputVisitor *siv =DO_UPCAST (StringInputVisitor, visitor, v); +char *endp = (char *) siv->string; +long long val =0 ; + +if (siv->string) { + val =strtosz_suffix_unit (siv->string, &endp, +STRTOSZ_DEFSUFFIX_B , unit); + }
I just noticed that strtosz_suffix_unit() is not as generic as I
expected: it interprets "100B" as "100", but the value we're reading may be completely unrelated to byte counts.
It would be nice to fix this later, but the current interface/behavior doesn't seem to break anything (as the k/M/G/T cases seem to work properly), and it even matches the current frequency parsing code on target-i386/cpu.c, so:
Quoted 23 lines
qapi/string-input-visitor.c +10
-0+if (!siv->string || val ==-1 || *endp) { +error_set (errp,QERR_INVALID_PARAMETER_VALUE , name, +"a value representable as a non-negative int64" ); +return ; + } + + *obj = val; +} +Visitor *string_input_get_visitor (StringInputVisitor *v) {return &v->visitor;@@ -132,6 +153,7 @@ StringInputVisitor *string_input_visitor_new(const char *str) v->visitor.type_str = parse_type_str; v->visitor.type_number = parse_type_number; v->visitor.start_optional = parse_start_optional; + v->visitor.type_unit_suffixed_int = parse_type_unit_suffixed_int; v->string = str;return v;Signature · 1 line
1.7.11.7
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH 1/2] qapi: add visitor for parsing int[KMGT] input string
In reply to Igor MammedovAm 06.12.2012 22:12, schrieb Igor Mammedov:
Quoted 46 lines
Caller of
visit_type_unit_suffixed_int()will have to specify value of 'K' suffix via unit argument.
For Kbytes it's 1024, for Khz it's 1000.Signed-off-by Igor Mammedov <[email protected]>---
v2:
- converttype_freqtotype_unit_suffixed_int.
- provideqapi_dealloc_type_unit_suffixed_int()impl.--- qapi/qapi-dealloc-visitor.c | 7 +++++++ qapi/qapi-visit-core.c | 13 +++++++++++++ qapi/qapi-visit-core.h | 8 ++++++++ qapi/string-input-visitor.c | 22 ++++++++++++++++++++++ 4 files changed, 50 insertions(+)qapi/qapi-dealloc-visitor.c +7
-0@@ -143,6 +143,12 @@ static void qapi_dealloc_type_enum(Visitor *v, int *obj, const char *strings[], { } +static void qapi_dealloc_type_unit_suffixed_int (Visitor *v,int64_t *obj, +const char *name, +const int unit,Error **errp) +{ +} +Visitor *qapi_dealloc_get_visitor (QapiDeallocVisitor *v) {return &v->visitor;@@ -170,6 +176,7 @@ QapiDeallocVisitor *qapi_dealloc_visitor_new(void) v->visitor.type_str = qapi_dealloc_type_str; v->visitor.type_number = qapi_dealloc_type_number; v->visitor.type_size = qapi_dealloc_type_size; + v->visitor.type_unit_suffixed_int = qapi_dealloc_type_unit_suffixed_int;QTAILQ_INIT (&v->stack);qapi/qapi-visit-core.c +0
-0
qapi/qapi-visit-core.c void input_type_enum(Visitor *v, int *obj, const char *strings[], · line 318
Quoted 8 lines
qapi/qapi-visit-core.c +5
-0@@ -311,3 +311,16 @@ void input_type_enum(Visitor *v, int *obj, const char *strings[],g_free (enum_str); *obj = value; } + +void visit_type_unit_suffixed_int (Visitor *v,int64_t *obj,const char *name, +const int unit,Error **errp) +{ +if (!error_is_set (errp)) {
if (error_is_set(errp)) {
Quoted 13 lines
qapi/qapi-visit-core.c +8
-0+return ; + } +if (v->type_unit_suffixed_int) { + v->type_unit_suffixed_int (v, obj, name, unit, errp); + }else { +visit_type_int64 (v, obj, name, errp); + } +}qapi/qapi-visit-core.h +0
-0
qapi/qapi-visit-core.h struct Visitor · line 68
Quoted 7 lines
qapi/qapi-visit-core.h +4
-0@@ -62,6 +62,12 @@ struct Visitorvoid (*type_int64)(Visitor *v,int64_t *obj,const char *name,Error **errp);/* visit_type_size() falls back to (*type_uint64)() if type_size is unset */ void (*type_size)(Visitor *v,uint64_t *obj,const char *name,Error **errp); +/* +* visit_unit_suffixed_int() falls back to (*type_int64)() +* if type_unit_suffixed_int is unset +*/
Indentation is one off.
qapi/qapi-visit-core.h struct Visitor · line 70
Quoted 2 lines
qapi/qapi-visit-core.h +2
-0+void (*type_unit_suffixed_int)(Visitor *v,int64_t *obj,const char *name, +const int unit,Error **errp);
Are we expecting differently suffixed ints? Otherwise we could optionally shorten to type_suffixed_int (but that probably still doesn't fit within one comment line ;)).
Quoted 24 lines
qapi/qapi-visit-core.h +2
-0}; void visit_start_handle(Visitor *v, void **obj, const char *kind,@@ -91,5 +97,7 @@ void visit_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp);void visit_type_bool (Visitor *v,bool *obj,const char *name,Error **errp);void visit_type_str (Visitor *v,char **obj,const char *name,Error **errp);void visit_type_number (Visitor *v,double *obj,const char *name,Error **errp); +void visit_type_unit_suffixed_int (Visitor *v,int64_t *obj,const char *name, +const int unit,Error **errp);#endif qapi/string-input-visitor.c +5
-0@@ -110,6 +110,27 @@ static void parse_start_optional(Visitor *v, bool *present, *present = true; } +static void parse_type_unit_suffixed_int (Visitor *v,int64_t *obj, +const char *name,const int unit, +Error **errp) +{ +StringInputVisitor *siv =DO_UPCAST (StringInputVisitor, visitor, v);
qapi/string-input-visitor.c static void parse_start_optional(Visitor *v, bool *present, · line 127
Quoted 10 lines
qapi/string-input-visitor.c +10
-0+char *endp = (char *) siv->string; +long long val =0 ; + +if (siv->string) { + val =strtosz_suffix_unit (siv->string, &endp, +STRTOSZ_DEFSUFFIX_B , unit); + } +if (!siv->string || val ==-1 || *endp) { +error_set (errp,QERR_INVALID_PARAMETER_VALUE , name, +"a value representable as a non-negative int64" );
Weird indentation remaining, looks as if we could align with errp within 80 chars.
However, I wonder if "unit" is the (physically etc.) correct term here? Isn't the "unit" Hz / byte / ... and 1000 more of a conversion factor or something? At least that's the way I've seen unit used in the API of another project, passing an enum of Hertz, gram, meter/second, etc.
Andreas
Quoted 18 lines
qapi/string-input-visitor.c +7
-0+return ; + } + + *obj = val; +} +Visitor *string_input_get_visitor (StringInputVisitor *v) {return &v->visitor;@@ -132,6 +153,7 @@ StringInputVisitor *string_input_visitor_new(const char *str) v->visitor.type_str = parse_type_str; v->visitor.type_number = parse_type_number; v->visitor.start_optional = parse_start_optional; + v->visitor.type_unit_suffixed_int = parse_type_unit_suffixed_int; v->string = str;return v;
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Re: [Qemu-devel] [PATCH 1/2] qapi: add visitor for parsing int[KMGT] input string
On Fri, Dec 07, 2012 at 07:57:35PM +0100, Andreas Färber wrote:
[...]
Quoted 19 lines
Quoted 5 lines
qapi/string-input-visitor.c +5
-0+static void parse_type_unit_suffixed_int (Visitor *v,int64_t *obj, +const char *name,const int unit, +Error **errp) +{ +StringInputVisitor *siv =DO_UPCAST (StringInputVisitor, visitor, v);qapi/string-input-visitor.c static void parse_start_optional(Visitor *v, bool *present, · line 127
Quoted 10 lines
qapi/string-input-visitor.c +10
-0+char *endp = (char *) siv->string; +long long val =0 ; + +if (siv->string) { + val =strtosz_suffix_unit (siv->string, &endp, +STRTOSZ_DEFSUFFIX_B , unit); + } +if (!siv->string || val ==-1 || *endp) { +error_set (errp,QERR_INVALID_PARAMETER_VALUE , name, +"a value representable as a non-negative int64" );Weird indentation remaining, looks as if we could align with errp within 80 chars.
Quoted 4 lines
However, I wonder if "unit" is the (physically etc.) correct term here? Isn't the "unit" Hz / byte / ... and 1000 more of a conversion factor or something? At least that's the way I've seen unit used in the API of another project, passing an enum of Hertz, gram, meter/second, etc.
I also think that calling it "unit" is confusing. Strictly speaking, the "unit" we're dealing with is Hz (and the visitor simply don't care about unit, it only looks for "unit prefixes").
Can't we call the 1000/1024 parameter "base" or "factor", instead?
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH 1/2] qapi: add visitor for parsing int[KMGT] input string
In reply to Andreas FärberQuoted 42 lines · On Fri, 07 Dec 2012 19:57:35 +0100 Andreas Färber <[email protected]> wrote:
Am 06.12.2012 22:12, schrieb Igor Mammedov:
Quoted 41 lines
Caller of
visit_type_unit_suffixed_int()will have to specify value of 'K' suffix via unit argument.
For Kbytes it's 1024, for Khz it's 1000.Signed-off-by Igor Mammedov <[email protected]>---
v2:
- converttype_freqtotype_unit_suffixed_int.
- provideqapi_dealloc_type_unit_suffixed_int()impl.--- qapi/qapi-dealloc-visitor.c | 7 +++++++ qapi/qapi-visit-core.c | 13 +++++++++++++ qapi/qapi-visit-core.h | 8 ++++++++ qapi/string-input-visitor.c | 22 ++++++++++++++++++++++ 4 files changed, 50 insertions(+)qapi/qapi-dealloc-visitor.c +6
-0@@ -143,6 +143,12 @@ static void qapi_dealloc_type_enum(Visitor *v, int *obj, const char *strings[], { } +static void qapi_dealloc_type_unit_suffixed_int (Visitor *v,int64_t *obj, +const char *name, +const int unit,Error **errp) +{ +} +Visitor *qapi_dealloc_get_visitor (QapiDeallocVisitor *v) {return &v->visitor;@@ -170,6 +176,7 @@ QapiDeallocVisitor *qapi_dealloc_visitor_new(void) v->visitor.type_str = qapi_dealloc_type_str; v->visitor.type_number = qapi_dealloc_type_number; v->visitor.type_size = qapi_dealloc_type_size; + v->visitor.type_unit_suffixed_int = qapi_dealloc_type_unit_suffixed_int;QTAILQ_INIT (&v->stack);
Quoted 16 lines
Quoted 11 lines
qapi/qapi-visit-core.c +2
-0@@ -311,3 +311,16 @@ void input_type_enum(Visitor *v, int *obj, constchar *strings[],g_free (enum_str ); *obj = value; } + +void visit_type_unit_suffixed_int(Visitor *v, int64_t *obj, const char*name,
qapi/qapi-visit-core.c void input_type_enum(Visitor *v, int *obj, const char *strings[], · line 318
Quoted 3 lines
qapi/qapi-visit-core.c +3
-0+ const int unit, Error **errp) +{ +if (!error_is_set (errp)) {if (
error_is_set(errp)) {
Thanks, I'll fix it.
Quoted 15 lines
Quoted 15 lines
qapi/qapi-visit-core.c +8
-0+return ; + } +if (v->type_unit_suffixed_int) { + v->type_unit_suffixed_int (v, obj, name, unit, errp); + }else { +visit_type_int64 (v, obj, name, errp); + } +}qapi/qapi-visit-core.h +0
-0@@ -62,6 +62,12 @@ struct Visitorvoid (*type_int64)(Visitor *v,int64_t *obj,const char *name,Error **errp);/* visit_type_size() falls back to (*type_uint64)() if type_size
Quoted 8 lines
qapi/qapi-visit-core.h struct Visitor · line 68
Quoted 6 lines
is unset */ void (*type_size)(Visitor *v,
uint64_t*obj, const char *name, Error **errp);qapi/qapi-visit-core.h +4
-0+/* +* visit_unit_suffixed_int() falls back to (*type_int64)() +* if type_unit_suffixed_int is unset +*/ Indentation is one off.
ditto
Quoted 8 lines
Quoted 4 lines
+ void (*type_unit_suffixed_int)(Visitor *v,
int64_t*obj, const char
*name,
+ const int unit, Error **errp);Are we expecting differently suffixed ints? Otherwise we could optionally shorten to
type_suffixed_int(but that probably still doesn't fit within one comment line ;)).
Not with current implementation. I'll shorten it as you've suggested.
Quoted 32 lines
Quoted 32 lines
};
void visit_start_handle(Visitor *v, void **obj, const char *kind,
qapi/qapi-visit-core.h +0
-0@@ -91,5 +97,7 @@ void visit_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp); void visit_type_bool(Visitor *v, bool *obj,const char *name, Error **errp); void
visit_type_str(Visitor *v, char **obj, const char *name, Error **errp); voidvisit_type_number(Visitor *v, double *obj, const char *name, Error **errp); +void visit_type_unit_suffixed_int(Visitor *v,int64_t*obj, const char *name,qapi/qapi-visit-core.h +1
-0+ const int unit, Error **errp);#endif qapi/string-input-visitor.c +10
-0@@ -110,6 +110,27 @@ static void parse_start_optional(Visitor *v, bool *present, *present = true; } +static void parse_type_unit_suffixed_int (Visitor *v,int64_t *obj, +const char *name,const int unit, +Error **errp) +{ +StringInputVisitor *siv =DO_UPCAST (StringInputVisitor, visitor, v); +char *endp = (char *) siv->string; +long long val =0 ; + +if (siv->string) { + val = strtosz_suffix_unit(siv->string, &endp,
Quoted 8 lines
qapi/string-input-visitor.c static void parse_start_optional(Visitor *v, bool *present, · line 127
Quoted 5 lines
qapi/string-input-visitor.c +5
-0+ STRTOSZ_DEFSUFFIX_B, unit); + } +if (!siv->string || val ==-1 || *endp) { +error_set (errp,QERR_INVALID_PARAMETER_VALUE , name, +"a value representable as a non-negative int64" );Weird indentation remaining, looks as if we could align with errp within 80 chars.
Thanks, I'll fix it.
Quoted 5 lines
However, I wonder if "unit" is the (physically etc.) correct term here? Isn't the "unit" Hz / byte / ... and 1000 more of a conversion factor or something? At least that's the way I've seen unit used in the API of another project, passing an enum of Hertz, gram, meter/second, etc.
If we are to generalize it to integer than units might not make much sense, they could be anything. Perhaps 'suffix_factor' would be descriptive enough
+ adding documentation comment to the visitor.
Quoted 23 lines
Andreas
Quoted 18 lines
qapi/string-input-visitor.c +6
-0+return ; + } + + *obj = val; +} +Visitor *string_input_get_visitor (StringInputVisitor *v) {return &v->visitor;qapi/string-input-visitor.c +1
-0@@ -132,6 +153,7 @@ StringInputVisitor *string_input_visitor_new(const char *str) v->visitor.type_str = parse_type_str; v->visitor.type_number = parse_type_number; v->visitor.start_optional = parse_start_optional; + v->visitor.type_unit_suffixed_int = parse_type_unit_suffixed_int; v->string = str;return v;
Re: [Qemu-devel] [PATCH 1/2] qapi: add visitor for parsing int[KMGT] input string
Quoted 141 lines · Igor Mammedov
Quoted 42 lines · On Fri, 07 Dec 2012 19:57:35 +0100 Andreas Färber <[email protected]> wrote:
Am 06.12.2012 22:12, schrieb Igor Mammedov:
Quoted 41 lines
Caller of
visit_type_unit_suffixed_int()will have to specify value of 'K' suffix via unit argument.
For Kbytes it's 1024, for Khz it's 1000.Signed-off-by Igor Mammedov <[email protected]>---
v2:
- converttype_freqtotype_unit_suffixed_int.
- provideqapi_dealloc_type_unit_suffixed_int()impl.--- qapi/qapi-dealloc-visitor.c | 7 +++++++ qapi/qapi-visit-core.c | 13 +++++++++++++ qapi/qapi-visit-core.h | 8 ++++++++ qapi/string-input-visitor.c | 22 ++++++++++++++++++++++ 4 files changed, 50 insertions(+)qapi/qapi-dealloc-visitor.c +6
-0@@ -143,6 +143,12 @@ static void qapi_dealloc_type_enum(Visitor *v, int *obj, const char *strings[], { } +static void qapi_dealloc_type_unit_suffixed_int (Visitor *v,int64_t *obj, +const char *name, +const int unit,Error **errp) +{ +} +Visitor *qapi_dealloc_get_visitor (QapiDeallocVisitor *v) {return &v->visitor;@@ -170,6 +176,7 @@ QapiDeallocVisitor *qapi_dealloc_visitor_new(void) v->visitor.type_str = qapi_dealloc_type_str; v->visitor.type_number = qapi_dealloc_type_number; v->visitor.type_size = qapi_dealloc_type_size; + v->visitor.type_unit_suffixed_int = qapi_dealloc_type_unit_suffixed_int;QTAILQ_INIT (&v->stack);Quoted 16 lines
Quoted 11 lines
qapi/qapi-visit-core.c +2
-0@@ -311,3 +311,16 @@ void input_type_enum(Visitor *v, int *obj, constchar *strings[],g_free (enum_str ); *obj = value; } + +void visit_type_unit_suffixed_int(Visitor *v, int64_t *obj, const char*name,
qapi/qapi-visit-core.c void input_type_enum(Visitor *v, int *obj, const char *strings[], · line 318
Quoted 3 lines
qapi/qapi-visit-core.c +3
-0+ const int unit, Error **errp) +{ +if (!error_is_set (errp)) {if (
error_is_set(errp)) {Thanks, I'll fix it.
Quoted 15 lines
Quoted 15 lines
qapi/qapi-visit-core.c +8
-0+return ; + } +if (v->type_unit_suffixed_int) { + v->type_unit_suffixed_int (v, obj, name, unit, errp); + }else { +visit_type_int64 (v, obj, name, errp); + } +}qapi/qapi-visit-core.h +0
-0@@ -62,6 +62,12 @@ struct Visitorvoid (*type_int64)(Visitor *v,int64_t *obj,const char *name,Error **errp);/* visit_type_size() falls back to (*type_uint64)() if type_size Quoted 8 lines
qapi/qapi-visit-core.h struct Visitor · line 68
Quoted 6 lines
is unset */ void (*type_size)(Visitor *v,
uint64_t*obj, const char *name, Error **errp);qapi/qapi-visit-core.h +4
-0+/* +* visit_unit_suffixed_int() falls back to (*type_int64)() +* if type_unit_suffixed_int is unset +*/ Indentation is one off.
ditto
Quoted 8 lines
Quoted 4 lines
+ void (*type_unit_suffixed_int)(Visitor *v,
int64_t*obj, const char
*name,
+ const int unit, Error **errp);Are we expecting differently suffixed ints? Otherwise we could optionally shorten to
type_suffixed_int(but that probably still doesn't fit within one comment line ;)).Not with current implementation. I'll shorten it as you've suggested.
Quoted 32 lines
Quoted 32 lines
};
void visit_start_handle(Visitor *v, void **obj, const char *kind,
qapi/qapi-visit-core.h +0
-0@@ -91,5 +97,7 @@ void visit_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp); void visit_type_bool(Visitor *v, bool *obj,const char *name, Error **errp); void
visit_type_str(Visitor *v, char **obj, const char *name, Error **errp); voidvisit_type_number(Visitor *v, double *obj, const char *name, Error **errp); +void visit_type_unit_suffixed_int(Visitor *v,int64_t*obj, const char *name,qapi/qapi-visit-core.h +1
-0+ const int unit, Error **errp);#endif qapi/string-input-visitor.c +10
-0@@ -110,6 +110,27 @@ static void parse_start_optional(Visitor *v, bool *present, *present = true; } +static void parse_type_unit_suffixed_int (Visitor *v,int64_t *obj, +const char *name,const int unit, +Error **errp) +{ +StringInputVisitor *siv =DO_UPCAST (StringInputVisitor, visitor, v); +char *endp = (char *) siv->string; +long long val =0 ; + +if (siv->string) { + val = strtosz_suffix_unit(siv->string, &endp,Quoted 8 lines
qapi/string-input-visitor.c static void parse_start_optional(Visitor *v, bool *present, · line 127
Quoted 5 lines
qapi/string-input-visitor.c +5
-0+ STRTOSZ_DEFSUFFIX_B, unit); + } +if (!siv->string || val ==-1 || *endp) { +error_set (errp,QERR_INVALID_PARAMETER_VALUE , name, +"a value representable as a non-negative int64" );Weird indentation remaining, looks as if we could align with errp within 80 chars.
Thanks, I'll fix it.
Quoted 1 line
Quoted 7 lines
Quoted 4 lines
However, I wonder if "unit" is the (physically etc.) correct term here? Isn't the "unit" Hz / byte / ... and 1000 more of a conversion factor or something? At least that's the way I've seen unit used in the API of another project, passing an enum of Hertz, gram, meter/second, etc.
If we are to generalize it to integer than units might not make much sense, they could be anything. Perhaps '
suffix_factor' would be descriptive enough
+ adding documentation comment to the visitor.
The real distinction I think is base=2 vs. base=10, but that might cause confusion WRT to how the numberical value should be intepreted (10==2 vs. 10==10), so maybe suffix_base==2|10, or suffix_factor==1000/1024 as you suggested. I think I'd prefer the former but either works for me.
Quoted 25 lines
Quoted 24 lines
Andreas
Quoted 18 lines
qapi/string-input-visitor.c +6
-0+return ; + } + + *obj = val; +} +Visitor *string_input_get_visitor (StringInputVisitor *v) {return &v->visitor;qapi/string-input-visitor.c +1
-0@@ -132,6 +153,7 @@ StringInputVisitor *string_input_visitor_new(const char *str) v->visitor.type_str = parse_type_str; v->visitor.type_number = parse_type_number; v->visitor.start_optional = parse_start_optional; + v->visitor.type_unit_suffixed_int = parse_type_unit_suffixed_int; v->string = str;return v;
Re: [Qemu-devel] [PATCH 1/2] qapi: add visitor for parsing int[KMGT] input string
Quoted 146 lines · On Mon, 10 Dec 2012 11:27:46 -0600 mdroth <[email protected]> wrote:
Quoted 145 lines · Igor Mammedov
Quoted 42 lines · On Fri, 07 Dec 2012 19:57:35 +0100 Andreas Färber <[email protected]> wrote:
Am 06.12.2012 22:12, schrieb Igor Mammedov:
Quoted 41 lines
Caller of
visit_type_unit_suffixed_int()will have to specify value of 'K' suffix via unit argument.
For Kbytes it's 1024, for Khz it's 1000.Signed-off-by Igor Mammedov <[email protected]>---
v2:
- converttype_freqtotype_unit_suffixed_int.
- provideqapi_dealloc_type_unit_suffixed_int()impl.--- qapi/qapi-dealloc-visitor.c | 7 +++++++ qapi/qapi-visit-core.c | 13 +++++++++++++ qapi/qapi-visit-core.h | 8 ++++++++ qapi/string-input-visitor.c | 22 ++++++++++++++++++++++ 4 files changed, 50 insertions(+)qapi/qapi-dealloc-visitor.c +6
-0@@ -143,6 +143,12 @@ static void qapi_dealloc_type_enum(Visitor *v, int *obj, const char *strings[], { } +static void qapi_dealloc_type_unit_suffixed_int (Visitor *v,int64_t *obj, +const char *name, +const int unit,Error **errp) +{ +} +Visitor *qapi_dealloc_get_visitor (QapiDeallocVisitor *v) {return &v->visitor;@@ -170,6 +176,7 @@ QapiDeallocVisitor *qapi_dealloc_visitor_new(void) v->visitor.type_str = qapi_dealloc_type_str; v->visitor.type_number = qapi_dealloc_type_number; v->visitor.type_size = qapi_dealloc_type_size; + v->visitor.type_unit_suffixed_int = qapi_dealloc_type_unit_suffixed_int;QTAILQ_INIT (&v->stack);Quoted 16 lines
Quoted 11 lines
qapi/qapi-visit-core.c +2
-0@@ -311,3 +311,16 @@ void input_type_enum(Visitor *v, int *obj, constchar *strings[],g_free (enum_str ); *obj = value; } + +void visit_type_unit_suffixed_int(Visitor *v, int64_t *obj, const char*name,
qapi/qapi-visit-core.c void input_type_enum(Visitor *v, int *obj, const char *strings[], · line 318
Quoted 3 lines
qapi/qapi-visit-core.c +3
-0+ const int unit, Error **errp) +{ +if (!error_is_set (errp)) {if (
error_is_set(errp)) {Thanks, I'll fix it.
Quoted 15 lines
Quoted 15 lines
qapi/qapi-visit-core.c +8
-0+return ; + } +if (v->type_unit_suffixed_int) { + v->type_unit_suffixed_int (v, obj, name, unit, errp); + }else { +visit_type_int64 (v, obj, name, errp); + } +}qapi/qapi-visit-core.h +0
-0@@ -62,6 +62,12 @@ struct Visitorvoid (*type_int64)(Visitor *v,int64_t *obj,const char *name,Error **errp);/* visit_type_size() falls back to (*type_uint64)() if type_size Quoted 8 lines
qapi/qapi-visit-core.h struct Visitor · line 68
Quoted 6 lines
is unset */ void (*type_size)(Visitor *v,
uint64_t*obj, const char *name, Error **errp);qapi/qapi-visit-core.h +4
-0+/* +* visit_unit_suffixed_int() falls back to (*type_int64)() +* if type_unit_suffixed_int is unset +*/ Indentation is one off.
ditto
Quoted 8 lines
Quoted 4 lines
+ void (*type_unit_suffixed_int)(Visitor *v,
int64_t*obj, const char
*name,
+ const int unit, Error **errp);Are we expecting differently suffixed ints? Otherwise we could optionally shorten to
type_suffixed_int(but that probably still doesn't fit within one comment line ;)).Not with current implementation. I'll shorten it as you've suggested.
Quoted 32 lines
Quoted 32 lines
};
void visit_start_handle(Visitor *v, void **obj, const char *kind,
qapi/qapi-visit-core.h +0
-0@@ -91,5 +97,7 @@ void visit_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp); void visit_type_bool(Visitor *v, bool *obj,const char *name, Error **errp); void
visit_type_str(Visitor *v, char **obj, const char *name, Error **errp); voidvisit_type_number(Visitor *v, double *obj, const char *name, Error **errp); +void visit_type_unit_suffixed_int(Visitor *v,int64_t*obj, const char *name,qapi/qapi-visit-core.h +1
-0+ const int unit, Error **errp);#endif qapi/string-input-visitor.c +10
-0@@ -110,6 +110,27 @@ static void parse_start_optional(Visitor *v, bool *present, *present = true; } +static void parse_type_unit_suffixed_int (Visitor *v,int64_t *obj, +const char *name,const int unit, +Error **errp) +{ +StringInputVisitor *siv =DO_UPCAST (StringInputVisitor, visitor, v); +char *endp = (char *) siv->string; +long long val =0 ; + +if (siv->string) { + val = strtosz_suffix_unit(siv->string, &endp,Quoted 8 lines
qapi/string-input-visitor.c static void parse_start_optional(Visitor *v, bool *present, · line 127
Quoted 5 lines
qapi/string-input-visitor.c +5
-0+ STRTOSZ_DEFSUFFIX_B, unit); + } +if (!siv->string || val ==-1 || *endp) { +error_set (errp,QERR_INVALID_PARAMETER_VALUE , name, +"a value representable as a non-negative int64" );Weird indentation remaining, looks as if we could align with errp within 80 chars.
Thanks, I'll fix it.
Quoted 5 lines
However, I wonder if "unit" is the (physically etc.) correct term here? Isn't the "unit" Hz / byte / ... and 1000 more of a conversion factor or something? At least that's the way I've seen unit used in the API of another project, passing an enum of Hertz, gram, meter/second, etc.
Quoted 8 lines
Quoted 3 lines
If we are to generalize it to integer than units might not make much sense, they could be anything. Perhaps '
suffix_factor' would be descriptive enough
+ adding documentation comment to the visitor.The real distinction I think is base=2 vs. base=10, but that might cause confusion WRT to how the numberical value should be intepreted (10==2 vs. 10==10), so maybe suffix_base==2|10, or suffix_factor==1000/1024 as you suggested. I think I'd prefer the former but either works for me.
I'd prefer suffix_factor to avoid confusion with word 'base' which is commonly used in conversion routines (i.e. man strtoll).
Quoted 27 lines
Quoted 26 lines
Quoted 25 lines
Andreas
Quoted 18 lines
qapi/string-input-visitor.c +6
-0+return ; + } + + *obj = val; +} +Visitor *string_input_get_visitor (StringInputVisitor *v) {return &v->visitor;qapi/string-input-visitor.c +1
-0@@ -132,6 +153,7 @@ StringInputVisitor *string_input_visitor_new(const char *str) v->visitor.type_str = parse_type_str; v->visitor.type_number = parse_type_number; v->visitor.start_optional = parse_start_optional; + v->visitor.type_unit_suffixed_int = parse_type_unit_suffixed_int; v->string = str;return v;
Signature · 2 lines
Regards, Igor
PATCH 2/2 target-i386: use visit_type_unit_suffixed_int() to parse tsc_freq property value
In reply to Igor Mammedov---
v2:
- replace visit_type_freq() with visit_type_unit_suffixed_int()
in x86_cpuid_set_tsc_freq() --- target-i386/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target-i386/cpu.c +1 -1
@@ -1195,7 +1195,7 @@ static void x86_cpuid_set_tsc_freq(Object *obj, Visitor *v, void *opaque,const int64_t max =INT64_MAX ;int64_t value; -visit_type_int (v, &value, name, errp); +visit_type_unit_suffixed_int (v, &value, name,1000 , errp);if (error_is_set (errp)) {return ; }
Signature · 1 line
1.7.11.7
Re: [Qemu-devel] [PATCH 2/2] target-i386: use visit_type_unit_suffixed_int() to parse tsc_freq property value
Quoted 1 line · Igor Mammedov
Signed-off-by Igor Mammedov <[email protected]>
Quoted 24 lines
---
v2:
- replacevisit_type_freq()withvisit_type_unit_suffixed_int()in x86_cpuid_set_tsc_freq() --- target-i386/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target-i386/cpu.c +1
-1@@ -1195,7 +1195,7 @@ static void x86_cpuid_set_tsc_freq(Object *obj, Visitor *v, void *opaque,const int64_t max =INT64_MAX ;int64_t value; -visit_type_int (v, &value, name, errp); +visit_type_unit_suffixed_int (v, &value, name,1000 , errp);if (error_is_set (errp)) {return ; }Signature · 1 line
1.7.11.7
Re: [Qemu-devel] [PATCH 2/2] target-i386: use visit_type_unit_suffixed_int() to parse tsc_freq property value
In reply to Igor MammedovQuoted 5 lines · Igor Mammedov
Signed-off-by Igor Mammedov <[email protected]>---
v2:
- replacevisit_type_freq()withvisit_type_unit_suffixed_int()in x86_cpuid_set_tsc_freq()
visit_type_unit_suffixed_int() matches the behavior of the current tsc_freq parsing code on cpu_x86_parse_featurestr(), so:
Quoted 20 lines
--- target-i386/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target-i386/cpu.c +1
-1@@ -1195,7 +1195,7 @@ static void x86_cpuid_set_tsc_freq(Object *obj, Visitor *v, void *opaque,const int64_t max =INT64_MAX ;int64_t value; -visit_type_int (v, &value, name, errp); +visit_type_unit_suffixed_int (v, &value, name,1000 , errp);if (error_is_set (errp)) {return ; }Signature · 1 line
1.7.11.7
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH 2/2] target-i386: use visit_type_unit_suffixed_int() to parse tsc_freq property value
In reply to Igor MammedovAm 06.12.2012 22:12, schrieb Igor Mammedov:
Quoted 14 lines
Signed-off-by Igor Mammedov <[email protected]>---
v2:
- replacevisit_type_freq()withvisit_type_unit_suffixed_int()in x86_cpuid_set_tsc_freq() --- target-i386/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target-i386/cpu.c +0
-0
target-i386/cpu.c static void x86_cpuid_set_tsc_freq(Object *obj, Visitor *v, void *opaque, · line 1201
Quoted 8 lines
target-i386/cpu.c +1
-1@@ -1195,7 +1195,7 @@ static void x86_cpuid_set_tsc_freq(Object *obj, Visitor *v, void *opaque,const int64_t max =INT64_MAX ;int64_t value; -visit_type_int (v, &value, name, errp); +visit_type_unit_suffixed_int (v, &value, name,1000 , errp);if (error_is_set (errp)) {return ; }
This trivial usage is fine obviously. But since this series set out to make things more generic I am missing at least one use case for 1024. Does nothing like that exist in qdev-properties.c or so already?
Andreas
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Re: [Qemu-devel] [PATCH 2/2] target-i386: use visit_type_unit_suffixed_int() to parse tsc_freq property value
Quoted 18 lines · Andreas Färber
Am 06.12.2012 22:12, schrieb Igor Mammedov:
Quoted 17 lines
Signed-off-by Igor Mammedov <[email protected]>---
v2:
- replacevisit_type_freq()withvisit_type_unit_suffixed_int()in x86_cpuid_set_tsc_freq() --- target-i386/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target-i386/cpu.c +0
-0@@ -1195,7 +1195,7 @@ static void x86_cpuid_set_tsc_freq(Object *obj, Visitor *v, void *opaque,const int64_t max =INT64_MAX ;int64_t value;
Quoted 9 lines
target-i386/cpu.c static void x86_cpuid_set_tsc_freq(Object *obj, Visitor *v, void *opaque, · line 1201
Quoted 5 lines
target-i386/cpu.c +1
-1-visit_type_int (v, &value, name, errp); +visit_type_unit_suffixed_int (v, &value, name,1000 , errp);if (error_is_set (errp)) {return ; }This trivial usage is fine obviously. But since this series set out to make things more generic I am missing at least one use case for 1024. Does nothing like that exist in
qdev-properties.cor so already?
cutils.c has:
int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
{
return strtosz_suffix_unit(nptr, end, default_suffix, 1024);
}$ git grep -w strtosz_suffix [...] qapi/opts-visitor.c: val = strtosz_suffix(opt->str ? opt->str : "", &endptr, qemu-img.c: sval = strtosz_suffix(argv[optind++], &end, STRTOSZ_DEFSUFFIX_B); qemu-img.c: sval = strtosz_suffix(optarg, &end, STRTOSZ_DEFSUFFIX_B);
The opts-visitor.c match, in turn, is inside opts_type_size(), that's the ->type_size method of OptsVisitor. There are many 'size' elements inside qapi-schema.json.
I don't see any code using visit_type_size() directly, but I see two users of type 'size' on qapi-schema.json: NetdevTapOptions and NetdevDumpOptions.
I didn't know that we already had a visitor method using the suffixed-int parsing code. Should we change the visit_type_size() code to be to use use the new generic ->type_suffixed_int method and kill ->type_size?
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH 2/2] target-i386: use visit_type_unit_suffixed_int() to parse tsc_freq property value
Quoted 47 lines · On Fri, 7 Dec 2012 18:09:06 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 18 lines · Andreas Färber
Am 06.12.2012 22:12, schrieb Igor Mammedov:
Quoted 17 lines
Signed-off-by Igor Mammedov <[email protected]>---
v2:
- replacevisit_type_freq()withvisit_type_unit_suffixed_int()in x86_cpuid_set_tsc_freq() --- target-i386/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target-i386/cpu.c +0
-0@@ -1195,7 +1195,7 @@ static void x86_cpuid_set_tsc_freq(Object *obj, Visitor *v, void *opaque, const int64_t max = INT64_MAX;int64_t value;Quoted 9 lines
target-i386/cpu.c static void x86_cpuid_set_tsc_freq(Object *obj, Visitor *v, void *opaque, · line 1201
Quoted 5 lines
target-i386/cpu.c +1
-1-visit_type_int (v, &value, name, errp); +visit_type_unit_suffixed_int (v, &value, name,1000 , errp);if (error_is_set (errp)) {return ; }This trivial usage is fine obviously. But since this series set out to make things more generic I am missing at least one use case for 1024. Does nothing like that exist in
qdev-properties.cor so already?
cutils.chas:
int64_tstrtosz_suffix(const char *nptr, char **end, const chardefault_suffix) { return strtosz_suffix_unit(nptr, end, default_suffix, 1024); }$ git grep -w strtosz_suffix [...] qapi/opts-visitor.c: val = strtosz_suffix(opt->str ? opt->str : "", &endptr, qemu-img.c: sval = strtosz_suffix(argv[optind++], &end, STRTOSZ_DEFSUFFIX_B); qemu-img.c: sval = strtosz_suffix(optarg, &end, STRTOSZ_DEFSUFFIX_B);The
opts-visitor.cmatch, in turn, is insideopts_type_size(), that's the ->type_size method of OptsVisitor. There are many 'size' elements inside qapi-schema.json.
Quoted 6 lines
I don't see any code using
visit_type_size()directly, but I see two users of type 'size' on qapi-schema.json: NetdevTapOptions and NetdevDumpOptions.I didn't know that we already had a visitor method using the suffixed-int parsing code. Should we change the
visit_type_size()code to be to use use the new generic ->type_suffixed_int method and kill ->type_size?
If there isn't strong opposition to do it in incremental way, I'd prefer for these patches go in first.
And then later fix users of visit_type_size() to use type_suffixed_int() or maybe have a new type_suffixed_uint() so that size could be represented as uint64_t instead of int64_t as it's now. That would require to rewrite strtosz_* and its callers a bit.
Re: [Qemu-devel] [PATCH 2/2] target-i386: use visit_type_unit_suffixed_int() to parse tsc_freq property value
Quoted 57 lines · Igor Mammedov
Quoted 47 lines · On Fri, 7 Dec 2012 18:09:06 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 18 lines · Andreas Färber
Am 06.12.2012 22:12, schrieb Igor Mammedov:
Quoted 17 lines
Signed-off-by Igor Mammedov <[email protected]>---
v2:
- replacevisit_type_freq()withvisit_type_unit_suffixed_int()in x86_cpuid_set_tsc_freq() --- target-i386/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target-i386/cpu.c +0
-0@@ -1195,7 +1195,7 @@ static void x86_cpuid_set_tsc_freq(Object *obj, Visitor *v, void *opaque, const int64_t max = INT64_MAX;int64_t value;Quoted 9 lines
target-i386/cpu.c static void x86_cpuid_set_tsc_freq(Object *obj, Visitor *v, void *opaque, · line 1201
Quoted 5 lines
target-i386/cpu.c +1
-1-visit_type_int (v, &value, name, errp); +visit_type_unit_suffixed_int (v, &value, name,1000 , errp);if (error_is_set (errp)) {return ; }This trivial usage is fine obviously. But since this series set out to make things more generic I am missing at least one use case for 1024. Does nothing like that exist in
qdev-properties.cor so already?
cutils.chas:
int64_tstrtosz_suffix(const char *nptr, char **end, const chardefault_suffix) { return strtosz_suffix_unit(nptr, end, default_suffix, 1024); }$ git grep -w strtosz_suffix [...] qapi/opts-visitor.c: val = strtosz_suffix(opt->str ? opt->str : "", &endptr, qemu-img.c: sval = strtosz_suffix(argv[optind++], &end, STRTOSZ_DEFSUFFIX_B); qemu-img.c: sval = strtosz_suffix(optarg, &end, STRTOSZ_DEFSUFFIX_B);The
opts-visitor.cmatch, in turn, is insideopts_type_size(), that's the ->type_size method of OptsVisitor. There are many 'size' elements inside qapi-schema.json.Quoted 6 lines
I don't see any code using
visit_type_size()directly, but I see two users of type 'size' on qapi-schema.json: NetdevTapOptions and NetdevDumpOptions.I didn't know that we already had a visitor method using the suffixed-int parsing code. Should we change the
visit_type_size()code to be to use use the new generic ->type_suffixed_int method and kill ->type_size?
Quoted 7 lines
If there isn't strong opposition to do it in incremental way, I'd prefer for these patches go in first.
And then later fix users of
visit_type_size()to usetype_suffixed_int()or maybe have a newtype_suffixed_uint()so that size could be represented asuint64_tinstead ofint64_tas it's now. That would require to rewrite strtosz_* and its callers a bit.
I think that seems reasonable. Between the 2 that should give us a nice way to support [KMGx] suffixes for options in a backward-compatible way.
Shame that users don't have a well-established way to specify base 2 vs. 10, but so long as we document our choice for each option that should cover most cases well enough.
Re: [Qemu-devel] [PATCH 2/2] target-i386: use visit_type_unit_suffixed_int() to parse tsc_freq property value
In reply to Andreas FärberQuoted 18 lines · On Fri, 07 Dec 2012 20:00:09 +0100 Andreas Färber <[email protected]> wrote:
Am 06.12.2012 22:12, schrieb Igor Mammedov:
Quoted 17 lines
Signed-off-by Igor Mammedov <[email protected]>---
v2:
- replacevisit_type_freq()withvisit_type_unit_suffixed_int()in x86_cpuid_set_tsc_freq() --- target-i386/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target-i386/cpu.c +0
-0@@ -1195,7 +1195,7 @@ static void x86_cpuid_set_tsc_freq(Object *obj, Visitor *v, void *opaque,const int64_t max =INT64_MAX ;int64_t value;
Quoted 9 lines
target-i386/cpu.c static void x86_cpuid_set_tsc_freq(Object *obj, Visitor *v, void *opaque, · line 1201
Quoted 5 lines
target-i386/cpu.c +1
-1-visit_type_int (v, &value, name, errp); +visit_type_unit_suffixed_int (v, &value, name,1000 , errp);if (error_is_set (errp)) {return ; }This trivial usage is fine obviously. But since this series set out to make things more generic I am missing at least one use case for 1024. Does nothing like that exist in
qdev-properties.cor so already?
It would be nice to have qdev property for this, perhaps after cpu properties series we could introduce it and simplify target-i386/cpu.c code a bit.
Quoted 7 lines
Andreas
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Signature · 2 lines
Regards, Igor