Skip to content

Commit

Permalink
Add CCS_DESERIALIZE_OPTION_MAP_HANDLES option. Fix map bug in ruby.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerilk committed Oct 2, 2024
1 parent 77e6436 commit 329bb57
Show file tree
Hide file tree
Showing 14 changed files with 41 additions and 19 deletions.
11 changes: 8 additions & 3 deletions bindings/python/cconfigspace/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ class DeserializeOption(CEnumeration):
_members_ = [
('END', 0),
'HANDLE_MAP',
'MAP_HANDLES',
'VECTOR_CALLBACK',
'NON_BLOCKING',
'DATA_CALLBACK'
Expand Down Expand Up @@ -556,7 +557,7 @@ def serialize(self, format = 'binary', path = None, file_descriptor = None, call
return v

@classmethod
def deserialize(cls, format = 'binary', handle_map = None, vector_callback = None, path = None, buffer = None, file_descriptor = None, callback = None):
def deserialize(cls, format = 'binary', handle_map = None, map_handles = False, vector_callback = None, path = None, buffer = None, file_descriptor = None, callback = None):
if format != 'binary':
raise Error(Result(Result.ERROR_INVALID_VALUE))
mode_count = 0;
Expand All @@ -568,8 +569,12 @@ def deserialize(cls, format = 'binary', handle_map = None, vector_callback = Non
mode_count += 1
if not mode_count == 1:
raise Error(Result(Result.ERROR_INVALID_VALUE))
if map_handles and not handle_map:
raise Error(Result(Result.ERROR_INVALID_VALUE))
o = ccs_object(0)
options = [DeserializeOption.END]
if map_handles:
options = [DeserializeOption.MAP_HANDLES] + options
if handle_map:
options = [DeserializeOption.HANDLE_MAP, handle_map.handle] + options
if vector_callback:
Expand Down Expand Up @@ -692,8 +697,8 @@ def _register_serialize_callback(handle, callback_data):
_register_destroy_callback(handle)
_data_store[value]['serialize_calback'] = callback_data

def deserialize(format = 'binary', handle_map = None, path = None, buffer = None, file_descriptor = None, vector_callback = None, vector_callback_data = None, callback = None, callback_data = None):
return Object.deserialize(format = format, handle_map = handle_map, path = path, buffer = buffer, file_descriptor = file_descriptor, vector_callback = vector_callback, callback = callback)
def deserialize(format = 'binary', handle_map = None, map_handles = False, path = None, buffer = None, file_descriptor = None, vector_callback = None, vector_callback_data = None, callback = None, callback_data = None):
return Object.deserialize(format = format, handle_map = handle_map, map_handles = map_handles, path = path, buffer = buffer, file_descriptor = file_descriptor, vector_callback = vector_callback, callback = callback)

def _set_destroy_callback(handle, callback):
if callback is None:
Expand Down
16 changes: 10 additions & 6 deletions bindings/ruby/lib/cconfigspace/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ def read_ccs_result_t

DatumFlags = bitmask FFI::Type::UINT32, :ccs_datum_flags_t, [
:CCS_DATUM_FLAG_TRANSIENT,
:CCS_DATUM_FLAG_UNPOOLED ]
:CCS_DATUM_FLAG_UNPOOLED,
:CCS_DATUM_FLAG_ID ]

NumericType = enum FFI::Type::INT32, :ccs_numeric_type_t, [
:CCS_NUMERIC_TYPE_INT, DataType.to_native(:CCS_DATA_TYPE_INT, nil),
Expand Down Expand Up @@ -227,6 +228,7 @@ def read_ccs_numeric_type_t
DeserializeOptions = enum FFI::Type::INT32, :ccs_deserialize_option_t, [
:CCS_DESERIALIZE_OPTION_END, 0,
:CCS_DESERIALIZE_OPTION_HANDLE_MAP,
:CCS_DESERIALIZE_OPTION_MAP_HANDLES,
:CCS_DESERIALIZE_OPTION_VECTOR_CALLBACK,
:CCS_DESERIALIZE_OPTION_NON_BLOCKING,
:CCS_DESERIALIZE_OPTION_DATA_CALLBACK ]
Expand Down Expand Up @@ -733,17 +735,19 @@ def serialize(format: :binary, path: nil, file_descriptor: nil, callback: nil)
return result
end

def self.deserialize(format: :binary, handle_map: nil, path: nil, buffer: nil, file_descriptor: nil, vector_callback: nil, vector_callback_data: nil, callback: nil)
def self.deserialize(format: :binary, handle_map: nil, map_handles: false, path: nil, buffer: nil, file_descriptor: nil, vector_callback: nil, vector_callback_data: nil, callback: nil)
raise CCSError, :CCS_RESULT_ERROR_INVALID_VALUE if format != :binary
format = :CCS_SERIALIZE_FORMAT_BINARY
mode_count = 0
mode_count += 1 if path
mode_count += 1 if buffer
mode_count += 1 if file_descriptor
raise CCSError, :CCS_RESULT_ERROR_INVALID_VALUE unless mode_count == 1
raise CCSError, :CCS_RESULT_ERROR_INVALID_VALUE if map_handles && !handle_map
ptr = MemoryPointer::new(:ccs_object_t)
options = []
options.concat [:ccs_deserialize_option_t, :CCS_DESERIALIZE_OPTION_HANDLE_MAP, :ccs_map_t, handle_map.handle] if handle_map
options.concat [:ccs_deserialize_option_t, :CCS_DESERIALIZE_OPTION_MAP_HANDLES] if map_handles
if vector_callback
cb_wrapper = CCS.get_deserialize_vector_callback_wrapper(&vector_callback)
options.concat [:ccs_deserialize_option_t, :CCS_DESERIALIZE_OPTION_VECTOR_CALLBACK, :ccs_object_deserialize_vector_callback, cb_wrapper, :value, vector_callback_data]
Expand Down Expand Up @@ -786,7 +790,7 @@ def user_data=(ud)

end

@@data_store = Hash.new { |h, k| h[k] = { callbacks: [], user_data: nil, serialize_calback: nil, strings: [] } }
@@data_store = Hash.new { |h, k| h[k] = { callbacks: [], user_data: nil, serialize_callback: nil, strings: [] } }

# Delete wrappers are responsible for deregistering the object data_store
def self.register_vector(handle, vector_data)
Expand Down Expand Up @@ -832,7 +836,7 @@ def self.register_callback(handle, callback_data)
def self.register_serialize_callback(handle, callback_data)
value = handle.address
register_destroy_callback(handle) unless @@data_store.include?(value)
@@data_store[value][:serialize_calback] = callback_data
@@data_store[value][:serialize_callback] = callback_data
end

def self.set_destroy_callback(handle, &block)
Expand Down Expand Up @@ -913,8 +917,8 @@ def self.set_serialize_callback(handle, &block)
register_serialize_callback(handle, cb_data)
end

def self.deserialize(format: :binary, handle_map: nil, path: nil, buffer: nil, file_descriptor: nil, vector_callback: nil, callback: nil)
return CCS::Object.deserialize(format: format, handle_map: handle_map, path: path, buffer: buffer, file_descriptor: file_descriptor, vector_callback: vector_callback, callback: callback)
def self.deserialize(format: :binary, handle_map: nil, map_handles: false, path: nil, buffer: nil, file_descriptor: nil, vector_callback: nil, callback: nil)
return CCS::Object.deserialize(format: format, handle_map: handle_map, map_handles: map_handles, path: path, buffer: buffer, file_descriptor: file_descriptor, vector_callback: vector_callback, callback: callback)
end

end
2 changes: 1 addition & 1 deletion bindings/ruby/lib/cconfigspace/map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def include?(key)

def pairs
sz = size
return [] if count == 0
return [] if sz == 0
keys = MemoryPointer::new(:ccs_datum_t, sz)
values = MemoryPointer::new(:ccs_datum_t, sz)
CCS.error_check CCS.ccs_map_get_pairs(@handle, sz, keys, values, nil)
Expand Down
10 changes: 8 additions & 2 deletions include/cconfigspace/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -1025,10 +1025,16 @@ enum ccs_deserialize_option_e {
/**
* The next parameter is a ccs_handle_map_t object that must contain
* the mappings required to deserialize an object (usually bindings or
* expressions). I given, will also add a mapping between the object
* original handle and its current handle.
* expressions).
*/
CCS_DESERIALIZE_OPTION_HANDLE_MAP,
/**
* Secifies that handles have to be mapped. If given,
* #CCS_DESERIALIZE_OPTION_HANDLE_MAP must be set and the given map
* will be updated to contain the mapping between serialized object
* handles and deserialized object handles.
*/
CCS_DESERIALIZE_OPTION_MAP_HANDLES,
/**
* The next parameter is a pointer to a callback of type
* ccs_object_deserialize_vector_callback_t and its user data, that
Expand Down
3 changes: 1 addition & 2 deletions src/cconfigspace.c
Original file line number Diff line number Diff line change
Expand Up @@ -709,15 +709,14 @@ _ccs_object_deserialize_file_descriptor(
va_list args)
{
ccs_result_t res = CCS_RESULT_SUCCESS;
int fd;
int non_blocking;
size_t header_size;
ssize_t offset;
_ccs_object_deserialize_options_t opts = {NULL, CCS_FALSE, NULL, NULL,
NULL, NULL, NULL};
_ccs_file_descriptor_state_t state = {NULL, 0, NULL, 0, -1, 0};
_ccs_file_descriptor_state_t *pstate = NULL;
fd = va_arg(args, int);
int fd = va_arg(args, int);
CCS_VALIDATE(_ccs_object_deserialize_options(
format, CCS_SERIALIZE_OPERATION_FILE_DESCRIPTOR, args, &opts));
non_blocking = !!(opts.ppfd_state);
Expand Down
5 changes: 5 additions & 0 deletions src/cconfigspace_deserialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ _ccs_object_deserialize_options(
case CCS_DESERIALIZE_OPTION_HANDLE_MAP:
opts->handle_map = va_arg(args, ccs_map_t);
CCS_CHECK_OBJ(opts->handle_map, CCS_OBJECT_TYPE_MAP);
break;
case CCS_DESERIALIZE_OPTION_MAP_HANDLES:
opts->map_values = CCS_TRUE;
break;
case CCS_DESERIALIZE_OPTION_VECTOR_CALLBACK:
Expand Down Expand Up @@ -83,6 +85,9 @@ _ccs_object_deserialize_options(
}
opt = (ccs_deserialize_option_t)va_arg(args, int32_t);
}
CCS_REFUTE(
opts->map_values && !opts->handle_map,
CCS_RESULT_ERROR_INVALID_VALUE);
return CCS_RESULT_SUCCESS;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/test_configuration_space.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ test_deserialize(void)
(ccs_object_t *)&space, CCS_SERIALIZE_FORMAT_BINARY,
CCS_SERIALIZE_OPERATION_MEMORY, buff_size, buff,
CCS_DESERIALIZE_OPTION_HANDLE_MAP, map,
CCS_DESERIALIZE_OPTION_END);
CCS_DESERIALIZE_OPTION_MAP_HANDLES, CCS_DESERIALIZE_OPTION_END);
assert(err == CCS_RESULT_SUCCESS);

err = ccs_map_get(map, ccs_object(space_ref), &d);
Expand Down
2 changes: 1 addition & 1 deletion tests/test_feature_space.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ test_deserialize(void)
(ccs_object_t *)&feature_space, CCS_SERIALIZE_FORMAT_BINARY,
CCS_SERIALIZE_OPERATION_MEMORY, buff_size, buff,
CCS_DESERIALIZE_OPTION_HANDLE_MAP, map,
CCS_DESERIALIZE_OPTION_END);
CCS_DESERIALIZE_OPTION_MAP_HANDLES, CCS_DESERIALIZE_OPTION_END);
assert(err == CCS_RESULT_SUCCESS);

err = ccs_context_get_parameter_by_name(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_random_features_tuner.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ test(void)
(ccs_object_t *)&tuner_copy, CCS_SERIALIZE_FORMAT_BINARY,
CCS_SERIALIZE_OPERATION_MEMORY, buff_size, buff,
CCS_DESERIALIZE_OPTION_HANDLE_MAP, map,
CCS_DESERIALIZE_OPTION_END);
CCS_DESERIALIZE_OPTION_MAP_HANDLES, CCS_DESERIALIZE_OPTION_END);
assert(err == CCS_RESULT_SUCCESS);

err = ccs_map_get(map, ccs_object((ccs_object_t)tuner), &d);
Expand Down
2 changes: 1 addition & 1 deletion tests/test_random_tree_tuner.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ test(void)
(ccs_object_t *)&tuner_copy, CCS_SERIALIZE_FORMAT_BINARY,
CCS_SERIALIZE_OPERATION_MEMORY, buff_size, buff,
CCS_DESERIALIZE_OPTION_HANDLE_MAP, map,
CCS_DESERIALIZE_OPTION_END);
CCS_DESERIALIZE_OPTION_MAP_HANDLES, CCS_DESERIALIZE_OPTION_END);
assert(err == CCS_RESULT_SUCCESS);

err = ccs_tuner_get_history(tuner_copy, NULL, 100, history, &count);
Expand Down
2 changes: 1 addition & 1 deletion tests/test_random_tuner.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ test(void)
(ccs_object_t *)&tuner_copy, CCS_SERIALIZE_FORMAT_BINARY,
CCS_SERIALIZE_OPERATION_MEMORY, buff_size, buff,
CCS_DESERIALIZE_OPTION_HANDLE_MAP, map,
CCS_DESERIALIZE_OPTION_END);
CCS_DESERIALIZE_OPTION_MAP_HANDLES, CCS_DESERIALIZE_OPTION_END);
assert(err == CCS_RESULT_SUCCESS);

err = ccs_tuner_get_history(tuner_copy, NULL, 100, history, &count);
Expand Down
1 change: 1 addition & 0 deletions tests/test_user_defined_features_tuner.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ test(void)
(ccs_object_t *)&tuner_copy, CCS_SERIALIZE_FORMAT_BINARY,
CCS_SERIALIZE_OPERATION_MEMORY, buff_size, buff,
CCS_DESERIALIZE_OPTION_HANDLE_MAP, map,
CCS_DESERIALIZE_OPTION_MAP_HANDLES,
CCS_DESERIALIZE_OPTION_VECTOR_CALLBACK,
&deserialize_vector_callback, (void *)NULL,
CCS_DESERIALIZE_OPTION_END);
Expand Down
1 change: 1 addition & 0 deletions tests/test_user_defined_tree_tuner.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ test(void)
(ccs_object_t *)&tuner_copy, CCS_SERIALIZE_FORMAT_BINARY,
CCS_SERIALIZE_OPERATION_MEMORY, buff_size, buff,
CCS_DESERIALIZE_OPTION_HANDLE_MAP, map,
CCS_DESERIALIZE_OPTION_MAP_HANDLES,
CCS_DESERIALIZE_OPTION_VECTOR_CALLBACK,
&deserialize_vector_callback, (void *)NULL,
CCS_DESERIALIZE_OPTION_END);
Expand Down
1 change: 1 addition & 0 deletions tests/test_user_defined_tuner.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ test(void)
(ccs_object_t *)&tuner_copy, CCS_SERIALIZE_FORMAT_BINARY,
CCS_SERIALIZE_OPERATION_MEMORY, buff_size, buff,
CCS_DESERIALIZE_OPTION_HANDLE_MAP, map,
CCS_DESERIALIZE_OPTION_MAP_HANDLES,
CCS_DESERIALIZE_OPTION_VECTOR_CALLBACK,
&deserialize_vector_callback, (void *)NULL,
CCS_DESERIALIZE_OPTION_END);
Expand Down

0 comments on commit 329bb57

Please sign in to comment.