passenger 5.1.7 → 5.1.8

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of passenger might be problematic. Click here for more details.

Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +13 -2
  3. data/CONTRIBUTING.md +1 -1
  4. data/build/agent.rb +1 -1
  5. data/build/cxx_tests.rb +6 -0
  6. data/build/support/cxx_dependency_map.rb +1286 -391
  7. data/build/support/general.rb +0 -26
  8. data/resources/templates/standalone/rails_asset_pipeline.erb +2 -2
  9. data/src/agent/Core/ApiServer.h +49 -44
  10. data/src/agent/Core/ApplicationPool/Pool.h +1 -1
  11. data/src/agent/Core/ApplicationPool/Process.h +1 -1
  12. data/src/agent/Core/ApplicationPool/Socket.h +1 -1
  13. data/src/agent/Core/Controller.h +16 -8
  14. data/src/agent/Core/Controller/CheckoutSession.cpp +1 -1
  15. data/src/agent/Core/Controller/Config.cpp +68 -0
  16. data/src/agent/Core/Controller/Config.h +70 -34
  17. data/src/agent/Core/Controller/ForwardResponse.cpp +5 -5
  18. data/src/agent/Core/Controller/Hooks.cpp +5 -14
  19. data/src/agent/Core/Controller/Implementation.cpp +1 -1
  20. data/src/agent/Core/Controller/InitRequest.cpp +31 -29
  21. data/src/agent/Core/Controller/InitializationAndShutdown.cpp +4 -4
  22. data/src/agent/Core/Controller/InternalUtils.cpp +3 -3
  23. data/src/agent/Core/Controller/Miscellaneous.cpp +1 -1
  24. data/src/agent/Core/Controller/Request.h +2 -2
  25. data/src/agent/Core/Controller/SendRequest.cpp +5 -5
  26. data/src/agent/Core/Controller/StateInspection.cpp +1 -1
  27. data/src/agent/Core/Controller/TurboCaching.h +2 -2
  28. data/src/agent/Core/CoreMain.cpp +2 -2
  29. data/src/agent/Core/ResponseCache.h +3 -3
  30. data/src/agent/Core/SpawningKit/BackgroundIOCapturer.h +3 -3
  31. data/src/agent/Core/SpawningKit/DirectSpawner.h +2 -2
  32. data/src/agent/Core/SpawningKit/PipeWatcher.h +3 -3
  33. data/src/agent/Core/SpawningKit/SmartSpawner.h +2 -2
  34. data/src/agent/Core/SpawningKit/Spawner.h +1 -1
  35. data/src/agent/Core/UnionStation/Connection.h +1 -1
  36. data/src/agent/Core/UnionStation/Context.h +1 -1
  37. data/src/agent/Core/UnionStation/Transaction.h +1 -1
  38. data/src/agent/Shared/ApiServerUtils.h +73 -27
  39. data/src/agent/Shared/Base.cpp +61 -73
  40. data/src/agent/UstRouter/ApiServer.h +34 -45
  41. data/src/agent/UstRouter/Controller.h +86 -60
  42. data/src/agent/UstRouter/RemoteSender.h +1 -1
  43. data/src/agent/UstRouter/RemoteSink.h +1 -1
  44. data/src/agent/Watchdog/ApiServer.h +42 -50
  45. data/src/agent/Watchdog/WatchdogMain.cpp +1 -1
  46. data/src/apache2_module/Configuration.hpp +1 -1
  47. data/src/apache2_module/Hooks.cpp +27 -13
  48. data/src/cxx_supportlib/AppTypes.h +1 -1
  49. data/src/cxx_supportlib/BackgroundEventLoop.cpp +1 -1
  50. data/src/cxx_supportlib/ConfigKit/AsyncUtils.h +86 -0
  51. data/src/cxx_supportlib/ConfigKit/Common.h +6 -3
  52. data/src/cxx_supportlib/ConfigKit/IN_PRACTICE.md +1039 -0
  53. data/src/cxx_supportlib/ConfigKit/README.md +112 -497
  54. data/src/cxx_supportlib/ConfigKit/Schema.h +78 -15
  55. data/src/cxx_supportlib/ConfigKit/Store.h +272 -53
  56. data/src/cxx_supportlib/ConfigKit/SubComponentUtils.h +59 -0
  57. data/src/cxx_supportlib/ConfigKit/Utils.h +26 -65
  58. data/src/cxx_supportlib/ConfigKit/ValidationUtils.h +69 -0
  59. data/src/cxx_supportlib/ConfigKit/VariantMapUtils.h +7 -4
  60. data/src/cxx_supportlib/Constants.h +4 -1
  61. data/src/cxx_supportlib/Crypto.cpp +1 -1
  62. data/src/cxx_supportlib/DataStructures/StringKeyTable.h +26 -7
  63. data/src/cxx_supportlib/FileDescriptor.h +1 -1
  64. data/src/cxx_supportlib/Hooks.h +1 -1
  65. data/src/cxx_supportlib/LoggingKit/Assert.h +130 -0
  66. data/src/cxx_supportlib/LoggingKit/Config.h +97 -0
  67. data/src/cxx_supportlib/LoggingKit/Context.h +94 -0
  68. data/src/cxx_supportlib/LoggingKit/Forward.h +95 -0
  69. data/src/cxx_supportlib/LoggingKit/Implementation.cpp +695 -0
  70. data/src/cxx_supportlib/LoggingKit/Logging.h +204 -0
  71. data/src/cxx_supportlib/LoggingKit/LoggingKit.h +33 -0
  72. data/src/cxx_supportlib/LveLoggingDecorator.h +1 -1
  73. data/src/cxx_supportlib/MemoryKit/mbuf.cpp +1 -1
  74. data/src/cxx_supportlib/RandomGenerator.h +1 -1
  75. data/src/cxx_supportlib/SafeLibev.h +1 -1
  76. data/src/cxx_supportlib/ServerKit/AcceptLoadBalancer.h +1 -1
  77. data/src/cxx_supportlib/ServerKit/Channel.h +1 -1
  78. data/src/cxx_supportlib/ServerKit/FileBufferedChannel.h +1 -1
  79. data/src/cxx_supportlib/ServerKit/FileBufferedFdSinkChannel.h +1 -1
  80. data/src/cxx_supportlib/ServerKit/HttpChunkedBodyParser.h +1 -1
  81. data/src/cxx_supportlib/ServerKit/HttpHeaderParser.h +1 -1
  82. data/src/cxx_supportlib/ServerKit/HttpServer.h +48 -15
  83. data/src/cxx_supportlib/ServerKit/Server.h +79 -52
  84. data/src/cxx_supportlib/StaticString.h +12 -0
  85. data/src/cxx_supportlib/Utils/Curl.h +16 -0
  86. data/src/cxx_supportlib/Utils/FastStringStream.h +6 -1
  87. data/src/cxx_supportlib/Utils/ScopeGuard.h +1 -1
  88. data/src/cxx_supportlib/Utils/StrIntUtils.cpp +2 -19
  89. data/src/cxx_supportlib/WatchdogLauncher.h +3 -2
  90. data/src/ruby_supportlib/phusion_passenger.rb +3 -3
  91. data/src/ruby_supportlib/phusion_passenger/common_library.rb +12 -12
  92. data/src/ruby_supportlib/phusion_passenger/constants.rb +6 -3
  93. data/src/ruby_supportlib/phusion_passenger/standalone/start_command.rb +1 -0
  94. data/src/ruby_supportlib/phusion_passenger/standalone/stop_command.rb +1 -0
  95. metadata +14 -4
  96. data/src/cxx_supportlib/Logging.cpp +0 -295
  97. data/src/cxx_supportlib/Logging.h +0 -385
