コード例 #1
0
ファイル: comment.c プロジェクト: GreenLightt/php-src
/* {{{ proto void DOMComment::__construct([string value]); */
PHP_METHOD(domcomment, __construct)
{

	zval *id = getThis();
	xmlNodePtr nodep = NULL, oldnode = NULL;
	dom_object *intern;
	char *value = NULL;
	size_t value_len;

	if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "|s", &value, &value_len) == FAILURE) {
		return;
	}

	nodep = xmlNewComment((xmlChar *) value);

	if (!nodep) {
		php_dom_throw_error(INVALID_STATE_ERR, 1);
		RETURN_FALSE;
	}

	intern = Z_DOMOBJ_P(id);
	if (intern != NULL) {
		oldnode = dom_object_get_node(intern);
		if (oldnode != NULL) {
			php_libxml_node_free_resource(oldnode );
		}
		php_libxml_increment_node_ptr((php_libxml_node_object *)intern, (xmlNodePtr)nodep, (void *)intern);
	}
}
コード例 #2
0
ファイル: spl_fixedarray.c プロジェクト: 20uf/php-src
/* {{{ proto void SplFixedArray::__construct([int size])
*/
SPL_METHOD(SplFixedArray, __construct)
{
	zval *object = getThis();
	spl_fixedarray_object *intern;
	zend_long size = 0;

	if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "|l", &size) == FAILURE) {
		return;
	}

	if (size < 0) {
		zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "array size cannot be less than zero");
		return;
	}

	intern = Z_SPLFIXEDARRAY_P(object);

	if (intern->array) {
		/* called __construct() twice, bail out */
		return;
	}

	intern->array = emalloc(sizeof(spl_fixedarray));
	spl_fixedarray_init(intern->array, size);
}
コード例 #3
0
ファイル: attr.c プロジェクト: ghfjdksl/php-src
/* {{{ proto void DOMAttr::__construct(string name, [string value]) */
PHP_METHOD(domattr, __construct)
{
	zval *id = getThis();
	xmlAttrPtr nodep = NULL;
	xmlNodePtr oldnode = NULL;
	dom_object *intern;
	char *name, *value = NULL;
	size_t name_len, value_len, name_valid;

	if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s|s", &name, &name_len, &value, &value_len) == FAILURE) {
		return;
	}

	intern = Z_DOMOBJ_P(id);

	name_valid = xmlValidateName((xmlChar *) name, 0);
	if (name_valid != 0) {
		php_dom_throw_error(INVALID_CHARACTER_ERR, 1);
		RETURN_FALSE;
	}

	nodep = xmlNewProp(NULL, (xmlChar *) name, (xmlChar *) value);

	if (!nodep) {
		php_dom_throw_error(INVALID_STATE_ERR, 1);
		RETURN_FALSE;
	}

	oldnode = dom_object_get_node(intern);
	if (oldnode != NULL) {
		php_libxml_node_free_resource(oldnode );
	}
	php_libxml_increment_node_ptr((php_libxml_node_object *)intern, (xmlNodePtr)nodep, (void *)intern);
}
コード例 #4
0
ファイル: spl_dllist.c プロジェクト: dstogov/php-src
/* {{{ proto void SplDoublyLinkedList::__unserialize(array serialized) */
SPL_METHOD(SplDoublyLinkedList, __unserialize) {
	spl_dllist_object *intern = Z_SPLDLLIST_P(ZEND_THIS);
	HashTable *data;
	zval *flags_zv, *storage_zv, *members_zv, *elem;

	if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "h", &data) == FAILURE) {
		return;
	}

	flags_zv = zend_hash_index_find(data, 0);
	storage_zv = zend_hash_index_find(data, 1);
	members_zv = zend_hash_index_find(data, 2);
	if (!flags_zv || !storage_zv || !members_zv ||
			Z_TYPE_P(flags_zv) != IS_LONG || Z_TYPE_P(storage_zv) != IS_ARRAY ||
			Z_TYPE_P(members_zv) != IS_ARRAY) {
		zend_throw_exception(spl_ce_UnexpectedValueException,
			"Incomplete or ill-typed serialization data", 0);
		return;
	}

	intern->flags = (int) Z_LVAL_P(flags_zv);

	ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(storage_zv), elem) {
		spl_ptr_llist_push(intern->llist, elem);
	} ZEND_HASH_FOREACH_END();
