meantime, back at the ranch...

From: Date: Sun, 25 Jun 2006 08:20:33 +0000
Subject: meantime, back at the ranch...
Groups: php.gtk.dev 
Request: Send a blank email to php-gtk-dev+get-3161@lists.php.net to get a copy of this message
Things got a little better since I started efreeing the wretched alignment/position pointers. This is what happens when running both tests from last time now: C:\sandbox\php-gtk\main\php_gtk_util.c(738) : Freeing 0x00B396C0 (32 bytes), script=bug.php c:\sandbox\php5\zend\zend_hash.c(169) : Actual location (location was relayed) Last leak repeated 3 times C:\sandbox\php-gtk\main\php_gtk_util.c(742) : Freeing 0x00B347E8 (35 bytes), script=bug.php c:\sandbox\php5\zend\zend_hash.c(383) : Actual location (location was relayed) Last leak repeated 5 times === Total 10 memory leaks detected === The remaining leaks both come somewhere during the call to php_gtk_array_as_hash() during varargs parsing. Apart from that everything there's working properly now, correct values returned et al. And there's another, thankfully non-problematic method in this patch (get_tab()). - Steph

Index: ext/gtk+/pango.overrides =================================================================== RCS file: /repository/php-gtk/ext/gtk+/pango.overrides,v retrieving revision 1.7 diff -u -r1.7 pango.overrides --- ext/gtk+/pango.overrides 31 Jul 2005 10:14:44 -0000 1.7 +++ ext/gtk+/pango.overrides 25 Jun 2006 08:11:41 -0000 @@ -11,6 +11,10 @@ *_get_type %% +ignore + pango_tab_array_new_with_positions + +%% override pango_color_parse PHP_METHOD { @@ -70,3 +74,91 @@ ink.height, logical.x, logical.y, logical.width, logical.height); } + +%% +override pango_tab_array_new +PHP_METHOD +{ + zval *user_args = NULL, *php_first_alignment = NULL; + zval **position, **alignment; + PangoTabAlign first_alignment, current_alignment; + gint first_position = 0, i = 0, size = 0; + zend_bool positions_in_pixels = FALSE; + phpg_gboxed_t *pobj = NULL; + + if (ZEND_NUM_ARGS() > 2) { + if (!php_gtk_parse_varargs(ZEND_NUM_ARGS(), 3, &user_args, "bVi", &positions_in_pixels, &php_first_alignment, &first_position)) { + PHPG_THROW_CONSTRUCT_EXCEPTION(PangoTabArray); + } + } else { + if (!php_gtk_parse_args(ZEND_NUM_ARGS(), "|bVi", &positions_in_pixels, &php_first_alignment, &first_position)) { + PHPG_THROW_CONSTRUCT_EXCEPTION(PangoTabArray); + } + } + + if (php_first_alignment && phpg_gvalue_get_enum(PANGO_TYPE_TAB_ALIGN, php_first_alignment, (gint *)&first_alignment) == FAILURE) { + PHPG_THROW_CONSTRUCT_EXCEPTION(PangoTabArray); + } + + pobj = zend_object_store_get_object(this_ptr TSRMLS_CC); + pobj->gtype = PANGO_TYPE_TAB_ARRAY; + + if (ZEND_NUM_ARGS() < 3) { + pobj->boxed = pango_tab_array_new(size, positions_in_pixels); + } else if (ZEND_NUM_ARGS() == 3) { + size = 1; + pobj->boxed = pango_tab_array_new_with_positions(size, positions_in_pixels, first_alignment, first_position); + } else { + + if (zend_hash_num_elements(Z_ARRVAL_P(user_args)) % 2) { + php_error(E_WARNING, "PangoTabArray::new_with_positions(): argument list should consist of alignment/position pairs"); + PHPG_THROW_CONSTRUCT_EXCEPTION(PangoTabArray); + } + + size = (zend_hash_num_elements(Z_ARRVAL_P(user_args)) / 2) + 1; + pobj->boxed = pango_tab_array_new_with_positions(size, positions_in_pixels, first_alignment, first_position); + + zend_hash_internal_pointer_reset(Z_ARRVAL_P(user_args)); + while (zend_hash_get_current_data(Z_ARRVAL_P(user_args), (void **)&alignment) == SUCCESS) { + zend_hash_move_forward(Z_ARRVAL_P(user_args)); + zend_hash_get_current_data(Z_ARRVAL_P(user_args), (void **)&position); + zend_hash_move_forward(Z_ARRVAL_P(user_args)); + + if (phpg_gvalue_get_enum(PANGO_TYPE_TAB_ALIGN, *alignment, (gint *)&current_alignment) == FAILURE || Z_TYPE_PP(position) != IS_LONG) { + php_error(E_WARNING, "PangoTabArray::new_with_positions(): each alignment/position pair has to be PangoTabAlign/number"); + PHPG_THROW_CONSTRUCT_EXCEPTION(PangoTabArray); + } + + i++; + pango_tab_array_set_tab(pobj->boxed, i, current_alignment, Z_LVAL_PP(position)); + efree(*alignment); + efree(*position); + } + efree(user_args); + } + if (!pobj->boxed) { + PHPG_THROW_CONSTRUCT_EXCEPTION(PangoTabArray); + } + pobj->free_on_destroy = TRUE; +} + +%% +override pango_tab_array_get_tab +PHP_METHOD +{ + gint tab_index, location, size; + PangoTabAlign alignment; + + NOT_STATIC_METHOD(); + + if (!php_gtk_parse_args(ZEND_NUM_ARGS(), "i", &tab_index)) + return; + + size = pango_tab_array_get_size((PangoTabArray *)PHPG_GBOXED(this_ptr)); + if (tab_index >= size) { + PHPG_THROW_EXCEPTION(phpg_generic_exception, "PangoTabArray::get_tab(): the requested index is greater than the size of the array"); + } + + pango_tab_array_get_tab((PangoTabArray *)PHPG_GBOXED(this_ptr), tab_index, &alignment, &location); + php_gtk_build_value(&return_value, "(ii)", alignment, location); +}
« previous php.gtk.dev (#3161) next »