passenger 5.0.28 → 5.0.29

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 (82) hide show
  1. checksums.yaml +4 -4
  2. data/.editorconfig +5 -0
  3. data/CHANGELOG +13 -0
  4. data/build/apache2.rb +3 -3
  5. data/build/common_library.rb +3 -3
  6. data/build/nginx.rb +4 -4
  7. data/build/packaging.rb +9 -8
  8. data/build/support/cxx_dependency_map.rb +9 -7
  9. data/build/support/general.rb +39 -0
  10. data/build/support/vendor/cxxcodebuilder/CxxCodeBuilder.sublime-project +8 -0
  11. data/build/support/vendor/cxxcodebuilder/Gemfile +4 -0
  12. data/build/support/vendor/cxxcodebuilder/Gemfile.lock +28 -0
  13. data/build/support/vendor/cxxcodebuilder/LICENSE.md +19 -0
  14. data/build/support/vendor/cxxcodebuilder/README.md +98 -0
  15. data/build/support/vendor/cxxcodebuilder/Rakefile +4 -0
  16. data/build/support/vendor/cxxcodebuilder/lib/cxxcodebuilder.rb +23 -0
  17. data/build/support/vendor/cxxcodebuilder/lib/cxxcodebuilder/builder.rb +574 -0
  18. data/build/support/vendor/cxxcodebuilder/lib/cxxcodebuilder/initializer_builder.rb +166 -0
  19. data/build/test_basics.rb +2 -1
  20. data/resources/templates/standalone/server.erb +6 -4
  21. data/src/agent/Core/Controller/ForwardResponse.cpp +5 -5
  22. data/src/agent/Watchdog/WatchdogMain.cpp +0 -10
  23. data/src/apache2_module/ConfigurationCommands.cpp +181 -248
  24. data/src/apache2_module/ConfigurationCommands.cpp.cxxcodebuilder +127 -0
  25. data/src/apache2_module/ConfigurationFields.hpp +135 -51
  26. data/src/apache2_module/ConfigurationFields.hpp.cxxcodebuilder +113 -0
  27. data/src/apache2_module/ConfigurationSetters.cpp +414 -459
  28. data/src/apache2_module/ConfigurationSetters.cpp.cxxcodebuilder +144 -0
  29. data/src/apache2_module/CreateDirConfig.cpp +49 -52
  30. data/src/apache2_module/CreateDirConfig.cpp.cxxcodebuilder +81 -0
  31. data/src/apache2_module/Hooks.cpp +0 -14
  32. data/src/apache2_module/MergeDirConfig.cpp +136 -226
  33. data/src/apache2_module/MergeDirConfig.cpp.cxxcodebuilder +97 -0
  34. data/src/apache2_module/SetHeaders.cpp +92 -143
  35. data/src/apache2_module/SetHeaders.cpp.cxxcodebuilder +106 -0
  36. data/src/cxx_supportlib/Constants.h +86 -146
  37. data/src/cxx_supportlib/Constants.h.cxxcodebuilder +43 -0
  38. data/src/cxx_supportlib/DataStructures/LString.h +40 -23
  39. data/src/cxx_supportlib/MemoryKit/mbuf.cpp +60 -25
  40. data/src/cxx_supportlib/MemoryKit/mbuf.h +50 -25
  41. data/src/cxx_supportlib/ServerKit/CookieUtils.h +36 -3
  42. data/src/cxx_supportlib/ServerKit/HeaderTable.h +2 -8
  43. data/src/cxx_supportlib/ServerKit/HttpServer.h +6 -15
  44. data/src/cxx_supportlib/WatchdogLauncher.cpp +4 -4
  45. data/src/cxx_supportlib/WatchdogLauncher.h +2 -3
  46. data/src/nginx_module/CacheLocationConfig.c +623 -780
  47. data/src/nginx_module/CacheLocationConfig.c.cxxcodebuilder +214 -0
  48. data/src/nginx_module/Configuration.h +1 -1
  49. data/src/nginx_module/ConfigurationCommands.c +404 -535
  50. data/src/nginx_module/ConfigurationCommands.c.cxxcodebuilder +157 -0
  51. data/src/nginx_module/CreateLocationConfig.c +82 -206
  52. data/src/nginx_module/CreateLocationConfig.c.cxxcodebuilder +98 -0
  53. data/src/nginx_module/LocationConfig.h +97 -0
  54. data/src/nginx_module/LocationConfig.h.cxxcodebuilder +131 -0
  55. data/src/nginx_module/MergeLocationConfig.c +157 -278
  56. data/src/nginx_module/MergeLocationConfig.c.cxxcodebuilder +144 -0
  57. data/src/nginx_module/ngx_http_passenger_module.c +4 -10
  58. data/src/ruby_supportlib/phusion_passenger.rb +4 -4
  59. data/src/ruby_supportlib/phusion_passenger/config/validate_install_command.rb +2 -2
  60. data/src/ruby_supportlib/phusion_passenger/packaging.rb +2 -0
  61. data/src/ruby_supportlib/phusion_passenger/platform_info/compiler.rb +6 -0
  62. data/src/ruby_supportlib/phusion_passenger/platform_info/cxx_portability.rb +1 -1
  63. data/src/ruby_supportlib/phusion_passenger/standalone/start_command.rb +27 -8
  64. data/src/ruby_supportlib/phusion_passenger/vendor/daemon_controller.rb +120 -2
  65. data/src/ruby_supportlib/phusion_passenger/vendor/daemon_controller/lock_file.rb +1 -1
  66. data/src/ruby_supportlib/phusion_passenger/vendor/daemon_controller/spawn.rb +4 -4
  67. data/src/ruby_supportlib/phusion_passenger/vendor/daemon_controller/version.rb +1 -1
  68. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/api.rb +5 -5
  69. metadata +24 -15
  70. data/src/apache2_module/ConfigurationCommands.cpp.erb +0 -109
  71. data/src/apache2_module/ConfigurationFields.hpp.erb +0 -98
  72. data/src/apache2_module/ConfigurationSetters.cpp.erb +0 -128
  73. data/src/apache2_module/CreateDirConfig.cpp.erb +0 -72
  74. data/src/apache2_module/MergeDirConfig.cpp.erb +0 -82
  75. data/src/apache2_module/SetHeaders.cpp.erb +0 -91
  76. data/src/cxx_supportlib/Constants.h.erb +0 -41
  77. data/src/nginx_module/CacheLocationConfig.c.erb +0 -171
  78. data/src/nginx_module/ConfigurationCommands.c.erb +0 -144
  79. data/src/nginx_module/ConfigurationFields.h +0 -145
  80. data/src/nginx_module/ConfigurationFields.h.erb +0 -112
  81. data/src/nginx_module/CreateLocationConfig.c.erb +0 -78
  82. data/src/nginx_module/MergeLocationConfig.c.erb +0 -118
