[dpdk-dev,v3,1/4] cfgfile: remove EAL dependency

Message ID 1498559210-104084-2-git-send-email-jacekx.piasecki@intel.com (mailing list archive)
State Superseded, archived
Headers

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/checkpatch success coding style OK

Commit Message

Jacek Piasecki June 27, 2017, 10:26 a.m. UTC
  This patch removes the dependency to EAL in cfgfile library.

Signed-off-by: Jacek Piasecki <jacekx.piasecki@intel.com>
---
 lib/librte_cfgfile/Makefile      |  1 +
 lib/librte_cfgfile/rte_cfgfile.c | 29 +++++++++++++++++------------
 2 files changed, 18 insertions(+), 12 deletions(-)
  

Comments

Bruce Richardson June 30, 2017, 9:44 a.m. UTC | #1
On Tue, Jun 27, 2017 at 12:26:47PM +0200, Jacek Piasecki wrote:
> This patch removes the dependency to EAL in cfgfile library.
> 
> Signed-off-by: Jacek Piasecki <jacekx.piasecki@intel.com>
> ---
>  lib/librte_cfgfile/Makefile      |  1 +
>  lib/librte_cfgfile/rte_cfgfile.c | 29 +++++++++++++++++------------
>  2 files changed, 18 insertions(+), 12 deletions(-)
> 
> diff --git a/lib/librte_cfgfile/Makefile b/lib/librte_cfgfile/Makefile
> index 755ef11..0bee43e 100644
> --- a/lib/librte_cfgfile/Makefile
> +++ b/lib/librte_cfgfile/Makefile
> @@ -38,6 +38,7 @@ LIB = librte_cfgfile.a
>  
>  CFLAGS += -O3
>  CFLAGS += $(WERROR_FLAGS)
> +CFLAGS += -I$(SRCDIR)/../librte_eal/common/include
>  
>  EXPORT_MAP := rte_cfgfile_version.map
>  
> diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c
> index b54a523..c6ae3e3 100644
> --- a/lib/librte_cfgfile/rte_cfgfile.c
> +++ b/lib/librte_cfgfile/rte_cfgfile.c
> @@ -36,7 +36,6 @@
>  #include <string.h>
>  #include <ctype.h>
>  #include <rte_common.h>
> -#include <rte_string_fns.h>
>  
>  #include "rte_cfgfile.h"
>  
> @@ -258,19 +257,25 @@ rte_cfgfile_load_with_params(const char *filename, int flags,
>  
>  			struct rte_cfgfile_section *sect =
>  				cfg->sections[curr_section];
> -			int n;
> +
>  			char *split[2] = {NULL};
> -			n = rte_strsplit(buffer, sizeof(buffer), split, 2, '=');
> -			if (flags & CFG_FLAG_EMPTY_VALUES) {
> -				if ((n < 1) || (n > 2)) {
> -					printf("Error at line %d - cannot split string, n=%d\n",
> -					       lineno, n);
> -					goto error1;
> -				}
> +			split[0] = buffer;
> +			split[1] = memchr(buffer, '=', len);
> +
> +			/* when delimeter not found */
> +			if (split[1] == NULL) {
> +				printf("Error at line %d - cannot "
> +					"split string\n", lineno);
> +				goto error1;

This check for NULL is not needed, as earlier in the function we find
the following:

	if (buffer[0] != '[' && memchr(buffer, '=', len) == NULL)
		continue;

which means that there must be an "=" in buffer by the time we get to this
line.

>  			} else {

FYI, you don't need an else after a goto. Save indentation where we can!
:-)

/Bruce
  
Bruce Richardson June 30, 2017, 11:16 a.m. UTC | #2
On Fri, Jun 30, 2017 at 10:44:34AM +0100, Bruce Richardson wrote:
> On Tue, Jun 27, 2017 at 12:26:47PM +0200, Jacek Piasecki wrote:
> > This patch removes the dependency to EAL in cfgfile library.
> > 
> > Signed-off-by: Jacek Piasecki <jacekx.piasecki@intel.com>
> > ---
> >  lib/librte_cfgfile/Makefile      |  1 +
> >  lib/librte_cfgfile/rte_cfgfile.c | 29 +++++++++++++++++------------
> >  2 files changed, 18 insertions(+), 12 deletions(-)
> > 
> > diff --git a/lib/librte_cfgfile/Makefile b/lib/librte_cfgfile/Makefile
> > index 755ef11..0bee43e 100644
> > --- a/lib/librte_cfgfile/Makefile
> > +++ b/lib/librte_cfgfile/Makefile
> > @@ -38,6 +38,7 @@ LIB = librte_cfgfile.a
> >  
> >  CFLAGS += -O3
> >  CFLAGS += $(WERROR_FLAGS)
> > +CFLAGS += -I$(SRCDIR)/../librte_eal/common/include
> >  
> >  EXPORT_MAP := rte_cfgfile_version.map
> >  
> > diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c
> > index b54a523..c6ae3e3 100644
> > --- a/lib/librte_cfgfile/rte_cfgfile.c
> > +++ b/lib/librte_cfgfile/rte_cfgfile.c
> > @@ -36,7 +36,6 @@
> >  #include <string.h>
> >  #include <ctype.h>
> >  #include <rte_common.h>
> > -#include <rte_string_fns.h>
> >  
> >  #include "rte_cfgfile.h"
> >  
> > @@ -258,19 +257,25 @@ rte_cfgfile_load_with_params(const char *filename, int flags,
> >  
> >  			struct rte_cfgfile_section *sect =
> >  				cfg->sections[curr_section];
> > -			int n;
> > +
> >  			char *split[2] = {NULL};
> > -			n = rte_strsplit(buffer, sizeof(buffer), split, 2, '=');
> > -			if (flags & CFG_FLAG_EMPTY_VALUES) {
> > -				if ((n < 1) || (n > 2)) {
> > -					printf("Error at line %d - cannot split string, n=%d\n",
> > -					       lineno, n);
> > -					goto error1;
> > -				}
> > +			split[0] = buffer;
> > +			split[1] = memchr(buffer, '=', len);
> > +
> > +			/* when delimeter not found */
> > +			if (split[1] == NULL) {
> > +				printf("Error at line %d - cannot "
> > +					"split string\n", lineno);
> > +				goto error1;
> 
> This check for NULL is not needed, as earlier in the function we find
> the following:
> 
> 	if (buffer[0] != '[' && memchr(buffer, '=', len) == NULL)
> 		continue;
> 
> which means that there must be an "=" in buffer by the time we get to this
> line.
> 
> >  			} else {
> 
> FYI, you don't need an else after a goto. Save indentation where we can!
> :-)
> 
I see now that a later patch removes this unneeded "if", but it might be
better to move the removal back to this patch instead.

/Bruce
  

Patch

diff --git a/lib/librte_cfgfile/Makefile b/lib/librte_cfgfile/Makefile
index 755ef11..0bee43e 100644
--- a/lib/librte_cfgfile/Makefile
+++ b/lib/librte_cfgfile/Makefile
@@ -38,6 +38,7 @@  LIB = librte_cfgfile.a
 
 CFLAGS += -O3
 CFLAGS += $(WERROR_FLAGS)
+CFLAGS += -I$(SRCDIR)/../librte_eal/common/include
 
 EXPORT_MAP := rte_cfgfile_version.map
 
diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c
index b54a523..c6ae3e3 100644
--- a/lib/librte_cfgfile/rte_cfgfile.c
+++ b/lib/librte_cfgfile/rte_cfgfile.c
@@ -36,7 +36,6 @@ 
 #include <string.h>
 #include <ctype.h>
 #include <rte_common.h>
-#include <rte_string_fns.h>
 
 #include "rte_cfgfile.h"
 
@@ -258,19 +257,25 @@  rte_cfgfile_load_with_params(const char *filename, int flags,
 
 			struct rte_cfgfile_section *sect =
 				cfg->sections[curr_section];
-			int n;
+
 			char *split[2] = {NULL};
-			n = rte_strsplit(buffer, sizeof(buffer), split, 2, '=');
-			if (flags & CFG_FLAG_EMPTY_VALUES) {
-				if ((n < 1) || (n > 2)) {
-					printf("Error at line %d - cannot split string, n=%d\n",
-					       lineno, n);
-					goto error1;
-				}
+			split[0] = buffer;
+			split[1] = memchr(buffer, '=', len);
+
+			/* when delimeter not found */
+			if (split[1] == NULL) {
+				printf("Error at line %d - cannot "
+					"split string\n", lineno);
+				goto error1;
 			} else {
-				if (n != 2) {
-					printf("Error at line %d - cannot split string, n=%d\n",
-					       lineno, n);
+				/* when delimeter found */
+				*split[1] = '\0';
+				split[1]++;
+
+				if (!(flags & CFG_FLAG_EMPTY_VALUES) &&
+						(*split[1] == '\0')) {
+					printf("Error at line %d - cannot "
+						"split string\n", lineno);
 					goto error1;
 				}
 			}