Skip to content

Commit

Permalink
Merge branch 'main' into swift_error
Browse files Browse the repository at this point in the history
  • Loading branch information
waahm7 authored Aug 1, 2024
2 parents 3138c2c + 0a98aa0 commit f48763c
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 76 deletions.
23 changes: 16 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- 'main'

env:
BUILDER_VERSION: v0.9.55
BUILDER_VERSION: v0.9.62
BUILDER_HOST: https://d19elf31gohf1l.cloudfront.net
BUILDER_SOURCE: releases
PACKAGE_NAME: aws-c-common
Expand Down Expand Up @@ -174,17 +174,26 @@ jobs:
echo "Starting to run AppVerifier on all tests found by CTest"
python .\aws-c-common\scripts\appverifier_ctest.py --build_directory .\aws-c-common\build\aws-c-common
osx:
runs-on: macos-12 # latest
macos-x64:
runs-on: macos-14-large # latest
steps:
- name: Build ${{ env.PACKAGE_NAME }} + consumers
run: |
python3 -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz?run=${{ env.RUN }}', 'builder')"
chmod a+x builder
./builder build -p ${{ env.PACKAGE_NAME }}
osx-no-cpu-extensions:
runs-on: macos-12 # latest
macos:
runs-on: macos-14 # latest
steps:
- name: Build ${{ env.PACKAGE_NAME }} + consumers
run: |
python3 -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz?run=${{ env.RUN }}', 'builder')"
chmod a+x builder
./builder build -p ${{ env.PACKAGE_NAME }}
macos-no-cpu-extensions:
runs-on: macos-14 # latest
steps:
- name: Build ${{ env.PACKAGE_NAME }} + consumers
run: |
Expand Down Expand Up @@ -255,8 +264,8 @@ jobs:
python -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz?run=${{ env.RUN }}', 'builder.pyz')"
python builder.pyz build -p ${{ env.PACKAGE_NAME }} --config Debug
osx-debug:
runs-on: macos-12 # latest
macos-debug:
runs-on: macos-14 # latest
steps:
- name: Build ${{ env.PACKAGE_NAME }} + consumers
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/proof_ci_resources/config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Use exact versions (instead of "latest") so we're not broken by surprise upgrades.
cadical-tag: "rel-2.0.0" # tag of latest release: https://github.com/arminbiere/cadical/releases
cbmc-version: "6.0.0" # semver of latest release: https://github.com/diffblue/cbmc/releases
cbmc-viewer-version: "3.8" # semver of latest release: https://github.com/model-checking/cbmc-viewer/releases
cbmc-version: "6.1.0" # semver of latest release: https://github.com/diffblue/cbmc/releases
cbmc-viewer-version: "3.9" # semver of latest release: https://github.com/model-checking/cbmc-viewer/releases
kissat-tag: "rel-3.1.1" # tag of latest release: https://github.com/arminbiere/kissat/releases
litani-version: "1.29.0" # semver of latest release: https://github.com/awslabs/aws-build-accumulator/releases
proofs-dir: verification/cbmc/proofs
Expand Down
69 changes: 68 additions & 1 deletion include/aws/common/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,26 @@ AWS_EXTERN_C_BEGIN
*
* Note: You will need to free the memory for the aws_json_value using aws_json_destroy on the aws_json_value or
* on the object/array containing the aws_json_value.
* @param string A byte pointer to the string you want to store in the aws_json_value
* Note: might be slower than c_str version due to internal copy
* @param string A byte cursor you want to store in the aws_json_value
* @param allocator The allocator to use when creating the value
* @return A new string aws_json_value
*/
AWS_COMMON_API
struct aws_json_value *aws_json_value_new_string(struct aws_allocator *allocator, struct aws_byte_cursor string);

/**
* Creates a new string aws_json_value with the given string and returns a pointer to it.
*
* Note: You will need to free the memory for the aws_json_value using aws_json_destroy on the aws_json_value or
* on the object/array containing the aws_json_value.
* @param string c string pointer you want to store in the aws_json_value
* @param allocator The allocator to use when creating the value
* @return A new string aws_json_value
*/
AWS_COMMON_API
struct aws_json_value *aws_json_value_new_string_from_c_str(struct aws_allocator *allocator, const char *string);

/**
* Creates a new number aws_json_value with the given number and returns a pointer to it.
*
Expand Down Expand Up @@ -129,6 +142,7 @@ int aws_json_value_get_boolean(const struct aws_json_value *value, bool *output)
*
* Note that the aws_json_value will be destroyed when the aws_json_value object is destroyed
* by calling "aws_json_destroy()"
* Note: might be slower than c_str version due to internal copy
* @param object The object aws_json_value you want to add a value to.
* @param key The key to add the aws_json_value at.
* @param value The aws_json_value you want to add.
Expand All @@ -142,26 +156,66 @@ int aws_json_value_add_to_object(
struct aws_byte_cursor key,
struct aws_json_value *value);

/**
* Adds a aws_json_value to a object aws_json_value.
*
* Note that the aws_json_value will be destroyed when the aws_json_value object is destroyed
* by calling "aws_json_destroy()"
* @param object The object aws_json_value you want to add a value to.
* @param key The key to add the aws_json_value at.
* @param value The aws_json_value you want to add.
* @return AWS_OP_SUCCESS if adding was successful.
* Will return AWS_OP_ERROR if the object passed is invalid or if the passed key
* is already in use in the object.
*/
AWS_COMMON_API
int aws_json_value_add_to_object_c_str(struct aws_json_value *object, const char *key, struct aws_json_value *value);

