source q , odd number or arguments segfaults ?
| From: | Simon | Date: | Wed, 27 Jul 2005 16:38:53 +0000 |
| Subject: | source q , odd number or arguments segfaults ? | ||
| Groups: | php.gtk.dev | ||
| Request: | Send a blank email to php-gtk-dev+get-1476@lists.php.net to get a copy of this message | ||
Hi , this almost works , but since I am mostly a copy and paste artist , I really dont get whats up here ....
the below works , but only if the passed array is even in number .. e.g
$dialog->set_authors( array('Pinky','And', 'The', 'Brain' ) ) ;
works fine, but
$dialog->set_authors( array('Pinky', 'And' ,'The', 'Brain', 'doh') ) ;
segfaults ?
whyfor ??
I am sure it is something to do with this...
list = g_new( gchar *, len++ ) ;
which I do not think is doing what I thought itwas doing since the other problem is that the array needs to have at least 4 elements or it segfaults ~ BUT if I call set_artists() with an array of 4 strings THEN call set_authors() with just 2 strings then its ok ... set_artists & set_authors are essentially the same code only with different names.
e.g
$dialog->set_authors( array('Pinky' ,'And' ) ) ;
$dialog->set_artists( array('Pinky' ,'And' ,'The' , 'Brain' ) ) ;
segfaults , but
$dialog->set_artists( array('Pinky' ,'And' ,'The' , 'Brain' ) ) ;
$dialog->set_authors( array('Pinky' ,'And' ) ) ;
is fine
/**************************************************/
static PHP_METHOD(GtkAboutDialog, set_authors)
{
int len, i=0;
zval *php_list, **item;
const gchar **list;
NOT_STATIC_METHOD();
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/", &php_list) == FAILURE ) {
return;
}
len = zend_hash_num_elements(Z_ARRVAL_P(php_list));
list = g_new( gchar *, len++ ) ;
zend_hash_internal_pointer_reset(Z_ARRVAL_P(php_list));
while (zend_hash_get_current_data(Z_ARRVAL_P(php_list), (void **)&item) == SUCCESS) {
convert_to_string_ex( item ) ;
list[i++] = Z_STRVAL_PP( item ) ;
zend_hash_move_forward(Z_ARRVAL_P(php_list)) ;
}
gtk_about_dialog_set_authors( GTK_ABOUT_DIALOG(PHPG_GOBJECT(this_ptr)), list ) ;
g_free(list);
}
/**************************************************/
Regards,
Simon.