Skip to content

Commit

Permalink
apply the latest change
Browse files Browse the repository at this point in the history
  • Loading branch information
TingDaoK committed Jun 19, 2024
1 parent 15cee91 commit 78379e3
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 51 deletions.
54 changes: 22 additions & 32 deletions awscrt/cbor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,25 @@
from typing import Union, Any


class AwsCborElementType(IntEnum):
# Corresponding to `enum aws_cbor_element_type` in aws/common/cbor.h
UnsignedInt = 0
NegativeInt = 1
Float = 2
Bytes = 3
Text = 4
ArrayStart = 5
MapStart = 6
Tag = 7
Bool = 8
Null = 9
Undefined = 10
Break = 11
IndefBytes = 12
IndefStr = 13
IndefArray = 14
IndefMap = 15


class AwsCborTags(IntEnum):
# Corresponding to `enum aws_cbor_tags` in aws/common/cbor.h
StandardTime = 0
EpochTime = 1
UnsignedBigNum = 2
NegativeBigNum = 3
DecimalFraction = 4
BigFloat = 5
Unclassified = 6
class AwsCborType(IntEnum):
# Corresponding to `enum aws_cbor_type` in aws/common/cbor.h
Unknown = 0
UnsignedInt = 1
NegativeInt = 2
Float = 3
Bytes = 4
Text = 5
ArrayStart = 6
MapStart = 7
Tag = 8
Bool = 9
Null = 10
Undefined = 11
Break = 12
IndefBytes = 13
IndefStr = 14
IndefArray = 15
IndefMap = 16


class AwsCborEncoder(NativeResource):
Expand Down Expand Up @@ -152,7 +142,7 @@ def write_tag(self, tag_number: int):
return _awscrt.cbor_encoder_write_tag(self._binding, tag_number)

def write_null(self):
return _awscrt.cbor_encoder_write_simple_types(self._binding, AwsCborElementType.Null)
return _awscrt.cbor_encoder_write_simple_types(self._binding, AwsCborType.Null)

def write_bool(self, val: bool):
return _awscrt.cbor_encoder_write_bool(self._binding, val)
Expand Down Expand Up @@ -181,8 +171,8 @@ def __init__(self, src: bytes):
self._src = src
self._binding = _awscrt.cbor_decoder_new(src)

def peek_next_type(self) -> AwsCborElementType:
return AwsCborElementType(_awscrt.cbor_decoder_peek_type(self._binding))
def peek_next_type(self) -> AwsCborType:
return AwsCborType(_awscrt.cbor_decoder_peek_type(self._binding))