@@ -1,161 +1,101 @@
1
1
  /*
2
- * Phusion Passenger - https://www.phusionpassenger.com/
3
- * Copyright (c) 2010-2015 Phusion Holding B.V.
2
+ * encoding: utf-8
3
+ * Phusion Passenger - https://www.phusionpassenger.com/
4
+ * Copyright (c) 2010-2016 Phusion Holding B.V.
4
5
  *
5
- * "Passenger", "Phusion Passenger" and "Union Station" are registered
6
- * trademarks of Phusion Holding B.V.
6
+ * "Passenger", "Phusion Passenger" and "Union Station" are registered
7
+ * trademarks of Phusion Holding B.V.
7
8
  *
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:
9
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ * of this software and associated documentation files (the "Software"), to deal
11
+ * in the Software without restriction, including without limitation the rights
12
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ * copies of the Software, and to permit persons to whom the Software is
14
+ * furnished to do so, subject to the following conditions:
14
15
  *
15
- * The above copyright notice and this permission notice shall be included in
16
- * all copies or substantial portions of the Software.
16
+ * The above copyright notice and this permission notice shall be included in
17
+ * all copies or substantial portions of the Software.
17
18
  *
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.
19
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
+ * THE SOFTWARE.
25
26
  */
26
27
  #ifndef _PASSENGER_CONSTANTS_H_
27
28
  #define _PASSENGER_CONSTANTS_H_
28
29
 
29
- /* Constants.h is automatically generated from Constants.h.erb by the build system.
30
- * Most constants are derived from src/ruby_supportlib/phusion_passenger/constants.rb.
30
+ /*
31
+ * Constants.h is automatically generated from Constants.h.cxxcodebuilder by the build system.
32
+ * All constants are derived from src/ruby_supportlib/phusion_passenger/constants.rb.
31
33
  *
32
34
  * To force regenerating this file:
33
35
  * rm -f src/cxx_supportlib/Constants.h
34
36
  * rake src/cxx_supportlib/Constants.h
35
37
  */
36
38
 
