[libvirt] [PATCHv2 0/2] Fix docs for virBitmapParse

Split out from the other series. Peter Krempa (2): util: Fix docs for virBitmapParse conf: Fix usage of virBitmapParse src/conf/network_conf.c | 2 +- src/util/virbitmap.c | 23 +++++++++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) -- 1.8.1.1

This patch changes the name of the @sep argument to @terminator and clarifies it's usage. This patch also explicitly documents that whitespace can't be used as @terminator as it is skipped multiple times in the implementation. --- src/util/virbitmap.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c index ca82d1b..2cfe03a 100644 --- a/src/util/virbitmap.c +++ b/src/util/virbitmap.c @@ -265,6 +265,7 @@ char *virBitmapFormat(virBitmapPtr bitmap) /** * virBitmapParse: * @str: points to a string representing a human-readable bitmap + * @terminator: character separating the bitmap to parse * @bitmap: a bitmap created from @str * @bitmapSize: the upper limit of num of bits in created bitmap * @@ -275,13 +276,19 @@ char *virBitmapFormat(virBitmapPtr bitmap) * to set, and ^N, which means to unset the bit, and N-M for ranges of bits * to set. * + * To allow parsing of bitmaps within larger strings it is possible to set + * a termination character in the argument @terminator. When the character + * in @terminator is encountered in @str, the parsing of the bitmap stops. + * Pass 0 as @terminator if it is not needed. Whitespace characters may not + * be used as terminators. + * * Returns the number of bits set in @bitmap, or -1 in case of error. */ - -int virBitmapParse(const char *str, - char sep, - virBitmapPtr *bitmap, - size_t bitmapSize) +int +virBitmapParse(const char *str, + char terminator, + virBitmapPtr *bitmap, + size_t bitmapSize) { int ret = 0; bool neg = false; @@ -302,7 +309,7 @@ int virBitmapParse(const char *str, if (!*bitmap) return -1; - while (*cur != 0 && *cur != sep) { + while (*cur != 0 && *cur != terminator) { /* * 3 constructs are allowed: * - N : a single CPU number @@ -326,7 +333,7 @@ int virBitmapParse(const char *str, virSkipSpaces(&cur); - if (*cur == ',' || *cur == 0 || *cur == sep) { + if (*cur == ',' || *cur == 0 || *cur == terminator) { if (neg) { if (virBitmapIsSet(*bitmap, start)) { ignore_value(virBitmapClearBit(*bitmap, start)); @@ -366,7 +373,7 @@ int virBitmapParse(const char *str, cur++; virSkipSpaces(&cur); neg = false; - } else if (*cur == 0 || *cur == sep) { + } else if (*cur == 0 || *cur == terminator) { break; } else { goto parse_error; -- 1.8.1.1

On 01/23/2013 07:47 AM, Peter Krempa wrote:
This patch changes the name of the @sep argument to @terminator and clarifies it's usage. This patch also explicitly documents that whitespace can't be used as @terminator as it is skipped multiple times in the implementation. --- src/util/virbitmap.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-)
ACK. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

virNetworkObjUpdateParseFile used ',' as the termination character for virBitmapParse. This would break if an incontiguous range would be parsed. --- src/conf/network_conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 9c35ea8..c93916d 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -1856,7 +1856,7 @@ virNetworkObjUpdateParseFile(const char *filename, ctxt->node = node; class_id = virXPathString("string(./class_id[1]/@bitmap)", ctxt); if (class_id && - virBitmapParse(class_id, ',', + virBitmapParse(class_id, 0, &net->class_id, CLASS_ID_BITMAP_SIZE) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Malformed 'class_id' attribute: %s"), -- 1.8.1.1

On 01/23/2013 07:47 AM, Peter Krempa wrote:
virNetworkObjUpdateParseFile used ',' as the termination character for virBitmapParse. This would break if an incontiguous range would be
s/incontiguous/non-contiguous/
parsed. --- src/conf/network_conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
ACK.
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 9c35ea8..c93916d 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -1856,7 +1856,7 @@ virNetworkObjUpdateParseFile(const char *filename, ctxt->node = node; class_id = virXPathString("string(./class_id[1]/@bitmap)", ctxt); if (class_id && - virBitmapParse(class_id, ',', + virBitmapParse(class_id, 0, &net->class_id, CLASS_ID_BITMAP_SIZE) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Malformed 'class_id' attribute: %s"),
-- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On 01/23/13 16:04, Eric Blake wrote:
On 01/23/2013 07:47 AM, Peter Krempa wrote:
virNetworkObjUpdateParseFile used ',' as the termination character for virBitmapParse. This would break if an incontiguous range would be
s/incontiguous/non-contiguous/
parsed. --- src/conf/network_conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
ACK.
I fixed the commit msg and pushed the series. Thanks. Peter
participants (2)
-
Eric Blake
-
Peter Krempa