Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
Merge pull request #4045 from kodebach/kodebach/issue4043
Browse files Browse the repository at this point in the history
Fixes for gopts and spec
  • Loading branch information
markus2330 authored Sep 17, 2021
2 parents 6c016a1 + e7f62f2 commit 90fb5be
Show file tree
Hide file tree
Showing 20 changed files with 196 additions and 71 deletions.
8 changes: 4 additions & 4 deletions doc/news/_preparation_next_release.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ The following section lists news about the [plugins](https://www.libelektra.org/
### gopts

- The `gopts` plugin now includes deeply nested options and arguments in the generated help message. _(Tobias Schubert @qwepoizt)_
- Errors from `gopts` are now correctly reported. _(Klemens Böswirth)_

### <<Plugin2>>
### spec

- <<TODO>>
- <<TODO>>
- <<TODO>>
- The `spec` plugin now runs before other `postgetstorage` plugins, so that validation can happen during `kdbGet` as well.
This is especially relevant in combination with `gopts`. _(Klemens Böswirth)_

### <<Plugin3>>

Expand Down
1 change: 1 addition & 0 deletions examples/codegen/econf/spec.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ default = 0

[format/#]
type = struct
check/type = any
default = ""
gen/struct/type = FormatConf
gen/struct/depth = 2
Expand Down
3 changes: 3 additions & 0 deletions examples/codegen/tree/spec.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@ mountpoint = codegen_tree_example.conf

[root]
type = struct_ref
check/type = any
default = ""
check/reference = recursive
check/reference/restrict = ../tree/_

[tree/_]
type = struct
check/type = any
default = ""
gen/struct/type = Tree
gen/struct/alloc = 1

[tree/_/children/#]
type = struct_ref
check/type = any
default = ""
gen/struct/array/sizefield = childCount

Expand Down
71 changes: 51 additions & 20 deletions src/libs/elektra/kdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -794,13 +794,25 @@ static int elektraGetDoUpdateWithGlobalHooks (KDB * handle, Split * split, KeySe
{
case FIRST:
keySetName (parentKey, keyName (initialParent));
elektraGlobalGet (handle, ks, parentKey, GETSTORAGE, INIT);
elektraGlobalGet (handle, ks, parentKey, GETSTORAGE, MAXONCE);
if (elektraGlobalGet (handle, ks, parentKey, GETSTORAGE, INIT) == ELEKTRA_PLUGIN_ERROR)
{
return -1;
}
if (elektraGlobalGet (handle, ks, parentKey, GETSTORAGE, MAXONCE) == ELEKTRA_PLUGIN_ERROR)
{
return -1;
}
break;
case LAST:
keySetName (parentKey, keyName (initialParent));
elektraGlobalGet (handle, ks, parentKey, PROCGETSTORAGE, INIT);
elektraGlobalGet (handle, ks, parentKey, PROCGETSTORAGE, MAXONCE);
if (elektraGlobalGet (handle, ks, parentKey, PROCGETSTORAGE, INIT) == ELEKTRA_PLUGIN_ERROR)
{
return -1;
}
if (elektraGlobalGet (handle, ks, parentKey, PROCGETSTORAGE, MAXONCE) == ELEKTRA_PLUGIN_ERROR)
{
return -1;
}
elektraGlobalError (handle, ks, parentKey, PROCGETSTORAGE, DEINIT);
break;
default:
Expand Down Expand Up @@ -1262,11 +1274,16 @@ int kdbGet (KDB * handle, KeySet * ks, Key * parentKey)
elektraCacheLoad (handle, cache, parentKey, initialParent, cacheParent); // parentkey different from initialParent
}

int hasProcGetStorage = handle->globalPlugins[PROCGETSTORAGE][INIT] || handle->globalPlugins[PROCGETSTORAGE][MAXONCE] ||
handle->globalPlugins[PROCGETSTORAGE][DEINIT];

// Check if a update is needed at all
switch (elektraGetCheckUpdateNeeded (split, parentKey))
{
case -2: // We have a cache hit
if (elektraCacheLoadSplit (handle, split, ks, &cache, &cacheParent, parentKey, initialParent, debugGlobalPositions) != 0)
// TODO: cache breaks procgetstorage
if (hasProcGetStorage ||
elektraCacheLoadSplit (handle, split, ks, &cache, &cacheParent, parentKey, initialParent, debugGlobalPositions) != 0)
{
goto cachemiss;
}
Expand Down Expand Up @@ -1371,8 +1388,7 @@ int kdbGet (KDB * handle, KeySet * ks, Key * parentKey)
}

if (handle->globalPlugins[POSTGETSTORAGE][FOREACH] || handle->globalPlugins[POSTGETCLEANUP][FOREACH] ||
handle->globalPlugins[PROCGETSTORAGE][FOREACH] || handle->globalPlugins[PROCGETSTORAGE][INIT] ||
handle->globalPlugins[PROCGETSTORAGE][MAXONCE] || handle->globalPlugins[PROCGETSTORAGE][DEINIT])
handle->globalPlugins[PROCGETSTORAGE][FOREACH] || hasProcGetStorage)
{
clearError (parentKey);
if (elektraGetDoUpdateWithGlobalHooks (handle, split, ks, parentKey, initialParent, FIRST) == -1)
Expand All @@ -1394,6 +1410,19 @@ int kdbGet (KDB * handle, KeySet * ks, Key * parentKey)
ksClear (ks);
splitMergeBackends (split, ks);

if (elektraGlobalGet (handle, ks, parentKey, POSTGETSTORAGE, INIT) == ELEKTRA_PLUGIN_STATUS_ERROR)
{
goto error;
}
if (elektraGlobalGet (handle, ks, parentKey, POSTGETSTORAGE, MAXONCE) == ELEKTRA_PLUGIN_STATUS_ERROR)
{
goto error;
}
if (elektraGlobalGet (handle, ks, parentKey, POSTGETSTORAGE, DEINIT) == ELEKTRA_PLUGIN_STATUS_ERROR)
{
goto error;
}

clearError (parentKey);
if (elektraGetDoUpdateWithGlobalHooks (handle, split, ks, parentKey, initialParent, LAST) == -1)
{
Expand Down Expand Up @@ -1429,23 +1458,25 @@ int kdbGet (KDB * handle, KeySet * ks, Key * parentKey)

ksClear (ks);
splitMergeBackends (split, ks);
}

keySetName (parentKey, keyName (initialParent));
keySetName (parentKey, keyName (initialParent));

if (elektraGlobalGet (handle, ks, parentKey, POSTGETSTORAGE, INIT) == ELEKTRA_PLUGIN_STATUS_ERROR)
{
goto error;
}
if (elektraGlobalGet (handle, ks, parentKey, POSTGETSTORAGE, MAXONCE) == ELEKTRA_PLUGIN_STATUS_ERROR)
{
goto error;
}
if (elektraGlobalGet (handle, ks, parentKey, POSTGETSTORAGE, DEINIT) == ELEKTRA_PLUGIN_STATUS_ERROR)
{
goto error;
if (elektraGlobalGet (handle, ks, parentKey, POSTGETSTORAGE, INIT) == ELEKTRA_PLUGIN_STATUS_ERROR)
{
goto error;
}
if (elektraGlobalGet (handle, ks, parentKey, POSTGETSTORAGE, MAXONCE) == ELEKTRA_PLUGIN_STATUS_ERROR)
{
goto error;
}
if (elektraGlobalGet (handle, ks, parentKey, POSTGETSTORAGE, DEINIT) == ELEKTRA_PLUGIN_STATUS_ERROR)
{
goto error;
}
}

keySetName (parentKey, keyName (initialParent));

if (handle->globalPlugins[POSTGETCACHE][MAXONCE])
{
splitCacheStoreState (handle, split, handle->global, cacheParent, initialParent);
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/type/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The type checker plugin supports these types:
`any`, `enum`, `string`, `wstring` and `octet`.

- Checking `any` will always be successful, regardless of the content.
- `string` matches any non-empty key value.
- `string` matches any string key value.
- `octet` and `char` are equivalent to each other.
- `enum` will do enum checking as described below.
- `boolean` only allows the values `1` and `0`. See also [Normalization](#normalization).
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/type/testmod_type.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ void test_string (void)
{
Key * k = keyNew ("user:/anything", KEY_VALUE, "a", KEY_META, "check/type", "string", KEY_END);
keySetString (k, "");
succeed_if (!checkType (k), "empty string should not check successfully as string");
succeed_if (checkType (k), "empty string should check successfully as string");

keySetString (k, "ab");
succeed_if (checkType (k), "\"ab\" should check successfully as string");
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/type/types.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ bool elektraTypeCheckWChar (const Key * key)

bool elektraTypeCheckString (const Key * key)
{
return strlen (keyString (key)) != 0;
return keyIsString (key) == 1;
}

bool elektraTypeCheckWString (const Key * key)
Expand Down
71 changes: 54 additions & 17 deletions tests/shell/gen/highlevel/commands.check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ int commandKdb (Elektra * elektra, kdb_boolean_t terminal, void * userData)
int commandKdbGet (Elektra * elektra, kdb_boolean_t terminal, void * userData)
{
kdb_boolean_t verbose = elektraGet (elektra, ELEKTRA_TAG_GET_VERBOSE);
kdb_long_t maxLength = elektraGet (elektra, ELEKTRA_TAG_GET_MAXLENGTH);
const char * keyname = elektraGet (elektra, ELEKTRA_TAG_GET_KEYNAME);
printf ("commandKdbGet called %s, verbose: %d, keyname: %s\n", terminal ? "last" : "in the middle", verbose ? 1 : 0, keyname);
printf ("commandKdbGet called %s, verbose: %d, maxLength: " ELEKTRA_LONG_F ", keyname: %s\n", terminal ? "last" : "in the middle", verbose ? 1 : 0, maxLength, keyname);
return 0;
}
Expand Down Expand Up @@ -130,54 +131,90 @@ if [ "$res" = "0" ]; then
res=$?
echo "dummy exited with: $res"

if command -v valgrind; then
valgrind --error-exitcode=2 --leak-check=full --leak-resolution=high --track-origins=yes --vgdb=no --trace-children=yes ./dummy
if [ "$res" = "0" ] && command -v valgrind; then
valgrind --error-exitcode=2 --show-leak-kinds=all --leak-check=full --leak-resolution=high --track-origins=yes --vgdb=no --trace-children=yes -- ./dummy
echo "valgrind dummy exited with: $res"
fi

res=$((res != 0))
fi

if [ "$res" = "0" ]; then
if [ "$res" = 0 ]; then
./dummy -v get -v ab cd
res=$?
echo "dummy -v get -v ab cd exited with: $res"

if command -v valgrind; then
valgrind --error-exitcode=2 --leak-check=full --leak-resolution=high --track-origins=yes --vgdb=no --trace-children=yes ./dummy
echo "valgrind dummy -v get -v ab cd exited with: $res"
if [ "$res" = "0" ] && command -v valgrind; then
valgrind --error-exitcode=2 --show-leak-kinds=all --leak-check=full --leak-resolution=high --track-origins=yes --vgdb=no --trace-children=yes -- ./dummy -v get -v ab cd
echo "valgrind dummy -v get -v ab cd exited with: $?"
fi

res=$((res != 0))
fi

if [ "$res" = "0" ]; then
./dummy -v get --max-length=10 ab cd
res=$?
echo "dummy -v get --max-length=10 ab cd exited with: $res"

if [ "$res" = "0" ] && command -v valgrind; then
valgrind --error-exitcode=2 --show-leak-kinds=all --leak-check=full --leak-resolution=high --track-origins=yes --vgdb=no --trace-children=yes -- ./dummy -v get --max-length=10 ab cd
echo "valgrind dummy -v get -v ab cd exited with: $?"
fi

res=$((res != 0))
fi

if [ "$res" = "0" ]; then
./dummy -v get --max-length=notanint ab cd
res=$?
echo "dummy -v get --max-length=notanint ab cd exited with: $res"

if [ "$res" = "0" ] && command -v valgrind; then
valgrind --error-exitcode=2 --show-leak-kinds=all --leak-check=full --leak-resolution=high --track-origins=yes --vgdb=no --trace-children=yes -- ./dummy -v get --max-length=notanint ab cd
echo "valgrind dummy -v get -v ab cd exited with: $?"
fi

res=$((res == 0))
fi

if [ "$res" = "0" ]; then
./dummy get meta -v a b
res=$?
echo "dummy get meta -v a b exited with: $res"

if command -v valgrind; then
valgrind --error-exitcode=2 --leak-check=full --leak-resolution=high --track-origins=yes --vgdb=no --trace-children=yes ./dummy
echo "valgrind dummy get meta -v a b exited with: $res"
if [ "$res" = "0" ] && command -v valgrind; then
valgrind --error-exitcode=2 --show-leak-kinds=all --leak-check=full --leak-resolution=high --track-origins=yes --vgdb=no --trace-children=yes -- ./dummy get meta -v a b
echo "valgrind dummy get meta -v a b exited with: $?"
fi

res=$((res != 0))
fi

if [ "$res" = "0" ]; then
./dummy set def -2
./dummy set -- def -2
res=$?
echo "dummy set def -2 exited with: $res"

if command -v valgrind; then
valgrind --error-exitcode=2 --leak-check=full --leak-resolution=high --track-origins=yes --vgdb=no --trace-children=yes ./dummy
echo "valgrind dummy set def -2 exited with: $res"
if [ "$res" = "0" ] && command -v valgrind; then
valgrind --error-exitcode=2 --show-leak-kinds=all --leak-check=full --leak-resolution=high --track-origins=yes --vgdb=no --trace-children=yes -- ./dummy set def -2
echo "valgrind dummy set def -2 exited with: $?"
fi

res=$((res != 0))
fi

if [ "$res" = "0" ]; then
./dummy abc -v def
res=$?
echo "dummy abc -v def exited with: $res"

if command -v valgrind; then
valgrind --error-exitcode=2 --leak-check=full --leak-resolution=high --track-origins=yes --vgdb=no --trace-children=yes ./dummy
echo "valgrind dummy abc -v def exited with: $res"
if [ "$res" = "0" ] && command -v valgrind; then
valgrind --error-exitcode=2 --show-leak-kinds=all --leak-check=full --leak-resolution=high --track-origins=yes --vgdb=no --trace-children=yes -- ./dummy abc -v def
echo "valgrind dummy abc -v def exited with: $?"
fi

res=$((res != 0))
fi

cd ..
Expand Down
6 changes: 6 additions & 0 deletions tests/shell/gen/highlevel/commands.data.ini
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ opt = v
opt/long = verbose
opt/arg = none

[get/maxlength]
type = long
default = -1
opt/long = max-length
opt/arg = required

[get/keyname]
type = string
default = ""
Expand Down
3 changes: 2 additions & 1 deletion tests/shell/gen/highlevel/commands.expected.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@

static KeySet * embeddedSpec (void)
{
return ksNew (13,
return ksNew (14,
keyNew ("/", KEY_META, "command", "", KEY_META, "default", "", KEY_META, "gen/command/function", "commandKdb", KEY_META, "mountpoint", "tests_gen_elektra_commands.ini", KEY_META, "type", "string", KEY_END),
keyNew ("/dynamic/#", KEY_META, "args", "remaining", KEY_META, "default", "", KEY_META, "type", "string", KEY_END),
keyNew ("/get", KEY_META, "command", "get", KEY_META, "default", "", KEY_META, "gen/command/function", "commandKdbGet", KEY_META, "type", "string", KEY_END),
keyNew ("/get/keyname", KEY_META, "args", "indexed", KEY_META, "args/index", "0", KEY_META, "default", "", KEY_META, "type", "string", KEY_END),
keyNew ("/get/maxlength", KEY_META, "default", "-1", KEY_META, "opt/arg", "required", KEY_META, "opt/long", "max-length", KEY_META, "type", "long", KEY_END),
keyNew ("/get/meta", KEY_META, "command", "meta", KEY_META, "default", "", KEY_META, "gen/command/function", "commandKdbGetMeta", KEY_META, "type", "string", KEY_END),
keyNew ("/get/meta/keyname", KEY_META, "args", "indexed", KEY_META, "args/index", "0", KEY_META, "default", "", KEY_META, "type", "string", KEY_END),
keyNew ("/get/meta/metaname", KEY_META, "args", "indexed", KEY_META, "args/index", "1", KEY_META, "default", "", KEY_META, "type", "string", KEY_END),
Expand Down
41 changes: 41 additions & 0 deletions tests/shell/gen/highlevel/commands.expected.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ extern "C" {
*///
#define ELEKTRA_TAG_GET_KEYNAME GetKeyname

/**
* Tag name for 'get/maxlength'
*
*///
#define ELEKTRA_TAG_GET_MAXLENGTH GetMaxlength

/**
* Tag name for 'get/meta'
*
Expand Down Expand Up @@ -331,6 +337,41 @@ static inline void ELEKTRA_SET (ELEKTRA_TAG_GET_KEYNAME) (Elektra * elektra,



/**
* Get the value of key 'get/maxlength' (tag #ELEKTRA_TAG_GET_MAXLENGTH).
*
* @param elektra Instance of Elektra. Create with loadConfiguration().
*
* @return the value of 'get/maxlength'.
*///
static inline kdb_long_t ELEKTRA_GET (ELEKTRA_TAG_GET_MAXLENGTH) (Elektra * elektra )
{

return ELEKTRA_GET (Long) (elektra, "get/maxlength");
}


/**
* Set the value of key 'get/maxlength' (tag #ELEKTRA_TAG_GET_MAXLENGTH).
*
* @param elektra Instance of Elektra. Create with loadConfiguration().
* @param value The value of 'get/maxlength'.
* @param error Pass a reference to an ElektraError pointer.
* Will only be set in case of an error.
*///
static inline void ELEKTRA_SET (ELEKTRA_TAG_GET_MAXLENGTH) (Elektra * elektra,
kdb_long_t value, ElektraError ** error)
{

ELEKTRA_SET (Long) (elektra, "get/maxlength", value, error);
}




/**
* Get the value of key 'get/meta' (tag #ELEKTRA_TAG_GET_META).
*
Expand Down
Loading

0 comments on commit 90fb5be

Please sign in to comment.