Skip to content

Commit

Permalink
replace keyDupOld placeholder with new keyDup
Browse files Browse the repository at this point in the history
  • Loading branch information
kodebach committed Mar 1, 2021
1 parent 796a5c0 commit ae419e6
Show file tree
Hide file tree
Showing 73 changed files with 350 additions and 333 deletions.
4 changes: 2 additions & 2 deletions benchmarks/benchmarks.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ static void recGenerateKeySet (KeySet * ks, Key * key, KsTreeVertex * vertex)
// add if Key
if (vertex->isKey)
{
Key * dupKey = keyDupOld (key);
Key * dupKey = keyDup (key, KEY_CP_ALL);
if (!dupKey)
{
printExit ("recGenerateKeySet: Can not dup Key");
Expand All @@ -473,7 +473,7 @@ static void recGenerateKeySet (KeySet * ks, Key * key, KsTreeVertex * vertex)
// go to children
for (size_t i = 0; i < vertex->numberofChildren; ++i)
{
Key * dupKey = keyDupOld (key);
Key * dupKey = keyDup (key, KEY_CP_ALL);
if (!dupKey)
{
printExit ("recGenerateKeySet: Can not dup Key");
Expand Down
2 changes: 1 addition & 1 deletion examples/functional.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ int ksFilter (KeySet * result, KeySet * input, int (*filter) (Key * k))
else if (rc != 0)
{
++ret;
ksAppendKey (result, keyDupOld (current));
ksAppendKey (result, keyDup (current, KEY_CP_ALL));
}
}
ksSetCursor (input, cursor);
Expand Down
8 changes: 4 additions & 4 deletions examples/keyset.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@

void f (const Key * source)
{
Key * dup = keyDupOld (source);
Key * dup = keyDup (source, KEY_CP_ALL);
printf ("\tin f\n");

keyDel (dup);
}

void g (const Key * source, KeySet * ks)
{
Key * dup = keyDupOld (source);
Key * dup = keyDup (source, KEY_CP_ALL);
printf ("\tin g\n");

ksAppendKey (ks, dup);
Expand Down Expand Up @@ -68,7 +68,7 @@ void dupAppend (void)
//! [dup append]
KeySet * ks = ksNew (1, KS_END);
Key * k = keyNew ("user:/ref/key", KEY_END);
ksAppendKey (ks, keyDupOld (k));
ksAppendKey (ks, keyDup (k, KEY_CP_ALL));
ksDel (ks);
// now we still can work with the key k!
keyDel (k);
Expand Down Expand Up @@ -101,7 +101,7 @@ int main (void)

ksRewind (ks);
origKey = ksNext (ks);
key = keyDupOld (origKey);
key = keyDup (origKey, KEY_CP_ALL);
printf ("A duplication of the key %s with value %s\n", keyName (key), keyString (key));

keyDel (key);
Expand Down
6 changes: 3 additions & 3 deletions src/bindings/cpp/include/key.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class Key
inline ckdb::Key * operator* () const;

inline ckdb::Key * release ();
inline ckdb::Key * dup () const;
inline ckdb::Key * dup (elektraCopyFlags flags = KEY_CP_ALL) const;
inline ~Key ();


Expand Down Expand Up @@ -813,9 +813,9 @@ ckdb::Key * Key::release ()
/**
* @copydoc keyDup
*/
ckdb::Key * Key::dup () const
ckdb::Key * Key::dup (elektraCopyFlags flags) const
{
return ckdb::keyDupOld (getKey ());
return ckdb::keyDup (getKey (), flags);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/bindings/glib/gelektra-key.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,16 @@ gssize gelektra_key_getref (const GElektraKey * key)
* Returns: (transfer full): A duplicated #GElektraKey
* see keyDup
*/
GElektraKey * gelektra_key_dup (const GElektraKey * key)
GElektraKey * gelektra_key_dup (const GElektraKey * key, elektraCopyFlags flags)
{
return gelektra_key_make (keyDupOld (key->key));
return gelektra_key_make (keyDup (key->key, flags));
}

/**
* gelektra_key_copy: (skip)
* see keyCopy
*/
GElektraKey * gelektra_key_copy (const GElektraKey * key, GElektraKey * dest, elektraKeyFlags flags)
GElektraKey * gelektra_key_copy (const GElektraKey * key, GElektraKey * dest, elektraCopyFlags flags)
{
Key * ret = keyCopy (dest->key, key->key, flags);
return ret == NULL ? NULL : dest;
Expand Down
4 changes: 2 additions & 2 deletions src/bindings/glib/gelektra-key.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ gssize gelektra_key_decref (GElektraKey * key);
gssize gelektra_key_getref (const GElektraKey * key);

/* basic methods */
GElektraKey * gelektra_key_dup (const GElektraKey * key);
GElektraKey * gelektra_key_copy (const GElektraKey * key, GElektraKey * dest, elektraKeyFlags flags);
GElektraKey * gelektra_key_dup (const GElektraKey * key, elektraCopyFlags flags);
GElektraKey * gelektra_key_copy (const GElektraKey * key, GElektraKey * dest, elektraCopyFlags flags);
gint gelektra_key_clear (GElektraKey * key);

/* operators */
Expand Down
4 changes: 2 additions & 2 deletions src/bindings/glib/tests/testglib_key.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ static void test_basic (void)
{
GElektraKey * key;

key = gelektra_key_dup (g_key);
key = gelektra_key_dup (g_key, KEY_CP_ALL);
gelektra_key_incref (key);
succeed_if (gelektra_key_getref (key) == 2, "refcount should be 2");
succeed_if (gelektra_key_getref (g_key) == 1, "refcount should be still 1");
Expand Down Expand Up @@ -142,7 +142,7 @@ static void test_operators (void)
succeed_if (!gelektra_key_equal (g_key, g_bkey), "keys shouldn't be equal");
succeed_if (gelektra_key_cmp (g_key, g_bkey) != 0, "keys shouldn't be equal");

GElektraKey * key = gelektra_key_dup (g_key);
GElektraKey * key = gelektra_key_dup (g_key, KEY_CP_ALL);
succeed_if (gelektra_key_equal (g_key, key), "keys should be equal");
succeed_if (gelektra_key_cmp (g_key, key) == 0, "keys should be equal");
g_object_unref (key);
Expand Down
2 changes: 1 addition & 1 deletion src/bindings/intercept/fs/intercept.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ void init (void)
else
tmp->value = createAbsolutePath (keyString (key), cwd);
tmp->oflags = (unsigned short) -1;
Key * lookupKey = keyDupOld (key);
Key * lookupKey = keyDup (key, KEY_CP_ALL);
keyAddBaseName (lookupKey, "readonly");
Key * found = ksLookup (ks, lookupKey, 0);
if (found)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public interface Elektra extends Library {

Pointer keyNew (String name, Object... args);

Pointer keyDupOld (Pointer source);
Pointer keyDup (Pointer source, int flags);

int keyCopy (Pointer dest, Pointer source);
int keyCopy (Pointer dest, Pointer source, int flags);

int keyClear (Pointer key); // not needed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ public class Key implements Iterable<String>
public static final int KEY_META = 1 << 15;
public static final int KEY_NULL = 1 << 16;

public static final int KEY_CP_NAME = 1 << 0;
public static final int KEY_CP_STRING = 1 << 1;
public static final int KEY_CP_VALUE = 1 << 2;
public static final int KEY_CP_META = 1 << 3;
public static final int KEY_CP_ALL = KEY_CP_NAME | KEY_CP_VALUE | KEY_CP_META;

/**
* Indicates a generic key exception occurred.
*/
Expand Down Expand Up @@ -412,19 +418,32 @@ public void addWarning (final String text, final Object... args)
*/
public Key dup ()
{
return new Key (Elektra.INSTANCE.keyDupOld (get ()));
return dup (KEY_CP_ALL);
}

/**
* Duplicates the key
*
* @param flags what parts of the key to copy (a combination of KEY_CP_* flags)
*
* @return New Key object containing the same information as this key
*/
public Key dup (final int flags)
{
return new Key (Elektra.INSTANCE.keyDup (get (), flags));
}

/**
* Copies the information from the source key into this key. Does nothing if null is provided.
*
* @param source Source Key object containing the information to copy
* @param flags what parts of the key to copy (a combination of KEY_CP_* flags)
*/
public void copy (final Key source)
public void copy (final Key source, final int flags)
{
if (source != null)
{
Elektra.INSTANCE.keyCopy (get (), source.get ());
Elektra.INSTANCE.keyCopy (get (), source.get (), flags);
}
}

Expand Down
26 changes: 16 additions & 10 deletions src/bindings/rust/elektra/src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,14 @@ impl<'a> StringKey<'a> {

/// Returns a deep copy of the key.
pub fn duplicate<'b>(&'a self) -> StringKey<'b> {
// TODO: binding
let dup_ptr = unsafe {
let dup = elektra_sys::keyDup(self.as_ref(), 0);
elektra_sys::keyCopyAllMeta(dup, self.as_ref());
dup
// FIXME: binding
let dup_ptr = unsafe {
let name = CString::new("/").unwrap();
elektra_sys::keyCopy(
elektra_sys::keyNew (name.as_ptr(), elektra_sys::KEY_END),
self.as_ref(),
elektra_sys::KEY_CP_ALL
)
};
unsafe { StringKey::from_ptr(dup_ptr) }
}
Expand Down Expand Up @@ -250,11 +253,14 @@ impl<'a> BinaryKey<'a> {

/// Returns a deep copy of the key.
pub fn duplicate<'b>(&'a self) -> BinaryKey<'b> {
// TODO: binding
let dup_ptr = unsafe {
let dup = elektra_sys::keyDup(self.as_ref(), 0);
elektra_sys::keyCopyAllMeta(dup, self.as_ref());
dup
// FIXME: binding
let dup_ptr = unsafe {
let name = CString::new("/").unwrap();
elektra_sys::keyCopy(
elektra_sys::keyNew (name.as_ptr(), elektra_sys::KEY_END),
self.as_ref(),
elektra_sys::KEY_CP_ALL
)
};
unsafe { BinaryKey::from_ptr(dup_ptr) }
}
Expand Down
10 changes: 0 additions & 10 deletions src/include/kdb.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -208,16 +208,6 @@ static inline Key *keyDup (const Key *source, elektraCopyFlags flags)
return keyCopy (keyNew ("/", 0), source, flags);
}

// FIXME: remove once migrated
static inline Key *keyDupOld (const Key *source)
{
if (source == 0)
{
return 0;
}
return keyCopy (keyNew ("/", 0), source, KEY_CP_ALL);
}

/**************************************
*
* KeySet methods
Expand Down
3 changes: 1 addition & 2 deletions src/libs/ease/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,7 @@ Key * elektraArrayGetNextKey (KeySet * arrayKeys)
if (!last) return 0;

ksAppendKey (arrayKeys, last);
Key * newKey = keyDupOld (last);
keySetBinary (newKey, 0, 0);
Key * newKey = keyDup (last, KEY_CP_NAME);
int ret = elektraArrayIncName (newKey);

if (ret == -1)
Expand Down
2 changes: 1 addition & 1 deletion src/libs/elektra/backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static Backend * elektraBackendAllocate (void)
int elektraBackendSetMountpoint (Backend * backend, KeySet * elektraConfig, Key * errorKey)
{
Key * root = ksCurrent (elektraConfig);
Key * searchMountpoint = keyDupOld (root);
Key * searchMountpoint = keyDup (root, KEY_CP_NAME);
keyAddBaseName (searchMountpoint, "mountpoint");
Key * foundMountpoint = ksLookup (elektraConfig, searchMountpoint, 0);
keyDel (searchMountpoint);
Expand Down
12 changes: 6 additions & 6 deletions src/libs/elektra/kdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ KeySet * ksRenameKeys (KeySet * config, const char * name)

while ((cur = ksPop (config)) != 0)
{
Key * dupKey = keyDupOld (cur);
Key * dupKey = keyDup (cur, KEY_CP_ALL);
keySetName (dupKey, name);
keyAddName (dupKey, keyName (cur) + rootSize - 1);
ksAppendKey (newConfig, dupKey);
Expand Down Expand Up @@ -260,7 +260,7 @@ KDB * kdbOpen (Key * errorKey)

int errnosave = errno;
KDB * handle = elektraCalloc (sizeof (struct _KDB));
Key * initialParent = keyDupOld (errorKey);
Key * initialParent = keyDup (errorKey, KEY_CP_ALL);

handle->global = ksNew (0, KS_END);
handle->modules = ksNew (0, KS_END);
Expand Down Expand Up @@ -404,7 +404,7 @@ int kdbClose (KDB * handle, Key * errorKey)
return -1;
}

Key * initialParent = keyDupOld (errorKey);
Key * initialParent = keyDup (errorKey, KEY_CP_ALL);
int errnosave = errno;
splitDel (handle->split);

Expand Down Expand Up @@ -1006,7 +1006,7 @@ int kdbGet (KDB * handle, KeySet * ks, Key * parentKey)
}

int errnosave = errno;
Key * initialParent = keyDupOld (parentKey);
Key * initialParent = keyDup (parentKey, KEY_CP_ALL);

ELEKTRA_LOG ("now in new kdbGet (%s)", keyName (parentKey));

Expand Down Expand Up @@ -1038,7 +1038,7 @@ int kdbGet (KDB * handle, KeySet * ks, Key * parentKey)
}

cache = ksNew (0, KS_END);
cacheParent = keyDupOld (mountGetMountpoint (handle, keyName (initialParent)));
cacheParent = keyDup (mountGetMountpoint (handle, keyName (initialParent)), KEY_CP_ALL);
if (cacheParent == NULL)
{
cacheParent = keyNew ("default:/", KEY_VALUE, "default", KEY_END);
Expand Down Expand Up @@ -1588,7 +1588,7 @@ int kdbSet (KDB * handle, KeySet * ks, Key * parentKey)
}

int errnosave = errno;
Key * initialParent = keyDupOld (parentKey);
Key * initialParent = keyDup (parentKey, KEY_CP_ALL);

ELEKTRA_LOG ("now in new kdbSet (%s) %p %zd", keyName (parentKey), (void *) handle, ksGetSize (ks));

Expand Down
10 changes: 5 additions & 5 deletions src/libs/elektra/keyset.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ KeySet * ksDeepDup (const KeySet * source)
for (i = 0; i < s; ++i)
{
Key * k = source->array[i];
Key * d = keyDupOld (k);
Key * d = keyDup (k, KEY_CP_ALL);
if (!test_bit (k->flags, KEY_FLAG_SYNC))
{
keyClearSync (d);
Expand Down Expand Up @@ -1786,7 +1786,7 @@ static Key * elektraLookupByCascading (KeySet * ks, Key * key, elektraLookupFlag
}

// we found a spec key, so we know what to do
specKey = keyDupOld (specKey);
specKey = keyDup (specKey, KEY_CP_ALL);
keySetBinary (specKey, keyValue (key), keyGetValueSize (key));
elektraCopyCallbackMeta (specKey, key);
found = elektraLookupBySpec (ks, specKey, options);
Expand Down Expand Up @@ -2120,7 +2120,7 @@ static Key * elektraLookupSearch (KeySet * ks, Key * key, elektraLookupFlags opt

static Key * elektraLookupCreateKey (KeySet * ks, Key * key, ELEKTRA_UNUSED elektraLookupFlags options)
{
Key * ret = keyDupOld (key);
Key * ret = keyDup (key, KEY_CP_ALL);
ksAppendKey (ks, ret);
return ret;
}
Expand Down Expand Up @@ -2229,7 +2229,7 @@ Key * ksLookup (KeySet * ks, Key * key, elektraLookupFlags options)
if (options & KDB_O_SPEC)
{
Key * lookupKey = key;
if (test_bit (key->flags, KEY_FLAG_RO_NAME)) lookupKey = keyDupOld (key);
if (test_bit (key->flags, KEY_FLAG_RO_NAME)) lookupKey = keyDup (key, KEY_CP_NAME);
ret = elektraLookupBySpec (ks, lookupKey, options & mask);
if (test_bit (key->flags, KEY_FLAG_RO_NAME))
{
Expand All @@ -2240,7 +2240,7 @@ Key * ksLookup (KeySet * ks, Key * key, elektraLookupFlags options)
else if (!(options & KDB_O_NOCASCADING) && strcmp (name, "") && name[0] == '/')
{
Key * lookupKey = key;
if (test_bit (key->flags, KEY_FLAG_RO_NAME)) lookupKey = keyDupOld (key);
if (test_bit (key->flags, KEY_FLAG_RO_NAME)) lookupKey = keyDup (key, KEY_CP_NAME);
ret = elektraLookupByCascading (ks, lookupKey, options & mask);
if (test_bit (key->flags, KEY_FLAG_RO_NAME))
{
Expand Down
Loading

0 comments on commit ae419e6

Please sign in to comment.