37
-
38
- #define AGENT_EXE "PassengerAgent"
39
-
40
- #define DEB_APACHE_MODULE_PACKAGE "libapache2-mod-passenger"
41
-
42
- #define DEB_DEV_PACKAGE "passenger-dev"
43
-
44
- #define DEB_MAIN_PACKAGE "passenger"
45
-
46
- #define DEB_NGINX_PACKAGE "nginx-extras"
47
-
48
- #define DEFAULT_ANALYTICS_LOG_GROUP ""
49
-
50
- #define DEFAULT_ANALYTICS_LOG_PERMISSIONS "u=rwx,g=rx,o=rx"
51
-
52
- #define DEFAULT_ANALYTICS_LOG_USER "nobody"
53
-
54
- #define DEFAULT_APP_ENV "production"
55
-
56
- #define DEFAULT_APP_THREAD_COUNT 1
57
-
58
- #define DEFAULT_CONCURRENCY_MODEL "process"
59
-
60
- #define DEFAULT_FILE_BUFFERED_CHANNEL_THRESHOLD 131072
61
-
62
- #define DEFAULT_HTTP_SERVER_LISTEN_ADDRESS "tcp://127.0.0.1:3000"
63
-
64
- #define DEFAULT_INTEGRATION_MODE "standalone"
65
-
66
- #define DEFAULT_LOG_LEVEL 3
67
-
68
- #define DEFAULT_LVE_MIN_UID 500
69
-
70
- #define DEFAULT_MAX_POOL_SIZE 6
71
-
72
- #define DEFAULT_MAX_PRELOADER_IDLE_TIME 300
73
-
74
- #define DEFAULT_MAX_REQUEST_QUEUE_SIZE 100
75
-
76
- #define DEFAULT_MBUF_CHUNK_SIZE 512
77
-
78
- #define DEFAULT_NODEJS "node"
79
-
80
- #define DEFAULT_POOL_IDLE_TIME 300
81
-
82
- #define DEFAULT_PYTHON "python"
83
-
84
- #define DEFAULT_RESPONSE_BUFFER_HIGH_WATERMARK 134217728
85
-
86
- #define DEFAULT_RUBY "ruby"
87
-
88
- #define DEFAULT_SOCKET_BACKLOG 2048
89
-
90
- #define DEFAULT_SPAWN_METHOD "smart"
91
-
92
- #define DEFAULT_START_TIMEOUT 90000
93
-
94
- #define DEFAULT_STAT_THROTTLE_RATE 10
95
-
96
- #define DEFAULT_STICKY_SESSIONS_COOKIE_NAME "_passenger_route"
97
-
98
- #define DEFAULT_UNION_STATION_GATEWAY_ADDRESS "gateway.unionstationapp.com"
99
-
100
- #define DEFAULT_UNION_STATION_GATEWAY_PORT 443
101
-
102
- #define DEFAULT_UST_ROUTER_LISTEN_ADDRESS "tcp://127.0.0.1:9344"
103
-
104
- #define DEFAULT_WEB_APP_USER "nobody"
105
-
106
- #define ENTERPRISE_URL "https://www.phusionpassenger.com/enterprise"
107
-
108
- #define FEEDBACK_FD 3
109
-
110
- #define FLYING_PASSENGER_NAME "Flying Passenger"
111
-
112
- #define GLOBAL_NAMESPACE_DIRNAME "passenger"
113
-
114
- #define MESSAGE_SERVER_MAX_PASSWORD_SIZE 100
115
-
116
- #define MESSAGE_SERVER_MAX_USERNAME_SIZE 100
117
-
118
- #define PASSENGER_API_VERSION "0.3"
119
-
120
- #define PASSENGER_API_VERSION_MAJOR 0
121
-
122
- #define PASSENGER_API_VERSION_MINOR 3
123
-
124
- #define PASSENGER_DEFAULT_USER "nobody"
125
-
126
- #define PASSENGER_VERSION "5.0.28"
127
-
128
- #define POOL_HELPER_THREAD_STACK_SIZE 262144
129
-
130
- #define PROCESS_SHUTDOWN_TIMEOUT 60
131
-
132
- #define PROCESS_SHUTDOWN_TIMEOUT_DISPLAY "1 minute"
133
-
134
- #define PROGRAM_NAME "Phusion Passenger"
135
-
136
- #define RPM_APACHE_MODULE_PACKAGE "mod_passenger"
137
-
138
- #define RPM_DEV_PACKAGE "passenger-devel"
139
-
140
- #define RPM_MAIN_PACKAGE "passenger"
141
-
142
- #define RPM_NGINX_PACKAGE "nginx"
143
-
144
- #define SERVER_INSTANCE_DIR_STRUCTURE_MAJOR_VERSION 3
145
-
146
- #define SERVER_INSTANCE_DIR_STRUCTURE_MINOR_VERSION 0
147
-
148
- #define SERVER_INSTANCE_DIR_STRUCTURE_MIN_SUPPORTED_MINOR_VERSION 0
149
-
150
- #define SERVER_KIT_MAX_SERVER_ENDPOINTS 4
151
-
152
- #define SERVER_TOKEN_NAME "Phusion_Passenger"
153
-
154
- #define SHORT_PROGRAM_NAME "Passenger"
155
-
156
- #define SUPPORT_URL "https://www.phusionpassenger.com/documentation_and_support"
157
-
158
- #define USER_NAMESPACE_DIRNAME ".passenger"
159
-
160
-
161
- #endif /* _PASSENGER_CONSTANTS_H */
39
+ #define AGENT_EXE "PassengerAgent"
40
+ #define DEB_APACHE_MODULE_PACKAGE "libapache2-mod-passenger"
41
+ #define DEB_DEV_PACKAGE "passenger-dev"
42
+ #define DEB_MAIN_PACKAGE "passenger"
43
+ #define DEB_NGINX_PACKAGE "nginx-extras"
44
+ #define DEFAULT_ANALYTICS_LOG_GROUP ""
45
+ #define DEFAULT_ANALYTICS_LOG_PERMISSIONS "u=rwx,g=rx,o=rx"
46
+ #define DEFAULT_ANALYTICS_LOG_USER "nobody"
47
+ #define DEFAULT_APP_ENV "production"
48
+ #define DEFAULT_APP_THREAD_COUNT 1
49
+ #define DEFAULT_CONCURRENCY_MODEL "process"
50
+ #define DEFAULT_FILE_BUFFERED_CHANNEL_THRESHOLD 131072
51
+ #define DEFAULT_HTTP_SERVER_LISTEN_ADDRESS "tcp://127.0.0.1:3000"
52
+ #define DEFAULT_INTEGRATION_MODE "standalone"
53
+ #define DEFAULT_LOG_LEVEL 3
54
+ #define DEFAULT_LVE_MIN_UID 500
55
+ #define DEFAULT_MAX_POOL_SIZE 6
56
+ #define DEFAULT_MAX_PRELOADER_IDLE_TIME 300
57
+ #define DEFAULT_MAX_REQUEST_QUEUE_SIZE 100
58
+ #define DEFAULT_MBUF_CHUNK_SIZE 512
59
+ #define DEFAULT_NODEJS "node"
60
+ #define DEFAULT_POOL_IDLE_TIME 300
61
+ #define DEFAULT_PYTHON "python"
62
+ #define DEFAULT_RESPONSE_BUFFER_HIGH_WATERMARK 134217728
63
+ #define DEFAULT_RUBY "ruby"
64
+ #define DEFAULT_SOCKET_BACKLOG 2048
65
+ #define DEFAULT_SPAWN_METHOD "smart"
66
+ #define DEFAULT_START_TIMEOUT 90000
67
+ #define DEFAULT_STAT_THROTTLE_RATE 10
68
+ #define DEFAULT_STICKY_SESSIONS_COOKIE_NAME "_passenger_route"
69
+ #define DEFAULT_UNION_STATION_GATEWAY_ADDRESS "gateway.unionstationapp.com"
70
+ #define DEFAULT_UNION_STATION_GATEWAY_PORT 443
71
+ #define DEFAULT_UST_ROUTER_LISTEN_ADDRESS "tcp://127.0.0.1:9344"
72
+ #define DEFAULT_WEB_APP_USER "nobody"
73
+ #define ENTERPRISE_URL "https://www.phusionpassenger.com/enterprise"
74
+ #define FEEDBACK_FD 3
75
+ #define FLYING_PASSENGER_NAME "Flying Passenger"
76
+ #define GLOBAL_NAMESPACE_DIRNAME "passenger"
77
+ #define MESSAGE_SERVER_MAX_PASSWORD_SIZE 100
78
+ #define MESSAGE_SERVER_MAX_USERNAME_SIZE 100
79
+ #define PASSENGER_API_VERSION "0.3"
80
+ #define PASSENGER_API_VERSION_MAJOR 0
81
+ #define PASSENGER_API_VERSION_MINOR 3
82
+ #define PASSENGER_DEFAULT_USER "nobody"
83
+ #define PASSENGER_VERSION "5.0.29"
84
+ #define POOL_HELPER_THREAD_STACK_SIZE 262144
85
+ #define PROCESS_SHUTDOWN_TIMEOUT 60
86
+ #define PROCESS_SHUTDOWN_TIMEOUT_DISPLAY "1 minute"
87
+ #define PROGRAM_NAME "Phusion Passenger"
88
+ #define RPM_APACHE_MODULE_PACKAGE "mod_passenger"
89
+ #define RPM_DEV_PACKAGE "passenger-devel"
90
+ #define RPM_MAIN_PACKAGE "passenger"
91
+ #define RPM_NGINX_PACKAGE "nginx"
92
+ #define SERVER_INSTANCE_DIR_STRUCTURE_MAJOR_VERSION 3
93
+ #define SERVER_INSTANCE_DIR_STRUCTURE_MINOR_VERSION 0
94
+ #define SERVER_INSTANCE_DIR_STRUCTURE_MIN_SUPPORTED_MINOR_VERSION 0
95
+ #define SERVER_KIT_MAX_SERVER_ENDPOINTS 4
96
+ #define SERVER_TOKEN_NAME "Phusion_Passenger"
97
+ #define SHORT_PROGRAM_NAME "Passenger"
98
+ #define SUPPORT_URL "https://www.phusionpassenger.com/documentation_and_support"
99
+ #define USER_NAMESPACE_DIRNAME ".passenger"
100
+
101
+ #endif /* _PASSENGER_CONSTANTS_H_ */
@@ -0,0 +1,43 @@
1
+ # encoding: utf-8
2
+ # Phusion Passenger - https://www.phusionpassenger.com/
3
+ # Copyright (c) 2010-2016 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
+ comment copyright_header_for(__FILE__)
27
+
28
+ guard_macros '_PASSENGER_CONSTANTS_H_' do
29
+ comment %q{
30
+ Constants.h is automatically generated from Constants.h.cxxcodebuilder by the build system.
31
+ All constants are derived from src/ruby_supportlib/phusion_passenger/constants.rb.
32
+
33
+ To force regenerating this file:
34
+ rm -f src/cxx_supportlib/Constants.h
35
+ rake src/cxx_supportlib/Constants.h
36
+ }
37
+
38
+ separator
39
+
40
+ PhusionPassenger::SharedConstants.constants.sort.each do |constant_name|
41
+ define("#{constant_name} #{PhusionPassenger::SharedConstants.const_get(constant_name).inspect}")
42
+ end
43
+ end
@@ -28,6 +28,7 @@
28
28
 
