Skip to content

Commit

Permalink
Merge pull request #3135 from grondo/no-sds
Browse files Browse the repository at this point in the history
remove the simple dynamic string (sds) code from libutil
  • Loading branch information
mergify[bot] committed Aug 12, 2020
2 parents c3cecee + 3fc7a9e commit 43c5f59
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 1,607 deletions.
1 change: 0 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ CODE_COVERAGE_IGNORE_PATTERN = \
"/usr/lib*" \
"*/bindings/python/*" \
"*/common/liblsd/*" \
"*/common/libutil/sds.*" \
"*/common/liboptparse/getopt*" \
"*/common/libtestutil/*" \
"*/common/libyuarel/*"
Expand Down
1 change: 0 additions & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ coverage:
- ".*/common/libtomlc99/.*"
- ".*/common/liboptparse/getopt*"
- ".*/bindings/python/.*.c"
- ".*/common/libutil/sds.*"
- ".*/common/libminilzo/.*"
- "/usr/include/.*"
- "/usr/lib/.*"
Expand Down
53 changes: 29 additions & 24 deletions src/cmd/cmdhelp.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,44 @@
#endif
#include <glob.h>
#include <string.h>
#include <argz.h>
#include <czmq.h>
#include <jansson.h>

#include "src/common/libutil/log.h"
#include "src/common/libutil/xzmalloc.h"
#include "src/common/libutil/sds.h"

#include "cmdhelp.h"

struct cmdhelp {
sds cmd;
sds description;
char *cmd;
char *description;
};

static struct cmdhelp *cmdhelp_create (const char *cmd, const char *desc)
{
struct cmdhelp *ch = xzmalloc (sizeof (*ch));
ch->cmd = sdsnew (cmd);
ch->description = sdsnew (desc);
if (!ch->cmd || !ch->description) {
free (ch);
return (NULL);
}
return (ch);
}

static void cmdhelp_destroy (struct cmdhelp **p)
{
if (*p) {
struct cmdhelp *ch = *p;
sdsfree (ch->cmd);
sdsfree (ch->description);
free (ch->cmd);
free (ch->description);
free (ch);
*p = NULL;
}
}

static struct cmdhelp *cmdhelp_create (const char *cmd, const char *desc)
{
struct cmdhelp *ch = calloc (1, sizeof (*ch));
if (!ch)
return NULL;
ch->cmd = strdup (cmd);
ch->description = strdup (desc);
if (!ch->cmd || !ch->description) {
cmdhelp_destroy (&ch);
return (NULL);
}
return (ch);
}

static void cmd_list_destroy (zlist_t *zl)
{
struct cmdhelp *ch;
Expand Down Expand Up @@ -226,13 +227,17 @@ static void emit_command_help_from_pattern (const char *pattern, FILE *fp)

void emit_command_help (const char *plist, FILE *fp)
{
int i, count;
sds *p;
if (!(p = sdssplitlen (plist, strlen (plist), ":", 1, &count)))
char *argz = NULL;
size_t argz_len = 0;
char *entry = NULL;

if (argz_create_sep (plist, ':', &argz, &argz_len) != 0)
return;
for (i = 0; i < count; i++)
emit_command_help_from_pattern (p[i], fp);
sdsfreesplitres (p, count);

while ((entry = argz_next (argz, argz_len, entry)))
emit_command_help_from_pattern (entry, fp);

free (argz);
}

/*
Expand Down
24 changes: 19 additions & 5 deletions src/common/liboptparse/test/optparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
* SPDX-License-Identifier: LGPL-3.0
\************************************************************/

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>

#include "src/common/libtap/tap.h"
#include "src/common/liboptparse/optparse.h"
#include "src/common/libutil/sds.h"

static void *myfatal_h = NULL;

Expand All @@ -20,22 +24,32 @@ int myfatal (void *h, int exit_code)
return (0);
}

sds usage_out = NULL;
char * usage_out = NULL;
size_t usage_len = 0;

void output_f (const char *fmt, ...)
{
va_list ap;
sds s = usage_out ? usage_out : sdsempty();
char s[4096];
int len;
va_start (ap, fmt);
usage_out = sdscatvprintf (s, fmt, ap);
if ((len = vsnprintf (s, sizeof (s), fmt, ap)) >= sizeof (s))
BAIL_OUT ("unexpected snprintf failure");
va_end (ap);
if (!(usage_out = realloc (usage_out, usage_len + len + 1)))
BAIL_OUT ("realloc failed usage_len = %d", usage_len);
usage_out[usage_len] = '\0';
strcat (usage_out, s);
usage_len += len + 1;
}

void usage_output_is (const char *expected, const char *msg)
{
ok (usage_out != NULL, "optparse_print_usage");
is (usage_out, expected, msg);
sdsfree (usage_out);
free (usage_out);
usage_out = NULL;
usage_len = 0;
}

void usage_ok (optparse_t *p, const char *expected, const char *msg)
Expand Down
3 changes: 0 additions & 3 deletions src/common/libutil/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ libutil_la_SOURCES = \
cleanup.h \
unlink_recursive.c \
unlink_recursive.h \
sds.c \
sds.h \
sdsalloc.h \
iterators.h \
macros.h \
sha1.h \
Expand Down

0 comments on commit 43c5f59

Please sign in to comment.