Skip to content

Commit e2aa05e

Browse files
authored
Merge pull request #21 from phalcon/development
1.0.3
2 parents df2fb8a + 475ce65 commit e2aa05e

File tree

16 files changed

+503
-138
lines changed

16 files changed

+503
-138
lines changed

.appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: 1.0.2-{build}
1+
version: 1.0.3-{build}
22

33
build: false
44
environment:

CHANGELOG.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
66

77
## [Unreleased]
88

9+
## [1.0.3] - 2017-05-13
10+
### Added
11+
- Make parser return error message on failure
12+
- Added support of `$_ENV` global var [#1224](https://github.com/phalcon/zephir/issues/1224)
13+
- Amended tests
14+
15+
### Changed
16+
- Improved installer: use `sudo` only if `make install` fails
17+
18+
### Fixed
19+
- Treat warnings as errors
20+
- Fix memory leak for PHP5
21+
922
## [1.0.2] - 2017-04-14
1023
### Added
1124
- Added an ability to use parentheses in for loops [#3](https://github.com/phalcon/php-zephir-parser/issues/3)
@@ -32,6 +45,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
3245
- Removing unused structures
3346
- Removing unused variables
3447

35-
## [1.0.0] - 2017-03-26
48+
## 1.0.0 - 2017-03-26
3649
### Added
3750
- Initial stable release
51+
52+
[Unreleased]: https://github.com/phalcon/php-zephir-parser/compare/v1.0.3...HEAD
53+
[1.0.3]: https://github.com/phalcon/php-zephir-parser/compare/v1.0.2...v1.0.3
54+
[1.0.2]: https://github.com/phalcon/php-zephir-parser/compare/v1.0.1...v1.0.2
55+
[1.0.1]: https://github.com/phalcon/php-zephir-parser/compare/v1.0.0...v1.0.1

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.2
1+
1.0.3

install-development

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
# Example:
2121
# ./install-development --phpize /usr/bin/phpize5.6 --php-config /usr/bin/php-config5.6
2222

23-
set -e
24-
2523
export ZEND_DONT_UNLOAD_MODULES=1
2624
export USE_ZEND_ALLOC=0
2725

@@ -56,7 +54,7 @@ if [ x"$CC" == x ]; then
5654
exit 1
5755
fi
5856

59-
export CFLAGS="-g3 -O0 -Wall -fvisibility=hidden -march=native"
57+
export CFLAGS="-g3 -O0 -Wall -Werror -fvisibility=hidden"
6058

6159
if [ x"$CC" == xclang ]; then
6260
export CFLAGS="${CFLAGS} -fcolor-diagnostics"
@@ -162,11 +160,11 @@ ${PHPIZE_BIN}
162160

163161
make -j"$(getconf _NPROCESSORS_ONLN)"
164162

165-
make test CFLAGS="-O0 -g" NO_INTERACTION=1
163+
make test NO_INTERACTION=1
166164

167165
echo
168166

169-
sudo make install
167+
make install || sudo make install
170168

171169
echo
172170

parser/base.c

Lines changed: 61 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const xx_token_names xx_tokens[] =
2020
{ XX_T_INTEGER, "INTEGER" },
2121
{ XX_T_DOUBLE, "DOUBLE" },
2222
{ XX_T_STRING, "STRING" },
23-
{ XX_T_IDENTIFIER, "IDENTIFIER" },
23+
{ XX_T_IDENTIFIER, "IDENTIFIER" },
2424
{ XX_T_AT, "@" },
2525
{ XX_T_COMMA, "," },
2626
{ XX_T_ASSIGN, "=" },
@@ -72,7 +72,7 @@ static void xx_parse_with_token(void* xx_parser, int opcode, int parsercode, xx_
7272
/**
7373
* Parses a programm and returning an intermediate array representation
7474
*/
75-
void xx_parse_program(zval *return_value, char *program, size_t program_length, char *file_path, zval **error_msg) {
75+
void xx_parse_program(zval *return_value, char *program, size_t program_length, char *file_path, zval *error_msg) {
7676

7777
char *error;
7878
xx_scanner_state *state;
@@ -433,16 +433,15 @@ void xx_parse_program(zval *return_value, char *program, size_t program_length,
433433
case XX_T_TYPE_VAR:
434434
xx_(xx_parser, XX_TYPE_VAR, NULL, parser_status);
435435
break;
436-
case XX_T_TYPE_OBJECT:
437-
xx_(xx_parser, XX_TYPE_OBJECT, NULL, parser_status);
438-
break;
439-
case XX_T_TYPE_RESOURCE:
440-
xx_(xx_parser, XX_TYPE_RESOURCE, NULL, parser_status);
441-
break;
442-
case XX_T_TYPE_CALLABLE:
443-
xx_(xx_parser, XX_TYPE_CALLABLE, NULL, parser_status);
444-
break;
445-
436+
case XX_T_TYPE_OBJECT:
437+
xx_(xx_parser, XX_TYPE_OBJECT, NULL, parser_status);
438+
break;
439+
case XX_T_TYPE_RESOURCE:
440+
xx_(xx_parser, XX_TYPE_RESOURCE, NULL, parser_status);
441+
break;
442+
case XX_T_TYPE_CALLABLE:
443+
xx_(xx_parser, XX_TYPE_CALLABLE, NULL, parser_status);
444+
break;
446445
case XX_T_ADD:
447446
xx_(xx_parser, XX_ADD, NULL, parser_status);
448447
break;
@@ -521,12 +520,24 @@ void xx_parse_program(zval *return_value, char *program, size_t program_length,
521520

522521
default:
523522
parser_status->status = XX_PARSING_FAILED;
524-
if (!*error_msg) {
523+
if (error_msg && Z_TYPE_P(error_msg) != IS_ARRAY) {
525524
int length = (48 + strlen(file_path));
526525
error = emalloc(sizeof(char) * length);
527526
snprintf(error, length, "Scanner: unknown opcode %d on in %s line %d", token.opcode, file_path, state->active_line);
528-
//ZVAL_STRING(*error_msg, error, 1);
527+
528+
array_init(error_msg);
529+
#if PHP_VERSION_ID >= 70000
530+
add_assoc_string(error_msg, "type", "error");
531+
add_assoc_string(error_msg, "message", error);
532+
add_assoc_string(error_msg, "file", state->active_file);
529533
efree(error);
534+
#else
535+
add_assoc_string(error_msg, "type", "error", 1);
536+
add_assoc_string(error_msg, "message", error, 0);
537+
add_assoc_string(error_msg, "file", state->active_file, 1);
538+
#endif
539+
add_assoc_long(error_msg, "line", state->active_line);
540+
add_assoc_long(error_msg, "char", state->active_char);
530541
}
531542
break;
532543
}
@@ -543,20 +554,27 @@ void xx_parse_program(zval *return_value, char *program, size_t program_length,
543554
switch (scanner_status) {
544555
case XX_SCANNER_RETCODE_ERR:
545556
case XX_SCANNER_RETCODE_IMPOSSIBLE:
546-
{
557+
if (error_msg && Z_TYPE_P(error_msg) == IS_NULL) {
547558
error = emalloc(sizeof(char) * 1024);
548559
if (state->start) {
549560
snprintf(error, 1024, "Scanner error: %d %s", scanner_status, state->start);
550561
} else {
551562
snprintf(error, 1024, "Scanner error: %d", scanner_status);
552563
}
553-
#if PHP_VERSION_ID < 70000
554-
ALLOC_INIT_ZVAL(*error_msg);
555-
ZVAL_STRING(*error_msg, error, 1);
564+
565+
array_init(error_msg);
566+
#if PHP_VERSION_ID >= 70000
567+
add_assoc_string(error_msg, "type", "error");
568+
add_assoc_string(error_msg, "message", error);
569+
add_assoc_string(error_msg, "file", state->active_file);
570+
efree(error);
556571
#else
557-
ZVAL_STRING(*error_msg, error);
572+
add_assoc_string(error_msg, "type", "error", 1);
573+
add_assoc_string(error_msg, "message", error, 0);
574+
add_assoc_string(error_msg, "file", state->active_file, 1);
558575
#endif
559-
efree(error);
576+
add_assoc_long(error_msg, "line", state->active_line);
577+
add_assoc_long(error_msg, "char", state->active_char);
560578
status = FAILURE;
561579
}
562580
break;
@@ -570,18 +588,31 @@ void xx_parse_program(zval *return_value, char *program, size_t program_length,
570588

571589
if (parser_status->status != XX_PARSING_OK) {
572590
status = FAILURE;
573-
if (parser_status->syntax_error) {
574-
#if PHP_VERSION_ID < 70000
575-
if (!*error_msg) {
576-
ALLOC_INIT_ZVAL(*error_msg);
577-
ZVAL_STRING(*error_msg, parser_status->syntax_error, 1);
578-
}
591+
if (parser_status->syntax_error && error_msg && Z_TYPE_P(error_msg) != IS_ARRAY) {
592+
array_init(error_msg);
593+
#if PHP_VERSION_ID >= 70000
594+
add_assoc_string(error_msg, "type", "error");
595+
add_assoc_string(error_msg, "message", parser_status->syntax_error);
596+
add_assoc_string(error_msg, "file", state->active_file);
597+
efree(parser_status->syntax_error);
579598
#else
580-
if (Z_TYPE_P(*error_msg) == IS_UNDEF) {
581-
ZVAL_STRING(*error_msg, parser_status->syntax_error);
582-
}
599+
add_assoc_string(error_msg, "type", "error", 1);
600+
add_assoc_string(error_msg, "message", parser_status->syntax_error, 0);
601+
add_assoc_string(error_msg, "file", state->active_file, 1);
602+
#endif
603+
add_assoc_long(error_msg, "line", state->active_line);
604+
add_assoc_long(error_msg, "char", state->active_char);
605+
606+
parser_status->syntax_error = NULL;
607+
}
608+
else if (error_msg && Z_TYPE_P(error_msg) != IS_ARRAY) {
609+
#if PHP_VERSION_ID >= 70000
610+
assert(Z_TYPE(parser_status->ret) == IS_ARRAY);
611+
ZVAL_ZVAL(error_msg, &parser_status->ret, 1, 1);
612+
#else
613+
assert(Z_TYPE_P(parser_status->ret) == IS_ARRAY);
614+
ZVAL_ZVAL(error_msg, parser_status->ret, 1, 1);
583615
#endif
584-
efree(parser_status->syntax_error);
585616
}
586617
}
587618

parser/scanner.re

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,11 @@ int xx_get_token(xx_scanner_state *s, xx_scanner_token *token) {
635635
token->opcode = XX_T_IDENTIFIER;
636636
return 0;
637637
}
638+
639+
if (!strcmp(token->value, "_ENV")) {
640+
token->opcode = XX_T_IDENTIFIER;
641+
return 0;
642+
}
638643
}
639644

640645
/* This is hack */

php_zephir_parser.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ extern zend_module_entry zephir_parser_module_entry;
2424
#define phpext_zephir_parser_ptr &zephir_parser_module_entry
2525

2626
#define PHP_ZEPHIR_PARSER_NAME "Zephir Parser"
27-
#define PHP_ZEPHIR_PARSER_VERSION "1.0.2"
27+
#define PHP_ZEPHIR_PARSER_VERSION "1.0.3"
2828
#define PHP_ZEPHIR_PARSER_AUTHOR "Zephir Team and contributors"
2929
#define PHP_ZEPHIR_PARSER_DESCRIPTION "The Zephir Parser delivered as a C extension for the PHP language."
3030

@@ -42,7 +42,7 @@ extern zend_module_entry zephir_parser_module_entry;
4242

4343
#define ZEPHIR_PARSER_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(zephir_parser, v)
4444

45-
#if defined(ZTS) && defined(COMPILE_DL_ZEPHIR_PARSER)
45+
#if defined(ZTS) && defined(COMPILE_DL_ZEPHIR_PARSER) && PHP_VERSION_ID >= 70000
4646
ZEND_TSRMLS_CACHE_EXTERN();
4747
#endif
4848

unit-tests/Data/globals/simple.zep

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace Example;
2+
3+
class Test
4+
{
5+
public function all()
6+
{
7+
var _get = _GET;
8+
var _post = _POST;
9+
var _request = _REQUEST;
10+
var _cookie = _COOKIE;
11+
var _server = _SERVER;
12+
var _session = _SESSION;
13+
var _files = _FILES;
14+
var _env = _ENV;
15+
}
16+
}

0 commit comments

Comments
 (0)