Ernesto Fernández e154903743
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>
2025-01-06 10:53:36 +08:00

59 lines
1.3 KiB
C

/*
* pet.h
*
* A pet for sale in the pet store
*/
#ifndef _pet_H_
#define _pet_H_
#include <string.h>
#include "../external/cJSON.h"
#include "../include/list.h"
#include "../include/keyValuePair.h"
#include "../include/binary.h"
typedef struct pet_t pet_t;
#include "category.h"
#include "tag.h"
// Enum STATUS for pet
typedef enum { openapi_petstore_pet_STATUS_NULL = 0, openapi_petstore_pet_STATUS_available, openapi_petstore_pet_STATUS_pending, openapi_petstore_pet_STATUS_sold } openapi_petstore_pet_STATUS_e;
char* pet_status_ToString(openapi_petstore_pet_STATUS_e status);
openapi_petstore_pet_STATUS_e pet_status_FromString(char* status);
typedef struct pet_t {
long id; //numeric
struct category_t *category; //model
char *name; // string
list_t *photo_urls; //primitive container
list_t *tags; //nonprimitive container
openapi_petstore_pet_STATUS_e status; //enum
int _library_owned; // Is the library responsible for freeing this object?
} pet_t;
__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
);
void pet_free(pet_t *pet);
pet_t *pet_parseFromJSON(cJSON *petJSON);
cJSON *pet_convertToJSON(pet_t *pet);
#endif /* _pet_H_ */