Elizabeth Marie Smith
2012-08-15 15:39:11 UTC
Commit: 806a8657de680df02bf47d0a7413d16650fdef83
Author: Elizabeth M Smith <***@gmail.com> Wed, 15 Aug 2012 11:39:11 -0400
Parents: b9901ae6000b45d2883122fcbc13dcfba6cbf61c
Branches: master
Link: http://git.php.net/?p=php/gtk-src.git;a=commitdiff;h=806a8657de680df02bf47d0a7413d16650fdef83
Log:
Add little hack to make sure user classes get
their constructor's run when used with libglade or
gtkbuilder and that constructors ar never double
constructed
Also added signal example for using TYPE_PHP_VALUE
Changed paths:
M demos/examples/signals.php
M generator/templates.php
M main/phpg_gobject.c
Diff:
diff --git a/demos/examples/signals.php b/demos/examples/signals.php
index 9c7b381..bf5d677 100644
--- a/demos/examples/signals.php
+++ b/demos/examples/signals.php
@@ -4,11 +4,18 @@ class NewType extends GtkButton {
public $__gsignals = array(
'clicked' => 'override',
'mashed' => array(GObject::SIGNAL_RUN_LAST, GObject::TYPE_BOOLEAN, array(GObject::TYPE_LONG, GtkRequisition::gtype)),
+ 'weird' => array(GObject::SIGNAL_RUN_FIRST, GObject::TYPE_NONE, array(Gobject::TYPE_PHP_VALUE)),
);
function __construct()
{
parent::__construct();
+ $this->emit('weird', 'hello dolly');
+ }
+
+ function __do_weird($arg)
+ {
+ echo "NewType: class closure for `weird` called with arguments {$arg} \n";
}
function __do_clicked()
diff --git a/generator/templates.php b/generator/templates.php
index 0bec10c..6a643c2 100644
--- a/generator/templates.php
+++ b/generator/templates.php
@@ -53,17 +53,22 @@ static PHP_METHOD(%(class), %(name))
{
%(var_list)\tGObject *wrapped_obj;
+ phpg_gobject_t *pobj = zend_object_store_get_object(this_ptr TSRMLS_CC);
+ if (pobj->obj != NULL) {
+ return;
+ }
+
if (!php_gtk_parse_args(ZEND_NUM_ARGS(), \"%(specs)\"%(parse_list))) {
- PHPG_THROW_CONSTRUCT_EXCEPTION(%(class));
+ PHPG_THROW_CONSTRUCT_EXCEPTION(%(class));
}
%(pre_code)
wrapped_obj = (GObject *) %(cname)(%(arg_list));
%(post_code)
if (!wrapped_obj) {
- PHPG_THROW_CONSTRUCT_EXCEPTION(%(class));
+ PHPG_THROW_CONSTRUCT_EXCEPTION(%(class));
}
%(post_create_code)
- phpg_gobject_set_wrapper(this_ptr, wrapped_obj TSRMLS_CC);
+ phpg_gobject_set_wrapper(this_ptr, wrapped_obj TSRMLS_CC);
}\n\n";
const static_constructor_body = "
@@ -150,51 +155,61 @@ e\n\n";
const constructor_with_props = "
static PHP_METHOD(%(class), %(name))
{
- GParameter params[%(n_params)];
+ GParameter params[%(n_params)];
zval *php_args[%(n_args)] = { NULL, };
char *prop_names[] = { %(props) NULL };
- GObject *wrapped_obj;
- guint i, n_params;
+ GObject *wrapped_obj;
+ guint i, n_params;
GType gtype = phpg_gtype_from_zval(this_ptr TSRMLS_CC);
- if (!php_gtk_parse_args(ZEND_NUM_ARGS(), \"%(specs)\"%(parse_list))) {
- PHPG_THROW_CONSTRUCT_EXCEPTION(%(class));
- }
+ phpg_gobject_t *pobj = zend_object_store_get_object(this_ptr TSRMLS_CC);
+ if (pobj->obj != NULL) {
+ return;
+ }
+
+ if (!php_gtk_parse_args(ZEND_NUM_ARGS(), \"%(specs)\"%(parse_list))) {
+ PHPG_THROW_CONSTRUCT_EXCEPTION(%(class));
+ }
memset(¶ms, 0, %(n_params) * sizeof(GParameter));
- if (!phpg_parse_ctor_props(gtype, php_args, params, &n_params, prop_names TSRMLS_CC)) {
- PHPG_THROW_CONSTRUCT_EXCEPTION(%(class));
- }
+ if (!phpg_parse_ctor_props(gtype, php_args, params, &n_params, prop_names TSRMLS_CC)) {
+ PHPG_THROW_CONSTRUCT_EXCEPTION(%(class));
+ }
%(pre_code)
- wrapped_obj = (GObject *) g_object_newv(gtype, n_params, params);
+ wrapped_obj = (GObject *) g_object_newv(gtype, n_params, params);
%(post_code)
- if (!wrapped_obj) {
- PHPG_THROW_CONSTRUCT_EXCEPTION(%(class));
- }
+ if (!wrapped_obj) {
+ PHPG_THROW_CONSTRUCT_EXCEPTION(%(class));
+ }
for (i = 0; i < n_params; i++) {
g_value_unset(¶ms[i].value);
- }
- phpg_gobject_set_wrapper(this_ptr, wrapped_obj TSRMLS_CC);
+ }
+ phpg_gobject_set_wrapper(this_ptr, wrapped_obj TSRMLS_CC);
}\n\n";
const constructor_without_props = "
static PHP_METHOD(%(class), %(name))
{
- GObject *wrapped_obj;
+ GObject *wrapped_obj;
- if (!php_gtk_parse_args(ZEND_NUM_ARGS(), \"\")) {
- PHPG_THROW_CONSTRUCT_EXCEPTION(%(class));
- }
+ phpg_gobject_t *pobj = zend_object_store_get_object(this_ptr TSRMLS_CC);
+ if (pobj->obj != NULL) {
+ return;
+ }
+
+ if (!php_gtk_parse_args(ZEND_NUM_ARGS(), \"\")) {
+ PHPG_THROW_CONSTRUCT_EXCEPTION(%(class));
+ }
%(pre_code)
- wrapped_obj = (GObject *) g_object_newv(phpg_gtype_from_zval(this_ptr TSRMLS_CC), 0, NULL);
+ wrapped_obj = (GObject *) g_object_newv(phpg_gtype_from_zval(this_ptr TSRMLS_CC), 0, NULL);
%(post_code)
- if (!wrapped_obj) {
- PHPG_THROW_CONSTRUCT_EXCEPTION(%(class));
- }
+ if (!wrapped_obj) {
+ PHPG_THROW_CONSTRUCT_EXCEPTION(%(class));
+ }
- phpg_gobject_set_wrapper(this_ptr, wrapped_obj TSRMLS_CC);
+ phpg_gobject_set_wrapper(this_ptr, wrapped_obj TSRMLS_CC);
}\n\n";
const deprecation_msg = "\n\tphpg_warn_deprecated(%s TSRMLS_CC);\n";
const method1_call = "%s(%s(PHP_GTK_GET(this_ptr))%s)";
diff --git a/main/phpg_gobject.c b/main/phpg_gobject.c
index b1ce5b3..5f1e4cb 100644
--- a/main/phpg_gobject.c
+++ b/main/phpg_gobject.c
@@ -228,6 +228,10 @@ PHP_GTK_API void phpg_gobject_new(zval **zobj, GObject *obj TSRMLS_DC)
#ifdef ZTS
g_object_set_qdata(obj, gobject_wrapper_zts_key, (void*)TSRMLS_C);
#endif
+
+ if (ce->type == ZEND_USER_CLASS) {
+ zend_call_method_with_0_params(zobj, ce, &ce->constructor, "__construct", NULL);
+ }
}
}
/* }}} */
@@ -398,7 +402,7 @@ static void phpg_signal_connect_impl(INTERNAL_FUNCTION_PARAMETERS, int connect_t
if (!php_gtk_parse_varargs(ZEND_NUM_ARGS(), 2, &extra, "sV", &signal, &callback)) {
if (extra) {
zval_ptr_dtor(&extra);
- }
+ }
return;
}
@@ -1387,6 +1391,7 @@ static PHP_METHOD(GObject, register_type)
}
parent_type = phpg_gtype_from_class(ce TSRMLS_CC);
+
if (!parent_type) {
return;
}
@@ -1418,7 +1423,7 @@ static PHP_METHOD(GObject, register_type)
new_type = g_type_register_static(parent_type, type_name, &type_info, 0);
if (new_type == 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "could not create new GType");
-
+
if (free_name) {
g_free(type_name);
}
Author: Elizabeth M Smith <***@gmail.com> Wed, 15 Aug 2012 11:39:11 -0400
Parents: b9901ae6000b45d2883122fcbc13dcfba6cbf61c
Branches: master
Link: http://git.php.net/?p=php/gtk-src.git;a=commitdiff;h=806a8657de680df02bf47d0a7413d16650fdef83
Log:
Add little hack to make sure user classes get
their constructor's run when used with libglade or
gtkbuilder and that constructors ar never double
constructed
Also added signal example for using TYPE_PHP_VALUE
Changed paths:
M demos/examples/signals.php
M generator/templates.php
M main/phpg_gobject.c
Diff:
diff --git a/demos/examples/signals.php b/demos/examples/signals.php
index 9c7b381..bf5d677 100644
--- a/demos/examples/signals.php
+++ b/demos/examples/signals.php
@@ -4,11 +4,18 @@ class NewType extends GtkButton {
public $__gsignals = array(
'clicked' => 'override',
'mashed' => array(GObject::SIGNAL_RUN_LAST, GObject::TYPE_BOOLEAN, array(GObject::TYPE_LONG, GtkRequisition::gtype)),
+ 'weird' => array(GObject::SIGNAL_RUN_FIRST, GObject::TYPE_NONE, array(Gobject::TYPE_PHP_VALUE)),
);
function __construct()
{
parent::__construct();
+ $this->emit('weird', 'hello dolly');
+ }
+
+ function __do_weird($arg)
+ {
+ echo "NewType: class closure for `weird` called with arguments {$arg} \n";
}
function __do_clicked()
diff --git a/generator/templates.php b/generator/templates.php
index 0bec10c..6a643c2 100644
--- a/generator/templates.php
+++ b/generator/templates.php
@@ -53,17 +53,22 @@ static PHP_METHOD(%(class), %(name))
{
%(var_list)\tGObject *wrapped_obj;
+ phpg_gobject_t *pobj = zend_object_store_get_object(this_ptr TSRMLS_CC);
+ if (pobj->obj != NULL) {
+ return;
+ }
+
if (!php_gtk_parse_args(ZEND_NUM_ARGS(), \"%(specs)\"%(parse_list))) {
- PHPG_THROW_CONSTRUCT_EXCEPTION(%(class));
+ PHPG_THROW_CONSTRUCT_EXCEPTION(%(class));
}
%(pre_code)
wrapped_obj = (GObject *) %(cname)(%(arg_list));
%(post_code)
if (!wrapped_obj) {
- PHPG_THROW_CONSTRUCT_EXCEPTION(%(class));
+ PHPG_THROW_CONSTRUCT_EXCEPTION(%(class));
}
%(post_create_code)
- phpg_gobject_set_wrapper(this_ptr, wrapped_obj TSRMLS_CC);
+ phpg_gobject_set_wrapper(this_ptr, wrapped_obj TSRMLS_CC);
}\n\n";
const static_constructor_body = "
@@ -150,51 +155,61 @@ e\n\n";
const constructor_with_props = "
static PHP_METHOD(%(class), %(name))
{
- GParameter params[%(n_params)];
+ GParameter params[%(n_params)];
zval *php_args[%(n_args)] = { NULL, };
char *prop_names[] = { %(props) NULL };
- GObject *wrapped_obj;
- guint i, n_params;
+ GObject *wrapped_obj;
+ guint i, n_params;
GType gtype = phpg_gtype_from_zval(this_ptr TSRMLS_CC);
- if (!php_gtk_parse_args(ZEND_NUM_ARGS(), \"%(specs)\"%(parse_list))) {
- PHPG_THROW_CONSTRUCT_EXCEPTION(%(class));
- }
+ phpg_gobject_t *pobj = zend_object_store_get_object(this_ptr TSRMLS_CC);
+ if (pobj->obj != NULL) {
+ return;
+ }
+
+ if (!php_gtk_parse_args(ZEND_NUM_ARGS(), \"%(specs)\"%(parse_list))) {
+ PHPG_THROW_CONSTRUCT_EXCEPTION(%(class));
+ }
memset(¶ms, 0, %(n_params) * sizeof(GParameter));
- if (!phpg_parse_ctor_props(gtype, php_args, params, &n_params, prop_names TSRMLS_CC)) {
- PHPG_THROW_CONSTRUCT_EXCEPTION(%(class));
- }
+ if (!phpg_parse_ctor_props(gtype, php_args, params, &n_params, prop_names TSRMLS_CC)) {
+ PHPG_THROW_CONSTRUCT_EXCEPTION(%(class));
+ }
%(pre_code)
- wrapped_obj = (GObject *) g_object_newv(gtype, n_params, params);
+ wrapped_obj = (GObject *) g_object_newv(gtype, n_params, params);
%(post_code)
- if (!wrapped_obj) {
- PHPG_THROW_CONSTRUCT_EXCEPTION(%(class));
- }
+ if (!wrapped_obj) {
+ PHPG_THROW_CONSTRUCT_EXCEPTION(%(class));
+ }
for (i = 0; i < n_params; i++) {
g_value_unset(¶ms[i].value);
- }
- phpg_gobject_set_wrapper(this_ptr, wrapped_obj TSRMLS_CC);
+ }
+ phpg_gobject_set_wrapper(this_ptr, wrapped_obj TSRMLS_CC);
}\n\n";
const constructor_without_props = "
static PHP_METHOD(%(class), %(name))
{
- GObject *wrapped_obj;
+ GObject *wrapped_obj;
- if (!php_gtk_parse_args(ZEND_NUM_ARGS(), \"\")) {
- PHPG_THROW_CONSTRUCT_EXCEPTION(%(class));
- }
+ phpg_gobject_t *pobj = zend_object_store_get_object(this_ptr TSRMLS_CC);
+ if (pobj->obj != NULL) {
+ return;
+ }
+
+ if (!php_gtk_parse_args(ZEND_NUM_ARGS(), \"\")) {
+ PHPG_THROW_CONSTRUCT_EXCEPTION(%(class));
+ }
%(pre_code)
- wrapped_obj = (GObject *) g_object_newv(phpg_gtype_from_zval(this_ptr TSRMLS_CC), 0, NULL);
+ wrapped_obj = (GObject *) g_object_newv(phpg_gtype_from_zval(this_ptr TSRMLS_CC), 0, NULL);
%(post_code)
- if (!wrapped_obj) {
- PHPG_THROW_CONSTRUCT_EXCEPTION(%(class));
- }
+ if (!wrapped_obj) {
+ PHPG_THROW_CONSTRUCT_EXCEPTION(%(class));
+ }
- phpg_gobject_set_wrapper(this_ptr, wrapped_obj TSRMLS_CC);
+ phpg_gobject_set_wrapper(this_ptr, wrapped_obj TSRMLS_CC);
}\n\n";
const deprecation_msg = "\n\tphpg_warn_deprecated(%s TSRMLS_CC);\n";
const method1_call = "%s(%s(PHP_GTK_GET(this_ptr))%s)";
diff --git a/main/phpg_gobject.c b/main/phpg_gobject.c
index b1ce5b3..5f1e4cb 100644
--- a/main/phpg_gobject.c
+++ b/main/phpg_gobject.c
@@ -228,6 +228,10 @@ PHP_GTK_API void phpg_gobject_new(zval **zobj, GObject *obj TSRMLS_DC)
#ifdef ZTS
g_object_set_qdata(obj, gobject_wrapper_zts_key, (void*)TSRMLS_C);
#endif
+
+ if (ce->type == ZEND_USER_CLASS) {
+ zend_call_method_with_0_params(zobj, ce, &ce->constructor, "__construct", NULL);
+ }
}
}
/* }}} */
@@ -398,7 +402,7 @@ static void phpg_signal_connect_impl(INTERNAL_FUNCTION_PARAMETERS, int connect_t
if (!php_gtk_parse_varargs(ZEND_NUM_ARGS(), 2, &extra, "sV", &signal, &callback)) {
if (extra) {
zval_ptr_dtor(&extra);
- }
+ }
return;
}
@@ -1387,6 +1391,7 @@ static PHP_METHOD(GObject, register_type)
}
parent_type = phpg_gtype_from_class(ce TSRMLS_CC);
+
if (!parent_type) {
return;
}
@@ -1418,7 +1423,7 @@ static PHP_METHOD(GObject, register_type)
new_type = g_type_register_static(parent_type, type_name, &type_info, 0);
if (new_type == 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "could not create new GType");
-
+
if (free_name) {
g_free(type_name);
}
--
PHP-GTK CVS Mailing List (http://gtk.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
PHP-GTK CVS Mailing List (http://gtk.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php