/**
* Returns the aws_json_value at the given key.
* Note: might be slower than c_str version due to internal copy
* @param object The object aws_json_value you want to get the value from.
* @param key The key that the aws_json_value is at. Is case sensitive.
* @return The aws_json_value at the given key, otherwise NULL.
*/
AWS_COMMON_API
struct aws_json_value *aws_json_value_get_from_object(const struct aws_json_value *object, struct aws_byte_cursor key);

/**
* Returns the aws_json_value at the given key.
* Note: same as aws_json_value_get_from_object but with key as const char *.
* Prefer this method is you have a key thats already a valid char * as it is likely to be faster.
* @param object The object aws_json_value you want to get the value from.
* @param key The key that the aws_json_value is at. Is case sensitive.
* @return The aws_json_value at the given key, otherwise NULL.
*/
AWS_COMMON_API
struct aws_json_value *aws_json_value_get_from_object_c_str(const struct aws_json_value *object, const char *key);

/**
* Checks if there is a aws_json_value at the given key.
* Note: might be slower than c_str version due to internal copy
* @param object The value aws_json_value you want to check a key in.
* @param key The key that you want to check. Is case sensitive.
* @return True if a aws_json_value is found.
*/
AWS_COMMON_API
bool aws_json_value_has_key(const struct aws_json_value *object, struct aws_byte_cursor key);

/**
* Checks if there is a aws_json_value at the given key.
* Note: same as aws_json_value_has_key but with key as const char *.
* Prefer this method is you have a key thats already a valid char * as it is likely to be faster.
* @param object The value aws_json_value you want to check a key in.
* @param key The key that you want to check. Is case sensitive.
* @return True if a aws_json_value is found.
*/
AWS_COMMON_API
bool aws_json_value_has_key_c_str(const struct aws_json_value *object, const char *key);

/**
* Removes the aws_json_value at the given key.
* Note: might be slower than c_str version due to internal copy
* @param object The object aws_json_value you want to remove a aws_json_value in.
* @param key The key that the aws_json_value is at. Is case sensitive.
* @return AWS_OP_SUCCESS if the aws_json_value was removed.
Expand All @@ -171,6 +225,19 @@ bool aws_json_value_has_key(const struct aws_json_value *object, struct aws_byte
AWS_COMMON_API
int aws_json_value_remove_from_object(struct aws_json_value *object, struct aws_byte_cursor key);

/**
* Removes the aws_json_value at the given key.
* Note: same as aws_json_value_remove_from_object but with key as const char *.
* Prefer this method is you have a key thats already a valid char * as it is likely to be faster.
* @param object The object aws_json_value you want to remove a aws_json_value in.
* @param key The key that the aws_json_value is at. Is case sensitive.
* @return AWS_OP_SUCCESS if the aws_json_value was removed.
* Will return AWS_OP_ERR if the object passed is invalid or if the value
* at the key cannot be found.
*/
AWS_COMMON_API
int aws_json_value_remove_from_object_c_str(struct aws_json_value *object, const char *key);

/**
* @brief callback for iterating members of an object
* Iteration can be controlled as follows:
Expand Down
91 changes: 50 additions & 41 deletions source/json.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ struct aws_json_value *aws_json_value_new_string(struct aws_allocator *allocator
return ret_val;
}

struct aws_json_value *aws_json_value_new_string_from_c_str(struct aws_allocator *allocator, const char *string) {
(void)allocator; /* No need for allocator. It is overriden through hooks. */
void *ret_val = cJSON_CreateString(string);
return ret_val;
}

