Permalink
Browse files

Cleanup, removing length parameter to std::string

  • Loading branch information...
1 parent aa5797b commit fe9b9e77772d0b4457f5bdefee4b7b1c08c7c44d @jbboehr committed Mar 19, 2012
Showing with 510 additions and 571 deletions.
  1. +4 −1 .gitignore
  2. +1 −1 mustache
  3. +56 −62 mustache_data.cpp
  4. +281 −290 mustache_mustache.cpp
  5. +98 −175 mustache_template.cpp
  6. +2 −9 mustache_template.hpp
  7. +48 −17 php_mustache.cpp
  8. +16 −1 php_mustache.hpp
  9. +0 −15 tests/MustacheTemplate__render.phpt
  10. +4 −0 tests/MustacheTemplate__toArray.phpt
View
@@ -1,3 +1,5 @@
+.*project
+*~
.deps
.dirstamp
.libs
@@ -12,6 +14,7 @@ gmon*
nbproject
build
modules
+test.php
tests/*.diff
tests/*.exp
tests/*.php
@@ -38,4 +41,4 @@ missing
mkinstalldirs
run-tests.php
tmp-php.ini
-specs
+specs
Submodule mustache updated 1 files
+11 −9 tokenizer.cpp
View
@@ -19,36 +19,39 @@ static zend_object_handlers MustacheData_obj_handlers;
static void MustacheData_obj_free(void *object TSRMLS_DC)
{
- php_obj_MustacheData * payload = (php_obj_MustacheData *) object;
-
- mustache::Data * data = payload->data;
+ try {
+ php_obj_MustacheData * payload = (php_obj_MustacheData *) object;
+
+ if( payload->data != NULL ) {
+ delete payload->data;
+ }
- if( data != NULL ) {
- delete data;
+ efree(object);
+ } catch(...) {
+ mustache_exception_handler();
}
-
- efree(object);
}
static zend_object_value MustacheData_obj_create(zend_class_entry *class_type TSRMLS_DC)
{
- php_obj_MustacheData * payload;
- zval *tmp;
zend_object_value retval;
+
+ try {
+ php_obj_MustacheData * payload;
+ zval * tmp;
- payload = (php_obj_MustacheData *) emalloc(sizeof(php_obj_MustacheData));
- memset(payload, 0, sizeof(php_obj_MustacheData));
- payload->obj.ce = class_type;
+ payload = (php_obj_MustacheData *) emalloc(sizeof(php_obj_MustacheData));
+ memset(payload, 0, sizeof(php_obj_MustacheData));
+ payload->obj.ce = class_type;
- try {
- payload->data = new mustache::Data;
- } catch( std::bad_alloc& e ) {
payload->data = NULL;
- php_error(E_ERROR, "Failed to allocate memory when initializing MustacheData");
- }
- retval.handle = zend_objects_store_put(payload, NULL, (zend_objects_free_object_storage_t) MustacheData_obj_free, NULL TSRMLS_CC);
- retval.handlers = &MustacheData_obj_handlers;
+ retval.handle = zend_objects_store_put(payload, NULL, (zend_objects_free_object_storage_t) MustacheData_obj_free, NULL TSRMLS_CC);
+ retval.handlers = &MustacheData_obj_handlers;
+
+ } catch(...) {
+ mustache_exception_handler();
+ }
return retval;
}
@@ -78,36 +81,34 @@ PHP_MINIT_FUNCTION(mustache_data)
*/
PHP_METHOD(MustacheData, __construct)
{
- zend_class_entry * _this_ce;
- zval * _this_zval;
- php_obj_MustacheData * payload;
-
- zval * data;
-
- if( zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|z",
- &_this_zval, MustacheData_ce_ptr, &data) == FAILURE) {
- return;
- }
-
- _this_zval = getThis();
- _this_ce = Z_OBJCE_P(_this_zval);
-
- payload = (php_obj_MustacheData *) zend_object_store_get_object(_this_zval TSRMLS_CC);
-
- // Main
try {
+ // Custom parameters
+ zval * data;
+
+ // Check parameters
+ zval * _this_zval;
+ if( zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oz",
+ &_this_zval, MustacheData_ce_ptr, &data) == FAILURE) {
+ throw PhpInvalidParameterException();
+ }
+
+ // Class parameters
+ _this_zval = getThis();
+ zend_class_entry * _this_ce = Z_OBJCE_P(_this_zval);
+ php_obj_MustacheData * payload =
+ (php_obj_MustacheData *) zend_object_store_get_object(_this_zval TSRMLS_CC);
+
// Check if argument was given
if( data == NULL ) {
- return;
+ throw PhpInvalidParameterException();
}
// Convert data
+ payload->data = new mustache::Data();
mustache_data_from_zval(payload->data, data TSRMLS_CC);
- } catch( mustache::Exception& e ) {
- mustache_error_handler(e.what(), &e, return_value TSRMLS_CC);
- } catch( std::bad_alloc& e ) {
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "Memory allocation failed");
+ } catch(...) {
+ mustache_exception_handler();
}
}
/* }}} __construct */
@@ -116,24 +117,19 @@ PHP_METHOD(MustacheData, __construct)
*/
PHP_METHOD(MustacheData, toValue)
{
- zend_class_entry * _this_ce;
- zval * _this_zval;
- php_obj_MustacheData * payload;
-
- zval * datacpy = NULL;
-
- if( zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
- &_this_zval, MustacheData_ce_ptr) == FAILURE) {
- return;
- }
-
- _this_zval = getThis();
- _this_ce = Z_OBJCE_P(_this_zval);
+ try {
+ // Check parameters
+ zval * _this_zval;
+ if( zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
+ &_this_zval, MustacheData_ce_ptr) == FAILURE) {
+ throw PhpInvalidParameterException();
+ }
- payload = (php_obj_MustacheData *) zend_object_store_get_object(_this_zval TSRMLS_CC);
+ _this_zval = getThis();
+ zend_class_entry * _this_ce = Z_OBJCE_P(_this_zval);
+ php_obj_MustacheData * payload =
+ (php_obj_MustacheData *) zend_object_store_get_object(_this_zval TSRMLS_CC);
- // Main
- try {
// Check if data was initialized
if( payload->data == NULL ) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "MustacheData was not initialized properly");
@@ -142,16 +138,14 @@ PHP_METHOD(MustacheData, toValue)
}
// Reverse template data
- datacpy = mustache_data_to_zval(payload->data TSRMLS_CC);
+ zval * datacpy = mustache_data_to_zval(payload->data TSRMLS_CC);
// Copy data into return value
*return_value = *datacpy;
zval_copy_ctor(return_value);
- } catch( mustache::Exception& e ) {
- mustache_error_handler(e.what(), &e, return_value TSRMLS_CC);
- } catch( std::bad_alloc& e ) {
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "Memory allocation failed");
+ } catch(...) {
+ mustache_exception_handler();
}
}
/* }}} toValue */
Oops, something went wrong. Retry.

0 comments on commit fe9b9e7

Please sign in to comment.