コード例 #5
0
ファイル: entityreference.c プロジェクト: 0xhacking/php-src
/* {{{ proto void DOMEntityReference::__construct(string name); */
PHP_METHOD(domentityreference, __construct)
{
	zval *id = getThis();
	xmlNode *node;
	xmlNodePtr oldnode = NULL;
	dom_object *intern;
	char *name;
	size_t name_len, name_valid;

	if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s", &name, &name_len) == FAILURE) {
		return;
	}

	name_valid = xmlValidateName((xmlChar *) name, 0);
	if (name_valid != 0) {
		php_dom_throw_error(INVALID_CHARACTER_ERR, 1);
		RETURN_FALSE;
	}

	node = xmlNewReference(NULL, (xmlChar *) name);

	if (!node) {
		php_dom_throw_error(INVALID_STATE_ERR, 1);
		RETURN_FALSE;
	}

	intern = Z_DOMOBJ_P(id);
	if (intern != NULL) {
		oldnode = dom_object_get_node(intern);
		if (oldnode != NULL) {
			php_libxml_node_free_resource(oldnode );
		}
		php_libxml_increment_node_ptr((php_libxml_node_object *)intern, node, (void *)intern);
	}
}
コード例 #6
0
ファイル: source.c プロジェクト: gtkforphp/glib
/* {{{ proto void \Glib\Source->attach(Context $context)
        attaches a source to a main context
   */
PHP_METHOD(GlibSource, attach)
{
	zval *context_zval = NULL;
	glib_main_context_object *context_object;
	glib_source_object *source_object;

	if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "O", &context_zval, glib_ce_main_context) == FAILURE) {
		return;
	}

	if(context_zval == NULL) {
		zend_throw_exception(spl_ce_InvalidArgumentException, "Invalid context sent", 0);
		return;
	}

	context_object = Z_GLIB_MAIN_CONTEXT_P(context_zval);
	source_object = Z_GLIB_SOURCE_P(getThis());
	GLIB_CHECK_INITIALIZED(source_object->source, Glib\\Source)
	
	if(g_source_is_destroyed(source_object->source)) {
		zend_throw_exception(spl_ce_RuntimeException, "Source has been destroyed", 0);
		return;
	}

	RETURN_LONG(g_source_attach(source_object->source, context_object->main_context));
}
コード例 #7
0
/* {{{ proto Spoofchecker Spoofchecker::__construct()
 * Spoofchecker object constructor.
 */
