Skip to content

Commit

Permalink
Fix a few issues with the C generator (part 6) (#20332)
Browse files Browse the repository at this point in the history
* [C] Fail build on implicit function declarations

* [C] Complete changes from patch 34c3f8c

* Update samples

* [C] Fail build for global functions with no declaration

* [C] Use "static" for apiClient.c internal functions

* Update samples
  • Loading branch information
eafer authored Dec 21, 2024
1 parent 8790f7c commit 77e9c1f
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ cmake_policy(SET CMP0063 NEW)
set(CMAKE_C_VISIBILITY_PRESET default)
set(CMAKE_VISIBILITY_INLINES_HIDDEN OFF)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
set(CMAKE_C_FLAGS "-Werror=implicit-function-declaration -Werror=missing-declarations")

option(BUILD_SHARED_LIBS "Build using shared libraries" ON)

Expand All @@ -14,7 +15,7 @@ find_package(OpenSSL)
if (OPENSSL_FOUND)
message (STATUS "OPENSSL found")

set(CMAKE_C_FLAGS "-DOPENSSL")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DOPENSSL")
if(CMAKE_VERSION VERSION_LESS 3.4)
include_directories(${OPENSSL_INCLUDE_DIR})
include_directories(${OPENSSL_INCLUDE_DIRS})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,17 @@ void sslConfig_free(sslConfig_t *sslConfig) {
free(sslConfig);
}

void replaceSpaceWithPlus(char *stringToProcess) {
static void replaceSpaceWithPlus(char *stringToProcess) {
for(int i = 0; i < strlen(stringToProcess); i++) {
if(stringToProcess[i] == ' ') {
stringToProcess[i] = '+';
}
}
}

char *assembleTargetUrl(const char *basePath,
const char *operationParameter,
list_t *queryParameters) {
static char *assembleTargetUrl(const char *basePath,
const char *operationParameter,
list_t *queryParameters) {
int neededBufferSizeForQueryParameters = 0;
listEntry_t *listEntry;
Expand Down Expand Up @@ -234,7 +234,7 @@ char *assembleTargetUrl(const char *basePath,
return targetUrl;
}

char *assembleHeaderField(char *key, char *value) {
static char *assembleHeaderField(char *key, char *value) {
char *header = malloc(strlen(key) + strlen(value) + 3);
strcpy(header, key),
Expand All @@ -244,13 +244,13 @@ char *assembleHeaderField(char *key, char *value) {
return header;
}

void postData(CURL *handle, const char *bodyParameters, size_t bodyParametersLength) {
static void postData(CURL *handle, const char *bodyParameters, size_t bodyParametersLength) {
curl_easy_setopt(handle, CURLOPT_POSTFIELDS, bodyParameters);
curl_easy_setopt(handle, CURLOPT_POSTFIELDSIZE_LARGE,
(curl_off_t)bodyParametersLength);
}

int lengthOfKeyPair(keyValuePair_t *keyPair) {
static int lengthOfKeyPair(keyValuePair_t *keyPair) {
long length = 0;
if((keyPair->key != NULL) &&
(keyPair->value != NULL) )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ cJSON *{{classname}}_convertToJSON({{classname}}_t *{{classname}}) {
{{/isBoolean}}
{{#isEnum}}
{{#isString}}
if(cJSON_AddStringToObject(item, "{{{baseName}}}", {{{name}}}{{classname}}_ToString({{{classname}}}->{{{name}}})) == NULL)
if(cJSON_AddStringToObject(item, "{{{baseName}}}", {{classname}}_{{name}}_ToString({{{classname}}}->{{{name}}})) == NULL)
{
goto fail; //Enum
}
Expand Down
3 changes: 2 additions & 1 deletion samples/client/others/c/bearerAuth/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ cmake_policy(SET CMP0063 NEW)
set(CMAKE_C_VISIBILITY_PRESET default)
set(CMAKE_VISIBILITY_INLINES_HIDDEN OFF)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
set(CMAKE_C_FLAGS "-Werror=implicit-function-declaration -Werror=missing-declarations")

option(BUILD_SHARED_LIBS "Build using shared libraries" ON)

Expand All @@ -14,7 +15,7 @@ find_package(OpenSSL)
if (OPENSSL_FOUND)
message (STATUS "OPENSSL found")

set(CMAKE_C_FLAGS "-DOPENSSL")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DOPENSSL")
if(CMAKE_VERSION VERSION_LESS 3.4)
include_directories(${OPENSSL_INCLUDE_DIR})
include_directories(${OPENSSL_INCLUDE_DIRS})
Expand Down
14 changes: 7 additions & 7 deletions samples/client/others/c/bearerAuth/src/apiClient.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,17 @@ void sslConfig_free(sslConfig_t *sslConfig) {
free(sslConfig);
}

void replaceSpaceWithPlus(char *stringToProcess) {
static void replaceSpaceWithPlus(char *stringToProcess) {
for(int i = 0; i < strlen(stringToProcess); i++) {
if(stringToProcess[i] == ' ') {
stringToProcess[i] = '+';
}
}
}

char *assembleTargetUrl(const char *basePath,
const char *operationParameter,
list_t *queryParameters) {
static char *assembleTargetUrl(const char *basePath,
const char *operationParameter,
list_t *queryParameters) {
int neededBufferSizeForQueryParameters = 0;
listEntry_t *listEntry;

Expand Down Expand Up @@ -150,7 +150,7 @@ char *assembleTargetUrl(const char *basePath,
return targetUrl;
}

char *assembleHeaderField(char *key, char *value) {
static char *assembleHeaderField(char *key, char *value) {
char *header = malloc(strlen(key) + strlen(value) + 3);

strcpy(header, key),
Expand All @@ -160,13 +160,13 @@ char *assembleHeaderField(char *key, char *value) {
return header;
}

void postData(CURL *handle, const char *bodyParameters, size_t bodyParametersLength) {
static void postData(CURL *handle, const char *bodyParameters, size_t bodyParametersLength) {
curl_easy_setopt(handle, CURLOPT_POSTFIELDS, bodyParameters);
curl_easy_setopt(handle, CURLOPT_POSTFIELDSIZE_LARGE,
(curl_off_t)bodyParametersLength);
}

int lengthOfKeyPair(keyValuePair_t *keyPair) {
static int lengthOfKeyPair(keyValuePair_t *keyPair) {
long length = 0;
if((keyPair->key != NULL) &&
(keyPair->value != NULL) )
Expand Down
3 changes: 2 additions & 1 deletion samples/client/petstore/c-useJsonUnformatted/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ cmake_policy(SET CMP0063 NEW)
set(CMAKE_C_VISIBILITY_PRESET default)
set(CMAKE_VISIBILITY_INLINES_HIDDEN OFF)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
set(CMAKE_C_FLAGS "-Werror=implicit-function-declaration -Werror=missing-declarations")

option(BUILD_SHARED_LIBS "Build using shared libraries" ON)

Expand All @@ -14,7 +15,7 @@ find_package(OpenSSL)
if (OPENSSL_FOUND)
message (STATUS "OPENSSL found")

set(CMAKE_C_FLAGS "-DOPENSSL")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DOPENSSL")
if(CMAKE_VERSION VERSION_LESS 3.4)
include_directories(${OPENSSL_INCLUDE_DIR})
include_directories(${OPENSSL_INCLUDE_DIRS})
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/c-useJsonUnformatted/model/order.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ cJSON *order_convertToJSON(order_t *order) {

// order->status
if(order->status != openapi_petstore_order_STATUS_NULL) {
if(cJSON_AddStringToObject(item, "status", statusorder_ToString(order->status)) == NULL)
if(cJSON_AddStringToObject(item, "status", order_status_ToString(order->status)) == NULL)
{
goto fail; //Enum
}
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/c-useJsonUnformatted/model/pet.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ cJSON *pet_convertToJSON(pet_t *pet) {

// pet->status
if(pet->status != openapi_petstore_pet_STATUS_NULL) {
if(cJSON_AddStringToObject(item, "status", statuspet_ToString(pet->status)) == NULL)
if(cJSON_AddStringToObject(item, "status", pet_status_ToString(pet->status)) == NULL)
{
goto fail; //Enum
}
Expand Down
14 changes: 7 additions & 7 deletions samples/client/petstore/c-useJsonUnformatted/src/apiClient.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,17 @@ void sslConfig_free(sslConfig_t *sslConfig) {
free(sslConfig);
}

void replaceSpaceWithPlus(char *stringToProcess) {
static void replaceSpaceWithPlus(char *stringToProcess) {
for(int i = 0; i < strlen(stringToProcess); i++) {
if(stringToProcess[i] == ' ') {
stringToProcess[i] = '+';
}
}
}

char *assembleTargetUrl(const char *basePath,
const char *operationParameter,
list_t *queryParameters) {
static char *assembleTargetUrl(const char *basePath,
const char *operationParameter,
list_t *queryParameters) {
int neededBufferSizeForQueryParameters = 0;
listEntry_t *listEntry;

Expand Down Expand Up @@ -177,7 +177,7 @@ char *assembleTargetUrl(const char *basePath,
return targetUrl;
}

char *assembleHeaderField(char *key, char *value) {
static char *assembleHeaderField(char *key, char *value) {
char *header = malloc(strlen(key) + strlen(value) + 3);

strcpy(header, key),
Expand All @@ -187,13 +187,13 @@ char *assembleHeaderField(char *key, char *value) {
return header;
}

void postData(CURL *handle, const char *bodyParameters, size_t bodyParametersLength) {
static void postData(CURL *handle, const char *bodyParameters, size_t bodyParametersLength) {
curl_easy_setopt(handle, CURLOPT_POSTFIELDS, bodyParameters);
curl_easy_setopt(handle, CURLOPT_POSTFIELDSIZE_LARGE,
(curl_off_t)bodyParametersLength);
}

int lengthOfKeyPair(keyValuePair_t *keyPair) {
static int lengthOfKeyPair(keyValuePair_t *keyPair) {
long length = 0;
if((keyPair->key != NULL) &&
(keyPair->value != NULL) )
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/c/model/order.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ cJSON *order_convertToJSON(order_t *order) {

// order->status
if(order->status != openapi_petstore_order_STATUS_NULL) {
if(cJSON_AddStringToObject(item, "status", statusorder_ToString(order->status)) == NULL)
if(cJSON_AddStringToObject(item, "status", order_status_ToString(order->status)) == NULL)
{
goto fail; //Enum
}
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/c/model/pet.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ cJSON *pet_convertToJSON(pet_t *pet) {

// pet->status
if(pet->status != openapi_petstore_pet_STATUS_NULL) {
if(cJSON_AddStringToObject(item, "status", statuspet_ToString(pet->status)) == NULL)
if(cJSON_AddStringToObject(item, "status", pet_status_ToString(pet->status)) == NULL)
{
goto fail; //Enum
}
Expand Down
14 changes: 7 additions & 7 deletions samples/client/petstore/c/src/apiClient.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,17 @@ void sslConfig_free(sslConfig_t *sslConfig) {
free(sslConfig);
}

void replaceSpaceWithPlus(char *stringToProcess) {
static void replaceSpaceWithPlus(char *stringToProcess) {
for(int i = 0; i < strlen(stringToProcess); i++) {
if(stringToProcess[i] == ' ') {
stringToProcess[i] = '+';
}
}
}

char *assembleTargetUrl(const char *basePath,
const char *operationParameter,
list_t *queryParameters) {
static char *assembleTargetUrl(const char *basePath,
const char *operationParameter,
list_t *queryParameters) {
int neededBufferSizeForQueryParameters = 0;
listEntry_t *listEntry;

Expand Down Expand Up @@ -177,7 +177,7 @@ char *assembleTargetUrl(const char *basePath,
return targetUrl;
}

char *assembleHeaderField(char *key, char *value) {
static char *assembleHeaderField(char *key, char *value) {
char *header = malloc(strlen(key) + strlen(value) + 3);

strcpy(header, key),
Expand All @@ -187,13 +187,13 @@ char *assembleHeaderField(char *key, char *value) {
return header;
}

void postData(CURL *handle, const char *bodyParameters, size_t bodyParametersLength) {
static void postData(CURL *handle, const char *bodyParameters, size_t bodyParametersLength) {
curl_easy_setopt(handle, CURLOPT_POSTFIELDS, bodyParameters);
curl_easy_setopt(handle, CURLOPT_POSTFIELDSIZE_LARGE,
(curl_off_t)bodyParametersLength);
}

int lengthOfKeyPair(keyValuePair_t *keyPair) {
static int lengthOfKeyPair(keyValuePair_t *keyPair) {
long length = 0;
if((keyPair->key != NULL) &&
(keyPair->value != NULL) )
Expand Down

0 comments on commit 77e9c1f

Please sign in to comment.