[nginx] Use NGX_MAX_PATH_LEVEL where appropriate.
Ruslan Ermilov
ru at nginx.com
Wed Jul 6 13:19:59 UTC 2016
details: http://hg.nginx.org/nginx/rev/8bf484eef9ab
branches:
changeset: 6617:8bf484eef9ab
user: Ruslan Ermilov <ru at nginx.com>
date: Wed Jul 06 13:22:29 2016 +0300
description:
Use NGX_MAX_PATH_LEVEL where appropriate.
The macro was unused since 0.7.44.
diffstat:
src/core/ngx_file.c | 19 +++++++++----------
src/core/ngx_file.h | 4 ++--
src/http/ngx_http_file_cache.c | 10 +++++-----
3 files changed, 16 insertions(+), 17 deletions(-)
diffs (126 lines):
diff -r 82b0cd4a0324 -r 8bf484eef9ab src/core/ngx_file.c
--- a/src/core/ngx_file.c Wed Jul 06 13:10:06 2016 +0300
+++ b/src/core/ngx_file.c Wed Jul 06 13:22:29 2016 +0300
@@ -225,7 +225,7 @@ ngx_create_hashed_filename(ngx_path_t *p
file[path->name.len + path->len] = '/';
- for (n = 0; n < 3; n++) {
+ for (n = 0; n < NGX_MAX_PATH_LEVEL; n++) {
level = path->level[n];
if (level == 0) {
@@ -249,7 +249,7 @@ ngx_create_path(ngx_file_t *file, ngx_pa
pos = path->name.len;
- for (i = 0; i < 3; i++) {
+ for (i = 0; i < NGX_MAX_PATH_LEVEL; i++) {
if (path->level[i] == 0) {
break;
}
@@ -399,6 +399,8 @@ char *
ngx_conf_merge_path_value(ngx_conf_t *cf, ngx_path_t **path, ngx_path_t *prev,
ngx_path_init_t *init)
{
+ ngx_uint_t i;
+
if (*path) {
return NGX_CONF_OK;
}
@@ -419,13 +421,10 @@ ngx_conf_merge_path_value(ngx_conf_t *cf
return NGX_CONF_ERROR;
}
- (*path)->level[0] = init->level[0];
- (*path)->level[1] = init->level[1];
- (*path)->level[2] = init->level[2];
-
- (*path)->len = init->level[0] + (init->level[0] ? 1 : 0)
- + init->level[1] + (init->level[1] ? 1 : 0)
- + init->level[2] + (init->level[2] ? 1 : 0);
+ for (i = 0; i < NGX_MAX_PATH_LEVEL; i++) {
+ (*path)->level[i] = init->level[i];
+ (*path)->len += init->level[i] + (init->level[i] ? 1 : 0);
+ }
if (ngx_add_path(cf, path) != NGX_OK) {
return NGX_CONF_ERROR;
@@ -518,7 +517,7 @@ ngx_add_path(ngx_conf_t *cf, ngx_path_t
return NGX_ERROR;
}
- for (n = 0; n < 3; n++) {
+ for (n = 0; n < NGX_MAX_PATH_LEVEL; n++) {
if (p[i]->level[n] != path->level[n]) {
if (path->conf_file == NULL) {
if (p[i]->conf_file == NULL) {
diff -r 82b0cd4a0324 -r 8bf484eef9ab src/core/ngx_file.h
--- a/src/core/ngx_file.h Wed Jul 06 13:10:06 2016 +0300
+++ b/src/core/ngx_file.h Wed Jul 06 13:22:29 2016 +0300
@@ -49,7 +49,7 @@ typedef void (*ngx_path_loader_pt) (void
typedef struct {
ngx_str_t name;
size_t len;
- size_t level[3];
+ size_t level[NGX_MAX_PATH_LEVEL];
ngx_path_manager_pt manager;
ngx_path_loader_pt loader;
@@ -62,7 +62,7 @@ typedef struct {
typedef struct {
ngx_str_t name;
- size_t level[3];
+ size_t level[NGX_MAX_PATH_LEVEL];
} ngx_path_init_t;
diff -r 82b0cd4a0324 -r 8bf484eef9ab src/http/ngx_http_file_cache.c
--- a/src/http/ngx_http_file_cache.c Wed Jul 06 13:10:06 2016 +0300
+++ b/src/http/ngx_http_file_cache.c Wed Jul 06 13:22:29 2016 +0300
@@ -101,7 +101,7 @@ ngx_http_file_cache_init(ngx_shm_zone_t
return NGX_ERROR;
}
- for (n = 0; n < 3; n++) {
+ for (n = 0; n < NGX_MAX_PATH_LEVEL; n++) {
if (cache->path->level[n] != ocache->path->level[n]) {
ngx_log_error(NGX_LOG_EMERG, shm_zone->shm.log, 0,
"cache \"%V\" had previously different levels",
@@ -2257,7 +2257,7 @@ ngx_http_file_cache_set_slot(ngx_conf_t
p = value[i].data + 7;
last = value[i].data + value[i].len;
- for (n = 0; n < 3 && p < last; n++) {
+ for (n = 0; n < NGX_MAX_PATH_LEVEL && p < last; n++) {
if (*p > '0' && *p < '3') {
@@ -2268,7 +2268,7 @@ ngx_http_file_cache_set_slot(ngx_conf_t
break;
}
- if (*p++ == ':' && n < 2 && p != last) {
+ if (*p++ == ':' && n < NGX_MAX_PATH_LEVEL - 1 && p < last) {
continue;
}
@@ -2278,7 +2278,7 @@ ngx_http_file_cache_set_slot(ngx_conf_t
goto invalid_levels;
}
- if (cache->path->len < 10 + 3) {
+ if (cache->path->len < 10 + NGX_MAX_PATH_LEVEL) {
continue;
}
@@ -2450,7 +2450,7 @@ ngx_http_file_cache_set_slot(ngx_conf_t
ngx_memcpy(p, "/temp", sizeof("/temp"));
ngx_memcpy(&cache->temp_path->level, &cache->path->level,
- 3 * sizeof(size_t));
+ NGX_MAX_PATH_LEVEL * sizeof(size_t));
cache->temp_path->len = cache->path->len;
cache->temp_path->conf_file = cf->conf_file->file.name.data;
More information about the nginx-devel
mailing list