File tree Expand file tree Collapse file tree 10 files changed +42
-35
lines changed Expand file tree Collapse file tree 10 files changed +42
-35
lines changed Original file line number Diff line number Diff line change 1
1
Arduino JSON: change log
2
2
========================
3
3
4
+ HEAD
5
+ ----
6
+
7
+ * Removed global new operator overload (issue #40 , #45 and #46 )
8
+ * Added an example with EthernetServer
9
+
4
10
v4.1
5
11
----
6
12
Original file line number Diff line number Diff line change
1
+ // Copyright Benoit Blanchon 2014
2
+ // MIT License
3
+ //
4
+ // Arduino JSON library
5
+ // https://github.com/bblanchon/ArduinoJson
6
+
7
+ #pragma once
8
+
9
+ #include " ../JsonBuffer.hpp"
10
+
11
+ namespace ArduinoJson {
12
+ namespace Internals {
13
+
14
+ class JsonBufferAllocated {
15
+ public:
16
+ void *operator new (size_t n, JsonBuffer *jsonBuffer) throw () {
17
+ return jsonBuffer->alloc (n);
18
+ }
19
+ };
20
+ }
21
+ }
Original file line number Diff line number Diff line change 9
9
#include " ../JsonBuffer.hpp"
10
10
#include " ListConstIterator.hpp"
11
11
#include " ListIterator.hpp"
12
- #include " PlacementNew.hpp"
13
12
14
13
namespace ArduinoJson {
15
14
namespace Internals {
@@ -51,8 +50,7 @@ class List {
51
50
protected:
52
51
node_type *createNode () {
53
52
if (!_buffer) return NULL ;
54
- void *ptr = _buffer->alloc (sizeof (node_type));
55
- return ptr ? new (ptr) node_type () : NULL ;
53
+ return new (_buffer) node_type ();
56
54
}
57
55
58
56
void addNode (node_type *nodeToAdd) {
Original file line number Diff line number Diff line change 8
8
9
9
#include < stddef.h> // for NULL
10
10
11
+ #include " JsonBufferAllocated.hpp"
12
+
11
13
namespace ArduinoJson {
12
14
namespace Internals {
13
15
14
16
// A node for a singly-linked list.
15
17
// Used by List<T> and its iterators.
16
18
template <typename T>
17
- struct ListNode {
19
+ struct ListNode : public Internals ::JsonBufferAllocated {
18
20
ListNode () : next(NULL ) {}
19
21
20
- ListNode<T>* next;
22
+ ListNode<T> * next;
21
23
T content;
22
24
};
23
25
}
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 6
6
7
7
#pragma once
8
8
9
+ #include " Internals/JsonBufferAllocated.hpp"
9
10
#include " Internals/JsonPrintable.hpp"
10
11
#include " Internals/List.hpp"
11
12
#include " Internals/ReferenceType.hpp"
@@ -30,7 +31,8 @@ class JsonBuffer;
30
31
// It can also be deserialized from a JSON string via JsonBuffer::parseArray().
31
32
class JsonArray : public Internals ::JsonPrintable<JsonArray>,
32
33
public Internals::ReferenceType,
33
- public Internals::List<JsonVariant> {
34
+ public Internals::List<JsonVariant>,
35
+ public Internals::JsonBufferAllocated {
34
36
// JsonBuffer is a friend because it needs to call the private constructor.
35
37
friend class JsonBuffer ;
36
38
Original file line number Diff line number Diff line change 6
6
7
7
#pragma once
8
8
9
+ #include " Internals/JsonBufferAllocated.hpp"
9
10
#include " Internals/JsonPrintable.hpp"
10
11
#include " Internals/List.hpp"
11
12
#include " Internals/ReferenceType.hpp"
@@ -30,7 +31,8 @@ class JsonBuffer;
30
31
// It can also be deserialized from a JSON string via JsonBuffer::parseObject().
31
32
class JsonObject : public Internals ::JsonPrintable<JsonObject>,
32
33
public Internals::ReferenceType,
33
- public Internals::List<JsonPair> {
34
+ public Internals::List<JsonPair>,
35
+ public Internals::JsonBufferAllocated {
34
36
// JsonBuffer is a friend because it needs to call the private constructor.
35
37
friend class JsonBuffer ;
36
38
Original file line number Diff line number Diff line change 6
6
7
7
#include " ../../include/ArduinoJson/Internals/List.hpp"
8
8
9
- #include " ../../include/ArduinoJson/Internals/PlacementNew.hpp"
10
9
#include " ../../include/ArduinoJson/JsonPair.hpp"
11
10
#include " ../../include/ArduinoJson/JsonVariant.hpp"
12
11
Original file line number Diff line number Diff line change 7
7
#include " ../include/ArduinoJson/JsonBuffer.hpp"
8
8
9
9
#include " ../include/ArduinoJson/Internals/JsonParser.hpp"
10
- #include " ../include/ArduinoJson/Internals/PlacementNew.hpp"
11
10
#include " ../include/ArduinoJson/JsonArray.hpp"
12
11
#include " ../include/ArduinoJson/JsonObject.hpp"
13
12
14
13
using namespace ArduinoJson ;
15
14
using namespace ArduinoJson ::Internals;
16
15
17
16
JsonArray &JsonBuffer::createArray () {
18
- void *ptr = alloc (sizeof (JsonArray));
19
- if (ptr) return *new (ptr) JsonArray (this );
20
- return JsonArray::invalid ();
17
+ JsonArray *ptr = new (this ) JsonArray (this );
18
+ return ptr ? *ptr : JsonArray::invalid ();
21
19
}
22
20
23
21
JsonObject &JsonBuffer::createObject () {
24
- void *ptr = alloc (sizeof (JsonObject));
25
- if (ptr) return *new (ptr) JsonObject (this );
26
- return JsonObject::invalid ();
22
+ JsonObject *ptr = new (this ) JsonObject (this );
23
+ return ptr ? *ptr : JsonObject::invalid ();
27
24
}
28
25
29
26
JsonArray &JsonBuffer::parseArray (char *json, uint8_t nestingLimit) {
Original file line number Diff line number Diff line change 8
8
9
9
#include < string.h> // for strcmp
10
10
11
- #include " ../include/ArduinoJson/Internals/PlacementNew.hpp"
12
11
#include " ../include/ArduinoJson/Internals/StringBuilder.hpp"
13
12
#include " ../include/ArduinoJson/JsonArray.hpp"
14
13
#include " ../include/ArduinoJson/JsonBuffer.hpp"
You can’t perform that action at this time.
0 commit comments