diff options
author | Wim Lewis <wiml@omnigroup.com> | 2014-07-28 12:16:01 -0700 |
---|---|---|
committer | Wim Lewis <wiml@omnigroup.com> | 2014-07-28 12:16:01 -0700 |
commit | fb6344ef750a4d822ecd613819deba89b181b932 (patch) | |
tree | dc164af59c53ac5c8a59cfff6b3daa2df6f81b37 /skeletons | |
parent | 14e6b161463b8d256d4ab4aac5d0d8c63c0819cd (diff) |
Declare most internal, constant tables as const, particularly the
"specifics" structures and the tables they point to.
Diffstat (limited to 'skeletons')
-rw-r--r-- | skeletons/INTEGER.c | 6 | ||||
-rw-r--r-- | skeletons/INTEGER.h | 6 | ||||
-rw-r--r-- | skeletons/NativeEnumerated.c | 2 | ||||
-rw-r--r-- | skeletons/OCTET_STRING.h | 2 | ||||
-rw-r--r-- | skeletons/constr_CHOICE.c | 4 | ||||
-rw-r--r-- | skeletons/constr_CHOICE.h | 4 | ||||
-rw-r--r-- | skeletons/constr_SEQUENCE.c | 8 | ||||
-rw-r--r-- | skeletons/constr_SEQUENCE.h | 6 | ||||
-rw-r--r-- | skeletons/constr_SET.c | 33 | ||||
-rw-r--r-- | skeletons/constr_SET.h | 8 | ||||
-rw-r--r-- | skeletons/constr_SET_OF.h | 2 | ||||
-rw-r--r-- | skeletons/constr_TYPE.h | 16 | ||||
-rw-r--r-- | skeletons/der_encoder.c | 14 | ||||
-rw-r--r-- | skeletons/tests/check-PER-INTEGER.c | 2 |
14 files changed, 59 insertions, 54 deletions
diff --git a/skeletons/INTEGER.c b/skeletons/INTEGER.c index 2ddb5c7f..c9211c3f 100644 --- a/skeletons/INTEGER.c +++ b/skeletons/INTEGER.c @@ -208,8 +208,8 @@ INTEGER_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel, struct e2v_key { const char *start; const char *stop; - asn_INTEGER_enum_map_t *vemap; - unsigned int *evmap; + const asn_INTEGER_enum_map_t *vemap; + const unsigned int *evmap; }; static int INTEGER__compar_enum2value(const void *kp, const void *am) { @@ -232,7 +232,7 @@ INTEGER__compar_enum2value(const void *kp, const void *am) { static const asn_INTEGER_enum_map_t * INTEGER_map_enum2value(asn_INTEGER_specifics_t *specs, const char *lstart, const char *lstop) { - asn_INTEGER_enum_map_t *el_found; + const asn_INTEGER_enum_map_t *el_found; int count = specs ? specs->map_count : 0; struct e2v_key key; const char *lp; diff --git a/skeletons/INTEGER.h b/skeletons/INTEGER.h index fe08b038..2813f0cb 100644 --- a/skeletons/INTEGER.h +++ b/skeletons/INTEGER.h @@ -24,9 +24,9 @@ typedef struct asn_INTEGER_enum_map_s { } asn_INTEGER_enum_map_t; /* This type describes an enumeration for INTEGER and ENUMERATED types */ -typedef struct asn_INTEGER_specifics_s { - asn_INTEGER_enum_map_t *value2enum; /* N -> "tag"; sorted by N */ - unsigned int *enum2value; /* "tag" => N; sorted by tag */ +typedef const struct asn_INTEGER_specifics_s { + const asn_INTEGER_enum_map_t *value2enum; /* N -> "tag"; sorted by N */ + const unsigned int *enum2value; /* "tag" => N; sorted by tag */ int map_count; /* Elements in either map */ int extension; /* This map is extensible */ int strict_enumeration; /* Enumeration set is fixed */ diff --git a/skeletons/NativeEnumerated.c b/skeletons/NativeEnumerated.c index 1554220f..bdf1102c 100644 --- a/skeletons/NativeEnumerated.c +++ b/skeletons/NativeEnumerated.c @@ -145,7 +145,7 @@ NativeEnumerated_encode_uper(asn_TYPE_descriptor_t *td, asn_per_constraint_t *ct; int inext = 0; asn_INTEGER_enum_map_t key; - asn_INTEGER_enum_map_t *kf; + const asn_INTEGER_enum_map_t *kf; if(!sptr) _ASN_ENCODE_FAILED; if(!specs) _ASN_ENCODE_FAILED; diff --git a/skeletons/OCTET_STRING.h b/skeletons/OCTET_STRING.h index 8df9a182..013c7b13 100644 --- a/skeletons/OCTET_STRING.h +++ b/skeletons/OCTET_STRING.h @@ -63,7 +63,7 @@ OCTET_STRING_t *OCTET_STRING_new_fromBuf(asn_TYPE_descriptor_t *td, * Internally useful stuff. * ****************************/ -typedef struct asn_OCTET_STRING_specifics_s { +typedef const struct asn_OCTET_STRING_specifics_s { /* * Target structure description. */ diff --git a/skeletons/constr_CHOICE.c b/skeletons/constr_CHOICE.c index 6b699422..f366f754 100644 --- a/skeletons/constr_CHOICE.c +++ b/skeletons/constr_CHOICE.c @@ -183,11 +183,11 @@ CHOICE_decode_ber(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td, } do { - asn_TYPE_tag2member_t *t2m; + const asn_TYPE_tag2member_t *t2m; asn_TYPE_tag2member_t key; key.el_tag = tlv_tag; - t2m = (asn_TYPE_tag2member_t *)bsearch(&key, + t2m = (const asn_TYPE_tag2member_t *)bsearch(&key, specs->tag2el, specs->tag2el_count, sizeof(specs->tag2el[0]), _search4tag); if(t2m) { diff --git a/skeletons/constr_CHOICE.h b/skeletons/constr_CHOICE.h index 83404e6d..e824a220 100644 --- a/skeletons/constr_CHOICE.h +++ b/skeletons/constr_CHOICE.h @@ -12,7 +12,7 @@ extern "C" { #endif -typedef struct asn_CHOICE_specifics_s { +typedef const struct asn_CHOICE_specifics_s { /* * Target structure description. */ @@ -24,7 +24,7 @@ typedef struct asn_CHOICE_specifics_s { /* * Tags to members mapping table. */ - asn_TYPE_tag2member_t *tag2el; + const asn_TYPE_tag2member_t *tag2el; int tag2el_count; /* Canonical ordering of CHOICE elements, for PER */ diff --git a/skeletons/constr_SEQUENCE.c b/skeletons/constr_SEQUENCE.c index c405a18f..07dcedfb 100644 --- a/skeletons/constr_SEQUENCE.c +++ b/skeletons/constr_SEQUENCE.c @@ -310,16 +310,16 @@ SEQUENCE_decode_ber(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td, * Resort to a binary search over * sorted array of tags. */ - asn_TYPE_tag2member_t *t2m; + const asn_TYPE_tag2member_t *t2m; asn_TYPE_tag2member_t key; key.el_tag = tlv_tag; key.el_no = edx; - t2m = (asn_TYPE_tag2member_t *)bsearch(&key, + t2m = (const asn_TYPE_tag2member_t *)bsearch(&key, specs->tag2el, specs->tag2el_count, sizeof(specs->tag2el[0]), _t2e_cmp); if(t2m) { - asn_TYPE_tag2member_t *best = 0; - asn_TYPE_tag2member_t *t2m_f, *t2m_l; + const asn_TYPE_tag2member_t *best = 0; + const asn_TYPE_tag2member_t *t2m_f, *t2m_l; int edx_max = edx + elements[edx].optional; /* * Rewind to the first element with that tag, diff --git a/skeletons/constr_SEQUENCE.h b/skeletons/constr_SEQUENCE.h index 5f589d5c..c2aeb667 100644 --- a/skeletons/constr_SEQUENCE.h +++ b/skeletons/constr_SEQUENCE.h @@ -11,7 +11,7 @@ extern "C" { #endif -typedef struct asn_SEQUENCE_specifics_s { +typedef const struct asn_SEQUENCE_specifics_s { /* * Target structure description. */ @@ -21,14 +21,14 @@ typedef struct asn_SEQUENCE_specifics_s { /* * Tags to members mapping table (sorted). */ - asn_TYPE_tag2member_t *tag2el; + const asn_TYPE_tag2member_t *tag2el; int tag2el_count; /* * Optional members of the extensions root (roms) or additions (aoms). * Meaningful for PER. */ - int *oms; /* Optional MemberS */ + const int *oms; /* Optional MemberS */ int roms_count; /* Root optional members count */ int aoms_count; /* Additions optional members count */ diff --git a/skeletons/constr_SET.c b/skeletons/constr_SET.c index e8410a88..1fcbc2e4 100644 --- a/skeletons/constr_SET.c +++ b/skeletons/constr_SET.c @@ -175,7 +175,7 @@ SET_decode_ber(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td, * for optimization. */ for(;; ctx->step = 0) { - asn_TYPE_tag2member_t *t2m; + const asn_TYPE_tag2member_t *t2m; asn_TYPE_tag2member_t key; void *memb_ptr; /* Pointer to the member */ void **memb_ptr2; /* Pointer to that pointer */ @@ -225,7 +225,7 @@ SET_decode_ber(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td, } key.el_tag = tlv_tag; - t2m = (asn_TYPE_tag2member_t *)bsearch(&key, + t2m = (const asn_TYPE_tag2member_t *)bsearch(&key, specs->tag2el, specs->tag2el_count, sizeof(specs->tag2el[0]), _t2e_cmp); if(t2m) { @@ -439,7 +439,8 @@ SET_encode_der(asn_TYPE_descriptor_t *td, size_t computed_size = 0; asn_enc_rval_t er; int t2m_build_own = (specs->tag2el_count != td->elements_count); - asn_TYPE_tag2member_t *t2m; + const asn_TYPE_tag2member_t *t2m; + asn_TYPE_tag2member_t *t2m_build; int t2m_count; ssize_t ret; int edx; @@ -448,17 +449,16 @@ SET_encode_der(asn_TYPE_descriptor_t *td, * Use existing, or build our own tags map. */ if(t2m_build_own) { - t2m = (asn_TYPE_tag2member_t *)alloca( - td->elements_count * sizeof(t2m[0])); - if(!t2m) _ASN_ENCODE_FAILED; /* There are such platforms */ + t2m_build = (asn_TYPE_tag2member_t *)alloca( + td->elements_count * sizeof(t2m_build[0])); + if(!t2m_build) _ASN_ENCODE_FAILED; /* There are such platforms */ t2m_count = 0; } else { + t2m_build = NULL; /* * There is no untagged CHOICE in this SET. * Employ existing table. */ - t2m = specs->tag2el; - t2m_count = specs->tag2el_count; } /* @@ -479,8 +479,8 @@ SET_encode_der(asn_TYPE_descriptor_t *td, /* Mandatory elements missing */ _ASN_ENCODE_FAILED; if(t2m_build_own) { - t2m[t2m_count].el_no = edx; - t2m[t2m_count].el_tag = 0; + t2m_build[t2m_count].el_no = edx; + t2m_build[t2m_count].el_tag = 0; t2m_count++; } continue; @@ -499,8 +499,8 @@ SET_encode_der(asn_TYPE_descriptor_t *td, * Remember the outmost tag of this member. */ if(t2m_build_own) { - t2m[t2m_count].el_no = edx; - t2m[t2m_count].el_tag = asn_TYPE_outmost_tag( + t2m_build[t2m_count].el_no = edx; + t2m_build[t2m_count].el_tag = asn_TYPE_outmost_tag( elm->type, memb_ptr, elm->tag_mode, elm->tag); t2m_count++; } else { @@ -513,18 +513,21 @@ SET_encode_der(asn_TYPE_descriptor_t *td, /* * Finalize order of the components. */ - assert(t2m_count == td->elements_count); if(t2m_build_own) { /* * Sort the underlying members according to their * canonical tags order. DER encoding mandates it. */ - qsort(t2m, t2m_count, sizeof(specs->tag2el[0]), _t2e_cmp); + qsort(t2m_build, t2m_count, sizeof(specs->tag2el[0]), _t2e_cmp); + t2m = t2m_build; } else { /* * Tags are already sorted by the compiler. */ + t2m = specs->tag2el; + t2m_count = specs->tag2el_count; } + assert(t2m_count == td->elements_count); /* * Encode the TLV for the sequence itself. @@ -803,7 +806,7 @@ SET_encode_xer(asn_TYPE_descriptor_t *td, void *sptr, asn_SET_specifics_t *specs = (asn_SET_specifics_t *)td->specifics; asn_enc_rval_t er; int xcan = (flags & XER_F_CANONICAL); - asn_TYPE_tag2member_t *t2m = specs->tag2el_cxer; + const asn_TYPE_tag2member_t *t2m = specs->tag2el_cxer; int t2m_count = specs->tag2el_cxer_count; int edx; diff --git a/skeletons/constr_SET.h b/skeletons/constr_SET.h index 0c78ed59..6a3a1aa9 100644 --- a/skeletons/constr_SET.h +++ b/skeletons/constr_SET.h @@ -12,7 +12,7 @@ extern "C" { #endif -typedef struct asn_SET_specifics_s { +typedef const struct asn_SET_specifics_s { /* * Target structure description. */ @@ -25,21 +25,21 @@ typedef struct asn_SET_specifics_s { * Sometimes suitable for DER encoding (untagged CHOICE is present); * if so, tag2el_count will be greater than td->elements_count. */ - asn_TYPE_tag2member_t *tag2el; + const asn_TYPE_tag2member_t *tag2el; int tag2el_count; /* * Tags to members mapping table, second edition. * Suitable for CANONICAL-XER encoding. */ - asn_TYPE_tag2member_t *tag2el_cxer; + const asn_TYPE_tag2member_t *tag2el_cxer; int tag2el_cxer_count; /* * Extensions-related stuff. */ int extensible; /* Whether SET is extensible */ - unsigned int *_mandatory_elements; /* Bitmask of mandatory ones */ + const unsigned int *_mandatory_elements; /* Bitmask of mandatory ones */ } asn_SET_specifics_t; /* diff --git a/skeletons/constr_SET_OF.h b/skeletons/constr_SET_OF.h index bcd09662..75e18cfa 100644 --- a/skeletons/constr_SET_OF.h +++ b/skeletons/constr_SET_OF.h @@ -11,7 +11,7 @@ extern "C" { #endif -typedef struct asn_SET_OF_specifics_s { +typedef const struct asn_SET_OF_specifics_s { /* * Target structure description. */ diff --git a/skeletons/constr_TYPE.h b/skeletons/constr_TYPE.h index 88c88033..a9cd86dc 100644 --- a/skeletons/constr_TYPE.h +++ b/skeletons/constr_TYPE.h @@ -83,8 +83,8 @@ asn_outmost_tag_f asn_TYPE_outmost_tag; * The definitive description of the destination language's structure. */ typedef struct asn_TYPE_descriptor_s { - char *name; /* A name of the ASN.1 type. "" in some cases. */ - char *xml_tag; /* Name used in XML tag */ + const char *name; /* A name of the ASN.1 type. "" in some cases. */ + const char *xml_tag; /* Name used in XML tag */ /* * Generalized functions for dealing with the specific type. @@ -108,10 +108,10 @@ typedef struct asn_TYPE_descriptor_s { * Tags that are expected to occur. */ asn_outmost_tag_f *outmost_tag; /* <optional, internal> */ - ber_tlv_tag_t *tags; /* Effective tags sequence for this type */ - int tags_count; /* Number of tags which are expected */ - ber_tlv_tag_t *all_tags;/* Every tag for BER/containment */ - int all_tags_count; /* Number of tags */ + const ber_tlv_tag_t *tags; /* Effective tags sequence for this type */ + int tags_count; /* Number of tags which are expected */ + const ber_tlv_tag_t *all_tags; /* Every tag for BER/containment */ + int all_tags_count; /* Number of tags */ asn_per_constraints_t *per_constraints; /* PER compiled constraints */ @@ -125,7 +125,7 @@ typedef struct asn_TYPE_descriptor_s { * Additional information describing the type, used by appropriate * functions above. */ - void *specifics; + const void *specifics; } asn_TYPE_descriptor_t; /* @@ -147,7 +147,7 @@ typedef struct asn_TYPE_member_s { asn_constr_check_f *memb_constraints; /* Constraints validator */ asn_per_constraints_t *per_constraints; /* PER compiled constraints */ int (*default_value)(int setval, void **sptr); /* DEFAULT <value> */ - char *name; /* ASN.1 identifier of the element */ + const char *name; /* ASN.1 identifier of the element */ } asn_TYPE_member_t; /* diff --git a/skeletons/der_encoder.c b/skeletons/der_encoder.c index 6c859e1b..1c014802 100644 --- a/skeletons/der_encoder.c +++ b/skeletons/der_encoder.c @@ -80,8 +80,8 @@ der_write_tags(asn_TYPE_descriptor_t *sd, ber_tlv_tag_t tag, /* EXPLICIT or IMPLICIT tag */ asn_app_consume_bytes_f *cb, void *app_key) { - ber_tlv_tag_t *tags; /* Copy of tags stream */ - int tags_count; /* Number of tags */ + const ber_tlv_tag_t *tags; /* Copy of tags stream */ + int tags_count; /* Number of tags */ size_t overall_length; ssize_t *lens; int i; @@ -102,8 +102,9 @@ der_write_tags(asn_TYPE_descriptor_t *sd, * and initialize it appropriately. */ int stag_offset; - tags = (ber_tlv_tag_t *)alloca((sd->tags_count + 1) * sizeof(ber_tlv_tag_t)); - if(!tags) { /* Can fail on !x86 */ + ber_tlv_tag_t *tags_buf; + tags_buf = (ber_tlv_tag_t *)alloca((sd->tags_count + 1) * sizeof(ber_tlv_tag_t)); + if(!tags_buf) { /* Can fail on !x86 */ errno = ENOMEM; return -1; } @@ -111,10 +112,11 @@ der_write_tags(asn_TYPE_descriptor_t *sd, + 1 /* EXPLICIT or IMPLICIT tag is given */ - ((tag_mode == -1) && sd->tags_count); /* Copy tags over */ - tags[0] = tag; + tags_buf[0] = tag; stag_offset = -1 + ((tag_mode == -1) && sd->tags_count); for(i = 1; i < tags_count; i++) - tags[i] = sd->tags[i + stag_offset]; + tags_buf[i] = sd->tags[i + stag_offset]; + tags = tags_buf; } else { tags = sd->tags; tags_count = sd->tags_count; diff --git a/skeletons/tests/check-PER-INTEGER.c b/skeletons/tests/check-PER-INTEGER.c index 0d971b3a..1cb853bf 100644 --- a/skeletons/tests/check-PER-INTEGER.c +++ b/skeletons/tests/check-PER-INTEGER.c @@ -24,7 +24,7 @@ static void check_per_encode_constrained(int lineno, int unsigned_, long value, long lbound, unsigned long ubound, int bit_range) { INTEGER_t st; INTEGER_t *reconstructed_st = 0; - asn_INTEGER_specifics_t specs; + struct asn_INTEGER_specifics_s specs; asn_per_constraints_t cts; asn_enc_rval_t enc_rval; asn_dec_rval_t dec_rval; |