From a73ae673f08cab3efb709ba0ba649ef1e7a59cb9 Mon Sep 17 00:00:00 2001 From: Wim Lewis Date: Tue, 22 Jul 2014 19:55:30 -0700 Subject: Declare the permitted alphabet tables and code2value tables const. --- libasn1compiler/asn1c_constraint.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libasn1compiler/asn1c_constraint.c b/libasn1compiler/asn1c_constraint.c index bdabfff0..6fe896f9 100644 --- a/libasn1compiler/asn1c_constraint.c +++ b/libasn1compiler/asn1c_constraint.c @@ -315,7 +315,7 @@ asn1c_emit_constraint_tables(arg_t *arg, int got_size) { untl = (range_stop - range_start) + 1; untl += (untl % 16)?16 - (untl % 16):0; - OUT("static int permitted_alphabet_table_%d[%d] = {\n", + OUT("static const int permitted_alphabet_table_%d[%d] = {\n", arg->expr->_type_unique_index, max_table_size); for(n = 0; n < untl; n++) { cardinal += table[n] ? 1 : 0; @@ -347,7 +347,7 @@ asn1c_emit_constraint_tables(arg_t *arg, int got_size) { if((arg->flags & A1C_GEN_PER) && (etype & ASN_STRING_KM_MASK)) { int c; - OUT("static int permitted_alphabet_code2value_%d[%d] = {\n", + OUT("static const int permitted_alphabet_code2value_%d[%d] = {\n", arg->expr->_type_unique_index, cardinal); for(n = c = 0; c < max_table_size; c++) { if(table[c]) { @@ -396,7 +396,7 @@ asn1c_emit_constraint_tables(arg_t *arg, int got_size) { OUT("\n"); } else { if(use_table) { - OUT("int *table = permitted_alphabet_table_%d;\n", + OUT("const int *table = permitted_alphabet_table_%d;\n", arg->expr->_type_unique_index); emit_alphabet_check_loop(arg, 0); } else { -- cgit v1.2.3 From 14e6b161463b8d256d4ab4aac5d0d8c63c0819cd Mon Sep 17 00:00:00 2001 From: Wim Lewis Date: Wed, 23 Jul 2014 16:06:01 -0700 Subject: Declare the type descriptor and input buffer args of some functions as const. --- skeletons/INTEGER.c | 2 +- skeletons/OBJECT_IDENTIFIER.c | 10 +++++----- skeletons/OBJECT_IDENTIFIER.h | 8 ++++---- skeletons/RELATIVE-OID.c | 2 +- skeletons/RELATIVE-OID.h | 2 +- skeletons/constr_CHOICE.c | 4 ++-- skeletons/constr_TYPE.c | 2 +- skeletons/constr_TYPE.h | 2 +- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/skeletons/INTEGER.c b/skeletons/INTEGER.c index 38ddb60b..2ddb5c7f 100644 --- a/skeletons/INTEGER.c +++ b/skeletons/INTEGER.c @@ -106,7 +106,7 @@ static const asn_INTEGER_enum_map_t *INTEGER_map_enum2value(asn_INTEGER_specific * INTEGER specific human-readable output. */ static ssize_t -INTEGER__dump(asn_TYPE_descriptor_t *td, const INTEGER_t *st, asn_app_consume_bytes_f *cb, void *app_key, int plainOrXER) { +INTEGER__dump(const asn_TYPE_descriptor_t *td, const INTEGER_t *st, asn_app_consume_bytes_f *cb, void *app_key, int plainOrXER) { asn_INTEGER_specifics_t *specs=(asn_INTEGER_specifics_t *)td->specifics; char scratch[32]; /* Enough for 64-bit integer */ uint8_t *buf = st->buf; diff --git a/skeletons/OBJECT_IDENTIFIER.c b/skeletons/OBJECT_IDENTIFIER.c index aece31b0..84988832 100644 --- a/skeletons/OBJECT_IDENTIFIER.c +++ b/skeletons/OBJECT_IDENTIFIER.c @@ -65,9 +65,9 @@ OBJECT_IDENTIFIER_constraint(asn_TYPE_descriptor_t *td, const void *sptr, int -OBJECT_IDENTIFIER_get_single_arc(uint8_t *arcbuf, unsigned int arclen, signed int add, void *rvbufp, unsigned int rvsize) { +OBJECT_IDENTIFIER_get_single_arc(const uint8_t *arcbuf, unsigned int arclen, signed int add, void *rvbufp, unsigned int rvsize) { unsigned LE GCC_NOTUSED = 1; /* Little endian (x86) */ - uint8_t *arcend = arcbuf + arclen; /* End of arc */ + const uint8_t *arcend = arcbuf + arclen; /* End of arc */ unsigned int cache = 0; /* No more than 14 significant bits */ unsigned char *rvbuf = (unsigned char *)rvbufp; unsigned char *rvstart = rvbuf; /* Original start of the value buffer */ @@ -181,7 +181,7 @@ OBJECT_IDENTIFIER_get_single_arc(uint8_t *arcbuf, unsigned int arclen, signed in } ssize_t -OBJECT_IDENTIFIER__dump_arc(uint8_t *arcbuf, int arclen, int add, +OBJECT_IDENTIFIER__dump_arc(const uint8_t *arcbuf, int arclen, int add, asn_app_consume_bytes_f *cb, void *app_key) { char scratch[64]; /* Conservative estimate */ unsigned long accum; /* Bits accumulator */ @@ -212,7 +212,7 @@ OBJECT_IDENTIFIER__dump_arc(uint8_t *arcbuf, int arclen, int add, } int -OBJECT_IDENTIFIER_print_arc(uint8_t *arcbuf, int arclen, int add, +OBJECT_IDENTIFIER_print_arc(const uint8_t *arcbuf, int arclen, int add, asn_app_consume_bytes_f *cb, void *app_key) { if(OBJECT_IDENTIFIER__dump_arc(arcbuf, arclen, add, cb, app_key) < 0) @@ -360,7 +360,7 @@ OBJECT_IDENTIFIER_print(asn_TYPE_descriptor_t *td, const void *sptr, } int -OBJECT_IDENTIFIER_get_arcs(OBJECT_IDENTIFIER_t *oid, void *arcs, +OBJECT_IDENTIFIER_get_arcs(const OBJECT_IDENTIFIER_t *oid, void *arcs, unsigned int arc_type_size, unsigned int arc_slots) { void *arcs_end = (char *)arcs + (arc_type_size * arc_slots); int num_arcs = 0; diff --git a/skeletons/OBJECT_IDENTIFIER.h b/skeletons/OBJECT_IDENTIFIER.h index 2bb5d032..c2c6373e 100644 --- a/skeletons/OBJECT_IDENTIFIER.h +++ b/skeletons/OBJECT_IDENTIFIER.h @@ -68,7 +68,7 @@ xer_type_encoder_f OBJECT_IDENTIFIER_encode_xer; * WARNING: The function always returns the real number of arcs, * even if there is no sufficient (_arc_slots) provided. */ -int OBJECT_IDENTIFIER_get_arcs(OBJECT_IDENTIFIER_t *_oid, +int OBJECT_IDENTIFIER_get_arcs(const OBJECT_IDENTIFIER_t *_oid, void *_arcs, /* e.g., unsigned int arcs[N] */ unsigned int _arc_type_size, /* e.g., sizeof(arcs[0]) */ unsigned int _arc_slots /* e.g., N */); @@ -91,12 +91,12 @@ int OBJECT_IDENTIFIER_set_arcs(OBJECT_IDENTIFIER_t *_oid, /* * Print the specified OBJECT IDENTIFIER arc. */ -int OBJECT_IDENTIFIER_print_arc(uint8_t *arcbuf, int arclen, +int OBJECT_IDENTIFIER_print_arc(const uint8_t *arcbuf, int arclen, int add, /* Arbitrary offset, required to process the first two arcs */ asn_app_consume_bytes_f *cb, void *app_key); /* Same as above, but returns the number of written digits, instead of 0 */ -ssize_t OBJECT_IDENTIFIER__dump_arc(uint8_t *arcbuf, int arclen, int add, +ssize_t OBJECT_IDENTIFIER__dump_arc(const uint8_t *arcbuf, int arclen, int add, asn_app_consume_bytes_f *cb, void *app_key); /* @@ -127,7 +127,7 @@ int OBJECT_IDENTIFIER_parse_arcs(const char *oid_text, ssize_t oid_txt_length, * Internal functions. * Used by RELATIVE-OID implementation in particular. */ -int OBJECT_IDENTIFIER_get_single_arc(uint8_t *arcbuf, unsigned int arclen, +int OBJECT_IDENTIFIER_get_single_arc(const uint8_t *arcbuf, unsigned int arclen, signed int add, void *value, unsigned int value_size); int OBJECT_IDENTIFIER_set_single_arc(uint8_t *arcbuf, const void *arcval, unsigned int arcval_size, int _prepared_order); diff --git a/skeletons/RELATIVE-OID.c b/skeletons/RELATIVE-OID.c index 4275c0ab..5f4ad4a4 100644 --- a/skeletons/RELATIVE-OID.c +++ b/skeletons/RELATIVE-OID.c @@ -162,7 +162,7 @@ RELATIVE_OID_encode_xer(asn_TYPE_descriptor_t *td, void *sptr, } int -RELATIVE_OID_get_arcs(RELATIVE_OID_t *roid, +RELATIVE_OID_get_arcs(const RELATIVE_OID_t *roid, void *arcs, unsigned int arc_type_size, unsigned int arc_slots) { void *arcs_end = (char *)arcs + (arc_slots * arc_type_size); int num_arcs = 0; diff --git a/skeletons/RELATIVE-OID.h b/skeletons/RELATIVE-OID.h index 2235cfdd..65acaab4 100644 --- a/skeletons/RELATIVE-OID.h +++ b/skeletons/RELATIVE-OID.h @@ -25,7 +25,7 @@ xer_type_encoder_f RELATIVE_OID_encode_xer; **********************************/ /* See OBJECT_IDENTIFIER_get_arcs() function in OBJECT_IDENTIFIER.h */ -int RELATIVE_OID_get_arcs(RELATIVE_OID_t *_roid, +int RELATIVE_OID_get_arcs(const RELATIVE_OID_t *_roid, void *arcs, unsigned int arc_type_size, unsigned int arc_slots); /* See OBJECT_IDENTIFIER_set_arcs() function in OBJECT_IDENTIFIER.h */ diff --git a/skeletons/constr_CHOICE.c b/skeletons/constr_CHOICE.c index 5a1e0d38..6b699422 100644 --- a/skeletons/constr_CHOICE.c +++ b/skeletons/constr_CHOICE.c @@ -445,7 +445,7 @@ CHOICE_encode_der(asn_TYPE_descriptor_t *td, void *sptr, } ber_tlv_tag_t -CHOICE_outmost_tag(asn_TYPE_descriptor_t *td, const void *ptr, int tag_mode, ber_tlv_tag_t tag) { +CHOICE_outmost_tag(const asn_TYPE_descriptor_t *td, const void *ptr, int tag_mode, ber_tlv_tag_t tag) { asn_CHOICE_specifics_t *specs = (asn_CHOICE_specifics_t *)td->specifics; int present; @@ -458,7 +458,7 @@ CHOICE_outmost_tag(asn_TYPE_descriptor_t *td, const void *ptr, int tag_mode, ber present = _fetch_present_idx(ptr, specs->pres_offset, specs->pres_size); if(present > 0 || present <= td->elements_count) { - asn_TYPE_member_t *elm = &td->elements[present-1]; + const asn_TYPE_member_t *elm = &td->elements[present-1]; const void *memb_ptr; if(elm->flags & ATF_POINTER) { diff --git a/skeletons/constr_TYPE.c b/skeletons/constr_TYPE.c index 4bc88d44..322f68c8 100644 --- a/skeletons/constr_TYPE.c +++ b/skeletons/constr_TYPE.c @@ -17,7 +17,7 @@ static asn_app_consume_bytes_f _print2fp; * Return the outmost tag of the type. */ ber_tlv_tag_t -asn_TYPE_outmost_tag(asn_TYPE_descriptor_t *type_descriptor, +asn_TYPE_outmost_tag(const asn_TYPE_descriptor_t *type_descriptor, const void *struct_ptr, int tag_mode, ber_tlv_tag_t tag) { if(tag_mode) diff --git a/skeletons/constr_TYPE.h b/skeletons/constr_TYPE.h index 95507c80..88c88033 100644 --- a/skeletons/constr_TYPE.h +++ b/skeletons/constr_TYPE.h @@ -73,7 +73,7 @@ typedef int (asn_struct_print_f)( * Do not use it in your application. */ typedef ber_tlv_tag_t (asn_outmost_tag_f)( - struct asn_TYPE_descriptor_s *type_descriptor, + const struct asn_TYPE_descriptor_s *type_descriptor, const void *struct_ptr, int tag_mode, ber_tlv_tag_t tag); /* The instance of the above function type; used internally. */ asn_outmost_tag_f asn_TYPE_outmost_tag; -- cgit v1.2.3 From fb6344ef750a4d822ecd613819deba89b181b932 Mon Sep 17 00:00:00 2001 From: Wim Lewis Date: Mon, 28 Jul 2014 12:16:01 -0700 Subject: Declare most internal, constant tables as const, particularly the "specifics" structures and the tables they point to. --- libasn1compiler/asn1c_C.c | 18 +++++++++--------- skeletons/INTEGER.c | 6 +++--- skeletons/INTEGER.h | 6 +++--- skeletons/NativeEnumerated.c | 2 +- skeletons/OCTET_STRING.h | 2 +- skeletons/constr_CHOICE.c | 4 ++-- skeletons/constr_CHOICE.h | 4 ++-- skeletons/constr_SEQUENCE.c | 8 ++++---- skeletons/constr_SEQUENCE.h | 6 +++--- skeletons/constr_SET.c | 33 ++++++++++++++++++--------------- skeletons/constr_SET.h | 8 ++++---- skeletons/constr_SET_OF.h | 2 +- skeletons/constr_TYPE.h | 16 ++++++++-------- skeletons/der_encoder.c | 14 ++++++++------ skeletons/tests/check-PER-INTEGER.c | 2 +- 15 files changed, 68 insertions(+), 63 deletions(-) diff --git a/libasn1compiler/asn1c_C.c b/libasn1compiler/asn1c_C.c index 6fa6ad30..d49fd3fe 100644 --- a/libasn1compiler/asn1c_C.c +++ b/libasn1compiler/asn1c_C.c @@ -175,7 +175,7 @@ asn1c_lang_C_type_common_INTEGER(arg_t *arg) { */ REDIR(OT_STAT_DEFS); - OUT("static asn_INTEGER_enum_map_t asn_MAP_%s_value2enum_%d[] = {\n", + OUT("static const asn_INTEGER_enum_map_t asn_MAP_%s_value2enum_%d[] = {\n", MKID(expr), expr->_type_unique_index); qsort(v2e, el_count, sizeof(v2e[0]), compar_enumMap_byValue); for(eidx = 0; eidx < el_count; eidx++) { @@ -189,7 +189,7 @@ asn1c_lang_C_type_common_INTEGER(arg_t *arg) { OUT("\t/* This list is extensible */\n"); OUT("};\n"); - OUT("static unsigned int asn_MAP_%s_enum2value_%d[] = {\n", + OUT("static const unsigned int asn_MAP_%s_enum2value_%d[] = {\n", MKID(expr), expr->_type_unique_index); qsort(v2e, el_count, sizeof(v2e[0]), compar_enumMap_byName); for(eidx = 0; eidx < el_count; eidx++) { @@ -202,7 +202,7 @@ asn1c_lang_C_type_common_INTEGER(arg_t *arg) { OUT("\t/* This list is extensible */\n"); OUT("};\n"); - OUT("static asn_INTEGER_specifics_t asn_SPC_%s_specs_%d = {\n", + OUT("static const asn_INTEGER_specifics_t asn_SPC_%s_specs_%d = {\n", MKID(expr), expr->_type_unique_index); INDENT(+1); OUT("asn_MAP_%s_value2enum_%d,\t" @@ -234,7 +234,7 @@ asn1c_lang_C_type_common_INTEGER(arg_t *arg) { if(expr->expr_type == ASN_BASIC_INTEGER && asn1c_type_fits_long(arg, expr) == FL_FITS_UNSIGN) { REDIR(OT_STAT_DEFS); - OUT("static asn_INTEGER_specifics_t asn_SPC_%s_specs_%d = {\n", + OUT("static const asn_INTEGER_specifics_t asn_SPC_%s_specs_%d = {\n", MKID(expr), expr->_type_unique_index); INDENT(+1); OUT("0,\t"); @@ -383,7 +383,7 @@ asn1c_lang_C_type_SEQUENCE_def(arg_t *arg) { int elm = 0; int comma = 0; comp_mode = 0; - OUT("static int asn_MAP_%s_oms_%d[] = {", + OUT("static const int asn_MAP_%s_oms_%d[] = {", MKID(expr), expr->_type_unique_index); TQ_FOR(v, &(expr->members), next) { @@ -628,7 +628,7 @@ asn1c_lang_C_type_SET_def(arg_t *arg) { /* * Emit a map of mandatory elements. */ - OUT("static uint8_t asn_MAP_%s_mmap_%d", + OUT("static const uint8_t asn_MAP_%s_mmap_%d", MKID(expr), expr->_type_unique_index); p = MKID_safe(expr); OUT("[(%d + (8 * sizeof(unsigned int)) - 1) / 8]", elements); @@ -964,7 +964,7 @@ asn1c_lang_C_type_CHOICE_def(arg_t *arg) { int i; cmap = compute_canonical_members_order(arg, elements); if(cmap) { - OUT("static int asn_MAP_%s_cmap_%d[] = {", + OUT("static const int asn_MAP_%s_cmap_%d[] = {", MKID(expr), expr->_type_unique_index); for(i = 0; i < elements; i++) { @@ -1661,7 +1661,7 @@ emit_tag2member_map(arg_t *arg, tag2el_t *tag2el, int tag2el_count, const char * if(!tag2el_count) return 0; /* No top level tags */ - OUT("static asn_TYPE_tag2member_t asn_MAP_%s_tag2el%s_%d[] = {\n", + OUT("static const asn_TYPE_tag2member_t asn_MAP_%s_tag2el%s_%d[] = {\n", MKID(expr), opt_modifier?opt_modifier:"", expr->_type_unique_index); for(i = 0; i < tag2el_count; i++) { @@ -1730,7 +1730,7 @@ emit_tags_vectors(arg_t *arg, asn1p_expr_t *expr, int *tags_count_r, int *all_ta } #define EMIT_TAGS_TABLE(name, tags, tags_count) do { \ - OUT("static ber_tlv_tag_t asn_DEF_%s%s_tags_%d[] = {\n",\ + OUT("static const ber_tlv_tag_t asn_DEF_%s%s_tags_%d[] = {\n",\ MKID(expr), name, \ expr->_type_unique_index); \ INDENT(+1); \ 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; /* */ - 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 */ - 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; -- cgit v1.2.3 From 18c2ec9f1dfdc565dc8c6a1a9d826f5f9a5861b7 Mon Sep 17 00:00:00 2001 From: Wim Lewis Date: Tue, 29 Jul 2014 11:30:10 -0700 Subject: Declare the tags[] tables in skeletons as const. Constify the PER support structure. Constify a few other private tables in the skeleton code. --- skeletons/BIT_STRING.c | 2 +- skeletons/BMPString.c | 2 +- skeletons/BOOLEAN.c | 2 +- skeletons/ENUMERATED.c | 2 +- skeletons/GeneralString.c | 2 +- skeletons/GeneralizedTime.c | 2 +- skeletons/GraphicString.c | 2 +- skeletons/IA5String.c | 2 +- skeletons/INTEGER.c | 2 +- skeletons/ISO646String.c | 2 +- skeletons/NULL.c | 2 +- skeletons/NativeEnumerated.c | 2 +- skeletons/NativeInteger.c | 2 +- skeletons/NativeReal.c | 2 +- skeletons/NumericString.c | 2 +- skeletons/OBJECT_IDENTIFIER.c | 2 +- skeletons/OCTET_STRING.c | 12 ++++++------ skeletons/ObjectDescriptor.c | 2 +- skeletons/PrintableString.c | 8 ++++---- skeletons/REAL.c | 2 +- skeletons/RELATIVE-OID.c | 2 +- skeletons/T61String.c | 2 +- skeletons/TeletexString.c | 2 +- skeletons/UTCTime.c | 2 +- skeletons/UTF8String.c | 6 +++--- skeletons/UniversalString.c | 2 +- skeletons/VideotexString.c | 2 +- skeletons/VisibleString.c | 2 +- skeletons/per_support.h | 8 ++++---- skeletons/tests/check-PER-INTEGER.c | 2 +- skeletons/xer_support.c | 2 +- 31 files changed, 44 insertions(+), 44 deletions(-) diff --git a/skeletons/BIT_STRING.c b/skeletons/BIT_STRING.c index 9b982712..9bf47f09 100644 --- a/skeletons/BIT_STRING.c +++ b/skeletons/BIT_STRING.c @@ -9,7 +9,7 @@ /* * BIT STRING basic type description. */ -static ber_tlv_tag_t asn_DEF_BIT_STRING_tags[] = { +static const ber_tlv_tag_t asn_DEF_BIT_STRING_tags[] = { (ASN_TAG_CLASS_UNIVERSAL | (3 << 2)) }; static asn_OCTET_STRING_specifics_t asn_DEF_BIT_STRING_specs = { diff --git a/skeletons/BMPString.c b/skeletons/BMPString.c index 1aa8e511..458622cd 100644 --- a/skeletons/BMPString.c +++ b/skeletons/BMPString.c @@ -9,7 +9,7 @@ /* * BMPString basic type description. */ -static ber_tlv_tag_t asn_DEF_BMPString_tags[] = { +static const ber_tlv_tag_t asn_DEF_BMPString_tags[] = { (ASN_TAG_CLASS_UNIVERSAL | (30 << 2)), /* [UNIVERSAL 30] IMPLICIT ...*/ (ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) /* ... OCTET STRING */ }; diff --git a/skeletons/BOOLEAN.c b/skeletons/BOOLEAN.c index 1b74ea1c..2ba07840 100644 --- a/skeletons/BOOLEAN.c +++ b/skeletons/BOOLEAN.c @@ -9,7 +9,7 @@ /* * BOOLEAN basic type description. */ -static ber_tlv_tag_t asn_DEF_BOOLEAN_tags[] = { +static const ber_tlv_tag_t asn_DEF_BOOLEAN_tags[] = { (ASN_TAG_CLASS_UNIVERSAL | (1 << 2)) }; asn_TYPE_descriptor_t asn_DEF_BOOLEAN = { diff --git a/skeletons/ENUMERATED.c b/skeletons/ENUMERATED.c index 90761a2d..045554bb 100644 --- a/skeletons/ENUMERATED.c +++ b/skeletons/ENUMERATED.c @@ -11,7 +11,7 @@ /* * ENUMERATED basic type description. */ -static ber_tlv_tag_t asn_DEF_ENUMERATED_tags[] = { +static const ber_tlv_tag_t asn_DEF_ENUMERATED_tags[] = { (ASN_TAG_CLASS_UNIVERSAL | (10 << 2)) }; asn_TYPE_descriptor_t asn_DEF_ENUMERATED = { diff --git a/skeletons/GeneralString.c b/skeletons/GeneralString.c index 01b606be..c398d2b3 100644 --- a/skeletons/GeneralString.c +++ b/skeletons/GeneralString.c @@ -8,7 +8,7 @@ /* * GeneralString basic type description. */ -static ber_tlv_tag_t asn_DEF_GeneralString_tags[] = { +static const ber_tlv_tag_t asn_DEF_GeneralString_tags[] = { (ASN_TAG_CLASS_UNIVERSAL | (27 << 2)), /* [UNIVERSAL 27] IMPLICIT ...*/ (ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) /* ... OCTET STRING */ }; diff --git a/skeletons/GeneralizedTime.c b/skeletons/GeneralizedTime.c index 4b0ae5d4..9331cc70 100644 --- a/skeletons/GeneralizedTime.c +++ b/skeletons/GeneralizedTime.c @@ -145,7 +145,7 @@ static time_t timegm(struct tm *tm) { /* * GeneralizedTime basic type description. */ -static ber_tlv_tag_t asn_DEF_GeneralizedTime_tags[] = { +static const ber_tlv_tag_t asn_DEF_GeneralizedTime_tags[] = { (ASN_TAG_CLASS_UNIVERSAL | (24 << 2)), /* [UNIVERSAL 24] IMPLICIT ...*/ (ASN_TAG_CLASS_UNIVERSAL | (26 << 2)), /* [UNIVERSAL 26] IMPLICIT ...*/ (ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) /* ... OCTET STRING */ diff --git a/skeletons/GraphicString.c b/skeletons/GraphicString.c index 7d59d522..e572ccdf 100644 --- a/skeletons/GraphicString.c +++ b/skeletons/GraphicString.c @@ -8,7 +8,7 @@ /* * GraphicString basic type description. */ -static ber_tlv_tag_t asn_DEF_GraphicString_tags[] = { +static const ber_tlv_tag_t asn_DEF_GraphicString_tags[] = { (ASN_TAG_CLASS_UNIVERSAL | (25 << 2)), /* [UNIVERSAL 25] IMPLICIT ...*/ (ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) /* ... OCTET STRING */ }; diff --git a/skeletons/IA5String.c b/skeletons/IA5String.c index 02ecd3ee..0fdc0748 100644 --- a/skeletons/IA5String.c +++ b/skeletons/IA5String.c @@ -8,7 +8,7 @@ /* * IA5String basic type description. */ -static ber_tlv_tag_t asn_DEF_IA5String_tags[] = { +static const ber_tlv_tag_t asn_DEF_IA5String_tags[] = { (ASN_TAG_CLASS_UNIVERSAL | (22 << 2)), /* [UNIVERSAL 22] IMPLICIT ...*/ (ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) /* ... OCTET STRING */ }; diff --git a/skeletons/INTEGER.c b/skeletons/INTEGER.c index c9211c3f..4295a164 100644 --- a/skeletons/INTEGER.c +++ b/skeletons/INTEGER.c @@ -11,7 +11,7 @@ /* * INTEGER basic type description. */ -static ber_tlv_tag_t asn_DEF_INTEGER_tags[] = { +static const ber_tlv_tag_t asn_DEF_INTEGER_tags[] = { (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)) }; asn_TYPE_descriptor_t asn_DEF_INTEGER = { diff --git a/skeletons/ISO646String.c b/skeletons/ISO646String.c index d6ded0ef..8d681c82 100644 --- a/skeletons/ISO646String.c +++ b/skeletons/ISO646String.c @@ -8,7 +8,7 @@ /* * ISO646String basic type description. */ -static ber_tlv_tag_t asn_DEF_ISO646String_tags[] = { +static const ber_tlv_tag_t asn_DEF_ISO646String_tags[] = { (ASN_TAG_CLASS_UNIVERSAL | (26 << 2)), /* [UNIVERSAL 26] IMPLICIT ...*/ (ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) /* ... OCTET STRING */ }; diff --git a/skeletons/NULL.c b/skeletons/NULL.c index 02c0de06..8dcb6aa9 100644 --- a/skeletons/NULL.c +++ b/skeletons/NULL.c @@ -10,7 +10,7 @@ /* * NULL basic type description. */ -static ber_tlv_tag_t asn_DEF_NULL_tags[] = { +static const ber_tlv_tag_t asn_DEF_NULL_tags[] = { (ASN_TAG_CLASS_UNIVERSAL | (5 << 2)) }; asn_TYPE_descriptor_t asn_DEF_NULL = { diff --git a/skeletons/NativeEnumerated.c b/skeletons/NativeEnumerated.c index bdf1102c..ecf66d1b 100644 --- a/skeletons/NativeEnumerated.c +++ b/skeletons/NativeEnumerated.c @@ -15,7 +15,7 @@ /* * NativeEnumerated basic type description. */ -static ber_tlv_tag_t asn_DEF_NativeEnumerated_tags[] = { +static const ber_tlv_tag_t asn_DEF_NativeEnumerated_tags[] = { (ASN_TAG_CLASS_UNIVERSAL | (10 << 2)) }; asn_TYPE_descriptor_t asn_DEF_NativeEnumerated = { diff --git a/skeletons/NativeInteger.c b/skeletons/NativeInteger.c index cffd0be8..7f8e9276 100644 --- a/skeletons/NativeInteger.c +++ b/skeletons/NativeInteger.c @@ -16,7 +16,7 @@ /* * NativeInteger basic type description. */ -static ber_tlv_tag_t asn_DEF_NativeInteger_tags[] = { +static const ber_tlv_tag_t asn_DEF_NativeInteger_tags[] = { (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)) }; asn_TYPE_descriptor_t asn_DEF_NativeInteger = { diff --git a/skeletons/NativeReal.c b/skeletons/NativeReal.c index 605ecb05..3fd51a4c 100644 --- a/skeletons/NativeReal.c +++ b/skeletons/NativeReal.c @@ -17,7 +17,7 @@ /* * NativeReal basic type description. */ -static ber_tlv_tag_t asn_DEF_NativeReal_tags[] = { +static const ber_tlv_tag_t asn_DEF_NativeReal_tags[] = { (ASN_TAG_CLASS_UNIVERSAL | (9 << 2)) }; asn_TYPE_descriptor_t asn_DEF_NativeReal = { diff --git a/skeletons/NumericString.c b/skeletons/NumericString.c index 50fe4491..b669f571 100644 --- a/skeletons/NumericString.c +++ b/skeletons/NumericString.c @@ -8,7 +8,7 @@ /* * NumericString basic type description. */ -static ber_tlv_tag_t asn_DEF_NumericString_tags[] = { +static const ber_tlv_tag_t asn_DEF_NumericString_tags[] = { (ASN_TAG_CLASS_UNIVERSAL | (18 << 2)), /* [UNIVERSAL 18] IMPLICIT ...*/ (ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) /* ... OCTET STRING */ }; diff --git a/skeletons/OBJECT_IDENTIFIER.c b/skeletons/OBJECT_IDENTIFIER.c index 84988832..03bfc033 100644 --- a/skeletons/OBJECT_IDENTIFIER.c +++ b/skeletons/OBJECT_IDENTIFIER.c @@ -12,7 +12,7 @@ /* * OBJECT IDENTIFIER basic type description. */ -static ber_tlv_tag_t asn_DEF_OBJECT_IDENTIFIER_tags[] = { +static const ber_tlv_tag_t asn_DEF_OBJECT_IDENTIFIER_tags[] = { (ASN_TAG_CLASS_UNIVERSAL | (6 << 2)) }; asn_TYPE_descriptor_t asn_DEF_OBJECT_IDENTIFIER = { diff --git a/skeletons/OCTET_STRING.c b/skeletons/OCTET_STRING.c index f2eec13a..0356c9ca 100644 --- a/skeletons/OCTET_STRING.c +++ b/skeletons/OCTET_STRING.c @@ -11,15 +11,15 @@ /* * OCTET STRING basic type description. */ -static ber_tlv_tag_t asn_DEF_OCTET_STRING_tags[] = { +static const ber_tlv_tag_t asn_DEF_OCTET_STRING_tags[] = { (ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) }; -static asn_OCTET_STRING_specifics_t asn_DEF_OCTET_STRING_specs = { +static const asn_OCTET_STRING_specifics_t asn_DEF_OCTET_STRING_specs = { sizeof(OCTET_STRING_t), offsetof(OCTET_STRING_t, _asn_ctx), ASN_OSUBV_STR }; -static asn_per_constraints_t asn_DEF_OCTET_STRING_constraints = { +static const asn_per_constraints_t asn_DEF_OCTET_STRING_constraints = { { APC_CONSTRAINED, 8, 8, 0, 255 }, { APC_SEMI_CONSTRAINED, -1, -1, 0, 0 }, 0, 0 @@ -639,8 +639,8 @@ cb_failed: _ASN_ENCODE_FAILED; } -static struct OCTET_STRING__xer_escape_table_s { - char *string; +static const struct OCTET_STRING__xer_escape_table_s { + const char *string; int size; } OCTET_STRING__xer_escape_table[] = { #define OSXET(s) { s, sizeof(s) - 1 } @@ -702,7 +702,7 @@ OS__check_escaped_control_char(const void *buf, int size) { * nested table lookups). */ for(i = 0; i < 32 /* Don't spend time on the bottom half */; i++) { - struct OCTET_STRING__xer_escape_table_s *el; + const struct OCTET_STRING__xer_escape_table_s *el; el = &OCTET_STRING__xer_escape_table[i]; if(el->size == size && memcmp(buf, el->string, size) == 0) return i; diff --git a/skeletons/ObjectDescriptor.c b/skeletons/ObjectDescriptor.c index cd8e8a38..31bc1b2c 100644 --- a/skeletons/ObjectDescriptor.c +++ b/skeletons/ObjectDescriptor.c @@ -8,7 +8,7 @@ /* * ObjectDescriptor basic type description. */ -static ber_tlv_tag_t asn_DEF_ObjectDescriptor_tags[] = { +static const ber_tlv_tag_t asn_DEF_ObjectDescriptor_tags[] = { (ASN_TAG_CLASS_UNIVERSAL | (7 << 2)), /* [UNIVERSAL 7] IMPLICIT ... */ (ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) /* ... OCTET STRING */ }; diff --git a/skeletons/PrintableString.c b/skeletons/PrintableString.c index c8ee3ae3..173d7758 100644 --- a/skeletons/PrintableString.c +++ b/skeletons/PrintableString.c @@ -9,7 +9,7 @@ /* * ASN.1:1984 (X.409) */ -static int _PrintableString_alphabet[256] = { +static const int _PrintableString_alphabet[256] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */ 1, 0, 0, 0, 0, 0, 0, 2, 3, 4, 0, 5, 6, 7, 8, 9, /* . '() +,-./ */ @@ -19,7 +19,7 @@ static int _PrintableString_alphabet[256] = { 0,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63, /* abcdefghijklmno */ 64,65,66,67,68,69,70,71,72,73,74, 0, 0, 0, 0, 0, /* pqrstuvwxyz */ }; -static int _PrintableString_code2value[74] = { +static const int _PrintableString_code2value[74] = { 32,39,40,41,43,44,45,46,47,48,49,50,51,52,53,54, 55,56,57,58,61,63,65,66,67,68,69,70,71,72,73,74, 75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90, @@ -29,7 +29,7 @@ static int _PrintableString_code2value[74] = { /* * PrintableString basic type description. */ -static ber_tlv_tag_t asn_DEF_PrintableString_tags[] = { +static const ber_tlv_tag_t asn_DEF_PrintableString_tags[] = { (ASN_TAG_CLASS_UNIVERSAL | (19 << 2)), /* [UNIVERSAL 19] IMPLICIT ...*/ (ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) /* ... OCTET STRING */ }; @@ -41,7 +41,7 @@ static int asn_DEF_PrintableString_c2v(unsigned int code) { return _PrintableString_code2value[code]; return -1; } -static asn_per_constraints_t asn_DEF_PrintableString_constraints = { +static const asn_per_constraints_t asn_DEF_PrintableString_constraints = { { APC_CONSTRAINED, 4, 4, 0x20, 0x39 }, /* Value */ { APC_SEMI_CONSTRAINED, -1, -1, 0, 0 }, /* Size */ asn_DEF_PrintableString_v2c, diff --git a/skeletons/REAL.c b/skeletons/REAL.c index 1b8e30cf..1212050c 100644 --- a/skeletons/REAL.c +++ b/skeletons/REAL.c @@ -36,7 +36,7 @@ static volatile double real_zero GCC_NOTUSED = 0.0; /* * REAL basic type description. */ -static ber_tlv_tag_t asn_DEF_REAL_tags[] = { +static const ber_tlv_tag_t asn_DEF_REAL_tags[] = { (ASN_TAG_CLASS_UNIVERSAL | (9 << 2)) }; asn_TYPE_descriptor_t asn_DEF_REAL = { diff --git a/skeletons/RELATIVE-OID.c b/skeletons/RELATIVE-OID.c index 5f4ad4a4..44f27587 100644 --- a/skeletons/RELATIVE-OID.c +++ b/skeletons/RELATIVE-OID.c @@ -13,7 +13,7 @@ /* * RELATIVE-OID basic type description. */ -static ber_tlv_tag_t asn_DEF_RELATIVE_OID_tags[] = { +static const ber_tlv_tag_t asn_DEF_RELATIVE_OID_tags[] = { (ASN_TAG_CLASS_UNIVERSAL | (13 << 2)) }; asn_TYPE_descriptor_t asn_DEF_RELATIVE_OID = { diff --git a/skeletons/T61String.c b/skeletons/T61String.c index 98461bbb..115d7d43 100644 --- a/skeletons/T61String.c +++ b/skeletons/T61String.c @@ -8,7 +8,7 @@ /* * T61String basic type description. */ -static ber_tlv_tag_t asn_DEF_T61String_tags[] = { +static const ber_tlv_tag_t asn_DEF_T61String_tags[] = { (ASN_TAG_CLASS_UNIVERSAL | (20 << 2)), /* [UNIVERSAL 20] IMPLICIT ...*/ (ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) /* ... OCTET STRING */ }; diff --git a/skeletons/TeletexString.c b/skeletons/TeletexString.c index cc2acada..faad6973 100644 --- a/skeletons/TeletexString.c +++ b/skeletons/TeletexString.c @@ -8,7 +8,7 @@ /* * TeletexString basic type description. */ -static ber_tlv_tag_t asn_DEF_TeletexString_tags[] = { +static const ber_tlv_tag_t asn_DEF_TeletexString_tags[] = { (ASN_TAG_CLASS_UNIVERSAL | (20 << 2)), /* [UNIVERSAL 20] IMPLICIT ...*/ (ASN_TAG_CLASS_UNIVERSAL | (4 << 2)), /* ... OCTET STRING */ }; diff --git a/skeletons/UTCTime.c b/skeletons/UTCTime.c index 0abe1db7..edcbaf19 100644 --- a/skeletons/UTCTime.c +++ b/skeletons/UTCTime.c @@ -18,7 +18,7 @@ /* * UTCTime basic type description. */ -static ber_tlv_tag_t asn_DEF_UTCTime_tags[] = { +static const ber_tlv_tag_t asn_DEF_UTCTime_tags[] = { (ASN_TAG_CLASS_UNIVERSAL | (23 << 2)), /* [UNIVERSAL 23] IMPLICIT ...*/ (ASN_TAG_CLASS_UNIVERSAL | (26 << 2)), /* [UNIVERSAL 26] IMPLICIT ...*/ (ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) /* ... OCTET STRING */ diff --git a/skeletons/UTF8String.c b/skeletons/UTF8String.c index 7e73d775..5e4f2506 100644 --- a/skeletons/UTF8String.c +++ b/skeletons/UTF8String.c @@ -9,7 +9,7 @@ /* * UTF8String basic type description. */ -static ber_tlv_tag_t asn_DEF_UTF8String_tags[] = { +static const ber_tlv_tag_t asn_DEF_UTF8String_tags[] = { (ASN_TAG_CLASS_UNIVERSAL | (12 << 2)), /* [UNIVERSAL 12] IMPLICIT ...*/ (ASN_TAG_CLASS_UNIVERSAL | (4 << 2)), /* ... OCTET STRING */ }; @@ -41,7 +41,7 @@ asn_TYPE_descriptor_t asn_DEF_UTF8String = { * This is the table of length expectations. * The second half of this table is only applicable to the long sequences. */ -static int UTF8String_ht[2][16] = { +static const int UTF8String_ht[2][16] = { { /* 0x0 ... 0x7 */ /* 0000..0111 */ 1, 1, 1, 1, 1, 1, 1, 1, @@ -52,7 +52,7 @@ static int UTF8String_ht[2][16] = { 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, -1, -1 } }; -static int32_t UTF8String_mv[7] = { 0, 0, +static const int32_t UTF8String_mv[7] = { 0, 0, 0x00000080, 0x00000800, 0x00010000, diff --git a/skeletons/UniversalString.c b/skeletons/UniversalString.c index 7d16781f..b758be02 100644 --- a/skeletons/UniversalString.c +++ b/skeletons/UniversalString.c @@ -9,7 +9,7 @@ /* * UniversalString basic type description. */ -static ber_tlv_tag_t asn_DEF_UniversalString_tags[] = { +static const ber_tlv_tag_t asn_DEF_UniversalString_tags[] = { (ASN_TAG_CLASS_UNIVERSAL | (28 << 2)), /* [UNIVERSAL 28] IMPLICIT ...*/ (ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) /* ... OCTET STRING */ }; diff --git a/skeletons/VideotexString.c b/skeletons/VideotexString.c index df7233e5..09967db1 100644 --- a/skeletons/VideotexString.c +++ b/skeletons/VideotexString.c @@ -8,7 +8,7 @@ /* * VideotexString basic type description. */ -static ber_tlv_tag_t asn_DEF_VideotexString_tags[] = { +static const ber_tlv_tag_t asn_DEF_VideotexString_tags[] = { (ASN_TAG_CLASS_UNIVERSAL | (21 << 2)), /* [UNIVERSAL 21] IMPLICIT */ (ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) /* ... OCTET STRING */ }; diff --git a/skeletons/VisibleString.c b/skeletons/VisibleString.c index 3487b6f9..baf8d0c9 100644 --- a/skeletons/VisibleString.c +++ b/skeletons/VisibleString.c @@ -8,7 +8,7 @@ /* * VisibleString basic type description. */ -static ber_tlv_tag_t asn_DEF_VisibleString_tags[] = { +static const ber_tlv_tag_t asn_DEF_VisibleString_tags[] = { (ASN_TAG_CLASS_UNIVERSAL | (26 << 2)), /* [UNIVERSAL 26] IMPLICIT ...*/ (ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) /* ... OCTET STRING */ }; diff --git a/skeletons/per_support.h b/skeletons/per_support.h index 10c84ed0..a75ac94f 100644 --- a/skeletons/per_support.h +++ b/skeletons/per_support.h @@ -15,7 +15,7 @@ extern "C" { /* * Pre-computed PER constraints. */ -typedef struct asn_per_constraint_s { +typedef const struct asn_per_constraint_s { enum asn_per_constraint_flags { APC_UNCONSTRAINED = 0x0, /* No PER visible constraints */ APC_SEMI_CONSTRAINED = 0x1, /* Constrained at "lb" */ @@ -27,9 +27,9 @@ typedef struct asn_per_constraint_s { long lower_bound; /* "lb" value */ long upper_bound; /* "ub" value */ } asn_per_constraint_t; -typedef struct asn_per_constraints_s { - asn_per_constraint_t value; - asn_per_constraint_t size; +typedef const struct asn_per_constraints_s { + struct asn_per_constraint_s value; + struct asn_per_constraint_s size; int (*value2code)(unsigned int value); int (*code2value)(unsigned int code); } asn_per_constraints_t; diff --git a/skeletons/tests/check-PER-INTEGER.c b/skeletons/tests/check-PER-INTEGER.c index 1cb853bf..fe6cf3b2 100644 --- a/skeletons/tests/check-PER-INTEGER.c +++ b/skeletons/tests/check-PER-INTEGER.c @@ -25,7 +25,7 @@ check_per_encode_constrained(int lineno, int unsigned_, long value, long lbound, INTEGER_t st; INTEGER_t *reconstructed_st = 0; struct asn_INTEGER_specifics_s specs; - asn_per_constraints_t cts; + struct asn_per_constraints_s cts; asn_enc_rval_t enc_rval; asn_dec_rval_t dec_rval; asn_per_outp_t po; diff --git a/skeletons/xer_support.c b/skeletons/xer_support.c index 9e34e692..20f70d58 100644 --- a/skeletons/xer_support.c +++ b/skeletons/xer_support.c @@ -31,7 +31,7 @@ static pxml_chunk_type_e final_chunk_type[] = { }; -static int +static const int _charclass[256] = { 0,0,0,0,0,0,0,0, 0,1,1,0,1,1,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, -- cgit v1.2.3 From ca15fc65504b3029b7a1b42d9a31a7b798b06181 Mon Sep 17 00:00:00 2001 From: Wim Lewis Date: Wed, 30 Jul 2014 12:30:34 -0700 Subject: Avoid an unnecessary table lookup and its accompanying table (final_chunk_type[]). --- skeletons/xer_support.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/skeletons/xer_support.c b/skeletons/xer_support.c index 20f70d58..36b4bfbf 100644 --- a/skeletons/xer_support.c +++ b/skeletons/xer_support.c @@ -22,15 +22,6 @@ typedef enum { ST_COMMENT_CLO_RT /* "-->"[1] */ } pstate_e; -static pxml_chunk_type_e final_chunk_type[] = { - PXML_TEXT, - PXML_TAG_END, - PXML_COMMENT_END, - PXML_TAG_END, - PXML_COMMENT_END, -}; - - static const int _charclass[256] = { 0,0,0,0,0,0,0,0, 0,1,1,0,1,1,0,0, @@ -79,8 +70,11 @@ _charclass[256] = { #define TOKEN_CB(_type, _ns, _current_too) \ TOKEN_CB_CALL(_type, _ns, _current_too, 0) +#define PXML_TAG_FINAL_CHUNK_TYPE PXML_TAG_END +#define PXML_COMMENT_FINAL_CHUNK_TYPE PXML_COMMENT_END + #define TOKEN_CB_FINAL(_type, _ns, _current_too) \ - TOKEN_CB_CALL(final_chunk_type[_type], _ns, _current_too, 1) + TOKEN_CB_CALL( _type ## _FINAL_CHUNK_TYPE , _ns, _current_too, 1) /* * Parser itself -- cgit v1.2.3 From 59e8d2847ef4e4681a83a1f22fc442ac3862aa7b Mon Sep 17 00:00:00 2001 From: Wim Lewis Date: Mon, 4 Aug 2014 12:39:35 -0700 Subject: It's actually more efficient *not* to create a mutable static variable to hold this constant string's address. --- skeletons/BIT_STRING.c | 2 +- skeletons/INTEGER.c | 2 +- skeletons/OCTET_STRING.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/skeletons/BIT_STRING.c b/skeletons/BIT_STRING.c index 9bf47f09..9e0e50c6 100644 --- a/skeletons/BIT_STRING.c +++ b/skeletons/BIT_STRING.c @@ -140,7 +140,7 @@ cb_failed: int BIT_STRING_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel, asn_app_consume_bytes_f *cb, void *app_key) { - static const char *h2c = "0123456789ABCDEF"; + const char * const h2c = "0123456789ABCDEF"; char scratch[64]; const BIT_STRING_t *st = (const BIT_STRING_t *)sptr; uint8_t *buf; diff --git a/skeletons/INTEGER.c b/skeletons/INTEGER.c index 4295a164..8ead23d5 100644 --- a/skeletons/INTEGER.c +++ b/skeletons/INTEGER.c @@ -166,7 +166,7 @@ INTEGER__dump(const asn_TYPE_descriptor_t *td, const INTEGER_t *st, asn_app_cons /* Output in the long xx:yy:zz... format */ /* TODO: replace with generic algorithm (Knuth TAOCP Vol 2, 4.3.1) */ for(p = scratch; buf < buf_end; buf++) { - static const char *h2c = "0123456789ABCDEF"; + const char * const h2c = "0123456789ABCDEF"; if((p - scratch) >= (ssize_t)(sizeof(scratch) - 4)) { /* Flush buffer */ if(cb(scratch, p - scratch, app_key) < 0) diff --git a/skeletons/OCTET_STRING.c b/skeletons/OCTET_STRING.c index 0356c9ca..ece27a28 100644 --- a/skeletons/OCTET_STRING.c +++ b/skeletons/OCTET_STRING.c @@ -580,7 +580,7 @@ asn_enc_rval_t OCTET_STRING_encode_xer(asn_TYPE_descriptor_t *td, void *sptr, int ilevel, enum xer_encoder_flags_e flags, asn_app_consume_bytes_f *cb, void *app_key) { - static const char *h2c = "0123456789ABCDEF"; + const char * const h2c = "0123456789ABCDEF"; const OCTET_STRING_t *st = (const OCTET_STRING_t *)sptr; asn_enc_rval_t er; char scratch[16 * 3 + 4]; @@ -1655,7 +1655,7 @@ OCTET_STRING_encode_uper(asn_TYPE_descriptor_t *td, int OCTET_STRING_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel, asn_app_consume_bytes_f *cb, void *app_key) { - static const char *h2c = "0123456789ABCDEF"; + const char * const h2c = "0123456789ABCDEF"; const OCTET_STRING_t *st = (const OCTET_STRING_t *)sptr; char scratch[16 * 3 + 4]; char *p = scratch; -- cgit v1.2.3