Skip to content

Commit e878d6b

Browse files
committed
Detecting CJSON directories
1 parent 5dde822 commit e878d6b

File tree

8 files changed

+502
-277
lines changed

8 files changed

+502
-277
lines changed

src/aws-cpp-sdk-core/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
if (NOT LEGACY_BUILD)
22
add_library(aws-sdk-cpp-core)
33
add_library(aws-sdk-cpp::core ALIAS aws-sdk-cpp-core)
4+
45
target_include_directories(
56
aws-sdk-cpp-core
67
PUBLIC ${aws-crt-cpp_INCLUDE_DIRS}
8+
PUBLIC ${CJSON_INCLUDE_DIRS}
79
)
810
target_link_directories(
911
aws-sdk-cpp-core
1012
PUBLIC ${aws-crt-cpp_LIB_DIRS}
13+
PUBLIC ${CJSON_LIBRARY_DIRS}
1114
)
1215
target_link_libraries(
1316
aws-sdk-cpp-core
1417
aws-crt-cpp
18+
${CJSON_LIBRARIES}
1519
)
1620
add_subdirectory(include)
1721
add_subdirectory(source)

src/aws-cpp-sdk-core/include/aws/core/external/cjson/cJSON.h

Lines changed: 45 additions & 275 deletions
Large diffs are not rendered by default.

src/aws-cpp-sdk-core/include/aws/core/external/cjson/cJSON_legacy.h

Lines changed: 305 additions & 0 deletions
Large diffs are not rendered by default.

src/aws-cpp-sdk-core/source/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ add_subdirectory(monitoring)
77
add_subdirectory(net)
88
add_subdirectory(platform)
99
add_subdirectory(utils)
10+
add_subdirectory(transition)
1011

1112
target_sources(aws-sdk-cpp-core
1213
PRIVATE
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
message(FATAL_ERROR "Skip this directory when building with new build system")
1+
message(FATAL_ERROR "Skip this directory when building with new build system. Directory only used for Legacy builds.")

src/aws-cpp-sdk-core/source/external/cjson/cJSON.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
#pragma GCC visibility pop
5757
#endif
5858

59-
#include <aws/core/external/cjson/cJSON.h>
59+
#include <aws/core/external/cjson/cJSON_legacy.h>
6060

6161
/* define our own boolean type */
6262
// #ifdef true
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Files in this directory are wrappers used for transition between build processes in 1.10 release
2+
target_sources(aws-sdk-cpp-core
3+
PRIVATE
4+
${CMAKE_CURRENT_SOURCE_DIR}/cJSON.cpp
5+
)
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/*
2+
Copyright (c) 2009-2017 Dave Gamble and cJSON contributors
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy
5+
of this software and associated documentation files (the "Software"), to deal
6+
in the Software without restriction, including without limitation the rights
7+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the Software is
9+
furnished to do so, subject to the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included in
12+
all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
THE SOFTWARE.
21+
*/
22+
23+
/* cJSON */
24+
/* JSON parser in C. */
25+
26+
/* disable warnings about old C89 functions in MSVC */
27+
#if !defined(_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER)
28+
#define _CRT_SECURE_NO_DEPRECATE
29+
#endif
30+
31+
#ifdef __GNUC__
32+
#pragma GCC visibility push(default)
33+
#endif
34+
#if defined(_MSC_VER)
35+
#pragma warning (push)
36+
/* disable warning about single line comments in system headers */
37+
#pragma warning (disable : 4001)
38+
#endif
39+
40+
#include <string.h>
41+
#include <stdio.h>
42+
#include <stdlib.h>
43+
#include <limits.h>
44+
#include <ctype.h>
45+
46+
#ifdef ENABLE_LOCALES
47+
#include <locale.h>
48+
#endif
49+
50+
#if defined(_MSC_VER)
51+
#pragma warning (pop)
52+
#endif
53+
#ifdef __GNUC__
54+
#pragma GCC visibility pop
55+
#endif
56+
57+
#include <aws/core/external/cjson/cJSON.h>
58+
59+
typedef struct internal_hooks {
60+
void *(CJSON_CDECL *allocate)(size_t size);
61+
void (CJSON_CDECL *deallocate)(void *pointer);
62+
void *(CJSON_CDECL *reallocate)(void *pointer, size_t size);
63+
} internal_hooks;
64+
65+
#if defined(_MSC_VER)
66+
/* work around MSVC error C2322: '...' address of dllimport '...' is not static */
67+
static void * CJSON_AS4CPP_CDECL internal_malloc(size_t size)
68+
{
69+
return malloc(size);
70+
}
71+
static void CJSON_AS4CPP_CDECL internal_free(void *pointer)
72+
{
73+
free(pointer);
74+
}
75+
static void * CJSON_AS4CPP_CDECL internal_realloc(void *pointer, size_t size)
76+
{
77+
return realloc(pointer, size);
78+
}
79+
#else
80+
#define internal_malloc malloc
81+
#define internal_free free
82+
#define internal_realloc realloc
83+
#endif
84+
85+
static internal_hooks global_hooks = {internal_malloc, internal_free, internal_realloc};
86+
87+
static unsigned char *cJSON_AS4CPP_strdup(const unsigned char *string, const internal_hooks *const hooks) {
88+
size_t length = 0;
89+
unsigned char *copy = NULL;
90+
91+
if (string == NULL) {
92+
return NULL;
93+
}
94+
95+
length = strlen((const char *) string) + sizeof("");
96+
copy = (unsigned char *) hooks->allocate(length);
97+
if (copy == NULL) {
98+
return NULL;
99+
}
100+
memcpy(copy, string, length);
101+
102+
return copy;
103+
}
104+
105+
/* Internal constructor. */
106+
static cJSON *cJSON_AS4CPP_New_Item(const internal_hooks *const hooks) {
107+
cJSON *node = (cJSON *) hooks->allocate(sizeof(cJSON));
108+
if (node) {
109+
memset(node, '\0', sizeof(cJSON));
110+
}
111+
112+
return node;
113+
}
114+
115+
CJSON_PUBLIC(cJSON *)cJSON_AS4CPP_CreateInt64(long long num) {
116+
cJSON *item = cJSON_AS4CPP_New_Item(&global_hooks);
117+
if (item) {
118+
item->type = cJSON_Number;
119+
item->valuedouble = static_cast<double>(num);
120+
121+
// For integer which is out of the range of [INT_MIN, INT_MAX], it may lose precision if we cast it to double.
122+
// Instead, we keep the integer literal as a string.
123+
if (num > INT_MAX || num < INT_MIN) {
124+
char buf[21];
125+
sprintf(buf, "%lld", num);
126+
item->valuestring = (char *) cJSON_AS4CPP_strdup((const unsigned char *) buf, &global_hooks);
127+
}
128+
129+
/* use saturation in case of overflow */
130+
if (num >= INT_MAX) {
131+
item->valueint = INT_MAX;
132+
} else if (num <= INT_MIN) {
133+
item->valueint = INT_MIN;
134+
} else {
135+
item->valueint = (int) num;
136+
}
137+
}
138+
139+
return item;
140+
}

0 commit comments

Comments
 (0)