Fix a few issues with the C generator (part 8) (#20378)

* [C] Deprecate *_create() to avoid *_free() confusion

The behaviour of *_free() doesn't match *_create(), so the user should
avoid using them together. But they still need *_free() to clean up
library-allocated objects, so add a _library_owned flag to each struct
as an attempt to tell them apart. This isn't perfect though, because the
user may neglect to zero the field, but they would still see a warning
once in a while so it serves its purpose.

To prevent the new deprecation warnings (intended for the user) from
showing up during the library build itself, define a new family of
*_create_internal() functions, and turn *_create() into simple wrappers.

* Update samples

* add eafer to c technical committee

---------

Co-authored-by: William Cheng <wing328hk@gmail.com>
This commit is contained in:
Ernesto Fernández 2025-01-05 23:53:36 -03:00 committed by GitHub
parent 85c81bee5b
commit e154903743
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
35 changed files with 450 additions and 52 deletions

View File

@ -1210,7 +1210,7 @@ If you want to join the committee, please kindly apply by sending an email to te
| Android | @jaz-ah (2017/09) | | Android | @jaz-ah (2017/09) |
| Apex | | | Apex | |
| Bash | @frol (2017/07) @bkryza (2017/08) @kenjones-cisco (2017/09) | | Bash | @frol (2017/07) @bkryza (2017/08) @kenjones-cisco (2017/09) |
| C | @zhemant (2018/11) @ityuhui (2019/12) @michelealbano (2020/03) | | C | @zhemant (2018/11) @ityuhui (2019/12) @michelealbano (2020/03) @eafer (2024/12) |
| C++ | @ravinikam (2017/07) @stkrwork (2017/07) @etherealjoy (2018/02) @martindelille (2018/03) @muttleyxd (2019/08) | | C++ | @ravinikam (2017/07) @stkrwork (2017/07) @etherealjoy (2018/02) @martindelille (2018/03) @muttleyxd (2019/08) |
| C# | @mandrean (2017/08) @shibayan (2020/02) @Blackclaws (2021/03) @lucamazzanti (2021/05) @iBicha (2023/07) | | C# | @mandrean (2017/08) @shibayan (2020/02) @Blackclaws (2021/03) @lucamazzanti (2021/05) @iBicha (2023/07) |
| Clojure | | | Clojure | |

View File

@ -119,7 +119,7 @@ char* {{classname}}_{{name}}_ToString({{projectName}}_{{classVarName}}_{{enumNam
{{/isContainer}} {{/isContainer}}
{{/vars}} {{/vars}}
{{classname}}_t *{{classname}}_create( static {{classname}}_t *{{classname}}_create_internal(
{{#vars}} {{#vars}}
{{^isContainer}} {{^isContainer}}
{{^isPrimitiveType}} {{^isPrimitiveType}}
@ -205,14 +205,103 @@ char* {{classname}}_{{name}}_ToString({{projectName}}_{{classVarName}}_{{enumNam
{{classname}}_local_var->{{{name}}} = {{{name}}}; {{classname}}_local_var->{{{name}}} = {{{name}}};
{{/vars}} {{/vars}}
{{classname}}_local_var->_library_owned = 1;
return {{classname}}_local_var; return {{classname}}_local_var;
} }
__attribute__((deprecated)) {{classname}}_t *{{classname}}_create(
{{#vars}}
{{^isContainer}}
{{^isPrimitiveType}}
{{#isModel}}
{{#isEnum}}
{{projectName}}_{{classVarName}}_{{enumName}}_e {{name}}{{^-last}},{{/-last}}
{{/isEnum}}
{{^isEnum}}
{{datatype}}_t *{{name}}{{^-last}},{{/-last}}
{{/isEnum}}
{{/isModel}}
{{^isModel}}
{{^isFreeFormObject}}
{{^isEnum}}
{{datatype}}_t *{{name}}{{^-last}},{{/-last}}
{{/isEnum}}
{{#isEnum}}
{{projectName}}_{{dataType}}_{{enumName}}_e {{name}}{{^-last}},{{/-last}}
{{/isEnum}}
{{/isFreeFormObject}}
{{/isModel}}
{{#isUuid}}
{{datatype}} *{{name}}{{^-last}},{{/-last}}
{{/isUuid}}
{{#isEmail}}
{{datatype}} *{{name}}{{^-last}},{{/-last}}
{{/isEmail}}
{{#isFreeFormObject}}
{{datatype}}_t *{{name}}{{^-last}},{{/-last}}
{{/isFreeFormObject}}
{{/isPrimitiveType}}
{{#isPrimitiveType}}
{{#isNumeric}}
{{datatype}} {{name}}{{^-last}},{{/-last}}
{{/isNumeric}}
{{#isBoolean}}
{{datatype}} {{name}}{{^-last}},{{/-last}}
{{/isBoolean}}
{{#isEnum}}
{{#isString}}
{{projectName}}_{{classVarName}}_{{enumName}}_e {{name}}{{^-last}},{{/-last}}
{{/isString}}
{{/isEnum}}
{{^isEnum}}
{{#isString}}
{{datatype}} *{{name}}{{^-last}},{{/-last}}
{{/isString}}
{{/isEnum}}
{{#isByteArray}}
{{datatype}} *{{name}}{{^-last}},{{/-last}}
{{/isByteArray}}
{{#isBinary}}
{{datatype}} {{name}}{{^-last}},{{/-last}}
{{/isBinary}}
{{#isDate}}
{{datatype}} *{{name}}{{^-last}},{{/-last}}
{{/isDate}}
{{#isDateTime}}
{{datatype}} *{{name}}{{^-last}},{{/-last}}
{{/isDateTime}}
{{/isPrimitiveType}}
{{/isContainer}}
{{#isContainer}}
{{#isArray}}
{{#isPrimitiveType}}
{{datatype}}_t *{{name}}{{^-last}},{{/-last}}
{{/isPrimitiveType}}
{{^isPrimitiveType}}
{{datatype}}_t *{{name}}{{^-last}},{{/-last}}
{{/isPrimitiveType}}
{{/isArray}}
{{#isMap}}
{{datatype}} {{name}}{{^-last}},{{/-last}}
{{/isMap}}
{{/isContainer}}
{{/vars}}
) {
return {{classname}}_create_internal (
{{#vars}}
{{name}}{{^-last}},{{/-last}}
{{/vars}}
);
}
void {{classname}}_free({{classname}}_t *{{classname}}) { void {{classname}}_free({{classname}}_t *{{classname}}) {
if(NULL == {{classname}}){ if(NULL == {{classname}}){
return ; return ;
} }
if({{classname}}->_library_owned != 1){
fprintf(stderr, "WARNING: %s() does NOT free objects allocated by the user\n", "{{classname}}_free");
return ;
}
listEntry_t *listEntry; listEntry_t *listEntry;
{{#vars}} {{#vars}}
{{^isContainer}} {{^isContainer}}
@ -859,7 +948,7 @@ fail:
{{/vars}} {{/vars}}
{{classname}}_local_var = {{classname}}_create ( {{classname}}_local_var = {{classname}}_create_internal (
{{#vars}} {{#vars}}
{{^isContainer}} {{^isContainer}}
{{^isPrimitiveType}} {{^isPrimitiveType}}

View File

@ -154,9 +154,10 @@ typedef struct {{classname}}_t {
{{/isContainer}} {{/isContainer}}
{{/vars}} {{/vars}}
int _library_owned; // Is the library responsible for freeing this object?
} {{classname}}_t; } {{classname}}_t;
{{classname}}_t *{{classname}}_create( __attribute__((deprecated)) {{classname}}_t *{{classname}}_create(
{{#vars}} {{#vars}}
{{^isContainer}} {{^isContainer}}
{{^isPrimitiveType}} {{^isPrimitiveType}}

View File

@ -5,7 +5,7 @@
api_response_t *api_response_create( static api_response_t *api_response_create_internal(
int code, int code,
char *type, char *type,
char *message char *message
@ -18,14 +18,30 @@ api_response_t *api_response_create(
api_response_local_var->type = type; api_response_local_var->type = type;
api_response_local_var->message = message; api_response_local_var->message = message;
api_response_local_var->_library_owned = 1;
return api_response_local_var; return api_response_local_var;
} }
__attribute__((deprecated)) api_response_t *api_response_create(
int code,
char *type,
char *message
) {
return api_response_create_internal (
code,
type,
message
);
}
void api_response_free(api_response_t *api_response) { void api_response_free(api_response_t *api_response) {
if(NULL == api_response){ if(NULL == api_response){
return ; return ;
} }
if(api_response->_library_owned != 1){
fprintf(stderr, "WARNING: %s() does NOT free objects allocated by the user\n", "api_response_free");
return ;
}
listEntry_t *listEntry; listEntry_t *listEntry;
if (api_response->type) { if (api_response->type) {
free(api_response->type); free(api_response->type);
@ -113,7 +129,7 @@ api_response_t *api_response_parseFromJSON(cJSON *api_responseJSON){
} }
api_response_local_var = api_response_create ( api_response_local_var = api_response_create_internal (
code ? code->valuedouble : 0, code ? code->valuedouble : 0,
type && !cJSON_IsNull(type) ? strdup(type->valuestring) : NULL, type && !cJSON_IsNull(type) ? strdup(type->valuestring) : NULL,
message && !cJSON_IsNull(message) ? strdup(message->valuestring) : NULL message && !cJSON_IsNull(message) ? strdup(message->valuestring) : NULL

View File

@ -23,9 +23,10 @@ typedef struct api_response_t {
char *type; // string char *type; // string
char *message; // string char *message; // string
int _library_owned; // Is the library responsible for freeing this object?
} api_response_t; } api_response_t;
api_response_t *api_response_create( __attribute__((deprecated)) api_response_t *api_response_create(
int code, int code,
char *type, char *type,
char *message char *message

View File

@ -5,7 +5,7 @@
category_t *category_create( static category_t *category_create_internal(
long id, long id,
char *name char *name
) { ) {
@ -16,14 +16,28 @@ category_t *category_create(
category_local_var->id = id; category_local_var->id = id;
category_local_var->name = name; category_local_var->name = name;
category_local_var->_library_owned = 1;
return category_local_var; return category_local_var;
} }
__attribute__((deprecated)) category_t *category_create(
long id,
char *name
) {
return category_create_internal (
id,
name
);
}
void category_free(category_t *category) { void category_free(category_t *category) {
if(NULL == category){ if(NULL == category){
return ; return ;
} }
if(category->_library_owned != 1){
fprintf(stderr, "WARNING: %s() does NOT free objects allocated by the user\n", "category_free");
return ;
}
listEntry_t *listEntry; listEntry_t *listEntry;
if (category->name) { if (category->name) {
free(category->name); free(category->name);
@ -87,7 +101,7 @@ category_t *category_parseFromJSON(cJSON *categoryJSON){
} }
category_local_var = category_create ( category_local_var = category_create_internal (
id ? id->valuedouble : 0, id ? id->valuedouble : 0,
name && !cJSON_IsNull(name) ? strdup(name->valuestring) : NULL name && !cJSON_IsNull(name) ? strdup(name->valuestring) : NULL
); );

View File

@ -22,9 +22,10 @@ typedef struct category_t {
long id; //numeric long id; //numeric
char *name; // string char *name; // string
int _library_owned; // Is the library responsible for freeing this object?
} category_t; } category_t;
category_t *category_create( __attribute__((deprecated)) category_t *category_create(
long id, long id,
char *name char *name
); );

View File

@ -5,7 +5,7 @@
MappedModel_t *MappedModel_create( static MappedModel_t *MappedModel_create_internal(
int another_property, int another_property,
char *uuid_property char *uuid_property
) { ) {
@ -16,14 +16,28 @@ MappedModel_t *MappedModel_create(
MappedModel_local_var->another_property = another_property; MappedModel_local_var->another_property = another_property;
MappedModel_local_var->uuid_property = uuid_property; MappedModel_local_var->uuid_property = uuid_property;
MappedModel_local_var->_library_owned = 1;
return MappedModel_local_var; return MappedModel_local_var;
} }
__attribute__((deprecated)) MappedModel_t *MappedModel_create(
int another_property,
char *uuid_property
) {
return MappedModel_create_internal (
another_property,
uuid_property
);
}
void MappedModel_free(MappedModel_t *MappedModel) { void MappedModel_free(MappedModel_t *MappedModel) {
if(NULL == MappedModel){ if(NULL == MappedModel){
return ; return ;
} }
if(MappedModel->_library_owned != 1){
fprintf(stderr, "WARNING: %s() does NOT free objects allocated by the user\n", "MappedModel_free");
return ;
}
listEntry_t *listEntry; listEntry_t *listEntry;
if (MappedModel->uuid_property) { if (MappedModel->uuid_property) {
free(MappedModel->uuid_property); free(MappedModel->uuid_property);
@ -87,7 +101,7 @@ MappedModel_t *MappedModel_parseFromJSON(cJSON *MappedModelJSON){
} }
MappedModel_local_var = MappedModel_create ( MappedModel_local_var = MappedModel_create_internal (
another_property ? another_property->valuedouble : 0, another_property ? another_property->valuedouble : 0,
uuid_property && !cJSON_IsNull(uuid_property) ? strdup(uuid_property->valuestring) : NULL uuid_property && !cJSON_IsNull(uuid_property) ? strdup(uuid_property->valuestring) : NULL
); );

View File

@ -22,9 +22,10 @@ typedef struct MappedModel_t {
int another_property; //numeric int another_property; //numeric
char *uuid_property; // string char *uuid_property; // string
int _library_owned; // Is the library responsible for freeing this object?
} MappedModel_t; } MappedModel_t;
MappedModel_t *MappedModel_create( __attribute__((deprecated)) MappedModel_t *MappedModel_create(
int another_property, int another_property,
char *uuid_property char *uuid_property
); );

View File

@ -5,7 +5,7 @@
model_with_set_propertes_t *model_with_set_propertes_create( static model_with_set_propertes_t *model_with_set_propertes_create_internal(
list_t *tag_set, list_t *tag_set,
list_t *string_set list_t *string_set
) { ) {
@ -16,14 +16,28 @@ model_with_set_propertes_t *model_with_set_propertes_create(
model_with_set_propertes_local_var->tag_set = tag_set; model_with_set_propertes_local_var->tag_set = tag_set;
model_with_set_propertes_local_var->string_set = string_set; model_with_set_propertes_local_var->string_set = string_set;
model_with_set_propertes_local_var->_library_owned = 1;
return model_with_set_propertes_local_var; return model_with_set_propertes_local_var;
} }
__attribute__((deprecated)) model_with_set_propertes_t *model_with_set_propertes_create(
list_t *tag_set,
list_t *string_set
) {
return model_with_set_propertes_create_internal (
tag_set,
string_set
);
}
void model_with_set_propertes_free(model_with_set_propertes_t *model_with_set_propertes) { void model_with_set_propertes_free(model_with_set_propertes_t *model_with_set_propertes) {
if(NULL == model_with_set_propertes){ if(NULL == model_with_set_propertes){
return ; return ;
} }
if(model_with_set_propertes->_library_owned != 1){
fprintf(stderr, "WARNING: %s() does NOT free objects allocated by the user\n", "model_with_set_propertes_free");
return ;
}
listEntry_t *listEntry; listEntry_t *listEntry;
if (model_with_set_propertes->tag_set) { if (model_with_set_propertes->tag_set) {
list_ForEach(listEntry, model_with_set_propertes->tag_set) { list_ForEach(listEntry, model_with_set_propertes->tag_set) {
@ -146,7 +160,7 @@ model_with_set_propertes_t *model_with_set_propertes_parseFromJSON(cJSON *model_
} }
model_with_set_propertes_local_var = model_with_set_propertes_create ( model_with_set_propertes_local_var = model_with_set_propertes_create_internal (
tag_set ? tag_setList : NULL, tag_set ? tag_setList : NULL,
string_set ? string_setList : NULL string_set ? string_setList : NULL
); );

View File

@ -23,9 +23,10 @@ typedef struct model_with_set_propertes_t {
list_t *tag_set; //nonprimitive container list_t *tag_set; //nonprimitive container
list_t *string_set; //primitive container list_t *string_set; //primitive container
int _library_owned; // Is the library responsible for freeing this object?
} model_with_set_propertes_t; } model_with_set_propertes_t;
model_with_set_propertes_t *model_with_set_propertes_create( __attribute__((deprecated)) model_with_set_propertes_t *model_with_set_propertes_create(
list_t *tag_set, list_t *tag_set,
list_t *string_set list_t *string_set
); );

View File

@ -22,7 +22,7 @@ openapi_petstore_order_STATUS_e order_status_FromString(char* status){
return 0; return 0;
} }
order_t *order_create( static order_t *order_create_internal(
long id, long id,
long pet_id, long pet_id,
int quantity, int quantity,
@ -41,14 +41,36 @@ order_t *order_create(
order_local_var->status = status; order_local_var->status = status;
order_local_var->complete = complete; order_local_var->complete = complete;
order_local_var->_library_owned = 1;
return order_local_var; return order_local_var;
} }
__attribute__((deprecated)) order_t *order_create(
long id,
long pet_id,
int quantity,
char *ship_date,
openapi_petstore_order_STATUS_e status,
int complete
) {
return order_create_internal (
id,
pet_id,
quantity,
ship_date,
status,
complete
);
}
void order_free(order_t *order) { void order_free(order_t *order) {
if(NULL == order){ if(NULL == order){
return ; return ;
} }
if(order->_library_owned != 1){
fprintf(stderr, "WARNING: %s() does NOT free objects allocated by the user\n", "order_free");
return ;
}
listEntry_t *listEntry; listEntry_t *listEntry;
if (order->ship_date) { if (order->ship_date) {
free(order->ship_date); free(order->ship_date);
@ -195,7 +217,7 @@ order_t *order_parseFromJSON(cJSON *orderJSON){
} }
order_local_var = order_create ( order_local_var = order_create_internal (
id ? id->valuedouble : 0, id ? id->valuedouble : 0,
pet_id ? pet_id->valuedouble : 0, pet_id ? pet_id->valuedouble : 0,
quantity ? quantity->valuedouble : 0, quantity ? quantity->valuedouble : 0,

View File

@ -34,9 +34,10 @@ typedef struct order_t {
openapi_petstore_order_STATUS_e status; //enum openapi_petstore_order_STATUS_e status; //enum
int complete; //boolean int complete; //boolean
int _library_owned; // Is the library responsible for freeing this object?
} order_t; } order_t;
order_t *order_create( __attribute__((deprecated)) order_t *order_create(
long id, long id,
long pet_id, long pet_id,
int quantity, int quantity,

View File

@ -22,7 +22,7 @@ openapi_petstore_pet_STATUS_e pet_status_FromString(char* status){
return 0; return 0;
} }
pet_t *pet_create( static pet_t *pet_create_internal(
long id, long id,
category_t *category, category_t *category,
char *name, char *name,
@ -41,14 +41,36 @@ pet_t *pet_create(
pet_local_var->tags = tags; pet_local_var->tags = tags;
pet_local_var->status = status; pet_local_var->status = status;
pet_local_var->_library_owned = 1;
return pet_local_var; return pet_local_var;
} }
__attribute__((deprecated)) pet_t *pet_create(
long id,
category_t *category,
char *name,
list_t *photo_urls,
list_t *tags,
openapi_petstore_pet_STATUS_e status
) {
return pet_create_internal (
id,
category,
name,
photo_urls,
tags,
status
);
}
void pet_free(pet_t *pet) { void pet_free(pet_t *pet) {
if(NULL == pet){ if(NULL == pet){
return ; return ;
} }
if(pet->_library_owned != 1){
fprintf(stderr, "WARNING: %s() does NOT free objects allocated by the user\n", "pet_free");
return ;
}
listEntry_t *listEntry; listEntry_t *listEntry;
if (pet->category) { if (pet->category) {
category_free(pet->category); category_free(pet->category);
@ -275,7 +297,7 @@ pet_t *pet_parseFromJSON(cJSON *petJSON){
} }
pet_local_var = pet_create ( pet_local_var = pet_create_internal (
id ? id->valuedouble : 0, id ? id->valuedouble : 0,
category ? category_local_nonprim : NULL, category ? category_local_nonprim : NULL,
strdup(name->valuestring), strdup(name->valuestring),

View File

@ -36,9 +36,10 @@ typedef struct pet_t {
list_t *tags; //nonprimitive container list_t *tags; //nonprimitive container
openapi_petstore_pet_STATUS_e status; //enum openapi_petstore_pet_STATUS_e status; //enum
int _library_owned; // Is the library responsible for freeing this object?
} pet_t; } pet_t;
pet_t *pet_create( __attribute__((deprecated)) pet_t *pet_create(
long id, long id,
category_t *category, category_t *category,
char *name, char *name,

View File

@ -5,7 +5,7 @@
tag_t *tag_create( static tag_t *tag_create_internal(
long id, long id,
char *name char *name
) { ) {
@ -16,14 +16,28 @@ tag_t *tag_create(
tag_local_var->id = id; tag_local_var->id = id;
tag_local_var->name = name; tag_local_var->name = name;
tag_local_var->_library_owned = 1;
return tag_local_var; return tag_local_var;
} }
__attribute__((deprecated)) tag_t *tag_create(
long id,
char *name
) {
return tag_create_internal (
id,
name
);
}
void tag_free(tag_t *tag) { void tag_free(tag_t *tag) {
if(NULL == tag){ if(NULL == tag){
return ; return ;
} }
if(tag->_library_owned != 1){
fprintf(stderr, "WARNING: %s() does NOT free objects allocated by the user\n", "tag_free");
return ;
}
listEntry_t *listEntry; listEntry_t *listEntry;
if (tag->name) { if (tag->name) {
free(tag->name); free(tag->name);
@ -87,7 +101,7 @@ tag_t *tag_parseFromJSON(cJSON *tagJSON){
} }
tag_local_var = tag_create ( tag_local_var = tag_create_internal (
id ? id->valuedouble : 0, id ? id->valuedouble : 0,
name && !cJSON_IsNull(name) ? strdup(name->valuestring) : NULL name && !cJSON_IsNull(name) ? strdup(name->valuestring) : NULL
); );

View File

@ -22,9 +22,10 @@ typedef struct tag_t {
long id; //numeric long id; //numeric
char *name; // string char *name; // string
int _library_owned; // Is the library responsible for freeing this object?
} tag_t; } tag_t;
tag_t *tag_create( __attribute__((deprecated)) tag_t *tag_create(
long id, long id,
char *name char *name
); );

View File

@ -5,7 +5,7 @@
user_t *user_create( static user_t *user_create_internal(
long id, long id,
char *username, char *username,
char *first_name, char *first_name,
@ -32,14 +32,44 @@ user_t *user_create(
user_local_var->extra = extra; user_local_var->extra = extra;
user_local_var->preference = preference; user_local_var->preference = preference;
user_local_var->_library_owned = 1;
return user_local_var; return user_local_var;
} }
__attribute__((deprecated)) user_t *user_create(
long id,
char *username,
char *first_name,
char *last_name,
char *email,
char *password,
char *phone,
int user_status,
list_t* extra,
openapi_petstore_preference__e preference
) {
return user_create_internal (
id,
username,
first_name,
last_name,
email,
password,
phone,
user_status,
extra,
preference
);
}
void user_free(user_t *user) { void user_free(user_t *user) {
if(NULL == user){ if(NULL == user){
return ; return ;
} }
if(user->_library_owned != 1){
fprintf(stderr, "WARNING: %s() does NOT free objects allocated by the user\n", "user_free");
return ;
}
listEntry_t *listEntry; listEntry_t *listEntry;
if (user->username) { if (user->username) {
free(user->username); free(user->username);
@ -320,7 +350,7 @@ user_t *user_parseFromJSON(cJSON *userJSON){
} }
user_local_var = user_create ( user_local_var = user_create_internal (
id ? id->valuedouble : 0, id ? id->valuedouble : 0,
username && !cJSON_IsNull(username) ? strdup(username->valuestring) : NULL, username && !cJSON_IsNull(username) ? strdup(username->valuestring) : NULL,
first_name && !cJSON_IsNull(first_name) ? strdup(first_name->valuestring) : NULL, first_name && !cJSON_IsNull(first_name) ? strdup(first_name->valuestring) : NULL,

View File

@ -32,9 +32,10 @@ typedef struct user_t {
list_t* extra; //map list_t* extra; //map
openapi_petstore_preference__e preference; //referenced enum openapi_petstore_preference__e preference; //referenced enum
int _library_owned; // Is the library responsible for freeing this object?
} user_t; } user_t;
user_t *user_create( __attribute__((deprecated)) user_t *user_create(
long id, long id,
char *username, char *username,
char *first_name, char *first_name,

View File

@ -5,7 +5,7 @@
api_response_t *api_response_create( static api_response_t *api_response_create_internal(
int code, int code,
char *type, char *type,
char *message char *message
@ -18,14 +18,30 @@ api_response_t *api_response_create(
api_response_local_var->type = type; api_response_local_var->type = type;
api_response_local_var->message = message; api_response_local_var->message = message;
api_response_local_var->_library_owned = 1;
return api_response_local_var; return api_response_local_var;
} }
__attribute__((deprecated)) api_response_t *api_response_create(
int code,
char *type,
char *message
) {
return api_response_create_internal (
code,
type,
message
);
}
void api_response_free(api_response_t *api_response) { void api_response_free(api_response_t *api_response) {
if(NULL == api_response){ if(NULL == api_response){
return ; return ;
} }
if(api_response->_library_owned != 1){
fprintf(stderr, "WARNING: %s() does NOT free objects allocated by the user\n", "api_response_free");
return ;
}
listEntry_t *listEntry; listEntry_t *listEntry;
if (api_response->type) { if (api_response->type) {
free(api_response->type); free(api_response->type);
@ -113,7 +129,7 @@ api_response_t *api_response_parseFromJSON(cJSON *api_responseJSON){
} }
api_response_local_var = api_response_create ( api_response_local_var = api_response_create_internal (
code ? code->valuedouble : 0, code ? code->valuedouble : 0,
type && !cJSON_IsNull(type) ? strdup(type->valuestring) : NULL, type && !cJSON_IsNull(type) ? strdup(type->valuestring) : NULL,
message && !cJSON_IsNull(message) ? strdup(message->valuestring) : NULL message && !cJSON_IsNull(message) ? strdup(message->valuestring) : NULL

View File

@ -23,9 +23,10 @@ typedef struct api_response_t {
char *type; // string char *type; // string
char *message; // string char *message; // string
int _library_owned; // Is the library responsible for freeing this object?
} api_response_t; } api_response_t;
api_response_t *api_response_create( __attribute__((deprecated)) api_response_t *api_response_create(
int code, int code,
char *type, char *type,
char *message char *message

View File

@ -5,7 +5,7 @@
category_t *category_create( static category_t *category_create_internal(
long id, long id,
char *name char *name
) { ) {
@ -16,14 +16,28 @@ category_t *category_create(
category_local_var->id = id; category_local_var->id = id;
category_local_var->name = name; category_local_var->name = name;
category_local_var->_library_owned = 1;
return category_local_var; return category_local_var;
} }
__attribute__((deprecated)) category_t *category_create(
long id,
char *name
) {
return category_create_internal (
id,
name
);
}
void category_free(category_t *category) { void category_free(category_t *category) {
if(NULL == category){ if(NULL == category){
return ; return ;
} }
if(category->_library_owned != 1){
fprintf(stderr, "WARNING: %s() does NOT free objects allocated by the user\n", "category_free");
return ;
}
listEntry_t *listEntry; listEntry_t *listEntry;
if (category->name) { if (category->name) {
free(category->name); free(category->name);
@ -87,7 +101,7 @@ category_t *category_parseFromJSON(cJSON *categoryJSON){
} }
category_local_var = category_create ( category_local_var = category_create_internal (
id ? id->valuedouble : 0, id ? id->valuedouble : 0,
name && !cJSON_IsNull(name) ? strdup(name->valuestring) : NULL name && !cJSON_IsNull(name) ? strdup(name->valuestring) : NULL
); );

View File

@ -22,9 +22,10 @@ typedef struct category_t {
long id; //numeric long id; //numeric
char *name; // string char *name; // string
int _library_owned; // Is the library responsible for freeing this object?
} category_t; } category_t;
category_t *category_create( __attribute__((deprecated)) category_t *category_create(
long id, long id,
char *name char *name
); );

View File

@ -5,7 +5,7 @@
MappedModel_t *MappedModel_create( static MappedModel_t *MappedModel_create_internal(
int another_property, int another_property,
char *uuid_property char *uuid_property
) { ) {
@ -16,14 +16,28 @@ MappedModel_t *MappedModel_create(
MappedModel_local_var->another_property = another_property; MappedModel_local_var->another_property = another_property;
MappedModel_local_var->uuid_property = uuid_property; MappedModel_local_var->uuid_property = uuid_property;
MappedModel_local_var->_library_owned = 1;
return MappedModel_local_var; return MappedModel_local_var;
} }
__attribute__((deprecated)) MappedModel_t *MappedModel_create(
int another_property,
char *uuid_property
) {
return MappedModel_create_internal (
another_property,
uuid_property
);
}
void MappedModel_free(MappedModel_t *MappedModel) { void MappedModel_free(MappedModel_t *MappedModel) {
if(NULL == MappedModel){ if(NULL == MappedModel){
return ; return ;
} }
if(MappedModel->_library_owned != 1){
fprintf(stderr, "WARNING: %s() does NOT free objects allocated by the user\n", "MappedModel_free");
return ;
}
listEntry_t *listEntry; listEntry_t *listEntry;
if (MappedModel->uuid_property) { if (MappedModel->uuid_property) {
free(MappedModel->uuid_property); free(MappedModel->uuid_property);
@ -87,7 +101,7 @@ MappedModel_t *MappedModel_parseFromJSON(cJSON *MappedModelJSON){
} }
MappedModel_local_var = MappedModel_create ( MappedModel_local_var = MappedModel_create_internal (
another_property ? another_property->valuedouble : 0, another_property ? another_property->valuedouble : 0,
uuid_property && !cJSON_IsNull(uuid_property) ? strdup(uuid_property->valuestring) : NULL uuid_property && !cJSON_IsNull(uuid_property) ? strdup(uuid_property->valuestring) : NULL
); );

View File

@ -22,9 +22,10 @@ typedef struct MappedModel_t {
int another_property; //numeric int another_property; //numeric
char *uuid_property; // string char *uuid_property; // string
int _library_owned; // Is the library responsible for freeing this object?
} MappedModel_t; } MappedModel_t;
MappedModel_t *MappedModel_create( __attribute__((deprecated)) MappedModel_t *MappedModel_create(
int another_property, int another_property,
char *uuid_property char *uuid_property
); );

View File

@ -5,7 +5,7 @@
model_with_set_propertes_t *model_with_set_propertes_create( static model_with_set_propertes_t *model_with_set_propertes_create_internal(
list_t *tag_set, list_t *tag_set,
list_t *string_set list_t *string_set
) { ) {
@ -16,14 +16,28 @@ model_with_set_propertes_t *model_with_set_propertes_create(
model_with_set_propertes_local_var->tag_set = tag_set; model_with_set_propertes_local_var->tag_set = tag_set;
model_with_set_propertes_local_var->string_set = string_set; model_with_set_propertes_local_var->string_set = string_set;
model_with_set_propertes_local_var->_library_owned = 1;
return model_with_set_propertes_local_var; return model_with_set_propertes_local_var;
} }
__attribute__((deprecated)) model_with_set_propertes_t *model_with_set_propertes_create(
list_t *tag_set,
list_t *string_set
) {
return model_with_set_propertes_create_internal (
tag_set,
string_set
);
}
void model_with_set_propertes_free(model_with_set_propertes_t *model_with_set_propertes) { void model_with_set_propertes_free(model_with_set_propertes_t *model_with_set_propertes) {
if(NULL == model_with_set_propertes){ if(NULL == model_with_set_propertes){
return ; return ;
} }
if(model_with_set_propertes->_library_owned != 1){
fprintf(stderr, "WARNING: %s() does NOT free objects allocated by the user\n", "model_with_set_propertes_free");
return ;
}
listEntry_t *listEntry; listEntry_t *listEntry;
if (model_with_set_propertes->tag_set) { if (model_with_set_propertes->tag_set) {
list_ForEach(listEntry, model_with_set_propertes->tag_set) { list_ForEach(listEntry, model_with_set_propertes->tag_set) {
@ -146,7 +160,7 @@ model_with_set_propertes_t *model_with_set_propertes_parseFromJSON(cJSON *model_
} }
model_with_set_propertes_local_var = model_with_set_propertes_create ( model_with_set_propertes_local_var = model_with_set_propertes_create_internal (
tag_set ? tag_setList : NULL, tag_set ? tag_setList : NULL,
string_set ? string_setList : NULL string_set ? string_setList : NULL
); );

View File

@ -23,9 +23,10 @@ typedef struct model_with_set_propertes_t {
list_t *tag_set; //nonprimitive container list_t *tag_set; //nonprimitive container
list_t *string_set; //primitive container list_t *string_set; //primitive container
int _library_owned; // Is the library responsible for freeing this object?
} model_with_set_propertes_t; } model_with_set_propertes_t;
model_with_set_propertes_t *model_with_set_propertes_create( __attribute__((deprecated)) model_with_set_propertes_t *model_with_set_propertes_create(
list_t *tag_set, list_t *tag_set,
list_t *string_set list_t *string_set
); );

View File

@ -22,7 +22,7 @@ openapi_petstore_order_STATUS_e order_status_FromString(char* status){
return 0; return 0;
} }
order_t *order_create( static order_t *order_create_internal(
long id, long id,
long pet_id, long pet_id,
int quantity, int quantity,
@ -41,14 +41,36 @@ order_t *order_create(
order_local_var->status = status; order_local_var->status = status;
order_local_var->complete = complete; order_local_var->complete = complete;
order_local_var->_library_owned = 1;
return order_local_var; return order_local_var;
} }
__attribute__((deprecated)) order_t *order_create(
long id,
long pet_id,
int quantity,
char *ship_date,
openapi_petstore_order_STATUS_e status,
int complete
) {
return order_create_internal (
id,
pet_id,
quantity,
ship_date,
status,
complete
);
}
void order_free(order_t *order) { void order_free(order_t *order) {
if(NULL == order){ if(NULL == order){
return ; return ;
} }
if(order->_library_owned != 1){
fprintf(stderr, "WARNING: %s() does NOT free objects allocated by the user\n", "order_free");
return ;
}
listEntry_t *listEntry; listEntry_t *listEntry;
if (order->ship_date) { if (order->ship_date) {
free(order->ship_date); free(order->ship_date);
@ -195,7 +217,7 @@ order_t *order_parseFromJSON(cJSON *orderJSON){
} }
order_local_var = order_create ( order_local_var = order_create_internal (
id ? id->valuedouble : 0, id ? id->valuedouble : 0,
pet_id ? pet_id->valuedouble : 0, pet_id ? pet_id->valuedouble : 0,
quantity ? quantity->valuedouble : 0, quantity ? quantity->valuedouble : 0,

View File

@ -34,9 +34,10 @@ typedef struct order_t {
openapi_petstore_order_STATUS_e status; //enum openapi_petstore_order_STATUS_e status; //enum
int complete; //boolean int complete; //boolean
int _library_owned; // Is the library responsible for freeing this object?
} order_t; } order_t;
order_t *order_create( __attribute__((deprecated)) order_t *order_create(
long id, long id,
long pet_id, long pet_id,
int quantity, int quantity,

View File

@ -22,7 +22,7 @@ openapi_petstore_pet_STATUS_e pet_status_FromString(char* status){
return 0; return 0;
} }
pet_t *pet_create( static pet_t *pet_create_internal(
long id, long id,
category_t *category, category_t *category,
char *name, char *name,
@ -41,14 +41,36 @@ pet_t *pet_create(
pet_local_var->tags = tags; pet_local_var->tags = tags;
pet_local_var->status = status; pet_local_var->status = status;
pet_local_var->_library_owned = 1;
return pet_local_var; return pet_local_var;
} }
__attribute__((deprecated)) pet_t *pet_create(
long id,
category_t *category,
char *name,
list_t *photo_urls,
list_t *tags,
openapi_petstore_pet_STATUS_e status
) {
return pet_create_internal (
id,
category,
name,
photo_urls,
tags,
status
);
}
void pet_free(pet_t *pet) { void pet_free(pet_t *pet) {
if(NULL == pet){ if(NULL == pet){
return ; return ;
} }
if(pet->_library_owned != 1){
fprintf(stderr, "WARNING: %s() does NOT free objects allocated by the user\n", "pet_free");
return ;
}
listEntry_t *listEntry; listEntry_t *listEntry;
if (pet->category) { if (pet->category) {
category_free(pet->category); category_free(pet->category);
@ -275,7 +297,7 @@ pet_t *pet_parseFromJSON(cJSON *petJSON){
} }
pet_local_var = pet_create ( pet_local_var = pet_create_internal (
id ? id->valuedouble : 0, id ? id->valuedouble : 0,
category ? category_local_nonprim : NULL, category ? category_local_nonprim : NULL,
strdup(name->valuestring), strdup(name->valuestring),

View File

@ -36,9 +36,10 @@ typedef struct pet_t {
list_t *tags; //nonprimitive container list_t *tags; //nonprimitive container
openapi_petstore_pet_STATUS_e status; //enum openapi_petstore_pet_STATUS_e status; //enum
int _library_owned; // Is the library responsible for freeing this object?
} pet_t; } pet_t;
pet_t *pet_create( __attribute__((deprecated)) pet_t *pet_create(
long id, long id,
category_t *category, category_t *category,
char *name, char *name,

View File

@ -5,7 +5,7 @@
tag_t *tag_create( static tag_t *tag_create_internal(
long id, long id,
char *name char *name
) { ) {
@ -16,14 +16,28 @@ tag_t *tag_create(
tag_local_var->id = id; tag_local_var->id = id;
tag_local_var->name = name; tag_local_var->name = name;
tag_local_var->_library_owned = 1;
return tag_local_var; return tag_local_var;
} }
__attribute__((deprecated)) tag_t *tag_create(
long id,
char *name
) {
return tag_create_internal (
id,
name
);
}
void tag_free(tag_t *tag) { void tag_free(tag_t *tag) {
if(NULL == tag){ if(NULL == tag){
return ; return ;
} }
if(tag->_library_owned != 1){
fprintf(stderr, "WARNING: %s() does NOT free objects allocated by the user\n", "tag_free");
return ;
}
listEntry_t *listEntry; listEntry_t *listEntry;
if (tag->name) { if (tag->name) {
free(tag->name); free(tag->name);
@ -87,7 +101,7 @@ tag_t *tag_parseFromJSON(cJSON *tagJSON){
} }
tag_local_var = tag_create ( tag_local_var = tag_create_internal (
id ? id->valuedouble : 0, id ? id->valuedouble : 0,
name && !cJSON_IsNull(name) ? strdup(name->valuestring) : NULL name && !cJSON_IsNull(name) ? strdup(name->valuestring) : NULL
); );

View File

@ -22,9 +22,10 @@ typedef struct tag_t {
long id; //numeric long id; //numeric
char *name; // string char *name; // string
int _library_owned; // Is the library responsible for freeing this object?
} tag_t; } tag_t;
tag_t *tag_create( __attribute__((deprecated)) tag_t *tag_create(
long id, long id,
char *name char *name
); );

View File

@ -5,7 +5,7 @@
user_t *user_create( static user_t *user_create_internal(
long id, long id,
char *username, char *username,
char *first_name, char *first_name,
@ -32,14 +32,44 @@ user_t *user_create(
user_local_var->extra = extra; user_local_var->extra = extra;
user_local_var->preference = preference; user_local_var->preference = preference;
user_local_var->_library_owned = 1;
return user_local_var; return user_local_var;
} }
__attribute__((deprecated)) user_t *user_create(
long id,
char *username,
char *first_name,
char *last_name,
char *email,
char *password,
char *phone,
int user_status,
list_t* extra,
openapi_petstore_preference__e preference
) {
return user_create_internal (
id,
username,
first_name,
last_name,
email,
password,
phone,
user_status,
extra,
preference
);
}
void user_free(user_t *user) { void user_free(user_t *user) {
if(NULL == user){ if(NULL == user){
return ; return ;
} }
if(user->_library_owned != 1){
fprintf(stderr, "WARNING: %s() does NOT free objects allocated by the user\n", "user_free");
return ;
}
listEntry_t *listEntry; listEntry_t *listEntry;
if (user->username) { if (user->username) {
free(user->username); free(user->username);
@ -320,7 +350,7 @@ user_t *user_parseFromJSON(cJSON *userJSON){
} }
user_local_var = user_create ( user_local_var = user_create_internal (
id ? id->valuedouble : 0, id ? id->valuedouble : 0,
username && !cJSON_IsNull(username) ? strdup(username->valuestring) : NULL, username && !cJSON_IsNull(username) ? strdup(username->valuestring) : NULL,
first_name && !cJSON_IsNull(first_name) ? strdup(first_name->valuestring) : NULL, first_name && !cJSON_IsNull(first_name) ? strdup(first_name->valuestring) : NULL,

View File

@ -32,9 +32,10 @@ typedef struct user_t {
list_t* extra; //map list_t* extra; //map
openapi_petstore_preference__e preference; //referenced enum openapi_petstore_preference__e preference; //referenced enum
int _library_owned; // Is the library responsible for freeing this object?
} user_t; } user_t;
user_t *user_create( __attribute__((deprecated)) user_t *user_create(
long id, long id,
char *username, char *username,
char *first_name, char *first_name,