def get_remaining_bytes_len(self) -> int:
return _awscrt.cbor_decoder_get_remaining_bytes_len(self._binding)
Expand Down
2 changes: 1 addition & 1 deletion crt/aws-c-common
Submodule aws-c-common updated 52 files
+1 −1 .github/workflows/ci.yml
+4 −7 .github/workflows/clang-format.yml
+1 −1 CMakeLists.txt
+1 −0 cmake/AwsTestHarness.cmake
+47 −0 format-check.py
+0 −24 format-check.sh
+2 −4 include/aws/common/atomics.h
+1 −1 include/aws/common/byte_buf.h
+35 −44 include/aws/common/cbor.h
+2 −4 include/aws/common/condition_variable.h
+5 −2 include/aws/common/error.h
+2 −2 include/aws/common/logging.h
+1 −1 include/aws/common/macros.h
+2 −4 include/aws/common/mutex.h
+11 −1 include/aws/common/private/byte_buf.h
+0 −103 include/aws/common/promise.h
+2 −4 include/aws/common/rw_lock.h
+1 −1 include/aws/common/statistics.h
+1 −2 include/aws/common/thread.h
+12 −24 include/aws/testing/aws_test_harness.h
+8 −18 scripts/import_libcbor.py
+1 −1 source/allocator.c
+3 −1 source/android/logging.c
+4 −4 source/arch/intel/encoding_avx2.c
+6 −3 source/array_list.c
+19 −27 source/byte_buf.c
+92 −187 source/cbor.c
+1 −1 source/common.c
+2 −2 source/encoding.c
+17 −3 source/external/cJSON.c
+1 −1 source/external/cJSON.h
+0 −2 source/external/libcbor/cbor/configuration.h
+1 −14 source/host_utils.c
+37 −22 source/memtrace.c
+1 −1 source/posix/clock.c
+1 −1 source/priority_queue.c
+0 −118 source/promise.c
+3 −3 source/task_scheduler.c
+15 −6 source/uri.c
+1 −8 tests/CMakeLists.txt
+2 −0 tests/assert_test.c
+2 −2 tests/atomics_test.c
+44 −100 tests/cbor_test.c
+18 −14 tests/condition_variable_test.c
+9 −7 tests/error_test.c
+7 −6 tests/fuzz/cbor_decoding_transitive.c
+3 −3 tests/fuzz/cbor_double_encode_decode.c
+7 −8 tests/host_util_test.c
+12 −8 tests/memtrace_test.c
+0 −181 tests/promise_test.c
+1 −1 tests/thread_test.c
+2 −2 tests/uri_test.c
38 changes: 20 additions & 18 deletions source/cbor.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ static struct aws_cbor_decoder *s_cbor_decoder_from_capsule(PyObject *py_capsule
/* Runs when GC destroys the capsule */
static void s_cbor_decoder_capsule_destructor(PyObject *py_capsule) {
struct aws_cbor_decoder *decoder = s_cbor_decoder_from_capsule(py_capsule);
aws_cbor_decoder_release(decoder);
aws_cbor_decoder_destroy(decoder);
}

PyObject *aws_py_cbor_decoder_new(PyObject *self, PyObject *args) {
Expand All @@ -319,11 +319,11 @@ PyObject *aws_py_cbor_decoder_new(PyObject *self, PyObject *args) {
return NULL;
}

struct aws_cbor_decoder *decoder = aws_cbor_decoder_new(aws_py_get_allocator(), &src);
struct aws_cbor_decoder *decoder = aws_cbor_decoder_new(aws_py_get_allocator(), src);
AWS_ASSERT(decoder != NULL);
PyObject *py_capsule = PyCapsule_New(decoder, s_capsule_name_cbor_decoder, s_cbor_decoder_capsule_destructor);
if (!py_capsule) {
aws_cbor_decoder_release(decoder);
aws_cbor_decoder_destroy(decoder);
return NULL;
}

Expand Down Expand Up @@ -366,7 +366,7 @@ PyObject *aws_py_cbor_decoder_new(PyObject *self, PyObject *args) {
}

PyObject *aws_py_cbor_decoder_peek_type(PyObject *self, PyObject *args) {
enum aws_cbor_element_type out_type;
enum aws_cbor_type out_type;
S_DECODER_METHOD_START(aws_cbor_decoder_peek_type, out_type);
return PyLong_FromSize_t(out_type);
}
Expand All @@ -378,14 +378,16 @@ PyObject *aws_py_cbor_decoder_get_remaining_bytes_len(PyObject *self, PyObject *
}

PyObject *aws_py_cbor_decoder_consume_next_element(PyObject *self, PyObject *args) {
enum aws_cbor_element_type out_type;
S_DECODER_METHOD_START(aws_cbor_decoder_consume_next_element, out_type);
S_GET_DECODER();
if (aws_cbor_decoder_consume_next_single_element(decoder)) {
return PyErr_AwsLastError();
}
Py_RETURN_NONE;
}

PyObject *aws_py_cbor_decoder_consume_next_data_item(PyObject *self, PyObject *args) {
S_GET_DECODER();
if (aws_cbor_decoder_consume_next_data_item(decoder)) {
if (aws_cbor_decoder_consume_next_whole_data_item(decoder)) {
return PyErr_AwsLastError();
}
Py_RETURN_NONE;
Expand All @@ -407,7 +409,7 @@ static PyObject *s_cbor_decoder_pop_next_data_item_to_pyobject(struct aws_cbor_d
* helper to convert next data item to py_list
*/
static PyObject *s_cbor_decoder_pop_next_data_item_to_py_list(struct aws_cbor_decoder *decoder) {
enum aws_cbor_element_type out_type = AWS_CBOR_TYPE_MAX;
enum aws_cbor_type out_type = AWS_CBOR_TYPE_UNKNOWN;
if (aws_cbor_decoder_peek_type(decoder, &out_type)) {
return PyErr_AwsLastError();
}
Expand Down Expand Up @@ -440,7 +442,7 @@ static PyObject *s_cbor_decoder_pop_next_data_item_to_py_list(struct aws_cbor_de
return NULL;
}
/* Consume the inf array start */
aws_cbor_decoder_consume_next_element(decoder, NULL /*consumed_type*/);
aws_cbor_decoder_consume_next_single_element(decoder);
aws_cbor_decoder_peek_type(decoder, &out_type);
while (out_type != AWS_CBOR_TYPE_BREAK) {
item = s_cbor_decoder_pop_next_data_item_to_pyobject(decoder);
Expand Down Expand Up @@ -474,7 +476,7 @@ static PyObject *s_cbor_decoder_pop_next_data_item_to_py_list(struct aws_cbor_de
* helper to convert next data item to py_dict
*/
static PyObject *s_cbor_decoder_pop_next_data_item_to_py_dict(struct aws_cbor_decoder *decoder) {
enum aws_cbor_element_type out_type = AWS_CBOR_TYPE_MAX;
enum aws_cbor_type out_type = AWS_CBOR_TYPE_UNKNOWN;
if (aws_cbor_decoder_peek_type(decoder, &out_type)) {
return PyErr_AwsLastError();
}
Expand Down Expand Up @@ -513,7 +515,7 @@ static PyObject *s_cbor_decoder_pop_next_data_item_to_py_dict(struct aws_cbor_de
return NULL;
}
/* Consume the inf array start */
aws_cbor_decoder_consume_next_element(decoder, NULL /*consumed_type*/);
aws_cbor_decoder_consume_next_single_element(decoder);
aws_cbor_decoder_peek_type(decoder, &out_type);
while (out_type != AWS_CBOR_TYPE_BREAK) {
key = s_cbor_decoder_pop_next_data_item_to_pyobject(decoder);
Expand Down Expand Up @@ -554,7 +556,7 @@ static PyObject *s_cbor_decoder_pop_next_data_item_to_py_dict(struct aws_cbor_de
* helper to get the next inf byte
*/
static PyObject *s_cbor_decoder_pop_next_inf_bytes_to_py_bytes(struct aws_cbor_decoder *decoder) {
enum aws_cbor_element_type out_type = AWS_CBOR_TYPE_MAX;
enum aws_cbor_type out_type = AWS_CBOR_TYPE_UNKNOWN;
if (aws_cbor_decoder_peek_type(decoder, &out_type)) {
return PyErr_AwsLastError();
}
Expand All @@ -563,7 +565,7 @@ static PyObject *s_cbor_decoder_pop_next_inf_bytes_to_py_bytes(struct aws_cbor_d
return PyErr_AwsLastError();
}
/* consume the bytes start element */
aws_cbor_decoder_consume_next_element(decoder, NULL);
aws_cbor_decoder_consume_next_single_element(decoder);
if (aws_cbor_decoder_peek_type(decoder, &out_type)) {
return PyErr_AwsLastError();
}
Expand Down Expand Up @@ -591,7 +593,7 @@ static PyObject *s_cbor_decoder_pop_next_inf_bytes_to_py_bytes(struct aws_cbor_d
* helper to get the next inf string
*/
static PyObject *s_cbor_decoder_pop_next_inf_string_to_py_str(struct aws_cbor_decoder *decoder) {
enum aws_cbor_element_type out_type = AWS_CBOR_TYPE_MAX;
enum aws_cbor_type out_type = AWS_CBOR_TYPE_UNKNOWN;
if (aws_cbor_decoder_peek_type(decoder, &out_type)) {
return PyErr_AwsLastError();
}
Expand All @@ -600,7 +602,7 @@ static PyObject *s_cbor_decoder_pop_next_inf_string_to_py_str(struct aws_cbor_de
return PyErr_AwsLastError();
}
/* consume the bytes start element */
aws_cbor_decoder_consume_next_element(decoder, NULL);
aws_cbor_decoder_consume_next_single_element(decoder);
if (aws_cbor_decoder_peek_type(decoder, &out_type)) {
return PyErr_AwsLastError();
}
Expand Down Expand Up @@ -652,7 +654,7 @@ static PyObject *s_cbor_decoder_pop_next_tag_to_pyobject(struct aws_cbor_decoder
* Generic helper to convert a cbor encoded data to PyObject
*/
static PyObject *s_cbor_decoder_pop_next_data_item_to_pyobject(struct aws_cbor_decoder *decoder) {
enum aws_cbor_element_type out_type = AWS_CBOR_TYPE_MAX;
enum aws_cbor_type out_type = AWS_CBOR_TYPE_UNKNOWN;
if (aws_cbor_decoder_peek_type(decoder, &out_type)) {
return PyErr_AwsLastError();
}
Expand Down Expand Up @@ -685,8 +687,8 @@ static PyObject *s_cbor_decoder_pop_next_data_item_to_pyobject(struct aws_cbor_d
return s_cbor_decoder_pop_next_boolean_val_to_pyobject(decoder);
case AWS_CBOR_TYPE_NULL:
/* fall through */
case AWS_CBOR_TYPE_UNDEFINE:
aws_cbor_decoder_consume_next_element(decoder, NULL);
case AWS_CBOR_TYPE_UNDEFINED:
aws_cbor_decoder_consume_next_single_element(decoder);
Py_RETURN_NONE;
case AWS_CBOR_TYPE_MAP_START:
/* fall through */
Expand Down

0 comments on commit 78379e3

Please sign in to comment.