Skip to content

Commit ead54f0

Browse files
authored
Improved error handling and prevent segfault on invalid syntax (#41)
Fixes #30
1 parent 1985dfc commit ead54f0

36 files changed

+526
-369
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
*.c linguist-language=C
22
*.h linguist-language=C
33
*.w32 linguist-language=JavaScript
4+
*.inc linguist-language=PHP

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ php_test_results_*
4343
parser/lemon
4444
parser/scanner.c
4545
parser/parser.c
46+
parser/parser.php5.c
47+
parser/parser.php5.h
4648
parser/parser.php5.out
49+
parser/parser.php7.c
50+
parser/parser.php7.h
4751
parser/parser.php7.out
4852

4953
release

CHANGELOG.md

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

77
## [Unreleased]
88
### Changed
9-
- Extremely simplified installation of the extension using standard PHP workflow
9+
- Extremely simplified installation of the extension using standard PHP workflow [#38](https://github.com/phalcon/php-zephir-parser/issues/38)
10+
11+
### Fixed
12+
- Improved error handling and prevent segfault on invalid syntax [#30](https://github.com/phalcon/php-zephir-parser/issues/30)
1013

1114
### Removed
12-
- Removed no longer need BASH scripts
15+
- Removed no longer need BASH scripts to build and install extension
1316

1417
## [1.1.2] - 2018-01-23
1518
### Added

CODE_OF_CONDUCT.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making
6+
participation in our project and our community a harassment-free experience for everyone, regardless of age, body size,
7+
disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race,
8+
religion, or sexual identity and orientation.
9+
10+
## Our Standards
11+
12+
Examples of behavior that contributes to creating a positive environment include:
13+
14+
* Using welcoming and inclusive language
15+
* Being respectful of differing viewpoints and experiences
16+
* Gracefully accepting constructive criticism
17+
* Focusing on what is best for the community
18+
* Showing empathy towards other community members
19+
20+
Examples of unacceptable behavior by participants include:
21+
22+
* The use of sexualized language or imagery and unwelcome sexual attention or advances
23+
* Trolling, insulting/derogatory comments, and personal or political attacks
24+
* Public or private harassment
25+
* Publishing others' private information, such as a physical or electronic address, without explicit permission
26+
* Other conduct which could reasonably be considered inappropriate in a professional setting
27+
28+
## Our Responsibilities
29+
30+
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take
31+
appropriate and fair corrective action in response to any instances of unacceptable behavior.
32+
33+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits,
34+
issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any
35+
contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
36+
37+
## Scope
38+
39+
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the
40+
project or its community. Examples of representing a project or community include using an official project e-mail
41+
address, posting via an official social media account, or acting as an appointed representative at an online or offline
42+
event. Representation of a project may be further defined and clarified by project maintainers.
43+
44+
## Enforcement
45+
46+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at
47+
[email protected]. The project team will review and investigate all complaints, and will respond in a way that it
48+
deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the
49+
reporter of an incident. Further details of specific enforcement policies may be posted separately.
50+
51+
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent
52+
repercussions as determined by other members of the project's leadership.
53+
54+
## Attribution
55+
56+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
57+
available at [http://contributor-covenant.org/version/1/4][version]
58+
59+
[homepage]: http://contributor-covenant.org
60+
[version]: http://contributor-covenant.org/version/1/4/

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ If you have specific PHP versions running:
9696
```bash
9797
git clone git://github.com/phalcon/php-zephir-parser.git
9898
cd php-zephir-parser
99-
phpize
99+
/usr/local/bin/phpize
100100
./configure --with-php-config=/usr/local/bin/php-config
101101
make
102102
sudo make install
@@ -129,7 +129,7 @@ See the [LICENSE][:ext-license:] file for more information.
129129

130130
[:badge-travis:]: https://travis-ci.org/phalcon/php-zephir-parser.svg?branch=development
131131
[:badge-appveyor:]: https://ci.appveyor.com/api/projects/status/r4k8baw1iy54v2wt/branch/development?svg=true
132-
[:badge-codecov:]: https://codecov.io/gh/phalcon/php-zephir-parser/branch/developent/graph/badge.svg
132+
[:badge-codecov:]: https://codecov.io/gh/phalcon/php-zephir-parser/branch/development/graph/badge.svg
133133
[:badge-license:]: https://img.shields.io/badge/license-MIT-brightgreen.svg
134134
[:build-travis:]: https://travis-ci.org/phalcon/php-zephir-parser
135135
[:build-appveyor:]: https://ci.appveyor.com/project/sergeyklay/php-zephir-parser/branch/master

coverage.mk

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
OUTCOV=coverage.info
22
DIRCOV=coverage
33

4+
.PHONY: clean-coverage
45
clean-coverage:
56
-rm -fr $(OUTCOV) $(DIRCOV)
67

8+
# coverage-initial test coverage-capture
9+
.PHONY: coverage-initial
710
coverage-initial: clean-coverage
8-
@echo "Capture initial zero coverage data"
911
@$(LCOV) --directory ./parser --directory . --zerocounters
1012
@$(LCOV) --directory ./parser --directory . --capture --compat-libtool --initial --base-directory=. --output-file $(OUTCOV)
1113

14+
.PHONY: coverage-capture
1215
coverage-capture:
13-
@echo "Generating $@"
14-
@$(LCOV) --no-checksum --directory ./parser --directory . --capture --compat-libtool --output-file $(OUTCOV)
15-
@$(LCOV) --remove $(OUTCOV) "/usr*" --remove $(OUTCOV) "${HOME}/.phpenv/*" --remove $(OUTCOV) "${HOME}/build/include/*" --compat-libtool --output-file $(OUTCOV)
16+
@$(LCOV) --no-checksum --directory . --capture --compat-libtool --output-file $(OUTCOV)
17+
@$(LCOV) --remove $(OUTCOV) "/usr*" --remove $(OUTCOV) "${HOME}/.phpenv/*" --compat-libtool --output-file $(OUTCOV)
1618

19+
.PHONY: coverage-html
1720
coverage-html: coverage-capture
1821
@$(GENHTML) --legend --output-directory $(DIRCOV) --title "Zephir Parser code coverage" $(OUTCOV)

parser/base.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
11

2-
/*
3-
* This file is part of the Zephir Parser.
4-
*
5-
* (c) Zephir Team <[email protected]>
6-
*
7-
* For the full copyright and license information, please view the LICENSE
8-
* file that was distributed with this source code.
9-
*/
10-
112
const xx_token_names xx_tokens[] =
123
{
134
{ XX_T_INTEGER, "INTEGER" },
@@ -63,7 +54,7 @@ static void xx_parse_with_token(void* xx_parser, int opcode, int parsercode, xx_
6354
}
6455

6556
/**
66-
* Parses a programm and returning an intermediate array representation
57+
* Parses a program and returning an intermediate array representation
6758
*/
6859
void xx_parse_program(zval *return_value, char *program, size_t program_length, char *file_path, zval *error_msg) {
6960

tests/base/cblocks.phpt

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,35 @@
11
--TEST--
22
Tests recognizing wrapping C-code in CBLOCKs
33
--SKIPIF--
4-
<?php if (!extension_loaded("Zephir Parser")) print "skip The zephir_parser extension is not loaded"; ?>
4+
<?php include(__DIR__ . '/../skipif.inc'); ?>
55
--FILE--
6-
<?php require(__DIR__ . "/../zephir_parser_test.inc");
6+
<?php
7+
8+
$code =<<<ZEP
9+
namespace Example;
10+
11+
class Test
12+
{
13+
public function block()
14+
{
15+
%{
16+
17+
// Some comment
18+
19+
{
20+
while(1) {
21+
RETURN_MM_NULL();
22+
}
23+
}
24+
}%
25+
}
26+
}
27+
ZEP;
28+
29+
$ir = zephir_parse_file($code, '(eval code)');
730

8-
$ir = parse_file("base/cblocks.zep");
931
var_dump($ir);
10-
--EXPECTF--
32+
--EXPECT--
1133
array(2) {
1234
[0]=>
1335
array(5) {
@@ -16,7 +38,7 @@ array(2) {
1638
["name"]=>
1739
string(7) "Example"
1840
["file"]=>
19-
string(%d) "%s/tests/data/base/cblocks.zep"
41+
string(11) "(eval code)"
2042
["line"]=>
2143
int(3)
2244
["char"]=>
@@ -54,43 +76,43 @@ array(2) {
5476
["type"]=>
5577
string(6) "cblock"
5678
["value"]=>
57-
string(81) "
79+
string(150) "
5880
59-
// Some comment
81+
// Some comment
6082
61-
{
62-
while(1) {
63-
RETURN_MM_NULL();
64-
}
65-
}
66-
"
83+
{
84+
while(1) {
85+
RETURN_MM_NULL();
86+
}
87+
}
88+
"
6789
["file"]=>
68-
string(%d) "%s/tests/data/base/cblocks.zep"
90+
string(11) "(eval code)"
6991
["line"]=>
7092
int(17)
7193
["char"]=>
72-
int(2)
94+
int(5)
7395
}
7496
}
7597
["file"]=>
76-
string(%d) "%s/tests/data/base/cblocks.zep"
98+
string(11) "(eval code)"
7799
["line"]=>
78100
int(5)
79101
["last-line"]=>
80102
int(18)
81103
["char"]=>
82-
int(16)
104+
int(19)
83105
}
84106
}
85107
["file"]=>
86-
string(%d) "%s/tests/data/base/cblocks.zep"
108+
string(11) "(eval code)"
87109
["line"]=>
88110
int(3)
89111
["char"]=>
90112
int(5)
91113
}
92114
["file"]=>
93-
string(%d) "%s/tests/data/base/cblocks.zep"
115+
string(11) "(eval code)"
94116
["line"]=>
95117
int(3)
96118
["char"]=>

0 commit comments

Comments
 (0)