Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
chobie committed Sep 30, 2012
2 parents fbd4274 + 8bbfea0 commit 5c3190c
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 30 deletions.
50 changes: 35 additions & 15 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ PECL Sundown provides straight forward object oriented Markdown API and customiz
<email>[email protected]</email>
<active>yes</active>
</lead>
<date>2012-08-11</date>
<date>2012-09-30</date>
<version>
<release>0.3.7</release>
<release>0.3.8</release>
<api>0.3.7</api>
</version>
<stability>
Expand All @@ -26,21 +26,11 @@ PECL Sundown provides straight forward object oriented Markdown API and customiz
</stability>
<license uri="http://www.php.net/license">PHP</license>
<notes>
* bumped up 0.3.7
* bumped up 0.3.8

fixed SEGV when processing tableCell and prettify source codes.
- fixes #28 Wired memory limit error with autolink set.
Sundown\Render\Base callbacks are able to throw exceptions.

9582b04 update contributors
1f11ace update README
497d0a4 add a space after comma.
7bc4703 fix several compile warnings
a11eb98 update CFLAGS for fix compile warnings
9a86d00 fixes #26:prevent SEGV when calling Sundwon\Base\tableCell
26b77d6 change submodule to vmg/sundown from tanoku/sundown
ee8a132 Merge pull request #24 from reeze/patch-2
0a08969 Fix build in php-src
b0adcc7 Merge pull request #23 from reeze/patch-1
ebae34b Make travis report test failure since make test didn't report exit code
</notes>
<contents>
<dir name="/">
Expand Down Expand Up @@ -89,6 +79,7 @@ ebae34b Make travis report test failure since make test didn't report exit code
<file role="test" name="999-regression-no12.phpt" />
<file role="test" name="999-regression-no19.phpt" />
<file role="test" name="999-regression-no26.phpt" />
<file role="test" name="999-regression-no28.phpt" />
</dir>
<dir name="docs">
<file role="doc" name="ExtensionsAndRenderFlags.md" />
Expand Down Expand Up @@ -133,6 +124,35 @@ ebae34b Make travis report test failure since make test didn't report exit code
<providesextension>sundown</providesextension>
<extsrcrelease/>
<changelog>
<release>
<stability>
<release>beta</release>
<api>beta</api>
</stability>
<version>
<release>0.3.7</release>
<api>0.3.7</api>
</version>
<date>2012-08-11</date>
<notes>
* bumped up 0.3.7

fixed SEGV when processing tableCell and prettify source codes.

9582b04 update contributors
1f11ace update README
497d0a4 add a space after comma.
7bc4703 fix several compile warnings
a11eb98 update CFLAGS for fix compile warnings
9a86d00 fixes #26:prevent SEGV when calling Sundwon\Base\tableCell
26b77d6 change submodule to vmg/sundown from tanoku/sundown
ee8a132 Merge pull request #24 from reeze/patch-2
0a08969 Fix build in php-src
b0adcc7 Merge pull request #23 from reeze/patch-1
ebae34b Make travis report test failure since make test didn't report exit code
</notes>
</release>

<release>
<stability>
<release>beta</release>
Expand Down
15 changes: 13 additions & 2 deletions php_sundown.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@


#include "php_sundown.h"
ZEND_DECLARE_MODULE_GLOBALS(sundown)

#include "ext/standard/info.h"

extern void php_sundown_render_base_init(TSRMLS_D);
Expand Down Expand Up @@ -212,8 +214,12 @@ static zend_function_entry php_sundown_methods[] = {
};
/* }}} */