29
29
  #include <boost/cstdint.hpp>
30
30
  #include <oxt/backtrace.hpp>
31
+ #include <oxt/macros.hpp>
31
32
  #include <stdexcept>
32
33
  #include <cstring>
33
34
  #include <cassert>
@@ -99,7 +100,7 @@ psg_lstr_init(LString *str) {
99
100
  inline LString *
100
101
  psg_lstr_create(psg_pool_t *pool, const char *data, unsigned int size) {
101
102
  LString *result = (LString *) psg_palloc(pool, sizeof(LString));
102
- if (result == NULL) {
103
+ if (OXT_UNLIKELY(result == NULL)) {
103
104
  TRACE_POINT();
104
105
  throw std::bad_alloc();
105
106
  }
@@ -114,7 +115,7 @@ psg_lstr_create(psg_pool_t *pool, const StaticString &str) {
114
115
  }
115
116
 
116
117
  inline void
117
- psg_lstr_append_part(LString *str, LString::Part *part) {
118
+ _psg_lstr_append_part(LString *str, LString::Part *part) {
118
119
  if (str->size == 0) {
119
120
  str->start = part;
120
121
  str->end = part;
@@ -126,20 +127,6 @@ psg_lstr_append_part(LString *str, LString::Part *part) {
126
127
  part->next = NULL;
127
128
  }
128
129
 
129
- inline void
130
- psg_lstr_append_part_from_another_lstr(LString *str, psg_pool_t *pool, const LString::Part *part) {
131
- LString::Part *copy = (LString::Part *) psg_palloc(pool, sizeof(LString::Part));
132
- if (copy == NULL) {
133
- TRACE_POINT();
134
- throw std::bad_alloc();
135
- }
136
- *copy = *part;
137
- if (part->mbuf_block != NULL) {
138
- mbuf_block_ref(part->mbuf_block);
139
- }
140
- psg_lstr_append_part(str, copy);
141
- }
142
-
143
130
  inline void
144
131
  psg_lstr_append(LString *str, psg_pool_t *pool, const MemoryKit::mbuf &buffer,
145
132
  const char *data, unsigned int size)
@@ -147,16 +134,22 @@ psg_lstr_append(LString *str, psg_pool_t *pool, const MemoryKit::mbuf &buffer,
147
134
  if (size == 0) {
148
135
  return;
149
136
  }
137
+
138
+ assert(data >= buffer.start);
139
+ assert(data + size <= buffer.end);
140
+
150
141
  LString::Part *part = (LString::Part *) psg_palloc(pool, sizeof(LString::Part));
151
- if (part == NULL) {
142
+ if (OXT_UNLIKELY(part == NULL)) {
152
143
  TRACE_POINT();
153
144
  throw std::bad_alloc();
154
145
  }
146
+
147
+ // part->next is set to NULL by psg_lstr_append_part()
155
148
  part->mbuf_block = buffer.mbuf_block;
156
149
  part->data = data;
157
150
  part->size = size;
158
151
  mbuf_block_ref(buffer.mbuf_block);
159
- psg_lstr_append_part(str, part);
152
+ _psg_lstr_append_part(str, part);
160
153
  }
161
154
 
162
155
  inline void
@@ -169,16 +162,18 @@ psg_lstr_append(LString *str, psg_pool_t *pool, const char *data, unsigned int s
169
162
  if (size == 0) {
170
163
  return;
171
164
  }
165
+
172
166
  LString::Part *part = (LString::Part *) psg_palloc(pool, sizeof(LString::Part));
173
- if (part == NULL) {
167
+ if (OXT_UNLIKELY(part == NULL)) {
174
168
  TRACE_POINT();
175
169
  throw std::bad_alloc();
176
170
  }
177
- part->next = NULL;
171
+
172
+ // part->next is set to NULL by psg_lstr_append_part()
178
173
  part->mbuf_block = NULL;
179
174
  part->data = data;
180
175
  part->size = size;
181
- psg_lstr_append_part(str, part);
176
+ _psg_lstr_append_part(str, part);
182
177
  }
183
178
 
184
179
  inline void
@@ -186,6 +181,27 @@ psg_lstr_append(LString *str, psg_pool_t *pool, const char *data) {
186
181
  psg_lstr_append(str, pool, data, strlen(data));
187
182
  }
188
183
 
184
+ /**
185
+ * Move the parts in `from` to the end of `to`.
186
+ */
187
+ inline void
188
+ psg_lstr_move_and_append(LString *from, psg_pool_t *pool, LString *to) {
189
+ if (OXT_LIKELY(from != to)) {
190
+ if (from->size == 0) {
191
+ return;
192
+ }
193
+
194
+ if (to->size == 0) {
195
+ *to = *from;
196
+ } else {
197
+ to->end->next = from->start;
198
+ to->end = from->end;
199
+ to->size += from->size;
200
+ }
201
+ psg_lstr_init(from);
202
+ }
203
+ }
204
+
189
205
  inline LString *
190
206
  psg_lstr_null_terminate(const LString *str, psg_pool_t *pool) {
191
207
  LString *newstr;
@@ -193,7 +209,7 @@ psg_lstr_null_terminate(const LString *str, psg_pool_t *pool) {
193
209
  char *data, *pos;
194
210
 
195
211
  data = (char *) psg_pnalloc(pool, str->size + 1);
196
- if (data == NULL) {
212
+ if (OXT_UNLIKELY(data == NULL)) {
197
213
  TRACE_POINT();
198
214
  throw std::bad_alloc();
199
215
  }
@@ -208,10 +224,11 @@ psg_lstr_null_terminate(const LString *str, psg_pool_t *pool) {
208
224
  *pos = '\0';
209
225
 
210
226
  newstr = (LString *) psg_palloc(pool, sizeof(LString));
211
- if (newstr == NULL) {
227
+ if (OXT_UNLIKELY(newstr == NULL)) {
212
228
  TRACE_POINT();
213
229
  throw std::bad_alloc();
214
230
  }
231
+
215
232
  psg_lstr_init(newstr);
216
233
  psg_lstr_append(newstr, pool, data, str->size);
217
234
  return newstr;
@@ -25,11 +25,13 @@
25
25
  #include <ostream>
26
26
  #include <MemoryKit/mbuf.h>
27
27
  #include <Logging.h>
28
+ #include <StaticString.h>
29
+ #include <Utils/StrIntUtils.h>
28
30
 
29
31
  namespace Passenger {
30
32
  namespace MemoryKit {
31
33
 
32
- //#define MBUF_DEBUG
34
+ //#define MBUF_DEBUG_REFCOUNTS
33
35
 
34
36
  #define ASSERT_MBUF_BLOCK_PROPERTY(mbuf_block, expr) \
35
37
  do { \
@@ -54,6 +56,7 @@ _mbuf_block_mark_as_active(struct mbuf_pool *pool, struct mbuf_block *mbuf_block
54
56
  #ifdef MBUF_ENABLE_BACKTRACES
55
57
  mbuf_block->backtrace = strdup(oxt::thread::current_backtrace().c_str());
56
58
  #endif
59
+ mbuf_block->refcount = 1;
57
60
  pool->nactive_mbuf_blockq++;
58
61
  }
59
62
 
@@ -110,7 +113,6 @@ _mbuf_block_init(struct mbuf_pool *pool, char *buf, size_t block_offset)
110
113
  mbuf_block = (struct mbuf_block *)(buf + block_offset);
111
114
  mbuf_block->magic = MBUF_BLOCK_MAGIC;
112
115
  mbuf_block->pool = pool;
113
- mbuf_block->refcount = 1;
114
116
  mbuf_block->offset = 0;
115
117
 
116
118
  _mbuf_block_mark_as_active(pool, mbuf_block);
@@ -127,10 +129,11 @@ _mbuf_block_get(struct mbuf_pool *pool)
127
129
  assert(pool->nfree_mbuf_blockq > 0);
128
130
 
129
131
  mbuf_block = STAILQ_FIRST(&pool->free_mbuf_blockq);
132
+ ASSERT_MBUF_BLOCK_PROPERTY(mbuf_block, mbuf_block->magic == MBUF_BLOCK_MAGIC);
133
+ ASSERT_MBUF_BLOCK_PROPERTY(mbuf_block, mbuf_block->refcount == 0);
134
+
130
135
  pool->nfree_mbuf_blockq--;
131
136
  STAILQ_REMOVE_HEAD(&pool->free_mbuf_blockq, next);
132
-
133
- ASSERT_MBUF_BLOCK_PROPERTY(mbuf_block, mbuf_block->magic == MBUF_BLOCK_MAGIC);
134
137
  _mbuf_block_mark_as_active(pool, mbuf_block);
135
138
  return mbuf_block;
136
139
  }
@@ -162,7 +165,7 @@ mbuf_block_get(struct mbuf_pool *pool)
162
165
  mbuf_block->end - mbuf_block->start == (int) pool->mbuf_block_offset);
163
166
  ASSERT_MBUF_BLOCK_PROPERTY(mbuf_block, mbuf_block->start < mbuf_block->end);
164
167
 
165
- #ifdef MBUF_DEBUG
168
+ #ifdef MBUF_DEBUG_REFCOUNTS
166
169
  printf("[%p] mbuf_block get %p\n", oxt::thread_signature, mbuf_block);
167
170
  #endif
168
171
 
@@ -192,7 +195,7 @@ mbuf_block_new_standalone(struct mbuf_pool *pool, size_t size)
192
195
  ASSERT_MBUF_BLOCK_PROPERTY(mbuf_block,
193
196
  mbuf_block->start < mbuf_block->end);
194
197
 
195
- #ifdef MBUF_DEBUG
198
+ #ifdef MBUF_DEBUG_REFCOUNTS
196
199
  printf("[%p] mbuf_block new standalone %p\n", oxt::thread_signature, mbuf_block);
197
200
  #endif
198
201
 
@@ -204,7 +207,7 @@ mbuf_block_free(struct mbuf_block *mbuf_block)
204
207
  {
205
208
  char *buf;
206
209
 
207
- #ifdef MBUF_DEBUG
210
+ #ifdef MBUF_DEBUG_REFCOUNTS
208
211
  printf("[%p] mbuf_block free %p\n", oxt::thread_signature, mbuf_block);
209
212
  #endif
210
213
 
@@ -229,7 +232,7 @@ mbuf_block_free(struct mbuf_block *mbuf_block)
229
232
  void
230
233
  mbuf_block_put(struct mbuf_block *mbuf_block)
231
234
  {
232
- #ifdef MBUF_DEBUG
235
+ #ifdef MBUF_DEBUG_REFCOUNTS
233
236
  printf("[%p] mbuf_block put %p\n", oxt::thread_signature, mbuf_block);
234
237
  #endif
235
238
 
@@ -239,7 +242,6 @@ mbuf_block_put(struct mbuf_block *mbuf_block)
239
242
  ASSERT_MBUF_BLOCK_PROPERTY(mbuf_block, mbuf_block->pool->nactive_mbuf_blockq > 0);
240
243
  ASSERT_MBUF_BLOCK_PROPERTY(mbuf_block, mbuf_block->offset == 0);
241
244
 
242
- mbuf_block->refcount = 1;
243
245
  mbuf_block->pool->nfree_mbuf_blockq++;
244
246
  mbuf_block->pool->nactive_mbuf_blockq--;
245
247
  STAILQ_INSERT_HEAD(&mbuf_block->pool->free_mbuf_blockq, mbuf_block, next);
@@ -261,6 +263,11 @@ mbuf_block_remove(struct mhdr *mhdr, struct mbuf_block *mbuf_block)
261
263
  STAILQ_NEXT(mbuf_block, next) = NULL;
262
264
  }
263
265
 
266
+ void
267
+ _mbuf_block_assert_refcount_at_least_two(struct mbuf_block *mbuf_block) {
268
+ ASSERT_MBUF_BLOCK_PROPERTY(mbuf_block, mbuf_block->refcount >= 2);
269
+ }
270
+
264
271
  void
265
272
  mbuf_pool_init(struct mbuf_pool *pool)
266
273
  {
@@ -311,29 +318,41 @@ mbuf_pool_compact(struct mbuf_pool *pool)
311
318
  void
312
319
  mbuf_block_ref(struct mbuf_block *mbuf_block)
313
320
  {
314
- #ifdef MBUF_DEBUG
321
+ #ifdef MBUF_DEBUG_REFCOUNTS
315
322
  printf("[%p] mbuf_block ref %p: %u -> %u\n",
316
323
  oxt::thread_signature, mbuf_block,
317
324
  mbuf_block->refcount, mbuf_block->refcount + 1);
318
325
  #endif
326
+ ASSERT_MBUF_BLOCK_PROPERTY(mbuf_block, mbuf_block->refcount > 0);
319
327
  #ifdef MBUF_ENABLE_BACKTRACES
320
328
  mbuf_block->backtrace = strdup(oxt::thread::current_backtrace().c_str());
321
329
  #endif
330
+
331
+ ASSERT_MBUF_BLOCK_PROPERTY(mbuf_block, STAILQ_NEXT(mbuf_block, next) == NULL);
332
+ ASSERT_MBUF_BLOCK_PROPERTY(mbuf_block, mbuf_block->magic == MBUF_BLOCK_MAGIC);
333
+ ASSERT_MBUF_BLOCK_PROPERTY(mbuf_block, mbuf_block->pool->nactive_mbuf_blockq > 0);
334
+
322
335
  mbuf_block->refcount++;
323
336
  }
324
337
 
325
338
  void
326
339
  mbuf_block_unref(struct mbuf_block *mbuf_block)
327
340
  {
328
- #ifdef MBUF_DEBUG
341
+ #ifdef MBUF_DEBUG_REFCOUNTS
329
342
  printf("[%p] mbuf_block unref %p: %u -> %u\n",
330
343
  oxt::thread_signature, mbuf_block,
331
344
  mbuf_block->refcount, mbuf_block->refcount - 1);
332
345
  #endif
346
+
347
+ ASSERT_MBUF_BLOCK_PROPERTY(mbuf_block, STAILQ_NEXT(mbuf_block, next) == NULL);
348
+ ASSERT_MBUF_BLOCK_PROPERTY(mbuf_block, mbuf_block->magic == MBUF_BLOCK_MAGIC);
333
349
  ASSERT_MBUF_BLOCK_PROPERTY(mbuf_block, mbuf_block->refcount > 0);
350
+ ASSERT_MBUF_BLOCK_PROPERTY(mbuf_block, mbuf_block->pool->nactive_mbuf_blockq > 0);
351
+
334
352
  mbuf_block->refcount--;
335
353
  if (mbuf_block->refcount == 0) {
336
354
  if (mbuf_block->offset > 0) {
355
+ ASSERT_MBUF_BLOCK_PROPERTY(mbuf_block, mbuf_block->pool->nactive_mbuf_blockq > 0);
337
356
  mbuf_block->pool->nactive_mbuf_blockq--;
338
357
  mbuf_block_free(mbuf_block);
339
358
  } else {
@@ -357,8 +376,7 @@ mbuf_get(struct mbuf_pool *pool)
357
376
  }
358
377
 
359
378
  ASSERT_MBUF_BLOCK_PROPERTY(block, block->refcount == 1);
360
- block->refcount--;
361
- return mbuf(block, 0, block->end - block->start);
379
+ return mbuf(block, 0, block->end - block->start, mbuf::just_created_t());
362
380
  }
363
381
 
364
382
  mbuf
@@ -375,8 +393,7 @@ mbuf_get_with_size(struct mbuf_pool *pool, size_t size)
375
393
  }
376
394
 
377
395
  ASSERT_MBUF_BLOCK_PROPERTY(block, block->refcount == 1);
378
- block->refcount--;
379
- return mbuf(block, 0, size);
396
+ return mbuf(block, 0, size, mbuf::just_created_t());
380
397
  }
381
398
 
382
399
  static void
@@ -387,6 +404,8 @@ mbuf_block_print(struct mbuf_block *mbuf_block, std::ostream &stream)
387
404
  "mbuf_block.next: " << (void *) STAILQ_NEXT(mbuf_block, next) << "\n"
388
405
  "mbuf_block.start: " << (void *) mbuf_block->start << "\n"
389
406
  "mbuf_block.end: " << (void *) mbuf_block->end << "\n"
407
+ "mbuf_block.contents: \"" << cEscapeString(StaticString(mbuf_block->start,
408
+ mbuf_block->end - mbuf_block->start)) << "\"\n"
390
409
  "mbuf_block.refcount: " << mbuf_block->refcount << "\n"
391
410
  "mbuf_block.offset: " << mbuf_block->offset << "\n"
392
411
  "mbuf_block.pool: " << (void *) mbuf_block->pool << "\n"
@@ -418,18 +437,34 @@ mbuf::initialize_with_block(unsigned int start, unsigned int len) {
418
437
  }
419
438
 
420
439
  void
421
- mbuf::initialize_with_mbuf(const mbuf &mbuf, unsigned int start, unsigned int len) {
422
- mbuf_block = mbuf.mbuf_block;
440
+ mbuf::initialize_with_block_just_created(unsigned int start, unsigned int len) {
441
+ this->start = clamp<char *>(
442
+ mbuf_block->start + start,
443
+ mbuf_block->start,
444
+ mbuf_block->end);
445
+ this->end = clamp<char *>(
446
+ mbuf_block->start + start + len,
447
+ mbuf_block->start,
448
+ mbuf_block->end);
449
+ ASSERT_MBUF_BLOCK_PROPERTY(mbuf_block, mbuf_block->refcount == 1);
450
+ #ifdef MBUF_ENABLE_BACKTRACES
451
+ mbuf_block->backtrace = strdup(oxt::thread::current_backtrace().c_str());
452
+ #endif
453
+ }
454
+
455
+ void
456
+ mbuf::initialize_with_mbuf(const mbuf &other, unsigned int start, unsigned int len) {
457
+ mbuf_block = other.mbuf_block;
423
458
  this->start = clamp<char *>(
424
- mbuf.start + start,
425
- mbuf.start,
426
- mbuf.end);
459
+ other.start + start,
460
+ other.start,
461
+ other.end);
427
462
  this->end = clamp<char *>(
428
- mbuf.start + start + len,
429
- mbuf.start,
430
- mbuf.end);
431
- if (mbuf.mbuf_block != NULL) {
432
- mbuf_block_ref(mbuf.mbuf_block);
463
+ other.start + start + len,
464
+ other.start,
465
+ other.end);
466
+ if (other.mbuf_block != NULL) {
467
+ mbuf_block_ref(other.mbuf_block);
433
468
  }
434
469
  }
435
470