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

57 lines
1.3 KiB
C

/*
* order.h
*
* An order for a pets from the pet store
*/
#ifndef _order_H_
#define _order_H_
#include <string.h>
#include "../external/cJSON.h"
#include "../include/list.h"
#include "../include/keyValuePair.h"
#include "../include/binary.h"
typedef struct order_t order_t;
// Enum STATUS for order
typedef enum { openapi_petstore_order_STATUS_NULL = 0, openapi_petstore_order_STATUS_placed, openapi_petstore_order_STATUS_approved, openapi_petstore_order_STATUS_delivered } openapi_petstore_order_STATUS_e;
char* order_status_ToString(openapi_petstore_order_STATUS_e status);
openapi_petstore_order_STATUS_e order_status_FromString(char* status);
typedef struct order_t {
long id; //numeric
long pet_id; //numeric
int quantity; //numeric
char *ship_date; //date time
openapi_petstore_order_STATUS_e status; //enum
int complete; //boolean
int _library_owned; // Is the library responsible for freeing this object?
} order_t;
__attribute__((deprecated)) order_t *order_create(
long id,
long pet_id,
int quantity,
char *ship_date,
openapi_petstore_order_STATUS_e status,
int complete
);
void order_free(order_t *order);
order_t *order_parseFromJSON(cJSON *orderJSON);
cJSON *order_convertToJSON(order_t *order);
#endif /* _order_H_ */