@@ -0,0 +1,59 @@
1
+ /*
2
+ * Phusion Passenger - https://www.phusionpassenger.com/
3
+ * Copyright (c) 2017 Phusion Holding B.V.
4
+ *
5
+ * "Passenger", "Phusion Passenger" and "Union Station" are registered
6
+ * trademarks of Phusion Holding B.V.
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the "Software"), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in
16
+ * all copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ * THE SOFTWARE.
25
+ */
26
+ #ifndef _PASSENGER_CONFIG_KIT_SUB_COMPONENT_UTILS_H_
27
+ #define _PASSENGER_CONFIG_KIT_SUB_COMPONENT_UTILS_H_
28
+
29
+ #include <string>
30
+ #include <vector>
31
+ #include <stdexcept>
32
+
33
+ #include <jsoncpp/json.h>
34
+ #include <ConfigKit/Common.h>
35
+
36
+ namespace Passenger {
37
+ namespace ConfigKit {
38
+
39
+ using namespace std;
40
+
41
+
42
+ template<typename Component, typename Translator>
43
+ inline void
44
+ prepareConfigChangeForSubComponent(Component &component, const Translator &translator,
45
+ const Json::Value &updates, vector<ConfigKit::Error> &errors,
46
+ typename Component::ConfigChangeRequest &req)
47
+ {
48
+ vector<Error> tempErrors;
49
+ component.prepareConfigChange(translator.translate(updates),
50
+ tempErrors, req);
51
+ tempErrors = translator.reverseTranslate(tempErrors);
52
+ errors.insert(errors.end(), tempErrors.begin(), tempErrors.end());
53
+ }
54
+
55
+
56
+ } // namespace ConfigKit
57
+ } // namespace Passenger
58
+
59
+ #endif /* _PASSENGER_CONFIG_KIT_SUB_COMPONENT_UTILS_H_ */
@@ -29,10 +29,9 @@
29
29
  #include <string>
