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

Commit

Permalink
core: flags for keyDup and keyCopy
Browse files Browse the repository at this point in the history
temporarily replaces keyDup and keyCopy with keyDupOld and keyCopyOld
  • Loading branch information
kodebach committed Mar 1, 2021
1 parent 5c3b6e4 commit 47aa4fe
Show file tree
Hide file tree
Showing 72 changed files with 425 additions and 362 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 = keyDup (key);
Key * dupKey = keyDupOld (key);
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 = keyDup (key);
Key * dupKey = keyDupOld (key);
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, keyDup (current));
ksAppendKey (result, keyDupOld (current));
}
}
ksSetCursor (input, cursor);
Expand Down
6 changes: 3 additions & 3 deletions examples/keyCopy.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ Key * copy;
void h (Key * k)
{
// receive key c
keyCopy (k, copy);
keyCopyOld (k, copy);
// the caller will see the changed key k
}
//! [Basic Usage]

//! [Clear]
void g (Key * k)
{
keyCopy (k, 0);
keyCopyOld (k, 0);
// k is now an empty and fresh key
}
//! [Clear]
Expand All @@ -38,7 +38,7 @@ void j (Key * k)

// receive key c
memcpy (value, keyValue (k), size);
keyCopy (k, copy);
keyCopyOld (k, copy);
if (bstring)
keySetString (k, value);
else
Expand Down
10 changes: 5 additions & 5 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 = keyDup (source);
Key * dup = keyDupOld (source);
printf ("\tin f\n");

keyDel (dup);
}

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

ksAppendKey (ks, dup);
Expand All @@ -31,7 +31,7 @@ void h (Key * k)
Key * c = keyNew ("user:/from/h", KEY_END);
printf ("\tin h\n");

keyCopy (k, c);
keyCopyOld (k, c);
keyDel (c);
/* the caller will see the changed key k */
}
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, keyDup (k));
ksAppendKey (ks, keyDupOld (k));
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 = keyDup (origKey);
key = keyDupOld (origKey);
printf ("A duplication of the key %s with value %s\n", keyName (key), keyString (key));

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

inline void copy (const Key & other);
inline void copy (const Key & other, int flags = 0);
inline void clear ();
inline ckdb::Key * operator-> () const;

Expand Down Expand Up @@ -732,9 +732,9 @@ inline Key & Key::operator= (const Key & k)
/**
* @copydoc keyCopy
*/
inline void Key::copy (const Key & other)
inline void Key::copy (const Key & other, int flags)
{
ckdb::keyCopy (key, other.key);
ckdb::keyCopy (key, other.key, flags);
}

/**
Expand Down Expand Up @@ -815,7 +815,7 @@ ckdb::Key * Key::release ()
*/
ckdb::Key * Key::dup () const
{
return ckdb::keyDup (getKey ());
return ckdb::keyDupOld (getKey ());
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/bindings/glib/gelektra-key.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ gssize gelektra_key_getref (const GElektraKey * key)
*/
GElektraKey * gelektra_key_dup (const GElektraKey * key)
{
return gelektra_key_make (keyDup (key->key));
return gelektra_key_make (keyDupOld (key->key));
}

/**
Expand All @@ -204,7 +204,8 @@ GElektraKey * gelektra_key_dup (const GElektraKey * key)
*/
gint gelektra_key_copy (const GElektraKey * key, GElektraKey * dest)
{
return keyCopy (dest->key, key->key);
// TODO (kodebach): binding
return keyCopyOld (dest->key, key->key);
}

gint gelektra_key_clear (GElektraKey * 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 = keyDup (key);
Key * lookupKey = keyDupOld (key);
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,7 +37,7 @@ public interface Elektra extends Library {

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

Pointer keyDup (Pointer source);
Pointer keyDupOld (Pointer source);

int keyCopy (Pointer dest, Pointer source);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ public void addWarning (final String text, final Object... args)
*/
public Key dup ()
{
return new Key (Elektra.INSTANCE.keyDup (get ()));
return new Key (Elektra.INSTANCE.keyDupOld (get ()));
}

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

/// Returns a deep copy of the key.
pub fn duplicate<'b>(&'a self) -> StringKey<'b> {
let dup_ptr = unsafe { elektra_sys::keyDup(self.as_ref()) };
// TODO: binding
let dup_ptr = unsafe {
let dup = elektra_sys::keyDup(self.as_ref(), 0);
elektra_sys::keyCopyAllMeta(dup, self.as_ref());
dup
};
unsafe { StringKey::from_ptr(dup_ptr) }
}

Expand Down Expand Up @@ -245,7 +250,12 @@ impl<'a> BinaryKey<'a> {

/// Returns a deep copy of the key.
pub fn duplicate<'b>(&'a self) -> BinaryKey<'b> {
let dup_ptr = unsafe { elektra_sys::keyDup(self.as_ref()) };
// TODO: binding
let dup_ptr = unsafe {
let dup = elektra_sys::keyDup(self.as_ref(), 0);
elektra_sys::keyCopyAllMeta(dup, self.as_ref());
dup
};
unsafe { BinaryKey::from_ptr(dup_ptr) }
}

Expand Down
23 changes: 21 additions & 2 deletions src/include/kdb.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ int kdbEnsure (KDB * handle, KeySet * contract, Key * parentKey);
Key *keyNew(const char *keyname, ...);
Key *keyVNew(const char *keyname, va_list ap);

Key *keyDup(const Key *source);
int keyCopy(Key *dest, const Key *source);
Key *keyDup(const Key *source, elektraKeyFlags flags);
int keyCopy(Key *dest, const Key *source, elektraKeyFlags flags);

int keyClear(Key *key);
int keyDel(Key *key);
Expand Down Expand Up @@ -195,6 +195,25 @@ ssize_t keySetBinary(Key *key, const void *newBinary, size_t dataSize);
int keyLock (Key * key, elektraLockFlags what);
int keyIsLocked (const Key * key, elektraLockFlags what);

// FIXME: remove once migrated
static inline Key *keyDupOld (const Key *source)
{
Key * dup = keyDup (source, 0);
keyCopyAllMeta (dup, source);
return dup;
}

// FIXME: remove once migrated
static inline int keyCopyOld (Key *dest, const Key *source)
{
int ret = keyCopy (dest, source, 0);
if (ret > 0)
{
keyCopyAllMeta (dest, source);
}
return ret;
}

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

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

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 = keyDup (root);
Key * searchMountpoint = keyDupOld (root);
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 = keyDup (cur);
Key * dupKey = keyDupOld (cur);
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 = keyDup (errorKey);
Key * initialParent = keyDupOld (errorKey);

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 = keyDup (errorKey);
Key * initialParent = keyDupOld (errorKey);
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 = keyDup (parentKey);
Key * initialParent = keyDupOld (parentKey);

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 = keyDup (mountGetMountpoint (handle, keyName (initialParent)));
cacheParent = keyDupOld (mountGetMountpoint (handle, keyName (initialParent)));
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 = keyDup (parentKey);
Key * initialParent = keyDupOld (parentKey);

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

Expand Down
Loading

0 comments on commit 47aa4fe

Please sign in to comment.