This repository has been archived by the owner on Nov 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exception.c
153 lines (115 loc) · 4.68 KB
/
exception.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
+------------------------------------------------------------------------+
| Zephir Language |
+------------------------------------------------------------------------+
| Copyright (c) 2011-2014 Zephir Team (http://www.zephir-lang.com) |
+------------------------------------------------------------------------+
| This source file is subject to the New BSD License that is bundled |
| with this package in the file docs/LICENSE.txt. |
| |
| If you did not receive a copy of the license and are unable to |
| obtain it through the world-wide-web, please send an email |
| to license@zephir-lang.com so we can send you a copy immediately. |
+------------------------------------------------------------------------+
| Authors: Andres Gutierrez <andres@zephir-lang.com> |
| Eduar Carvajal <eduar@zephir-lang.com> |
| Vladimir Kolesnikov <vladimir@extrememember.com> |
+------------------------------------------------------------------------+
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_ext.h"
#include "php_main.h"
#include "ext/standard/php_string.h"
#include "kernel/main.h"
#include "kernel/memory.h"
#include "kernel/fcall.h"
#include "Zend/zend_exceptions.h"
/**
* Throws a zval object as exception
*/
void zephir_throw_exception(zval *object TSRMLS_DC){
Z_ADDREF_P(object);
zend_throw_exception_object(object TSRMLS_CC);
}
/**
* Throws a zval object as exception
*/
void zephir_throw_exception_debug(zval *object, const char *file, zend_uint line TSRMLS_DC){
zend_class_entry *default_exception_ce;
Z_ADDREF_P(object);
if (line > 0) {
default_exception_ce = zend_exception_get_default(TSRMLS_C);
zend_update_property_string(default_exception_ce, object, "file", sizeof("file")-1, file TSRMLS_CC);
zend_update_property_long(default_exception_ce, object, "line", sizeof("line")-1, line TSRMLS_CC);
}
zend_throw_exception_object(object TSRMLS_CC);
}
/**
* Throws an exception with a single string parameter + debug info
*/
void zephir_throw_exception_string_debug(zend_class_entry *ce, const char *message, zend_uint message_len, const char *file, zend_uint line TSRMLS_DC) {
zval *object, *msg;
int ZEPHIR_LAST_CALL_STATUS = 0;
zend_class_entry *default_exception_ce;
ALLOC_INIT_ZVAL(object);
object_init_ex(object, ce);
ALLOC_INIT_ZVAL(msg);
ZVAL_STRINGL(msg, message, message_len, 1);
ZEPHIR_CALL_METHOD(NULL, object, "__construct", NULL, msg);
zephir_check_call_status();
if (line > 0) {
default_exception_ce = zend_exception_get_default(TSRMLS_C);
zend_update_property_string(default_exception_ce, object, "file", sizeof("file")-1, file TSRMLS_CC);
zend_update_property_long(default_exception_ce, object, "line", sizeof("line")-1, line TSRMLS_CC);
}
zend_throw_exception_object(object TSRMLS_CC);
zval_ptr_dtor(&msg);
}
/**
* Throws an exception with a single string parameter
*/
void zephir_throw_exception_string(zend_class_entry *ce, const char *message, zend_uint message_len TSRMLS_DC){
zval *object, *msg;
int ZEPHIR_LAST_CALL_STATUS = 0;
ALLOC_INIT_ZVAL(object);
object_init_ex(object, ce);
ALLOC_INIT_ZVAL(msg);
ZVAL_STRINGL(msg, message, message_len, 1);
ZEPHIR_CALL_METHOD(NULL, object, "__construct", NULL, msg);
zephir_check_call_status();
zend_throw_exception_object(object TSRMLS_CC);
zval_ptr_dtor(&msg);
}
/**
* Throws an exception with a single zval parameter
*/
void zephir_throw_exception_zval_debug(zend_class_entry *ce, zval *message, const char *file, zend_uint line TSRMLS_DC){
zval *object;
int ZEPHIR_LAST_CALL_STATUS = 0;
zend_class_entry *default_exception_ce;
ALLOC_INIT_ZVAL(object);
object_init_ex(object, ce);
ZEPHIR_CALL_METHOD(NULL, object, "__construct", NULL, message);
zephir_check_call_status();
if (line > 0) {
default_exception_ce = zend_exception_get_default(TSRMLS_C);
zend_update_property_string(default_exception_ce, object, "file", sizeof("file")-1, file TSRMLS_CC);
zend_update_property_long(default_exception_ce, object, "line", sizeof("line")-1, line TSRMLS_CC);
}
zend_throw_exception_object(object TSRMLS_CC);
}
/**
* Throws an exception with a single zval parameter
*/
void zephir_throw_exception_zval(zend_class_entry *ce, zval *message TSRMLS_DC){
zval *object;
int ZEPHIR_LAST_CALL_STATUS = 0;
ALLOC_INIT_ZVAL(object);
object_init_ex(object, ce);
ZEPHIR_CALL_METHOD(NULL, object, "__construct", NULL, message);
zephir_check_call_status();
zend_throw_exception_object(object TSRMLS_CC);
}