Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use PHALCON_THROW_EXCEPTION_STR instead of phalcon_throw_exception_string #976

Merged
merged 1 commit into from Aug 2, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ext/annotations/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ int phannot_parse_annotations(zval *result, zval *comment, zval *file_path, zval
ZVAL_NULL(result);

if (Z_TYPE_P(comment) != IS_STRING) {
phalcon_throw_exception_string(phalcon_annotations_exception_ce, SL("Comment must be a string"), 1 TSRMLS_CC);
PHALCON_THROW_EXCEPTION_STR(phalcon_annotations_exception_ce, "Comment must be a string");
return FAILURE;
}

if(phannot_internal_parse_annotations(&result, comment, file_path, line, &error_msg TSRMLS_CC) == FAILURE){
phalcon_throw_exception_string(phalcon_annotations_exception_ce, Z_STRVAL_P(error_msg), Z_STRLEN_P(error_msg), 1 TSRMLS_CC);
PHALCON_THROW_EXCEPTION_STR(phalcon_annotations_exception_ce, Z_STRVAL_P(error_msg));
return FAILURE;
}

Expand Down
4 changes: 2 additions & 2 deletions ext/annotations/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1300,12 +1300,12 @@ int phannot_parse_annotations(zval *result, zval *comment, zval *file_path, zval
ZVAL_NULL(result);

if (Z_TYPE_P(comment) != IS_STRING) {
phalcon_throw_exception_string(phalcon_annotations_exception_ce, SL("Comment must be a string"), 1 TSRMLS_CC);
PHALCON_THROW_EXCEPTION_STR(phalcon_annotations_exception_ce, "Comment must be a string");
return FAILURE;
}

if(phannot_internal_parse_annotations(&result, comment, file_path, line, &error_msg TSRMLS_CC) == FAILURE){
phalcon_throw_exception_string(phalcon_annotations_exception_ce, Z_STRVAL_P(error_msg), Z_STRLEN_P(error_msg), 1 TSRMLS_CC);
PHALCON_THROW_EXCEPTION_STR(phalcon_annotations_exception_ce, Z_STRVAL_P(error_msg));
return FAILURE;
}

Expand Down
6 changes: 3 additions & 3 deletions ext/assets/filters/cssminifier.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,15 +281,15 @@ int phalcon_cssmin(zval *return_value, zval *style TSRMLS_DC) {
ZVAL_NULL(return_value);

if (Z_TYPE_P(style) != IS_STRING) {
phalcon_throw_exception_string(phalcon_assets_exception_ce, SL("Style must be a string"), 1 TSRMLS_CC);
PHALCON_THROW_EXCEPTION_STR(phalcon_assets_exception_ce, "Style must be a string");
return FAILURE;
}

if (phalcon_cssmin_internal(return_value, style, &error TSRMLS_CC) == FAILURE) {
if (Z_TYPE_P(error) == IS_STRING) {
phalcon_throw_exception_string(phalcon_assets_exception_ce, Z_STRVAL_P(error), Z_STRLEN_P(error), 1 TSRMLS_CC);
PHALCON_THROW_EXCEPTION_STR(phalcon_assets_exception_ce, Z_STRVAL_P(error));
} else {
phalcon_throw_exception_string(phalcon_assets_exception_ce, SL("Unknown error"), 1 TSRMLS_CC);
PHALCON_THROW_EXCEPTION_STR(phalcon_assets_exception_ce, "Unknown error");
}
return FAILURE;
}
Expand Down
6 changes: 3 additions & 3 deletions ext/assets/filters/jsminifier.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,15 +386,15 @@ int phalcon_jsmin(zval *return_value, zval *script TSRMLS_DC) {
ZVAL_NULL(return_value);

if (Z_TYPE_P(script) != IS_STRING) {
phalcon_throw_exception_string(phalcon_assets_exception_ce, SL("Script must be a string"), 1 TSRMLS_CC);
PHALCON_THROW_EXCEPTION_STR(phalcon_assets_exception_ce, "Script must be a string");
return FAILURE;
}

if (phalcon_jsmin_internal(return_value, script, &error TSRMLS_CC) == FAILURE){
if (Z_TYPE_P(error) == IS_STRING) {
phalcon_throw_exception_string(phalcon_assets_exception_ce, Z_STRVAL_P(error), Z_STRLEN_P(error), 1 TSRMLS_CC);
PHALCON_THROW_EXCEPTION_STR(phalcon_assets_exception_ce, Z_STRVAL_P(error));
} else {
phalcon_throw_exception_string(phalcon_assets_exception_ce, SL("Unknown error"), 1 TSRMLS_CC);
PHALCON_THROW_EXCEPTION_STR(phalcon_assets_exception_ce, "Unknown error");
}
return FAILURE;
}
Expand Down
2 changes: 1 addition & 1 deletion ext/cli/dispatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ PHP_METHOD(Phalcon_CLI_Dispatcher, _throwDispatchException){
* Throw the exception if it wasn't handled
*/
phalcon_throw_exception(exception TSRMLS_CC);
return;
RETURN_MM();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion ext/dispatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ PHP_METHOD(Phalcon_Dispatcher, dispatch){
* Exception wasn't handled, re throw it
*/
phalcon_throw_exception(exception TSRMLS_CC);
return;
RETURN_MM();
}
} else {
/**
Expand Down
13 changes: 2 additions & 11 deletions ext/kernel/exception.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@
void phalcon_throw_exception(zval *object TSRMLS_DC){
Z_ADDREF_P(object);
zend_throw_exception_object(object TSRMLS_CC);
phalcon_memory_restore_stack(TSRMLS_C);
}

/**
* Throws an exception with a single string parameter
*/
void phalcon_throw_exception_string(zend_class_entry *ce, const char *message, zend_uint message_len, int restore_stack TSRMLS_DC){
void phalcon_throw_exception_string(zend_class_entry *ce, const char *message, zend_uint message_len TSRMLS_DC){

zval *object, *msg;

Expand All @@ -59,16 +58,12 @@ void phalcon_throw_exception_string(zend_class_entry *ce, const char *message, z
zend_throw_exception_object(object TSRMLS_CC);

zval_ptr_dtor(&msg);

if (restore_stack) {
phalcon_memory_restore_stack(TSRMLS_C);
}
}

/**
* Throws an exception with a single zval parameter
*/
void phalcon_throw_exception_zval(zend_class_entry *ce, zval *message, int restore_stack TSRMLS_DC){
void phalcon_throw_exception_zval(zend_class_entry *ce, zval *message TSRMLS_DC){

zval *object;

Expand All @@ -78,10 +73,6 @@ void phalcon_throw_exception_zval(zend_class_entry *ce, zval *message, int resto
phalcon_call_method_p1_noret(object, "__construct", message);

zend_throw_exception_object(object TSRMLS_CC);

if (restore_stack) {
phalcon_memory_restore_stack(TSRMLS_C);
}
}

/**
Expand Down
34 changes: 24 additions & 10 deletions ext/kernel/exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,31 @@
+------------------------------------------------------------------------+
*/

#ifndef PHALCON_KERNEL_EXCEPTIONS_H
#define PHALCON_KERNEL_EXCEPTIONS_H

#include "Zend/zend.h"

/** Exceptions */
#define PHALCON_THROW_EXCEPTION_STR(class_entry, message) phalcon_throw_exception_string(class_entry, message, sizeof(message)-1, 1 TSRMLS_CC);
#define PHALCON_THROW_EXCEPTION_STRW(class_entry, message) phalcon_throw_exception_string(class_entry, message, sizeof(message)-1, 0 TSRMLS_CC);
#define PHALCON_THROW_EXCEPTION_ZVAL(class_entry, message) phalcon_throw_exception_zval(class_entry, message, 1 TSRMLS_CC);
#define PHALCON_THROW_EXCEPTION_ZVALW(class_entry, message) phalcon_throw_exception_zval(class_entry, message, 0 TSRMLS_CC);
#define PHALCON_THROW_EXCEPTION_STR(class_entry, message) \
do { \
phalcon_throw_exception_string(class_entry, message, strlen(message) TSRMLS_CC); \
phalcon_memory_restore_stack(TSRMLS_C); \
} while (0)

#define PHALCON_THROW_EXCEPTION_ZVAL(class_entry, message) \
do { \
phalcon_throw_exception_zval(class_entry, message TSRMLS_CC); \
phalcon_memory_restore_stack(TSRMLS_C); \
} while (0)

#define PHALCON_THROW_EXCEPTION_STRW(class_entry, message) phalcon_throw_exception_string(class_entry, message, strlen(message) TSRMLS_CC)
#define PHALCON_THROW_EXCEPTION_ZVALW(class_entry, message) phalcon_throw_exception_zval(class_entry, message TSRMLS_CC)

/** Throw Exceptions */
extern void phalcon_throw_exception(zval *object TSRMLS_DC);
extern void phalcon_throw_exception_string(zend_class_entry *ce, const char *message, zend_uint message_len, int restore_stack TSRMLS_DC);
extern void phalcon_throw_exception_zval(zend_class_entry *ce, zval *message, int restore_stack TSRMLS_DC);
extern void phalcon_throw_exception_internal(zval *exception TSRMLS_DC);
void phalcon_throw_exception(zval *object TSRMLS_DC);
void phalcon_throw_exception_string(zend_class_entry *ce, const char *message, zend_uint message_len TSRMLS_DC);
void phalcon_throw_exception_zval(zend_class_entry *ce, zval *message TSRMLS_DC);
void phalcon_throw_exception_internal(zval *exception TSRMLS_DC);

/** Catch Exceptions */
/* extern void phalcon_try_execute(zval *success, zval *return_value, zval *call_object, zval *params, zval **exception TSRMLS_DC); */
#endif /* PHALCON_KERNEL_EXCEPTIONS_H */
4 changes: 2 additions & 2 deletions ext/kernel/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,12 +327,12 @@ int phalcon_fetch_parameters(int num_args TSRMLS_DC, int required_args, int opti
int i;

if (num_args < required_args || (num_args > (required_args + optional_args))) {
phalcon_throw_exception_string(spl_ce_BadMethodCallException, SL("Wrong number of parameters"), 0 TSRMLS_CC);
phalcon_throw_exception_string(spl_ce_BadMethodCallException, SL("Wrong number of parameters") TSRMLS_CC);
return FAILURE;
}

if (num_args > arg_count) {
phalcon_throw_exception_string(spl_ce_BadMethodCallException, SL("Could not obtain parameters for parsing"), 0 TSRMLS_CC);
phalcon_throw_exception_string(spl_ce_BadMethodCallException, SL("Could not obtain parameters for parsing") TSRMLS_CC);
return FAILURE;
}

Expand Down
6 changes: 3 additions & 3 deletions ext/kernel/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ extern void PHALCON_FASTCALL phalcon_copy_ctor(zval *destiny, zval *origin);

/* Memory macros */
#define PHALCON_ALLOC_ZVAL(z) \
ALLOC_INIT_ZVAL(z);
ALLOC_INIT_ZVAL(z)

#define PHALCON_INIT_VAR(z) \
phalcon_memory_alloc(&z TSRMLS_CC);
phalcon_memory_alloc(&z TSRMLS_CC)

#define PHALCON_INIT_NVAR(z)\
if (z) { \
Expand Down Expand Up @@ -117,7 +117,7 @@ extern void PHALCON_FASTCALL phalcon_copy_ctor(zval *destiny, zval *origin);

/* */
#define PHALCON_OBS_VAR(z) \
phalcon_memory_observe(&z TSRMLS_CC);
phalcon_memory_observe(&z TSRMLS_CC)

#define PHALCON_OBS_NVAR(z)\
if (z) { \
Expand Down
6 changes: 3 additions & 3 deletions ext/kernel/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,7 @@ int phalcon_create_instance(zval *return_value, const zval *class_name TSRMLS_DC
zend_class_entry *ce;

if (Z_TYPE_P(class_name) != IS_STRING) {
phalcon_throw_exception_string(phalcon_exception_ce, SL("Invalid class name"), 0 TSRMLS_CC);
phalcon_throw_exception_string(phalcon_exception_ce, SL("Invalid class name") TSRMLS_CC);
return FAILURE;
}

Expand Down Expand Up @@ -1289,12 +1289,12 @@ int phalcon_create_instance_params(zval *return_value, const zval *class_name, z
HashTable *params_hash;

if (Z_TYPE_P(class_name) != IS_STRING) {
phalcon_throw_exception_string(phalcon_exception_ce, SL("Invalid class name"), 0 TSRMLS_CC);
phalcon_throw_exception_string(phalcon_exception_ce, SL("Invalid class name") TSRMLS_CC);
return FAILURE;
}

if (Z_TYPE_P(params) != IS_ARRAY) {
phalcon_throw_exception_string(phalcon_exception_ce, SL("Instantiation parameters must be an array"), 0 TSRMLS_CC);
phalcon_throw_exception_string(phalcon_exception_ce, SL("Instantiation parameters must be an array") TSRMLS_CC);
return FAILURE;
}

Expand Down
4 changes: 2 additions & 2 deletions ext/mvc/dispatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ PHP_METHOD(Phalcon_Mvc_Dispatcher, _throwDispatchException){
phalcon_call_method_p2_noret(exception, "__construct", exception_message, exception_code);

phalcon_throw_exception(exception TSRMLS_CC);
return;
RETURN_MM();
}

PHALCON_INIT_VAR(service);
Expand Down Expand Up @@ -216,7 +216,7 @@ PHP_METHOD(Phalcon_Mvc_Dispatcher, _throwDispatchException){
* Throw the exception if it wasn't handled
*/
phalcon_throw_exception(exception TSRMLS_CC);
return;
RETURN_MM();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion ext/mvc/model.c
Original file line number Diff line number Diff line change
Expand Up @@ -4140,7 +4140,7 @@ PHP_METHOD(Phalcon_Mvc_Model, save){
phalcon_call_method_p2_noret(exception, "__construct", this_ptr, error_messages);

phalcon_throw_exception(exception TSRMLS_CC);
return;
RETURN_MM();
}

RETURN_MM_FALSE;
Expand Down
2 changes: 1 addition & 1 deletion ext/mvc/model/query.c
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@ PHP_METHOD(Phalcon_Mvc_Model_Query, _getExpression){
phalcon_call_method_p1_noret(expression, "__construct", expression_message);

phalcon_throw_exception(expression TSRMLS_CC);
return;
RETURN_MM();

}

Expand Down
2 changes: 1 addition & 1 deletion ext/mvc/model/query/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ int phql_parse_phql(zval *result, zval *phql TSRMLS_DC) {
ZVAL_NULL(result);

if (phql_internal_parse_phql(&result, Z_STRVAL_P(phql), Z_STRLEN_P(phql), &error_msg TSRMLS_CC) == FAILURE) {
phalcon_throw_exception_string(phalcon_mvc_model_exception_ce, Z_STRVAL_P(error_msg), Z_STRLEN_P(error_msg), 1 TSRMLS_CC);
PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, Z_STRVAL_P(error_msg));
return FAILURE;
}

Expand Down
2 changes: 1 addition & 1 deletion ext/mvc/model/query/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -3039,7 +3039,7 @@ int phql_parse_phql(zval *result, zval *phql TSRMLS_DC) {
ZVAL_NULL(result);

if (phql_internal_parse_phql(&result, Z_STRVAL_P(phql), Z_STRLEN_P(phql), &error_msg TSRMLS_CC) == FAILURE) {
phalcon_throw_exception_string(phalcon_mvc_model_exception_ce, Z_STRVAL_P(error_msg), Z_STRLEN_P(error_msg), 1 TSRMLS_CC);
PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, Z_STRVAL_P(error_msg));
return FAILURE;
}

Expand Down
2 changes: 1 addition & 1 deletion ext/mvc/model/transaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ PHP_METHOD(Phalcon_Mvc_Model_Transaction, rollback){
phalcon_call_method_p2_noret(i0, "__construct", rollback_message, rollback_record);

phalcon_throw_exception(i0 TSRMLS_CC);
return;
RETURN_MM();
}

PHALCON_MM_RESTORE();
Expand Down
4 changes: 2 additions & 2 deletions ext/mvc/view/engine/volt/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,12 @@ int phvolt_parse_view(zval *result, zval *view_code, zval *template_path TSRMLS_
ZVAL_NULL(result);

if (Z_TYPE_P(view_code) != IS_STRING) {
phalcon_throw_exception_string(phalcon_mvc_view_exception_ce, SL("View code must be a string"), 1 TSRMLS_CC);
PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "View code must be a string");
return FAILURE;
}

if (phvolt_internal_parse_view(&result, view_code, template_path, &error_msg TSRMLS_CC) == FAILURE) {
phalcon_throw_exception_string(phalcon_mvc_view_exception_ce, Z_STRVAL_P(error_msg), Z_STRLEN_P(error_msg), 1 TSRMLS_CC);
PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, Z_STRVAL_P(error_msg));
return FAILURE;
}

Expand Down
4 changes: 2 additions & 2 deletions ext/mvc/view/engine/volt/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -3445,12 +3445,12 @@ int phvolt_parse_view(zval *result, zval *view_code, zval *template_path TSRMLS_
ZVAL_NULL(result);

if (Z_TYPE_P(view_code) != IS_STRING) {
phalcon_throw_exception_string(phalcon_mvc_view_exception_ce, SL("View code must be a string"), 1 TSRMLS_CC);
PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "View code must be a string");
return FAILURE;
}

if (phvolt_internal_parse_view(&result, view_code, template_path, &error_msg TSRMLS_CC) == FAILURE) {
phalcon_throw_exception_string(phalcon_mvc_view_exception_ce, Z_STRVAL_P(error_msg), Z_STRLEN_P(error_msg), 1 TSRMLS_CC);
PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, Z_STRVAL_P(error_msg));
return FAILURE;
}

Expand Down