[njs] Allocating njs_lexer_t on stack.
Dmitry Volyntsev
xeioex at nginx.com
Wed Feb 20 14:26:01 UTC 2019
details: https://hg.nginx.org/njs/rev/2101597aa18d
branches:
changeset: 786:2101597aa18d
user: hongzhidao <hongzhidao at gmail.com>
date: Sat Feb 16 23:18:43 2019 +0800
description:
Allocating njs_lexer_t on stack.
diffstat:
njs/njs.c | 22 ++++++++++------------
1 files changed, 10 insertions(+), 12 deletions(-)
diffs (47 lines):
diff -r 68e7119e97fe -r 2101597aa18d njs/njs.c
--- a/njs/njs.c Sat Feb 16 23:18:43 2019 +0800
+++ b/njs/njs.c Sat Feb 16 23:18:43 2019 +0800
@@ -217,7 +217,7 @@ nxt_int_t
njs_vm_compile(njs_vm_t *vm, u_char **start, u_char *end)
{
nxt_int_t ret;
- njs_lexer_t *lexer;
+ njs_lexer_t lexer;
njs_parser_t *parser, *prev;
njs_generator_t generator;
@@ -233,17 +233,15 @@ njs_vm_compile(njs_vm_t *vm, u_char **st
prev = vm->parser;
vm->parser = parser;
- lexer = nxt_mp_zalloc(vm->mem_pool, sizeof(njs_lexer_t));
- if (nxt_slow_path(lexer == NULL)) {
- return NJS_ERROR;
- }
+ nxt_memzero(&lexer, sizeof(njs_lexer_t));
- parser->lexer = lexer;
- lexer->start = *start;
- lexer->end = end;
- lexer->line = 1;
- lexer->file = vm->options.file;
- lexer->keywords_hash = vm->shared->keywords_hash;
+ lexer.start = *start;
+ lexer.end = end;
+ lexer.line = 1;
+ lexer.file = vm->options.file;
+ lexer.keywords_hash = vm->shared->keywords_hash;
+
+ parser->lexer = &lexer;
if (vm->backtrace != NULL) {
nxt_array_reset(vm->backtrace);
@@ -261,7 +259,7 @@ njs_vm_compile(njs_vm_t *vm, u_char **st
goto fail;
}
- *start = parser->lexer->start;
+ *start = lexer.start;
/*
* Reset the code array to prevent it from being disassembled
More information about the nginx-devel
mailing list