|
| 1 | +/* |
| 2 | + +----------------------------------------------------------------------+ |
| 3 | + | This file is part of the pinepain/php-v8 PHP extension. | |
| 4 | + | | |
| 5 | + | Copyright (c) 2015-2016 Bogdan Padalko <[email protected]> | |
| 6 | + | | |
| 7 | + | Licensed under the MIT license: http://opensource.org/licenses/MIT | |
| 8 | + | | |
| 9 | + | For the full copyright and license information, please view the | |
| 10 | + | LICENSE file that was distributed with this source or visit | |
| 11 | + | http://opensource.org/licenses/MIT | |
| 12 | + +----------------------------------------------------------------------+ |
| 13 | +*/ |
| 14 | + |
| 15 | +#ifdef HAVE_CONFIG_H |
| 16 | +#include "config.h" |
| 17 | +#endif |
| 18 | + |
| 19 | +#include "php_v8_ext_mem_interface.h" |
| 20 | +#include "php_v8_object_template.h" |
| 21 | +#include "php_v8_function_template.h" |
| 22 | +#include "php_v8_value.h" |
| 23 | +#include "php_v8.h" |
| 24 | + |
| 25 | +zend_class_entry *php_v8_ext_mem_interface_ce; |
| 26 | +#define this_ce php_v8_ext_mem_interface_ce |
| 27 | + |
| 28 | +void php_v8_ext_mem_interface_value_AdjustExternalAllocatedMemory(INTERNAL_FUNCTION_PARAMETERS) { |
| 29 | + zend_long change_in_bytes; |
| 30 | + |
| 31 | + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &change_in_bytes) == FAILURE) { |
| 32 | + return; |
| 33 | + } |
| 34 | + |
| 35 | + PHP_V8_VALUE_FETCH_INTO(getThis(), php_v8_value); |
| 36 | + |
| 37 | + RETURN_LONG(php_v8_value->persistent_data->adjustSize(change_in_bytes)); |
| 38 | +} |
| 39 | + |
| 40 | +void php_v8_ext_mem_interface_value_GetExternalAllocatedMemory(INTERNAL_FUNCTION_PARAMETERS) { |
| 41 | + if (zend_parse_parameters_none() == FAILURE) { |
| 42 | + return; |
| 43 | + } |
| 44 | + |
| 45 | + PHP_V8_VALUE_FETCH_INTO(getThis(), php_v8_value); |
| 46 | + |
| 47 | + RETURN_LONG(php_v8_value->persistent_data->getAdjustedSize()); |
| 48 | +} |
| 49 | + |
| 50 | + |
| 51 | +void php_v8_ext_mem_interface_function_template_AdjustExternalAllocatedMemory(INTERNAL_FUNCTION_PARAMETERS) { |
| 52 | + zend_long change_in_bytes; |
| 53 | + |
| 54 | + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &change_in_bytes) == FAILURE) { |
| 55 | + return; |
| 56 | + } |
| 57 | + |
| 58 | + PHP_V8_OBJECT_TEMPLATE_FETCH_INTO(getThis(), php_v8_object_template); |
| 59 | + |
| 60 | + RETURN_LONG(php_v8_object_template->persistent_data->adjustSize(change_in_bytes)); |
| 61 | +} |
| 62 | + |
| 63 | +void php_v8_ext_mem_interface_function_template_GetExternalAllocatedMemory(INTERNAL_FUNCTION_PARAMETERS) { |
| 64 | + if (zend_parse_parameters_none() == FAILURE) { |
| 65 | + return; |
| 66 | + } |
| 67 | + |
| 68 | + PHP_V8_OBJECT_TEMPLATE_FETCH_INTO(getThis(), php_v8_object_template); |
| 69 | + |
| 70 | + RETURN_LONG(php_v8_object_template->persistent_data->getAdjustedSize()); |
| 71 | +} |
| 72 | + |
| 73 | + |
| 74 | +void php_v8_ext_mem_interface_object_template_AdjustExternalAllocatedMemory(INTERNAL_FUNCTION_PARAMETERS) { |
| 75 | + zend_long change_in_bytes; |
| 76 | + |
| 77 | + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &change_in_bytes) == FAILURE) { |
| 78 | + return; |
| 79 | + } |
| 80 | + |
| 81 | + PHP_V8_FUNCTION_TEMPLATE_FETCH_INTO(getThis(), php_v8_function_template); |
| 82 | + |
| 83 | + RETURN_LONG(php_v8_function_template->persistent_data->adjustSize(change_in_bytes)); |
| 84 | +} |
| 85 | + |
| 86 | +void php_v8_ext_mem_interface_object_template_GetExternalAllocatedMemory(INTERNAL_FUNCTION_PARAMETERS) { |
| 87 | + if (zend_parse_parameters_none() == FAILURE) { |
| 88 | + return; |
| 89 | + } |
| 90 | + |
| 91 | + PHP_V8_FUNCTION_TEMPLATE_FETCH_INTO(getThis(), php_v8_function_template); |
| 92 | + |
| 93 | + RETURN_LONG(php_v8_function_template->persistent_data->getAdjustedSize()); |
| 94 | +} |
| 95 | + |
| 96 | + |
| 97 | +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_php_v8_ext_mem_interface_AdjustExternalAllocatedMemory, ZEND_RETURN_VALUE, 1, IS_LONG, NULL, 0) |
| 98 | + ZEND_ARG_TYPE_INFO(0, change_in_bytes, IS_LONG, 0) |
| 99 | +ZEND_END_ARG_INFO() |
| 100 | + |
| 101 | + |
| 102 | +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_php_v8_ext_mem_interface_GetExternalAllocatedMemory, ZEND_RETURN_VALUE, 0, IS_LONG, NULL, 0) |
| 103 | +ZEND_END_ARG_INFO() |
| 104 | + |
| 105 | + |
| 106 | +static const zend_function_entry php_v8_ext_mem_interface_methods[] = { |
| 107 | + PHP_ABSTRACT_ME(V8AdjustableExternalMemoryInterface, AdjustExternalAllocatedMemory, arginfo_php_v8_ext_mem_interface_AdjustExternalAllocatedMemory) |
| 108 | + PHP_ABSTRACT_ME(V8AdjustableExternalMemoryInterface, GetExternalAllocatedMemory, arginfo_php_v8_ext_mem_interface_GetExternalAllocatedMemory) |
| 109 | + |
| 110 | + PHP_FE_END |
| 111 | +}; |
| 112 | + |
| 113 | +PHP_MINIT_FUNCTION (php_v8_ext_mem_interface) { |
| 114 | + zend_class_entry ce; |
| 115 | + |
| 116 | + INIT_NS_CLASS_ENTRY(ce, PHP_V8_NS, "AdjustableExternalMemoryInterface", php_v8_ext_mem_interface_methods); |
| 117 | + this_ce = zend_register_internal_interface(&ce); |
| 118 | + |
| 119 | + return SUCCESS; |
| 120 | +} |
| 121 | + |
| 122 | + |
| 123 | +/* |
| 124 | + * Local variables: |
| 125 | + * tab-width: 4 |
| 126 | + * c-basic-offset: 4 |
| 127 | + * End: |
| 128 | + * vim600: noet sw=4 ts=4 fdm=marker |
| 129 | + * vim<600: noet sw=4 ts=4 |
| 130 | + */ |
0 commit comments