PHP_MINIT_FUNCTION(sundown) {

#ifdef ZTS
ts_allocate_id(&sundown_globals_id, sizeof(zend_sundown_globals), NULL, NULL);
#endif

php_sundown_init(TSRMLS_C);
php_sundown_render_base_init(TSRMLS_C);
php_sundown_render_html_init(TSRMLS_C);
Expand All @@ -225,6 +231,11 @@ PHP_MINIT_FUNCTION(sundown) {
return SUCCESS;
}

PHP_MSHUTDOWN_FUNCTION(sundown) {
return SUCCESS;
}



PHP_MINFO_FUNCTION(sundown)
{
Expand All @@ -242,7 +253,7 @@ zend_module_entry sundown_module_entry = {
"sundown",
NULL, /* Functions */
PHP_MINIT(sundown), /* MINIT */
NULL, /* MSHUTDOWN */
PHP_MSHUTDOWN(sundown), /* MSHUTDOWN */
NULL, /* RINIT */
NULL, /* RSHUTDOWN */
PHP_MINFO(sundown), /* MINFO */
Expand Down
41 changes: 33 additions & 8 deletions php_sundown.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,23 @@
extern zend_module_entry sundown_module_entry;
#define phpext_sundown_ptr &sundown_module_entry

#ifdef ZTS
#include "TSRM.h"
#endif

ZEND_BEGIN_MODULE_GLOBALS(sundown)
JMP_BUF jump;
ZEND_END_MODULE_GLOBALS(sundown)

/* Macro to access request-wide global variables. */
#ifdef ZTS
#define SUNDOWN_G(v) TSRMG(sundown_globals_id, zend_sundown_globals *, v)
#else
#define SUNDOWN_G(v) (sundown_globals.v)
#endif

ZEND_EXTERN_MODULE_GLOBALS(sundown)

extern zend_class_entry *sundown_class_entry, *php_sundown_buffer_class_entry;

typedef enum
Expand Down Expand Up @@ -76,15 +93,16 @@ typedef struct{
#define SPAN_CALLBACK_EX(buffer, method_name, ...) {\
struct php_sundown_renderopt_ex *opt = (struct php_sundown_renderopt_ex*)opaque;\
zval func, *ret;\
\
TSRMLS_FETCH();\
\
MAKE_STD_ZVAL(ret);\
ZVAL_STRING(&func, method_name, 1);\
\
if(call_user_function_v(NULL, &opt->self, &func, ret, __VA_ARGS__) == FAILURE){\
fprintf(stderr, "Can't call method %s\n", method_name);\
return 0;\
zval_ptr_dtor(&ret);\
zval_dtor(&func);\
LONGJMP(SUNDOWN_G(jump), 1);\
}\
if (ret != NULL) {\
if (ret != NULL) {\
bufput(buffer, Z_STRVAL_P(ret), Z_STRLEN_P(ret));\
}\
zval_ptr_dtor(&ret);\
Expand All @@ -95,13 +113,15 @@ typedef struct{

#define BLOCK_CALLBACK_EX(buffer, method_name, ...) {\
struct php_sundown_renderopt_ex *opt = (struct php_sundown_renderopt_ex*)opaque;\
TSRMLS_FETCH();\
zval func, *ret;\
\
MAKE_STD_ZVAL(ret);\
ZVAL_STRING(&func, method_name, 1);\
\
if(call_user_function_v(NULL, &opt->self, &func, ret, __VA_ARGS__) == FAILURE){\
fprintf(stderr, "Can't call method %s\n", method_name);\
zval_ptr_dtor(&ret);\
zval_dtor(&func);\
LONGJMP(SUNDOWN_G(jump), 1);\
}\
if (ret != NULL) {\
bufput(buffer, Z_STRVAL_P(ret), Z_STRLEN_P(ret));\
Expand Down Expand Up @@ -278,8 +298,13 @@ static void php_sundown__get_extensions(HashTable *table, unsigned int *enabled_
extensions |= MKDEXT_STRIKETHROUGH;
}

/* obsoleted? */
if (SUNDOWN_HAS_EXTENSION("lax_html_blocks")) {
extensions |= MKDEXT_LAX_HTML_BLOCKS;
extensions |= MKDEXT_LAX_SPACING;
}

if (SUNDOWN_HAS_EXTENSION("lax_spacing")) {
extensions |= MKDEXT_LAX_SPACING;
}

if (SUNDOWN_HAS_EXTENSION("space_after_headers")) {
Expand Down
2 changes: 1 addition & 1 deletion sundown
16 changes: 12 additions & 4 deletions sundown_markdown.c
Original file line number Diff line number Diff line change
Expand Up @@ -470,10 +470,19 @@ PHP_METHOD(sundown_markdown, render)

/* proceess markdown */
markdown = sd_markdown_new(enabled_extensions, 16, &sundown_render, &opt);
sd_markdown_render(output_buf, input_buf.data, input_buf.size, markdown);
sd_markdown_free(markdown);
if (SETJMP(SUNDOWN_G(jump)) == 0) {
sd_markdown_render(output_buf, input_buf.data, input_buf.size, markdown);
zval_dtor(&preprocess);
zval_ptr_dtor(&ret);
sd_markdown_free(markdown);
} else {
zval_dtor(&preprocess);
zval_ptr_dtor(&ret);
zval_ptr_dtor(&render);
sd_markdown_free(markdown);
return;
}

zval_ptr_dtor(&ret);
/* postprocess */
MAKE_STD_ZVAL(ret);
MAKE_STD_ZVAL(params[0]);
Expand All @@ -490,7 +499,6 @@ PHP_METHOD(sundown_markdown, render)
zval_ptr_dtor(&ret);
zval_ptr_dtor(&params[0]);
zval_dtor(&postprocess);
zval_dtor(&preprocess);
zval_ptr_dtor(&render);
}
/* }}} */
Expand Down
32 changes: 32 additions & 0 deletions tests/999-regression-no28.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
--TEST--
Check for https://github.com/chobie/php-sundown/issues/28 (Render should interrupt by exception)
--SKIPIF--
<?php if (!extension_loaded("sundown")) print "skip"; ?>
--FILE--
<?php
class R extends \Sundown\Render\Base
{
public function image($link, $title, $alt)
{
if ($link == 'doesnt/exists.jpg') {
throw new \Exception("err");
}
}
}

$c = <<<EOM
# Doc
![](doesnt/exists.jpg)
![](https://www.google.com/images/srpr/logo3w.png)
EOM;

$m = new \Sundown\Markdown(new R(), array('autolink' => true));
try {
$m->render($c);
} catch (Exception $e) {
echo $e->getMessage();
}
--EXPECT--
err

0 comments on commit 5c3190c

Please sign in to comment.