This is a static archive of the previous Open Grid Forum Redmine content management system saved from host redmine.ogf.org file /issues/116 at Fri, 04 Nov 2022 00:04:49 GMT bug #116: default callback method for freeing dictionary entries should be part of DRMAA2 implementation - DRMAAv2 C Binding - Open Grid Forum

bug #116

default callback method for freeing dictionary entries should be part of DRMAA2 implementation

Added by Daniel Gruber about 9 years ago. Updated over 7 years ago.

Status:closed Start date:09/12/2013
Priority:Normal Due date:
Assignee:- % Done:

0%

Category:-
Target version:-

Description

We have a dictionary type which accepts a callback function for freeing
the elements of the dictionary when an entry is deleted or the complete
dictionary is freed.

The dictionary always stores strings per definition.

When using the dictionary each application must define the same standard
callback function.

It would be much easier if a standard callback function would
be available (like it is for all list types).

This is the function working when strings are allocated on heap:

void drmaa2_dict_string_free(char** key, char** value)
{
drmaa2_string_free(key);
drmaa2_string_free(value);
}
drmaa2_dict dict = drmaa2_dict_create((drmaa2_dict_entryfree)drmaa2_dict_string_free);
if (drmaa2_dict_set(dict, strdup("key"), strdup("value")) != DRMAA2_SUCCESS) {
printf("Error: Could not set a new value in the dictionary.\n");
return;
}
if (drmaa2_dict_set(dict, strdup("key2"), strdup("")) != DRMAA2_SUCCESS) {
printf("Error: Could not set a new value in the dictionary.\n");
return;
}
/* Frees strings implicitly. */
drmaa2_dict_free(&dict);

History

Updated by Stefan Klauck about 9 years ago

Currently, there are two possibilities to use drmaa2 dictionaries:
As in Daniel's example with allocated strings.
Or with string literals (example below).

drmaa2_dict d = drmaa2_dict_create(NULL);
drmaa2_dict_set(d, "foo", "bar");
drmaa2_dict_free(&d)

As both need different deallocation callbacks, we currently need a callback parameter.

I agree with Daniel to add a standard callback for allocated strings.
However, the language binding should warn to use it only for allocated strings (and not for string literals).

(An other option would be to allow only a single dictionary usage possibility (with allocated or string literals).
We could then omit the callback parameter.
I don't like this option.)

Updated by Daniel Gruber about 9 years ago

You are right, the standard callback should only be used only for allocated strings
(which is a very common use case). Literals don't need to be freed, hence the callback
is NULL in such cases in our implementation.

Updated by Peter Tröger over 7 years ago

  • Status changed from submitted to closed

Fixed in the July 2015 errata.

(Other formats not available in this archive.

This is a static archive of the previous Open Grid Forum Redmine content management system saved from host redmine.ogf.org file /issues/116 at Fri, 04 Nov 2022 00:04:49 GMT