PHP_METHOD(Spoofchecker, __construct)
{
	int checks;
	zend_error_handling error_handling;
	SPOOFCHECKER_METHOD_INIT_VARS;

	if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "") == FAILURE) {
		return;
	}

	zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);

	SPOOFCHECKER_METHOD_FETCH_OBJECT_NO_CHECK;

	co->uspoof = uspoof_open(SPOOFCHECKER_ERROR_CODE_P(co));
	INTL_METHOD_CHECK_STATUS(co, "spoofchecker: unable to open ICU Spoof Checker");

	/* Single-script enforcement is on by default. This fails for languages
	 like Japanese that legally use multiple scripts within a single word,
	 so we turn it off.
	*/
	checks = uspoof_getChecks(co->uspoof, SPOOFCHECKER_ERROR_CODE_P(co));
	uspoof_setChecks(co->uspoof, checks & ~USPOOF_SINGLE_SCRIPT, SPOOFCHECKER_ERROR_CODE_P(co));
	zend_restore_error_handling(&error_handling);
}
コード例 #8
0
ファイル: closure.c プロジェクト: krakjoe/inspector
/* {{{ */
static PHP_METHOD(Closure, __construct)
{
	zval *closure;

	if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "O", &closure, zend_ce_closure) != SUCCESS) {
		return;
	}

	php_inspector_scope_construct(getThis(), (zend_function*) zend_get_closure_method_def(closure));
}
コード例 #9
0
ファイル: zwlog.c プロジェクト: krakjoe/zway
PHP_METHOD(ZWLog, error) {
	php_zwlog_t *pz = php_zwlog_fetch(getThis());
	zend_string *source = CG(empty_string),
				*message = CG(empty_string);
	zend_long level = pz->level,
			  error = NoError;

	if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "SlS|l", &source, &level, &message, &error) != SUCCESS) {
		return;
	}

	zlog_write(pz->zw, ZSTR_VAL(source), level, ZSTR_VAL(message), (ZWError) error);
}
コード例 #10
0
ファイル: zwlog.c プロジェクト: krakjoe/zway
PHP_METHOD(ZWLog, __construct) {
	php_zwlog_t *pz = php_zwlog_fetch(getThis());
	zend_long level = PHP_ZWLOG_DEBUG;
	zend_string *file = CG(empty_string),
				*mode = CG(empty_string);

	if (ZEND_NUM_ARGS() > 1) {
		if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "SS|l", &file, &mode, &level) != SUCCESS) {
			return;
		}
	} else if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "|l", &level) != SUCCESS) {
		return;
	}

	pz->level = level;

	if ((file && ZSTR_LEN(file)) && (mode && ZSTR_LEN(mode))) {
		FILE *stdio = fopen(ZSTR_VAL(file), ZSTR_VAL(mode));
		if (!stdio) {
			zend_throw_exception_ex(spl_ce_RuntimeException, errno, "cannot open %s(%s) for logging",
				ZSTR_VAL(file), ZSTR_VAL(mode));
		} else pz->zw = zlog_create(stdio, pz->level);
	} else pz->zw = zlog_create_syslog(pz->level);
}
コード例 #11
0
ファイル: simd.c プロジェクト: krakjoe/SIMD
PHP_METHOD(Float32x4, offsetGet)    {
	zend_long offset = -1;
	php_float32x4_t *p = php_float32x4_fetch();
	
	if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "l", &offset) != SUCCESS) {
		return;
	}
	
	/* check boundaries and return double */
	if (offset < 4 && offset > -1) {
		RETURN_DOUBLE((*p->v)[offset]);
	}
	
	RETURN_DOUBLE(-1);
}
コード例 #12
0
ファイル: source.c プロジェクト: gtkforphp/glib
/* {{{ proto void \Glib\Source->setPriority(int priority)
        sets the priority of a source
   */