30
30
  #include <vector>
31
31
 
32
- #include <jsoncpp/json.h>
33
-
34
32
  #include <ConfigKit/Common.h>
35
33
  #include <StaticString.h>
34
+ #include <DataStructures/StringKeyTable.h>
36
35
  #include <Utils/FastStringStream.h>
37
36
 
38
37
  namespace Passenger {
@@ -43,72 +42,11 @@ using namespace std;
43
42
  class Error;
44
43
 
45
44
 
46
- template<typename Component, typename Translator>
47
- inline bool
48
- previewConfigUpdateSubComponent(Component &component,
49
- const Json::Value &updates, const Translator &translator,
50
- vector<Error> &errors)
51
- {
52
- vector<Error> tempErrors;
53
-
54
- component.previewConfigUpdate(translator.translate(updates),
55
- tempErrors);
56
- tempErrors = translator.reverseTranslate(tempErrors);
57
- errors.insert(errors.end(), tempErrors.begin(), tempErrors.end());
58
- return errors.empty();
59
- }
60
-
61
- template<typename Component, typename Translator>
62
- inline void
63
- configureSubComponent(Component &component,
64
- const Json::Value &updates, const Translator &translator,
65
- vector<ConfigKit::Error> &errors)
66
- {
67
- vector<ConfigKit::Error> tempErrors;
68
-
69
- component.configure(translator.translate(updates), tempErrors);
70
- tempErrors = translator.reverseTranslate(tempErrors);
71
- errors.insert(errors.end(), tempErrors.begin(), tempErrors.end());
72
- }
73
-
74
- template<typename Component>
75
- inline void
76
- callPreviewConfigUpdateAndCallback(Component *component, Json::Value updates,
77
- ConfigKit::ConfigCallback callback)
78
- {
79
- vector<ConfigKit::Error> errors;
80
- Json::Value config = component->previewConfigUpdate(updates, errors);
81
- callback(config, errors);
82
- }
83
-
84
- template<typename Component>
85
- inline void
86
- callConfigureAndCallback(Component *component, Json::Value updates,
87
- ConfigKit::ConfigCallback callback)
88
- {
89
- vector<ConfigKit::Error> errors;
90
- if (component->configure(updates, errors)) {
91
- callback(component->inspectConfig(), errors);
92
- } else {
93
- callback(Json::nullValue, errors);
94
- }
95
- }
96
-
97
- template<typename Component>
98
- inline void
99
- callInspectConfigAndCallback(Component *component,
100
- ConfigKit::InspectCallback callback)
101
- {
102
- callback(component->inspectConfig());
103
- }
104
-
105
45
  inline StaticString
106
46
  getTypeString(Type type) {
107
47
  switch (type) {
108
48
  case STRING_TYPE:
109
49
  return P_STATIC_STRING("string");
110
- case PASSWORD_TYPE:
111
- return P_STATIC_STRING("password");
112
50
  case INT_TYPE:
113
51
  return P_STATIC_STRING("integer");
114
52
  case UINT_TYPE:
@@ -121,11 +59,34 @@ getTypeString(Type type) {
121
59
  return P_STATIC_STRING("array");
122
60
  case STRING_ARRAY_TYPE:
123
61
  return P_STATIC_STRING("array of strings");
62
+ case OBJECT_TYPE:
63
+ return P_STATIC_STRING("object");
64
+ case ANY_TYPE:
65
+ return P_STATIC_STRING("any");
124
66
  default:
125
67
  return P_STATIC_STRING("unknown");
126
68
  }
127
69
  }
128
70
 
71
+ inline vector<ConfigKit::Error>
72
+ deduplicateErrors(const vector<ConfigKit::Error> &errors) {
73
+ StringKeyTable<bool> messagesSeen;
74
+ vector<ConfigKit::Error>::const_iterator it, end = errors.end();
75
+ vector<ConfigKit::Error> result;
76
+
77
+ for (it = errors.begin(); it != end; it++) {
78
+ bool *tmp;
79
+ string message = it->getMessage();
80
+
81
+ if (!messagesSeen.lookup(message, &tmp)) {
82
+ messagesSeen.insert(message, true);
83
+ result.push_back(*it);
84
+ }
85
+ }
86
+
87
+ return result;
88
+ }
89
+
129
90
  inline string
130
91
  toString(const vector<Error> &errors) {
131
92
  FastStringStream<> stream;
@@ -141,7 +102,7 @@ toString(const vector<Error> &errors) {
141
102
  }
142
103
 
143
104
 
144
- } // ConfigKit
145
- } // Passenger
105
+ } // namespace ConfigKit
106
+ } // namespace Passenger
146
107
 
