Browse files

fix reference count and add test cases.

  • Loading branch information...
1 parent 913f423 commit 84e991b6213530353b821dfabac09c00481b7cd8 @chobie committed Feb 21, 2012
View
19 render_base.c
@@ -619,9 +619,13 @@ PHP_METHOD(sundown_render_base, __construct)
if (render_flags != NULL && Z_TYPE_P(render_flags) == IS_ARRAY) {
ALLOC_INIT_ZVAL(c_flags);
- ZVAL_ZVAL(c_flags, render_flags, 1, 1);
- add_property_zval_ex(getThis(),"render_flags",sizeof("render_flags"),c_flags TSRMLS_CC);
+ ZVAL_ZVAL(c_flags, render_flags, 1, 0);
+ } else {
+ MAKE_STD_ZVAL(c_flags);
+ array_init(c_flags);
}
+ add_property_zval_ex(getThis(),"render_flags",sizeof("render_flags"),c_flags TSRMLS_CC);
+
}
/* }}} */
@@ -644,14 +648,18 @@ PHP_METHOD(sundown_render_base, getRenderFlags)
*/
PHP_METHOD(sundown_render_base, setRenderFlags)
{
- zval *render_flags, *c_render_flags = NULL;
+ zval *render_flags, *c_render_flags, *tmp = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"a", &render_flags) == FAILURE) {
return;
}
-
- add_property_zval_ex(getThis(),"render_flags",sizeof("render_flags"),render_flags TSRMLS_CC);
+ MAKE_STD_ZVAL(c_render_flags);
+ ZVAL_ZVAL(c_render_flags,render_flags,1,0);
+ tmp = zend_read_property(sundown_render_base_class_entry, getThis(), "render_flags", sizeof("render_flags")-1, 0 TSRMLS_CC);
+ zval_ptr_dtor(&tmp);
+
+ add_property_zval_ex(getThis(),"render_flags",sizeof("render_flags"),c_render_flags TSRMLS_CC);
}
/* }}} */
@@ -661,7 +669,6 @@ PHP_METHOD(sundown_render_base, setRenderFlags)
PHP_METHOD(sundown_render_base, __destruct)
{
zval *render_flags;
-
render_flags = zend_read_property(sundown_render_base_class_entry, getThis(),"render_flags",sizeof("render_flags")-1, 0 TSRMLS_CC);
if (Z_TYPE_P(render_flags) == IS_ARRAY) {
zval_ptr_dtor(&render_flags);
View
21 render_html.c
@@ -819,29 +819,19 @@ PHP_METHOD(sundown_render_html, __construct)
if (render_flags != NULL && Z_TYPE_P(render_flags) == IS_ARRAY) {
ALLOC_INIT_ZVAL(c_flags);
- ZVAL_ZVAL(c_flags, render_flags, 1, 1);
- add_property_zval_ex(getThis(),"render_flags",sizeof("render_flags"),c_flags TSRMLS_CC);
+ ZVAL_ZVAL(c_flags, render_flags, 1, 0);
+ } else {
+ MAKE_STD_ZVAL(c_flags);
+ array_init(c_flags);
}
+ add_property_zval_ex(getThis(),"render_flags",sizeof("render_flags"),c_flags TSRMLS_CC);
object = (php_sundown_render_html_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
sdhtml_renderer(&object->cb, &opt.html, 0);
opt.self = getThis();
}
/* }}} */
-/* {{{ proto Sundown\Render\HTML::__destruct()
-*/
-PHP_METHOD(sundown_render_html, __destruct)
-{
- zval *render_flags;
-
- render_flags = zend_read_property(sundown_render_base_class_entry, getThis(),"render_flags",sizeof("render_flags")-1, 0 TSRMLS_CC);
- if (Z_TYPE_P(render_flags) == IS_ARRAY) {
- zval_ptr_dtor(&render_flags);
- }
-}
-
-
static zend_function_entry php_sundown_render_html_methods[] = {
PHP_ME(sundown_render_html, __construct, arginfo_sundown_render_html___construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
PHP_ME(sundown_render_html, block_code, arginfo_sundown_render_html_block_code, ZEND_ACC_PUBLIC)
@@ -870,7 +860,6 @@ static zend_function_entry php_sundown_render_html_methods[] = {
PHP_ME(sundown_render_html, normal_text, arginfo_sundown_render_html_normal_text, ZEND_ACC_PUBLIC)
PHP_ME(sundown_render_html, doc_header, arginfo_sundown_render_html_doc_header, ZEND_ACC_PUBLIC)
PHP_ME(sundown_render_html, doc_footer, arginfo_sundown_render_html_doc_footer, ZEND_ACC_PUBLIC)
- PHP_ME(sundown_render_html, __destruct, NULL, ZEND_ACC_PUBLIC)
{NULL,NULL,NULL}
};
View
2 render_xhtml.c
@@ -70,7 +70,7 @@ PHP_METHOD(sundown_render_xhtml, __construct)
if (render_flags != NULL && Z_TYPE_P(render_flags) == IS_ARRAY) {
ALLOC_INIT_ZVAL(c_flags);
- ZVAL_ZVAL(c_flags, render_flags, 1, 1);
+ ZVAL_ZVAL(c_flags, render_flags, 1, 0);
} else {
zval *t;
MAKE_STD_ZVAL(t);
View
16 tests/003-advanced-enabled-render-flags.phpt
@@ -123,14 +123,14 @@ bool(false)
bool(false)
bool(true)
render flags and extensions should not conflict 2:
-NULL
-NULL
-NULL
-NULL
-NULL
-NULL
-NULL
-NULL
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+bool(false)
test filter_html:
bool(true)
bool(false)
View
20 tests/003-advanced-get-render.phpt
@@ -0,0 +1,20 @@
+--TEST--
+Check for determine enabled extensions.
+--SKIPIF--
+<?php if (!extension_loaded("sundown")) print "skip"; ?>
+--FILE--
+<?php
+$render = new Sundown\Render\HTML();
+
+$markdown = new Sundown\Markdown($render, array());
+$r = $markdown->getRender();
+
+var_dump(spl_object_hash($render) == spl_object_hash($r));
+
+$r = $markdown->getRender();
+$r = $markdown->getRender();
+$r = $markdown->getRender();
+var_dump(spl_object_hash($render) == spl_object_hash($r));
+--EXPECT--
+bool(true)
+bool(true)
View
27 tests/003-advanced-render-base-get_render_flags.phpt
@@ -0,0 +1,27 @@
+--TEST--
+Check for Sundown\Render\HTML::list_box() feature
+--SKIPIF--
+<?php if (!extension_loaded("sundown")) print "skip"; ?>
+--FILE--
+<?php
+$render = new Sundown\Render\HTML();
+$res = $render->getRenderFlags();
+echo count($res) . PHP_EOL;
+$res = $render->getRenderFlags();
+echo count($res) . PHP_EOL;
+$render = new Sundown\Render\HTML(array("filter_html"=>true));
+$res = $render->getRenderFlags();
+var_dump($res);
+$res = $render->getRenderFlags();
+var_dump($res);
+--EXPECT--
+0
+0
+array(1) {
+ ["filter_html"]=>
+ bool(true)
+}
+array(1) {
+ ["filter_html"]=>
+ bool(true)
+}
View
37 tests/003-advanced-render-base-set_render_flags.phpt
@@ -0,0 +1,37 @@
+--TEST--
+Check for Sundown\Render\HTML::list_box() feature
+--SKIPIF--
+<?php if (!extension_loaded("sundown")) print "skip"; ?>
+--FILE--
+<?php
+$render = new Sundown\Render\HTML();
+$render->setRenderFlags(array("filter_html"=>true));
+$res = $render->getRenderFlags();
+echo count($res) . PHP_EOL;
+$res = $render->getRenderFlags();
+echo count($res) . PHP_EOL;
+$render = new Sundown\Render\HTML(array("filter_html"=>true));
+$res = $render->setRenderFlags(array("filter_html"=>false));
+$res = $render->getRenderFlags();
+var_dump($render);
+var_dump($res);
+$res = $render->getRenderFlags();
+var_dump($res);
+--EXPECT--
+1
+1
+object(Sundown\Render\HTML)#2 (1) {
+ ["render_flags"]=>
+ array(1) {
+ ["filter_html"]=>
+ bool(false)
+ }
+}
+array(1) {
+ ["filter_html"]=>
+ bool(false)
+}
+array(1) {
+ ["filter_html"]=>
+ bool(false)
+}
View
35 tests/003-advanced-set-extensions.phpt
@@ -0,0 +1,35 @@
+--TEST--
+Check for determine enabled extensions.
+--SKIPIF--
+<?php if (!extension_loaded("sundown")) print "skip"; ?>
+--FILE--
+<?php
+$render = new Sundown\Render\HTML();
+
+$extensions = array("no_intraemphasis","tables","fenced_code_blocks","autolink","strikethrough","lax_html_blocks","space_after_header","superscript");
+$enabled = array();
+foreach ($extensions as $ext) {
+ $enabled[$ext] = true;
+}
+
+$markdown = new Sundown\Markdown($render, array());
+$exts = $markdown->getExtensions();
+printf("ext count: %d\n", count($exts));
+
+echo "# do set extensions\n";
+$markdown->setExtensions($enabled);
+foreach ($markdown->getExtensions() as $ext_name => $ext_value) {
+ printf("%s => %d\n",$ext_name,$ext_value);
+}
+
+--EXPECT--
+ext count: 0
+# do set extensions
+no_intraemphasis => 1
+tables => 1
+fenced_code_blocks => 1
+autolink => 1
+strikethrough => 1
+lax_html_blocks => 1
+space_after_header => 1
+superscript => 1

0 comments on commit 84e991b

Please sign in to comment.