DEFAULT values for BOOLEANs are ignored
Go to github.com/vlm/asn1c for the latest version.
Brought to you by:
vlm
There are 3 issues:
1) The parser passes 0 for the value of TRUE when you have a DEFAULT TRUE. I fixed that in my local copy (pass 1 to asn1p_value_fromint)
2) The code in asn1c_C.c never calls the emit default value function because the default_value.type is never ATV_INTEGER. I removed that restriction in my sandbox, and I can code to generate.
3) The ber decoder doesn't do anything with default values.
Is there some history here as to why the default_value stuff is always expected to be an integer? The case statement in asn1c_C.c seems to obviate that.
Logged In: YES
user_id=1932039
Originator: YES
I found another problem. If I do enable the code generator for the default value, the member of a SET or SEQUENCE that has the DEFAULT isn't always emitted with a ATF_POINTER flag. For example, if I have
BOOLEAN myval DEFAULT TRUE
in my set, I get a BOOLEAN_t* in the set header.
But, if I have
BOOLEAN myval DEFAULT FALSE
in my set, I get a BOOLEAN_t in the set header.
I tried working around this by setting EM_INDIRECT on the flags in the asn1p_y.y code under the rule for DEFAULT markers, but that had no effect.
Logged In: YES
user_id=1932039
Originator: YES
I just found the source of that BOOLEAN inconsistency. In asn1c_C.c,
if (fits_long && ! expr->marker.default_value->value.v_integer)
expr->marker.flags &= ~EM_INDIRECT;
and a boolean is treated like an integer, so when FALSE is used, the if statement is true and removes the EM_INDIRECT flag. Very confusing code here.
I think the way to fix this is to handle BOOLEANs separately.
This still doesn't address the fact that the decoder doesn't use the default value.
Logged In: YES
user_id=1932039
Originator: YES
I'm able to get this working now. I added to the sequence decoder a pass prior to the actual decoding through the elements that look for optionals with defaults and initialize those elements with the default. For sets, I added a pass in phase 5 before the mandatory_presence check to only do that for elements that are not present but are optionals with defaults.