struct aws_json_value *aws_json_value_new_number(struct aws_allocator *allocator, double number) {
(void)allocator; // prevent warnings over unused parameter
return (void *)cJSON_CreateNumber(number);
Expand Down Expand Up @@ -78,92 +84,95 @@ int aws_json_value_add_to_object(
struct aws_byte_cursor key,
struct aws_json_value *value) {

int result = AWS_OP_ERR;
struct aws_string *tmp = aws_string_new_from_cursor(s_aws_json_module_allocator, &key);
int result = aws_json_value_add_to_object_c_str(object, aws_string_c_str(tmp), value);

aws_string_destroy_secure(tmp);
return result;
}

int aws_json_value_add_to_object_c_str(struct aws_json_value *object, const char *key, struct aws_json_value *value) {

struct cJSON *cjson = (struct cJSON *)object;
if (!cJSON_IsObject(cjson)) {
aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
goto done;
return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
}

struct cJSON *cjson_value = (struct cJSON *)value;
if (cJSON_IsInvalid(cjson_value)) {
result = aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
goto done;
return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
}
if (cJSON_HasObjectItem(cjson, aws_string_c_str(tmp))) {
goto done;
if (cJSON_HasObjectItem(cjson, key)) {
return AWS_OP_ERR;
}

cJSON_AddItemToObject(cjson, aws_string_c_str(tmp), cjson_value);
result = AWS_OP_SUCCESS;

done:
aws_string_destroy_secure(tmp);
return result;
cJSON_AddItemToObject(cjson, key, cjson_value);
return AWS_OP_SUCCESS;
}

struct aws_json_value *aws_json_value_get_from_object(const struct aws_json_value *object, struct aws_byte_cursor key) {

void *return_value = NULL;
struct aws_string *tmp = aws_string_new_from_cursor(s_aws_json_module_allocator, &key);
void *return_value = aws_json_value_get_from_object_c_str(object, aws_string_c_str(tmp));

aws_string_destroy_secure(tmp);
return return_value;
}

struct aws_json_value *aws_json_value_get_from_object_c_str(const struct aws_json_value *object, const char *key) {
const struct cJSON *cjson = (const struct cJSON *)object;
if (!cJSON_IsObject(cjson)) {
aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
goto done;
return NULL;
}
if (!cJSON_HasObjectItem(cjson, aws_string_c_str(tmp))) {
goto done;
if (!cJSON_HasObjectItem(cjson, key)) {
return NULL;
}

return_value = (void *)cJSON_GetObjectItem(cjson, aws_string_c_str(tmp));

done:
aws_string_destroy_secure(tmp);
return return_value;
return (void *)cJSON_GetObjectItem(cjson, key);
}

bool aws_json_value_has_key(const struct aws_json_value *object, struct aws_byte_cursor key) {

struct aws_string *tmp = aws_string_new_from_cursor(s_aws_json_module_allocator, &key);
bool result = false;
bool result = aws_json_value_has_key_c_str(object, aws_string_c_str(tmp));

aws_string_destroy_secure(tmp);
return result;
}

bool aws_json_value_has_key_c_str(const struct aws_json_value *object, const char *key) {
const struct cJSON *cjson = (const struct cJSON *)object;
if (!cJSON_IsObject(cjson)) {
goto done;
return false;
}
if (!cJSON_HasObjectItem(cjson, aws_string_c_str(tmp))) {
goto done;
if (!cJSON_HasObjectItem(cjson, key)) {
return false;
}
result = true;

done:
aws_string_destroy_secure(tmp);
return result;
return true;
}

int aws_json_value_remove_from_object(struct aws_json_value *object, struct aws_byte_cursor key) {

int result = AWS_OP_ERR;
struct aws_string *tmp = aws_string_new_from_cursor(s_aws_json_module_allocator, &key);
int result = aws_json_value_remove_from_object_c_str(object, aws_string_c_str(tmp));

aws_string_destroy_secure(tmp);
return result;
}

int aws_json_value_remove_from_object_c_str(struct aws_json_value *object, const char *key) {
struct cJSON *cjson = (struct cJSON *)object;
if (!cJSON_IsObject(cjson)) {
aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
goto done;
return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
}
if (!cJSON_HasObjectItem(cjson, aws_string_c_str(tmp))) {
goto done;
if (!cJSON_HasObjectItem(cjson, key)) {
return AWS_OP_ERR;
}

cJSON_DeleteItemFromObject(cjson, aws_string_c_str(tmp));
result = AWS_OP_SUCCESS;

done:
aws_string_destroy_secure(tmp);
return result;
cJSON_DeleteItemFromObject(cjson, key);
return AWS_OP_SUCCESS;
}

int aws_json_const_iterate_object(
Expand Down
19 changes: 19 additions & 0 deletions source/posix/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,25 @@ int aws_thread_launch(
if (attr_return) {
goto cleanup;
}
} else if (!options->stack_size) {
/**
* On some systems, the default stack size is too low (128KB on musl at the time of writing this), which can
* cause stack overflow when the dependency chain is long. Increase the stack size to at
* least 1MB, which is the default on Windows.
*/
size_t min_stack_size = (size_t)1 * 1024 * 1024;
size_t current_stack_size;
attr_return = pthread_attr_getstacksize(attributes_ptr, &current_stack_size);
if (attr_return) {
goto cleanup;
}

if (current_stack_size < min_stack_size) {
attr_return = pthread_attr_setstacksize(attributes_ptr, min_stack_size);
if (attr_return) {
goto cleanup;
}
}
}

/* AFAIK you can't set thread affinity on apple platforms, and it doesn't really matter since all memory
Expand Down
Loading

0 comments on commit f48763c

Please sign in to comment.