asn1: Add --decorate=... for internal bookkeeping
This option, `--decorate=TYPE-NAME:FIELD-TYPE:field-name[?]` allows one to add a field to any struct generated by the ASN.1 compiler for any SET or SEQUENCE type such that: - the field will be freed by the `free_TYPE_NAME()` function - the field will be copied by the `copy_TYPE_NAME()` function - the field will not be printed by the `print_TYPE_NAME()` function - the field will NOT be encoded or decoded This is useful for internal bookkeeping. The first use of this may well be for adding an optional field to `Principal` where information about name attributes will be stored, which will then allow us to have GSS name attributes for the krb5 mechanism w/o having to refactor the mechanism to use a different structure for representing `gss_name_t` mechnames than the one currently used (`Principal`; `krb5_principal` happens to be a typedef alias of `Principal *`). So w/o massive rototilling of the GSS krb5 mechanism we can have name attributes, _and_ we'll also be able to have those in the krb5 API as well w/o any massive rototilling there either.
This commit is contained in:
@@ -119,7 +119,7 @@ free_type (const char *name, const Type *t, int preserve)
|
||||
have_ellipsis->label,
|
||||
name, have_ellipsis->gen_name);
|
||||
fprintf(codefile, "}\n");
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TSetOf:
|
||||
@@ -179,6 +179,8 @@ void
|
||||
generate_type_free (const Symbol *s)
|
||||
{
|
||||
int preserve = preserve_type(s->name) ? TRUE : FALSE;
|
||||
int deco_opt;
|
||||
char *ft, *fn;
|
||||
|
||||
fprintf (codefile, "void ASN1CALL\n"
|
||||
"free_%s(%s *data)\n"
|
||||
@@ -186,6 +188,19 @@ generate_type_free (const Symbol *s)
|
||||
s->gen_name, s->gen_name);
|
||||
|
||||
free_type ("data", s->type, preserve);
|
||||
if (decorate_type(s->gen_name, &ft, &fn, &deco_opt)) {
|
||||
if (deco_opt) {
|
||||
fprintf(codefile, "if ((data)->%s) {\n", fn);
|
||||
fprintf(codefile, "free_%s((data)->%s);\n", ft, fn);
|
||||
fprintf(codefile, "free((data)->%s);\n", fn);
|
||||
fprintf(codefile, "(data)->%s = NULL;\n", fn);
|
||||
fprintf(codefile, "}\n");
|
||||
} else {
|
||||
fprintf(codefile, "free_%s(&(data)->%s);\n", ft, fn);
|
||||
}
|
||||
free(ft);
|
||||
free(fn);
|
||||
}
|
||||
fprintf (codefile, "}\n\n");
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user