-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathcairo_error.c
124 lines (109 loc) · 5.68 KB
/
cairo_error.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
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2014 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Elizabeth Smith <[email protected]> |
| Michael Maclean <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "zend_exceptions.h"
#include "php_cairo.h"
zend_class_entry *cairo_ce_cairoexception;
zend_class_entry *cairo_ce_cairostatus;
/* {{{ PHP_MINIT_FUNCTION */
PHP_MINIT_FUNCTION(cairo_error)
{
zend_class_entry ce, status_ce;
INIT_CLASS_ENTRY(ce, "CairoException", NULL);
cairo_ce_cairoexception = zend_register_internal_class_ex(&ce, zend_exception_get_default(TSRMLS_C), "Exception" TSRMLS_CC);
INIT_CLASS_ENTRY(status_ce, "CairoStatus", NULL);
cairo_ce_cairostatus = zend_register_internal_class(&status_ce TSRMLS_CC);
cairo_ce_cairostatus->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS | ZEND_ACC_FINAL_CLASS;
#define REGISTER_CAIRO_STATUS_LONG_CONST(const_name, value) \
zend_declare_class_constant_long(cairo_ce_cairostatus, const_name, sizeof(const_name)-1, (long)value TSRMLS_CC); \
REGISTER_LONG_CONSTANT(#value, value, CONST_CS | CONST_PERSISTENT);
REGISTER_CAIRO_STATUS_LONG_CONST("SUCCESS", CAIRO_STATUS_SUCCESS);
REGISTER_CAIRO_STATUS_LONG_CONST("NO_MEMORY", CAIRO_STATUS_NO_MEMORY);
REGISTER_CAIRO_STATUS_LONG_CONST("INVALID_RESTORE", CAIRO_STATUS_INVALID_RESTORE);
REGISTER_CAIRO_STATUS_LONG_CONST("INVALID_POP_GROUP", CAIRO_STATUS_INVALID_POP_GROUP);
REGISTER_CAIRO_STATUS_LONG_CONST("NO_CURRENT_POINT", CAIRO_STATUS_NO_CURRENT_POINT);
REGISTER_CAIRO_STATUS_LONG_CONST("INVALID_MATRIX", CAIRO_STATUS_INVALID_MATRIX);
REGISTER_CAIRO_STATUS_LONG_CONST("INVALID_STATUS", CAIRO_STATUS_INVALID_STATUS);
REGISTER_CAIRO_STATUS_LONG_CONST("NULL_POINTER", CAIRO_STATUS_NULL_POINTER);
REGISTER_CAIRO_STATUS_LONG_CONST("INVALID_STRING", CAIRO_STATUS_INVALID_STRING);
REGISTER_CAIRO_STATUS_LONG_CONST("INVALID_PATH_DATA", CAIRO_STATUS_INVALID_PATH_DATA);
REGISTER_CAIRO_STATUS_LONG_CONST("READ_ERROR", CAIRO_STATUS_READ_ERROR);
REGISTER_CAIRO_STATUS_LONG_CONST("WRITE_ERROR", CAIRO_STATUS_WRITE_ERROR);
REGISTER_CAIRO_STATUS_LONG_CONST("SURFACE_FINISHED", CAIRO_STATUS_SURFACE_FINISHED);
REGISTER_CAIRO_STATUS_LONG_CONST("SURFACE_TYPE_MISMATCH", CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
REGISTER_CAIRO_STATUS_LONG_CONST("PATTERN_TYPE_MISMATCH", CAIRO_STATUS_PATTERN_TYPE_MISMATCH);
REGISTER_CAIRO_STATUS_LONG_CONST("INVALID_CONTENT", CAIRO_STATUS_INVALID_CONTENT);
REGISTER_CAIRO_STATUS_LONG_CONST("INVALID_FORMAT", CAIRO_STATUS_INVALID_FORMAT);
REGISTER_CAIRO_STATUS_LONG_CONST("INVALID_VISUAL", CAIRO_STATUS_INVALID_VISUAL);
REGISTER_CAIRO_STATUS_LONG_CONST("FILE_NOT_FOUND", CAIRO_STATUS_FILE_NOT_FOUND);
REGISTER_CAIRO_STATUS_LONG_CONST("INVALID_DASH", CAIRO_STATUS_INVALID_DASH);
REGISTER_CAIRO_STATUS_LONG_CONST("INVALID_DSC_COMMENT", CAIRO_STATUS_INVALID_DSC_COMMENT);
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 4, 0)
REGISTER_CAIRO_STATUS_LONG_CONST("INVALID_INDEX", CAIRO_STATUS_INVALID_INDEX);
REGISTER_CAIRO_STATUS_LONG_CONST("CLIP_NOT_REPRESENTABLE", CAIRO_STATUS_CLIP_NOT_REPRESENTABLE);
#endif
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 6, 0)
REGISTER_CAIRO_STATUS_LONG_CONST("TEMP_FILE_ERROR", CAIRO_STATUS_TEMP_FILE_ERROR);
REGISTER_CAIRO_STATUS_LONG_CONST("INVALID_STRIDE", CAIRO_STATUS_INVALID_STRIDE);
#endif
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 8, 0)
REGISTER_CAIRO_STATUS_LONG_CONST("FONT_TYPE_MISMATCH", CAIRO_STATUS_FONT_TYPE_MISMATCH);
REGISTER_CAIRO_STATUS_LONG_CONST("USER_FONT_IMMUTABLE", CAIRO_STATUS_USER_FONT_IMMUTABLE);
REGISTER_CAIRO_STATUS_LONG_CONST("USER_FONT_ERROR", CAIRO_STATUS_USER_FONT_ERROR);
REGISTER_CAIRO_STATUS_LONG_CONST("NEGATIVE_COUNT", CAIRO_STATUS_NEGATIVE_COUNT);
REGISTER_CAIRO_STATUS_LONG_CONST("INVALID_CLUSTERS", CAIRO_STATUS_INVALID_CLUSTERS);
REGISTER_CAIRO_STATUS_LONG_CONST("INVALID_SLANT", CAIRO_STATUS_INVALID_SLANT);
REGISTER_CAIRO_STATUS_LONG_CONST("INVALID_WEIGHT", CAIRO_STATUS_INVALID_WEIGHT);
#endif
return SUCCESS;
}
/* }}} */
PHP_CAIRO_API void php_cairo_throw_exception(cairo_status_t status TSRMLS_DC)
{
char * error_message;
if (status == CAIRO_STATUS_SUCCESS) {
return;
}
error_message = estrdup(cairo_status_to_string(status));
zend_throw_exception(cairo_ce_cairoexception, error_message, status TSRMLS_CC);
efree(error_message);
return;
}
PHP_CAIRO_API void php_cairo_trigger_error(cairo_status_t status TSRMLS_DC)
{
char * error_message;
if (status == CAIRO_STATUS_SUCCESS) {
return;
}
error_message = estrdup(cairo_status_to_string(status));
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", error_message);
efree(error_message);
return;
}
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/