147
108
  #endif /* _PASSENGER_CONFIG_KIT_UTILS_H_ */
@@ -0,0 +1,69 @@
1
+ /*
2
+ * Phusion Passenger - https://www.phusionpassenger.com/
3
+ * Copyright (c) 2017 Phusion Holding B.V.
4
+ *
5
+ * "Passenger", "Phusion Passenger" and "Union Station" are registered
6
+ * trademarks of Phusion Holding B.V.
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the "Software"), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in
16
+ * all copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ * THE SOFTWARE.
25
+ */
26
+ #ifndef _PASSENGER_CONFIG_KIT_VALIDATION_UTILS_H_
27
+ #define _PASSENGER_CONFIG_KIT_VALIDATION_UTILS_H_
28
+
29
+ #include <ConfigKit/Store.h>
30
+ #include <string>
31
+ #include <vector>
32
+
33
+ namespace Passenger {
34
+ namespace ConfigKit {
35
+
36
+ using namespace std;
37
+
38
+
39
+ inline void
40
+ validateIntegrationMode(const Store &config, vector<Error> &errors) {
41
+ if (config["integration_mode"].isNull()) {
42
+ return;
43
+ }
44
+ string integrationMode = config["integration_mode"].asString();
45
+ if (integrationMode != "apache" && integrationMode != "nginx" && integrationMode != "standalone") {
46
+ errors.push_back(Error("'{{integration_mode}}' may only be one of 'apache', 'nginx', 'standalone'"));
47
+ }
48
+ }
49
+
50
+ inline void
51
+ validateStandaloneEngine(const Store &config, vector<Error> &errors) {
52
+ if (config["integration_mode"].asString() != "standalone") {
53
+ return;
54
+ }
55
+ string standaloneEngine = config["standalone_engine"].asString();
56
+ if (standaloneEngine.empty()) {
57
+ errors.push_back(Error("'{{standalone_engine}}' is required when '{{integration_mode}}' is 'standalone'"));
58
+ return;
59
+ }
60
+ if (standaloneEngine != "nginx" && standaloneEngine != "builtin") {
61
+ errors.push_back(Error("'{{standalone_engine}}' is must be either 'nginx' or 'builtin'"));
62
+ }
63
+ }
64
+
65
+
66
+ } // namespace ConfigKit
67
+ } // namespace Passenger
68
+
69
+ #endif /* _PASSENGER_CONFIG_KIT_VALIDATION_UTILS_H_ */
@@ -26,7 +26,7 @@
26
26
  #ifndef _PASSENGER_CONFIG_KIT_VARIANT_MAP_UTILS_H_
27
27
  #define _PASSENGER_CONFIG_KIT_VARIANT_MAP_UTILS_H_
28
28
 
29
- #include <Logging.h>
29
+ #include <LoggingKit/LoggingKit.h>
30
30
  #include <Exceptions.h>
31
31
  #include <ConfigKit/Schema.h>
32
32
  #include <Utils/StrIntUtils.h>