PHP_METHOD(GlibSource, setPriority)
{
	zend_long priority;
	gint set_priority;
	glib_source_object *source_object;

	if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "l", &priority) == FAILURE) {
		return;
	}

	source_object = Z_GLIB_SOURCE_P(getThis());
	GLIB_CHECK_INITIALIZED(source_object->source, Glib\\Source)
	set_priority = priority;

	g_source_set_priority(source_object->source, priority);
}
コード例 #13
0
ファイル: xpath.c プロジェクト: 0xhacking/php-src
/* {{{ proto void DOMXPath::__construct(DOMDocument doc) U */
PHP_METHOD(domxpath, __construct)
{
	zval *id = getThis(), *doc;
	xmlDocPtr docp = NULL;
	dom_object *docobj;
	dom_xpath_object *intern;
	xmlXPathContextPtr ctx, oldctx;

	if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "O", &doc, dom_document_class_entry) == FAILURE) {
		return;
	}

	DOM_GET_OBJ(docp, doc, xmlDocPtr, docobj);

	ctx = xmlXPathNewContext(docp);
	if (ctx == NULL) {
		php_dom_throw_error(INVALID_STATE_ERR, 1);
		RETURN_FALSE;
	}

	intern = Z_XPATHOBJ_P(id);
	if (intern != NULL) {
		oldctx = (xmlXPathContextPtr)intern->dom.ptr;
		if (oldctx != NULL) {
			php_libxml_decrement_doc_ref((php_libxml_node_object *) &intern->dom);
			xmlXPathFreeContext(oldctx);
		}

		xmlXPathRegisterFuncNS (ctx, (const xmlChar *) "functionString",
					   (const xmlChar *) "http://php.net/xpath",
					   dom_xpath_ext_function_string_php);
		xmlXPathRegisterFuncNS (ctx, (const xmlChar *) "function",
					   (const xmlChar *) "http://php.net/xpath",
					   dom_xpath_ext_function_object_php);

		intern->dom.ptr = ctx;
		ctx->userData = (void *)intern;
		intern->dom.document = docobj->document;
		php_libxml_increment_doc_ref((php_libxml_node_object *) &intern->dom, docp);
	}
}
コード例 #14
0
ファイル: simd.c プロジェクト: krakjoe/SIMD
PHP_METHOD(Float32x4, __construct) {
	double lanes[4] = php_float32x4_empty;
	float  flanes[4] = php_float32x4_empty;
	php_float32x4_t *p = php_float32x4_fetch();
	
	if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "dddd", &lanes[0], &lanes[1], &lanes[2], &lanes[3]) != SUCCESS) {
		return;
	}
	
	flanes[0] = (float) lanes[0];
	flanes[1] = (float) lanes[1];
	flanes[2] = (float) lanes[2];
	flanes[3] = (float) lanes[3];
	
	if (posix_memalign(
		(void**) &p->v, 16, sizeof(__m128)) != SUCCESS) {
		zend_throw_exception_ex(php_float32x4_exception_ce, 0, "memory alignment error");
	}
	
	*p->v = _mm_load_ps (flanes);
}
コード例 #15
0
ファイル: element.c プロジェクト: 13572293130/php-src
/* {{{ proto void DOMElement::__construct(string name, [string value], [string uri]) */
PHP_METHOD(domelement, __construct)
{

	zval *id = getThis();
	xmlNodePtr nodep = NULL, oldnode = NULL;
	dom_object *intern;
	char *name, *value = NULL, *uri = NULL;
	char *localname = NULL, *prefix = NULL;
	int errorcode = 0;
	size_t name_len, value_len = 0, uri_len = 0;
	int name_valid;
	xmlNsPtr nsptr = NULL;

	if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s|s!s", &name, &name_len, &value, &value_len, &uri, &uri_len) == FAILURE) {
		return;
	}

	name_valid = xmlValidateName((xmlChar *) name, 0);
	if (name_valid != 0) {
		php_dom_throw_error(INVALID_CHARACTER_ERR, 1);
		RETURN_FALSE;
	}

	/* Namespace logic is separate and only when uri passed in to insure no BC breakage */
	if (uri_len > 0) {
		errorcode = dom_check_qname(name, &localname, &prefix, uri_len, name_len);
		if (errorcode == 0) {
			nodep = xmlNewNode (NULL, (xmlChar *)localname);
			if (nodep != NULL && uri != NULL) {
				nsptr = dom_get_ns(nodep, uri, &errorcode, prefix);
				xmlSetNs(nodep, nsptr);
			}
		}
		xmlFree(localname);
		if (prefix != NULL) {
			xmlFree(prefix);
		}
		if (errorcode != 0) {
			if (nodep != NULL) {
				xmlFreeNode(nodep);
			}
			php_dom_throw_error(errorcode, 1);
			RETURN_FALSE;
		}
	} else {
	    /* If you don't pass a namespace uri, then you can't set a prefix */
	    localname = (char *) xmlSplitQName2((xmlChar *) name, (xmlChar **) &prefix);
	    if (prefix != NULL) {
			xmlFree(localname);
			xmlFree(prefix);
	        php_dom_throw_error(NAMESPACE_ERR, 1);
	        RETURN_FALSE;
	    }
		nodep = xmlNewNode(NULL, (xmlChar *) name);
	}

	if (!nodep) {
		php_dom_throw_error(INVALID_STATE_ERR, 1);
		RETURN_FALSE;
	}

	if (value_len > 0) {
		xmlNodeSetContentLen(nodep, (xmlChar *) value, value_len);
	}

	intern = Z_DOMOBJ_P(id);
	oldnode = dom_object_get_node(intern);
	if (oldnode != NULL) {
		php_libxml_node_free_resource(oldnode );
	}
	php_libxml_increment_node_ptr((php_libxml_node_object *)intern, nodep, (void *)intern);
}