本文整理汇总了C++中zend_throw_exception函数的典型用法代码示例。如果您正苦于以下问题:C++ zend_throw_exception函数的具体用法?C++ zend_throw_exception怎么用?C++ zend_throw_exception使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了zend_throw_exception函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SPL_METHOD
/* {{{ proto void SplDoublyLinkedList::offsetSet(mixed index, mixed newval)
Sets the value at the specified $index to $newval. */
SPL_METHOD(SplDoublyLinkedList, offsetSet)
{
zval *zindex, *value;
spl_dllist_object *intern;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "zz", &zindex, &value) == FAILURE) {
return;
}
intern = Z_SPLDLLIST_P(getThis());
if (Z_TYPE_P(zindex) == IS_NULL) {
/* $obj[] = ... */
spl_ptr_llist_push(intern->llist, value);
} else {
/* $obj[$foo] = ... */
zend_long index;
spl_ptr_llist_element *element;
index = spl_offset_convert_to_long(zindex);
if (index < 0 || index >= intern->llist->count) {
zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid or out of range", 0);
return;
}
element = spl_ptr_llist_offset(intern->llist, index, intern->flags & SPL_DLLIST_IT_LIFO);
if (element != NULL) {
/* call dtor on the old element as in spl_ptr_llist_pop */
if (intern->llist->dtor) {
intern->llist->dtor(element);
}
/* the element is replaced, delref the old one as in
* SplDoublyLinkedList::pop() */
zval_ptr_dtor(&element->data);
ZVAL_COPY_VALUE(&element->data, value);
/* new element, call ctor as in spl_ptr_llist_push */
if (intern->llist->ctor) {
intern->llist->ctor(element);
}
} else {
zval_ptr_dtor(value);
zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid", 0);
return;
}
}
} /* }}} */
示例2: php_grpc_read_args_array
void php_grpc_read_args_array(zval *args_array, grpc_channel_args *args) {
HashTable *array_hash;
//HashPosition array_pointer;
int args_index;
zval *data;
zend_string *key;
//zend_ulong index;
array_hash = HASH_OF(args_array);
if (!array_hash) {
zend_throw_exception(spl_ce_InvalidArgumentException,
"array_hash is NULL", 1);
return;
}
args->num_args = zend_hash_num_elements(array_hash);
args->args = ecalloc(args->num_args, sizeof(grpc_arg));
args_index = 0;
ZEND_HASH_FOREACH_STR_KEY_VAL(array_hash, key, data) {
/*for (zend_hash_internal_pointer_reset_ex(array_hash, &array_pointer);
(data = zend_hash_get_current_data_ex(array_hash,
&array_pointer)) != NULL;
zend_hash_move_forward_ex(array_hash, &array_pointer)) {
if (zend_hash_get_current_key_ex(array_hash, &key, &index,
&array_pointer) != HASH_KEY_IS_STRING) {
zend_throw_exception(spl_ce_InvalidArgumentException,
"args keys must be strings", 1);
return;
}*/
if (key == NULL) {
zend_throw_exception(spl_ce_InvalidArgumentException,
"args keys must be strings", 1);
}
args->args[args_index].key = ZSTR_VAL(key);
switch (Z_TYPE_P(data)) {
case IS_LONG:
args->args[args_index].value.integer = (int)Z_LVAL_P(data);
args->args[args_index].type = GRPC_ARG_INTEGER;
break;
case IS_STRING:
args->args[args_index].value.string = Z_STRVAL_P(data);
args->args[args_index].type = GRPC_ARG_STRING;
break;
default:
zend_throw_exception(spl_ce_InvalidArgumentException,
"args values must be int or string", 1);
return;
}
args_index++;
} ZEND_HASH_FOREACH_END();
}
示例3: zend_throw_exception
/* Selects a collection and returns it as zval. If the return value is no, an
* Exception is set. This only happens if the passed in DB was invalid. */
zval *php_mongo_db_selectcollection(zval *z_client, char *collection, int collection_len TSRMLS_DC)
{
zval *z_collection;
zval *return_value;
mongo_db *db;
db = (mongo_db*)zend_object_store_get_object(z_client TSRMLS_CC);
if (!(db->name)) {
zend_throw_exception(mongo_ce_Exception, "The MongoDB object has not been correctly initialized by its constructor", 0 TSRMLS_CC);
return NULL;
}
MAKE_STD_ZVAL(z_collection);
ZVAL_STRINGL(z_collection, collection, collection_len, 1);
MAKE_STD_ZVAL(return_value);
object_init_ex(return_value, mongo_ce_Collection);
php_mongo_collection_construct(return_value, z_client, collection, collection_len TSRMLS_CC);
if (EG(exception)) {
zval_ptr_dtor(&return_value);
return_value = NULL;
}
zval_ptr_dtor(&z_collection);
return return_value;
}
示例4: PHP_METHOD
PHP_METHOD(ArrayList, addToBottom){
zval* temp;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &temp) == FAILURE) {
RETURN_NULL();
}
list_object* obj = (list_object*) zend_object_store_get_object(getThis() TSRMLS_CC);
if (obj->object != NULL) {
try {
if(obj->type == TYPE_LONG) {
((List<long>*) obj->object)->addToBottom(zval2long(temp));
} else if (obj->type == TYPE_DOUBLE) {
((List<double>*) obj->object)->addToBottom(zval2double(temp));
} else if (obj->type == TYPE_BOOLEAN) {
((List<char>*) obj->object)->addToBottom(zval2bool(temp));
} else if (obj->type == TYPE_STRING) {
((List<char*>*) obj->object)->addToBottom(zval2str(temp, obj->memory_manager));
} else if (obj->type == TYPE_OBJECT) {
((List<zval*>*) obj->object)->addToBottom(zval2object(temp, obj->class_entry));
} else {
((List<zval*>*) obj->object)->addToBottom(temp);
}
} catch (const std::runtime_error& e) {
zend_throw_exception(NULL, e.what(), 0 TSRMLS_CC);
RETURN_NULL();
}
}
}
示例5: PHP_METHOD
/* {{{ Mosquitto\Client::onPublish() */
PHP_METHOD(Mosquitto_Client, onPublish)
{
mosquitto_client_object *object;
zend_fcall_info publish_callback = empty_fcall_info;
zend_fcall_info_cache publish_callback_cache = empty_fcall_info_cache;
PHP_MOSQUITTO_ERROR_HANDLING();
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "f!",
&publish_callback, &publish_callback_cache) == FAILURE) {
PHP_MOSQUITTO_RESTORE_ERRORS();
return;
}
PHP_MOSQUITTO_RESTORE_ERRORS();
object = (mosquitto_client_object *) mosquitto_client_object_get(getThis() TSRMLS_CC);
if (!ZEND_FCI_INITIALIZED(publish_callback)) {
zend_throw_exception(mosquitto_ce_exception, "Need a valid callback", 0 TSRMLS_CC);
}
object->publish_callback = publish_callback;
object->publish_callback_cache = publish_callback_cache;
Z_ADDREF_P(publish_callback.function_name);
if (publish_callback.object_ptr != NULL) {
Z_ADDREF_P(publish_callback.object_ptr);
}
mosquitto_publish_callback_set(object->client, php_mosquitto_publish_callback);
}
示例6: PHP_METHOD
/**
* Creates an IO event which will trigger when there is data to read and/or data to write
* on the supplied stream.
*
* @param callback the PHP callback to call
* @param resource the PHP stream to watch
* @param int either IOEvent::READ and/or IOEvent::WRITE depending on type of event
*/
PHP_METHOD(IOEvent, __construct)
{
dFILE_DESC;
dCALLBACK;
long events;
event_object *obj;
PARSE_PARAMETERS(IOEvent, "zZl", &callback, &fd, &events);
/* Check if we have the correct flags */
if( ! (events & (EV_READ | EV_WRITE)))
{
/* TODO: libev-specific exception class here */
zend_throw_exception(NULL, "libev\\IOEvent: events parameter must be "
"at least one of IOEvent::READ or IOEvent::WRITE", 1 TSRMLS_CC);
return;
}
EXTRACT_FILE_DESC(IOEvent, __construct);
CHECK_CALLBACK;
EVENT_OBJECT_PREPARE(obj, callback);
event_io_init(obj, (int) file_desc, (int) events);
}
示例7: PHP_METHOD
/* {{{ proto string MarkdownDocument::transformFragment(string $markdown_fragment [, int $flags = 0 ]) */
PHP_METHOD(markdowndoc, transformFragment)
{
char *markdown;
int markdown_len;
long flags = 0;
char *out = NULL;
int out_len;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l",
&markdown, &markdown_len, &flags) == FAILURE) {
RETURN_FALSE;
}
if (markdown_len == 0) {
RETURN_EMPTY_STRING();
}
out_len = mkd_line(markdown, markdown_len, &out, (mkd_flag_t) flags);
if (out_len < 0) {
zend_throw_exception(spl_ce_RuntimeException,
"Error parsing the fragment", 0 TSRMLS_CC);
RETVAL_FALSE;
} else {
RETVAL_STRINGL(out, out_len, 0);
}
if (Z_TYPE_P(return_value) == IS_BOOL && out != NULL) {
efree(out);
}
}
示例8: PHP_METHOD
/**
* Normal constructor for EventLoop instance.
*/
PHP_METHOD(EventLoop, __construct)
{
int backend = EVFLAG_AUTO;
event_loop_object *obj = (event_loop_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
assert( ! obj->loop);
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &backend) != SUCCESS) {
return;
}
/* Check parameter */
if(EVFLAG_AUTO != backend &&
EVBACKEND_SELECT != backend &&
EVBACKEND_POLL != backend &&
EVBACKEND_EPOLL != backend &&
EVBACKEND_KQUEUE != backend &&
EVBACKEND_DEVPOLL != backend &&
EVBACKEND_PORT != backend &&
EVBACKEND_ALL != backend) {
/* TODO: libev-specific exception class here */
zend_throw_exception(NULL, "libev\\EventLoop: backend parameter must be "
"one of the EventLoop::BACKEND_* constants.", 1 TSRMLS_DC);
return;
}
obj->loop = ev_loop_new(backend);
IF_DEBUG(ev_verify(obj->loop));
}
示例9: PHP_METHOD
PHP_METHOD(swoole_atomic_long, __construct)
{
zend_long value = 0;
#ifdef FAST_ZPP
ZEND_PARSE_PARAMETERS_START(0, 1)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(value)
ZEND_PARSE_PARAMETERS_END();
#else
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &value) == FAILURE)
{
RETURN_FALSE;
}
#endif
sw_atomic_long_t *atomic = SwooleG.memory_pool->alloc(SwooleG.memory_pool, sizeof(sw_atomic_long_t));
if (atomic == NULL)
{
zend_throw_exception(swoole_exception_class_entry_ptr, "global memory allocation failure.", SW_ERROR_MALLOC_FAIL TSRMLS_CC);
RETURN_FALSE;
}
*atomic = (sw_atomic_long_t) value;
swoole_set_object(getThis(), (void*) atomic);
RETURN_TRUE;
}
示例10: create_struct_ex
void create_struct_ex(zval *retval, Any *anyval, char *str, int str_len TSRMLS_DC)
{
Reference <XIdlReflection> *x_idl_reflec_p;
int type;
int rsrc_id;
try
{
//restore XIdlReflection resource
x_idl_reflec_p =
(Reference <XIdlReflection> *) zend_list_find(
PUNO_G(x_idl_reflec_rsrc_id),&type);
TEST_PTR(x_idl_reflec_p,);
Reference <XIdlClass> xIdlClass = (*x_idl_reflec_p)->forName(OUString(str,str_len,RTL_TEXTENCODING_ISO_8859_15,OSTRING_TO_OUSTRING_CVTFLAGS));
TEST_PTR(xIdlClass.is(),);
//Reference <XIdlField2> field (xidlfield, UNO_QUERY);
Any any_obj;
xIdlClass->createObject(any_obj);
if(anyval!=NULL)
{
any_obj.setValue((*anyval).getValue(),(*anyval).getValueType());
}
Any *any_obj_p= new Any(any_obj);
TEST_PTR(any_obj_p,);
//init object
object_init_ex (retval, ce_ptr);
puno_class_object *new_struct_p;
new_struct_p =
(puno_class_object *) zend_object_store_get_object(retval TSRMLS_CC);
TEST_PTR(new_struct_p,);
//type is Structs
new_struct_p->type = TypeClass_STRUCT;
//register and store the Any object
rsrc_id = ZEND_REGISTER_RESOURCE (
NULL, any_obj_p,
uno_any_rsrc_dtor);
TEST_PTR(rsrc_id,);
new_struct_p->this_rsrc_id = rsrc_id;
//register and store the XIdlClass Interface
Reference <XIdlClass> *x_idl_class_p=new Reference <XIdlClass> (xIdlClass);
TEST_PTR(x_idl_class_p,);
rsrc_id = ZEND_REGISTER_RESOURCE (
NULL, x_idl_class_p,
uno_refer_rsrc_dtor);
TEST_PTR(rsrc_id,);
new_struct_p->x_idl_class_rsrc_id = rsrc_id;
}
catch(Exception& e)
{
//throw PHP EXCEPTION
zend_throw_exception(zend_exception_get_default(),(char *)OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US).getStr(),0 TSRMLS_CC);
}
}
示例11: PHP_METHOD
/**
* Create SSL credentials.
* @param string pem_root_certs PEM encoding of the server root certificates
* @param string pem_private_key PEM encoding of the client's private key
* @param string pem_cert_chain PEM encoding of the client's certificate chain
* @return Credentials The new SSL credentials object
*/
PHP_METHOD(ServerCredentials, createSsl) {
zend_string *pem_root_certs = NULL;
zend_string *private_key;
zend_string *cert_chain;
grpc_ssl_pem_key_cert_pair pem_key_cert_pair;
/* "S!SS" == 1 nullable string, 2 strings */
/* TODO: support multiple key cert pairs. */
if (zend_parse_parameters(ZEND_NUM_ARGS(), "S!SS", &pem_root_certs,
&private_key, &cert_chain) == FAILURE) {
zend_throw_exception(spl_ce_InvalidArgumentException,
"createSsl expects 3 strings", 1);
return;
}
if (private_key) {
pem_key_cert_pair.private_key = ZSTR_VAL(private_key);
}
if (cert_chain) {
pem_key_cert_pair.cert_chain = ZSTR_VAL(cert_chain);
}
/* TODO: add a client_certificate_request field in ServerCredentials and pass
* it as the last parameter. */
grpc_server_credentials *creds =
grpc_ssl_server_credentials_create_ex(
pem_root_certs == NULL ? NULL :
ZSTR_VAL(pem_root_certs),
&pem_key_cert_pair, 1,
GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE, NULL);
grpc_php_wrap_server_credentials(creds, return_value);
RETURN_DESTROY_ZVAL(return_value);
}
示例12: SPL_METHOD
/* {{{ proto bool SplPriorityQueue::insert(mixed $value, mixed $priority)
Push $value with the priority $priodiry on the priorityqueue */
SPL_METHOD(SplPriorityQueue, insert)
{
zval *data, *priority, elem;
spl_heap_object *intern;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "zz", &data, &priority) == FAILURE) {
return;
}
intern = Z_SPLHEAP_P(getThis());
if (intern->heap->flags & SPL_HEAP_CORRUPTED) {
zend_throw_exception(spl_ce_RuntimeException, "Heap is corrupted, heap properties are no longer ensured.", 0);
return;
}
if (Z_REFCOUNTED_P(data)) Z_ADDREF_P(data);
if (Z_REFCOUNTED_P(priority)) Z_ADDREF_P(priority);
array_init(&elem);
add_assoc_zval_ex(&elem, "data", sizeof("data") - 1, data);
add_assoc_zval_ex(&elem, "priority", sizeof("priority") - 1, priority);
spl_ptr_heap_insert(intern->heap, &elem, getThis());
RETURN_TRUE;
}
示例13: php_com_throw_exception
void php_com_throw_exception(HRESULT code, char *message)
{
int free_msg = 0;
if (message == NULL) {
message = php_win32_error_to_msg(code);
free_msg = 1;
}
#if SIZEOF_ZEND_LONG == 8
zend_throw_exception(php_com_exception_class_entry, message, (zend_long)(uint32_t)code);
#else
zend_throw_exception(php_com_exception_class_entry, message, (zend_long)code);
#endif
if (free_msg) {
LocalFree(message);
}
}
示例14: php_rsa_check_padding
/* {{{ */
static int php_rsa_check_padding(phpc_long_t padding, zend_bool sigver TSRMLS_DC)
{
zend_bool ok;
switch (padding) {
case RSA_PKCS1_PADDING:
case RSA_NO_PADDING:
ok = 1;
break;
case RSA_PKCS1_OAEP_PADDING:
case RSA_SSLV23_PADDING:
ok = !sigver;
break;
case RSA_X931_PADDING:
ok = sigver;
break;
default:
ok = 0;
}
if (ok) {
return SUCCESS;
}
zend_throw_exception(php_rsa_exception_ce,
"Ivalid padding parameter",
PHP_RSA_ERROR_INVALID_PADDING TSRMLS_CC);
return FAILURE;
}
示例15: Z_SPLDLLIST_P
zend_object_iterator *spl_dllist_get_iterator(zend_class_entry *ce, zval *object, int by_ref) /* {{{ */
{
spl_dllist_it *iterator;
spl_dllist_object *dllist_object = Z_SPLDLLIST_P(object);
if (by_ref) {
zend_throw_exception(spl_ce_RuntimeException, "An iterator cannot be used with foreach by reference", 0);
return NULL;
}
iterator = emalloc(sizeof(spl_dllist_it));
zend_iterator_init((zend_object_iterator*)iterator);
ZVAL_COPY(&iterator->intern.it.data, object);
iterator->intern.it.funcs = &spl_dllist_it_funcs;
iterator->intern.ce = ce;
iterator->traverse_position = dllist_object->traverse_position;
iterator->traverse_pointer = dllist_object->traverse_pointer;
iterator->flags = dllist_object->flags & SPL_DLLIST_IT_MASK;
ZVAL_UNDEF(&iterator->intern.value);
SPL_LLIST_CHECK_ADDREF(iterator->traverse_pointer);
return &iterator->intern.it;
}