@@ -48,7 +48,7 @@ variantMapToJson(const Schema &schema, const VariantMap &options) {
48
48
  if (options.has(key)) {
49
49
  switch (entry.type) {
50
50
  case STRING_TYPE:
51
- case PASSWORD_TYPE:
51
+ case ANY_TYPE:
52
52
  doc[key.toString()] = options.get(key);
53
53
  break;
54
54
  case INT_TYPE:
@@ -74,6 +74,9 @@ variantMapToJson(const Schema &schema, const VariantMap &options) {
74
74
  doc[key.toString()] = subdoc;
75
75
  break;
76
76
  }
77
+ case OBJECT_TYPE:
78
+ // Not supported
79
+ break;
77
80
  default:
78
81
  P_BUG("Unknown type " + Passenger::toString((int) entry.type));
79
82
  break;
@@ -87,7 +90,7 @@ variantMapToJson(const Schema &schema, const VariantMap &options) {
87
90
  }
88
91
 
89
92
 
90
- } // ConfigKit
91
- } // Passenger
93
+ } // namespace ConfigKit
94
+ } // namespace Passenger
92
95
 
93
96
  #endif /* _PASSENGER_CONFIG_KIT_VARIANT_MAP_UTILS_H_ */
@@ -45,12 +45,15 @@
45
45
  #define DEFAULT_ANALYTICS_LOG_PERMISSIONS "u=rwx,g=rx,o=rx"
46
46
  #define DEFAULT_ANALYTICS_LOG_USER "nobody"
47
47
  #define DEFAULT_APP_ENV "production"
48
+ #define DEFAULT_APP_OUTPUT_LOG_LEVEL 3
49
+ #define DEFAULT_APP_OUTPUT_LOG_LEVEL_NAME "notice"
48
50
  #define DEFAULT_APP_THREAD_COUNT 1
49
51
  #define DEFAULT_CONCURRENCY_MODEL "process"
50
52
  #define DEFAULT_FILE_BUFFERED_CHANNEL_THRESHOLD 131072
51
53
  #define DEFAULT_HTTP_SERVER_LISTEN_ADDRESS "tcp://127.0.0.1:3000"
52
54
  #define DEFAULT_INTEGRATION_MODE "standalone"
53
55
  #define DEFAULT_LOG_LEVEL 3
56
+ #define DEFAULT_LOG_LEVEL_NAME "notice"
54
57
  #define DEFAULT_LVE_MIN_UID 500
55
58
  #define DEFAULT_MAX_POOL_SIZE 6
56
59
  #define DEFAULT_MAX_PRELOADER_IDLE_TIME 300
@@ -80,7 +83,7 @@
80
83
  #define PASSENGER_API_VERSION_MAJOR 0
81
84
  #define PASSENGER_API_VERSION_MINOR 3
82
85
  #define PASSENGER_DEFAULT_USER "nobody"
83
- #define PASSENGER_VERSION "5.1.7"
86
+ #define PASSENGER_VERSION "5.1.8"
84
87
  #define POOL_HELPER_THREAD_STACK_SIZE 262144
85
88
  #define PROCESS_SHUTDOWN_TIMEOUT 60
86
89
  #define PROCESS_SHUTDOWN_TIMEOUT_DISPLAY "1 minute"
@@ -26,7 +26,7 @@
26
26
 
27
27
  #include <Crypto.h>
28
28
  #include <modp_b64.h>
29
- #include <Logging.h>
29
+ #include <LoggingKit/LoggingKit.h>
30
30
  #include <string>
31
31
  #include <Utils/SystemTime.h>
32
32
  #include <Utils/StrIntUtils.h>
@@ -27,7 +27,14 @@
27
27
  #define _PASSENGER_DATA_STRUCTURES_STRING_KEY_TABLE_H_
28
28
 
29
29
  #include <boost/move/move.hpp>
30
+ #include <boost/config.hpp>
30
31
  #include <boost/cstdint.hpp>
32
+ // for std::swap()
33
+ #if __cplusplus >= 201103L
34
+ #include <utility>
35
+ #else
36
+ #include <algorithm>
37
+ #endif
31
38
  #include <limits>
32
39
  #include <cstring>
33
40
  #include <cassert>
@@ -245,7 +252,7 @@ private:
245
252
  }
246
253
 
247
254
  template<typename ValueType, typename LocalMoveSupport>
248
- void realInsert(const HashedStaticString &key, ValueType val, bool overwrite) {
255
+ Cell *realInsert(const HashedStaticString &key, ValueType val, bool overwrite) {
249
256
  assert(!key.empty());
250
257
  assert(key.size() <= MAX_KEY_LENGTH);
251
258
  assert(m_population < MAX_ITEMS);
@@ -271,18 +278,20 @@ private:
271
278
  cell->hash = key.hash();
272
279
  copyOrMoveValue(val, cell->value, LocalMoveSupport());
273
280
  nonEmptyIndex = cell - &m_cells[0];
274
- return;
281
+ return cell;
275
282
  } else if (compareKeys(cellKey, cell->keyLength, key)) {
276
283
  // Cell matches.
277
284
  if (overwrite) {
278
285
  copyOrMoveValue(val, cell->value, LocalMoveSupport());
279
286
  }
280
- return;
287
+ return cell;
281
288
  } else {
282
289
  cell = SKT_CIRCULAR_NEXT(cell);
283
290
  }
284
291
  }
285
292
  }
293
+
294
+ return NULL; // Never reached
286
295
  }
287
296
 
288
297
  public:
@@ -430,12 +439,12 @@ public:
430
439
  }
431
440
  }
432
441
 
433
- void insert(const HashedStaticString &key, const T &val, bool overwrite = true) {
434
- realInsert<const T &, SKT_DisableMoveSupport>(key, val, overwrite);
442
+ Cell *insert(const HashedStaticString &key, const T &val, bool overwrite = true) {
443
+ return realInsert<const T &, SKT_DisableMoveSupport>(key, val, overwrite);
435
444
  }
436
445
 
437
- void insertByMoving(const HashedStaticString &key, BOOST_RV_REF(T) val, bool overwrite = true) {
438
- realInsert<BOOST_RV_REF(T), SKT_EnableMoveSupport>(key, boost::move(val), overwrite);
446
+ Cell *insertByMoving(const HashedStaticString &key, BOOST_RV_REF(T) val, bool overwrite = true) {
447
+ return realInsert<BOOST_RV_REF(T), SKT_EnableMoveSupport>(key, boost::move(val), overwrite);
439
448
  }
440
449
 
441
450
  void erase(Cell *cell) {
@@ -528,6 +537,16 @@ public:
528
537
  return m_population == 0;
529
538
  }
530
539
 
540
+ void swap(StringKeyTable<T, MoveSupport> &other) BOOST_NOEXCEPT_OR_NOTHROW {
541
+ std::swap(m_cells, other.m_cells);
542
+ std::swap(m_arraySize, other.m_arraySize);
543
+ std::swap(m_population, other.m_population);
544
+ std::swap(nonEmptyIndex, other.nonEmptyIndex);
545
+ std::swap(m_storage, other.m_storage);
546
+ std::swap(m_storageSize, other.m_storageSize);
547
+ std::swap(m_storageUsed, other.m_storageUsed);
548
+ }
549
+
531
550
 
532
551
  friend class Iterator;
533
552
  class Iterator {
@@ -35,7 +35,7 @@
35
35
  #include <unistd.h>
36
36
  #include <cerrno>
37
37
 
38
- #include <Logging.h>
38
+ #include <LoggingKit/LoggingKit.h>
39
39
  #include <Exceptions.h>
40
40
 
41
41
  namespace Passenger {
@@ -42,7 +42,7 @@
42
42
  #include <stdlib.h>
43
43
  #include <unistd.h>
44
44
 
45
- #include <Logging.h>
45
+ #include <LoggingKit/LoggingKit.h>
46
46
  #include <Utils.h>
47
47
  #include <Utils/StrIntUtils.h>
48
48
  #include <Utils/VariantMap.h>
@@ -0,0 +1,130 @@
1
+ /*
2
+ * Phusion Passenger - https://www.phusionpassenger.com/
3
+ * Copyright (c) 2017 Phusion Holding B.V.
4
+ *
5
+ * "Passenger", "Phusion Passenger" and "Union Station" are registered
6
+ * trademarks of Phusion Holding B.V.
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the "Software"), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in
16
+ * all copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ * THE SOFTWARE.
25
+ */
26
+ #ifndef _PASSENGER_LOGGING_KIT_ASSERT_H_
27
+ #define _PASSENGER_LOGGING_KIT_ASSERT_H_
28
+
29
+ #include <oxt/backtrace.hpp>
30
+ #include <cstddef>
31
+ #include <cstdlib>
32
+
33
+ #include <LoggingKit/Logging.h>
34
+ #include <Utils/FastStringStream.h>
35
+
36
+ namespace Passenger {
37
+ namespace LoggingKit {
38
+
39
+
40
+ struct AssertionFailureInfo {
41
+ const char *filename;
42
+ const char *function; // May be NULL.
43
+ const char *expression;
44
+ unsigned int line;
45
+
46
+ AssertionFailureInfo()
47
+ : filename(NULL),
48
+ function(NULL),
49
+ expression(NULL),
50
+ line(0)
51
+ { }
52
+ };
53
+
54
+ // If assert() or similar fails, we attempt to store its information here.
55
+ extern AssertionFailureInfo lastAssertionFailure;
56
+
57
+
58
+ /*
59
+ * The P_BUG family of macros allow you to print a [BUG] error message
60
+ * and abort with a stack trace.
61
+ *
62
+ * P_BUG(expr)
63
+ * Prints the given expression and aborts.
64
+ *
65
+ * P_BUG_WITH_FORMATTER_CODE(varname, code)
66
+ * Same effect as P_BUG, but it allows more fine-grained control over the behavior.
67
+ * This macro declares the internal string stream object with a name defined by `varname`,
68
+ * and evaluates the `code`. The given code is supposed to use `<<` calls to append
69
+ * add text into the stream.
70
+ * When the code is done evaluating, this macro prints the string stream and aborts.
71
+ *
72
+ * P_BUG_UTP(expr)
73
+ * P_BUG_UTP_WITH_FORMATTER_CODE(varname, code)
74
+ * Like P_BUG/P_BUG_WITH_FORMATTER_CODE, but instead of allocating a `TRACE_POINT()`
75
+ * (which may conflict if the calling function already has one defined), it calls
76
+ * `UPDATE_TRACE_POINT()` instead.
77
+ */
78
+
79
+ /** Print a [BUG] error message and abort with a stack trace. */
80
+ #define P_BUG_WITH_FORMATTER_CODE(varname, code) \
81
+ do { \
82
+ TRACE_POINT(); \
83
+ const char *_exprStr; \
84
+ Passenger::FastStringStream<> varname; \
85
+ code \
86
+ _exprStr = Passenger::LoggingKit::_strdupFastStringStream(varname); \
87
+ Passenger::LoggingKit::lastAssertionFailure.filename = __FILE__; \
88
+ Passenger::LoggingKit::lastAssertionFailure.line = __LINE__; \
89
+ Passenger::LoggingKit::lastAssertionFailure.function = __PRETTY_FUNCTION__; \
90
+ Passenger::LoggingKit::lastAssertionFailure.expression = _exprStr; \
91
+ P_CRITICAL("[BUG] " << _exprStr); \
92
+ abort(); \
93
+ } while (false)
94
+
95
+ #define P_BUG_UTP_WITH_FORMATTER_CODE(varname, code) \
96
+ do { \
97
+ UPDATE_TRACE_POINT(); \
98
+ const char *_exprStr; \
99
+ Passenger::FastStringStream<> varname; \
100
+ code \
101
+ _exprStr = Passenger::LoggingKit::_strdupFastStringStream(varname); \
102
+ Passenger::LoggingKit::lastAssertionFailure.filename = __FILE__; \
103
+ Passenger::LoggingKit::lastAssertionFailure.line = __LINE__; \
104
+ Passenger::LoggingKit::lastAssertionFailure.function = __PRETTY_FUNCTION__; \
105
+ Passenger::LoggingKit::lastAssertionFailure.expression = _exprStr; \
106
+ P_CRITICAL("[BUG] " << _exprStr); \
107
+ abort(); \
108
+ } while (false)
109
+
110
+ #define P_BUG(expr) P_BUG_WITH_FORMATTER_CODE( _sstream , _sstream << expr; )
111
+ #define P_BUG_UTP(expr) P_BUG_UTP_WITH_FORMATTER_CODE( _sstream , _sstream << expr; )
112
+
113
+
114
+ /**
115
+ * Asserts whether the actual value equals the expected value.
116
+ * If not, it prints a message that prints how the two values differ
117
+ * and aborts.
118
+ */
119
+ #define P_ASSERT_EQ(value, expected) \
120
+ do { \
121
+ if (OXT_UNLIKELY(value != expected)) { \
122
+ P_BUG("Expected " << #value << " to be " << expected << ", got " << value); \
123
+ } \
124
+ } while (false)
125
+
126
+
127
+ } // namespace LoggingKit
128
+ } // namespace Passenger
129
+
130
+ #endif /* _PASSENGER_LOGGING_KIT_ASSERT_H_ */