[Kde-bindings] KDE/kdebindings
Thomas Moenicke
tm at php-qt.org
Sun Jul 20 15:14:28 UTC 2008
SVN commit 835432 by moenicke:
* added marshaller for char**
* simplified marshaller for IntR
* fixed marshaller for QStringList, tested with QCoreApplication::arguments()
* added linker symbol to the symbol list for building on MacOS
CCMAIL:: kde-bindings at kde.org
M +1 -0 cmake/modules/FindPHP5.cmake
M +119 -79 php/phpqt/src/handlers.cpp
--- trunk/KDE/kdebindings/cmake/modules/FindPHP5.cmake #835431:835432
@@ -117,6 +117,7 @@
__array_init
__zend_hash_init
__zval_ptr_dtor_wrapper
+__zval_dtor_func
)
SET(CMAKE_SHARED_MODULE_CREATE_C_FLAGS
"${CMAKE_SHARED_MODULE_CREATE_C_FLAGS},-U,${symbol}")
--- trunk/KDE/kdebindings/php/phpqt/src/handlers.cpp #835431:835432
@@ -196,9 +196,44 @@
m->unsupported();
}
-static void marshall_charPP(Marshall *m) {
- m->item().s_voidp = transformArray(m->var());
- m->next();
+static void marshall_charPP(Marshall *m)
+{
+ switch( m->action() )
+ {
+ case Marshall::FromZVAL:
+ {
+ zval* arglist = m->var();
+ if( arglist == NULL || arglist->type != IS_ARRAY || zend_hash_num_elements( arglist->value.ht ) == 0 )
+ {
+ m->item().s_voidp = 0;
+ break;
+ }
+ const int argc = zend_hash_num_elements( arglist->value.ht );
+ char** argv = new char* [ argc + 1 ];
+ HashTable *ht = arglist->value.ht;
+ long i = 0;
+ for( zend_hash_internal_pointer_reset( ht ); zend_hash_has_more_elements( ht ) == SUCCESS; zend_hash_move_forward( ht ) )
+ {
+ zval** value, tmpcopy;
+ if( zend_hash_get_current_data( ht, (void**) &value ) == FAILURE )
+ {
+ qDebug() << "invalid list element in argv/char**";
+ continue;
+ }
+ tmpcopy = **value;
+ zval_copy_ctor( &tmpcopy );
+ convert_to_string( &tmpcopy );
+ argv[ i ] = new char[ Z_STRLEN(tmpcopy) + 1 ];
+ strcpy( argv[ i ], Z_STRVAL(tmpcopy) );
+ zval_dtor( &tmpcopy );
+ i++;
+ }
+ argv[ i ] = 0;
+ m->item().s_voidp = argv;
+ m->next();
+ break;
+ }
+ }
}
static void marshall_charP(Marshall *m) {
@@ -314,95 +349,100 @@
}
}
-static void marshall_IntR(Marshall *m) {
- int* n = new int;
- *n = Z_LVAL_P(m->var());
- m->item().s_voidp = n;
- m->next();
- // walking down the stack
- // TODO could be stored in a list and deleted when shutting down the engine
-// delete n;
+static void marshall_IntR(Marshall *m)
+{
+
+ switch( m->action() )
+ {
+ case Marshall::FromZVAL:
+ {
+ m->item().s_voidp = &( Z_LVAL_P( m->var() ) );
+ break;
+ }
+ case Marshall::ToZVAL:
+ {
+ // TODO test me
+ int *ip = (int*) m->item().s_voidp;
+ m->var()->value.lval = *ip;
+ }
+ }
}
-static void marshall_QStringList(Marshall* m) {
-
- switch( m->action() ) {
- case Marshall::FromZVAL:
- {
- QStringList* stringList = new QStringList;
- zval* list = m->var();
+static void marshall_QStringList(Marshall* m)
+{
+ switch( m->action() )
+ {
+ case Marshall::FromZVAL:
+ {
+ QStringList* stringList = new QStringList;
+ zval* list = m->var();
char* assocKey;
ulong numKey;
- if ( list->type != IS_ARRAY ) {
- m->item().s_voidp = 0;
- break;
- }
- HashTable* list_hash = HASH_OF( list );
- zval **list_iterator;
- zend_hash_internal_pointer_reset( list_hash );
- while( zend_hash_has_more_elements( list_hash ) == SUCCESS )
- {
- zend_hash_get_current_key( list_hash, &assocKey, &numKey, 0 );
- zend_hash_get_current_data( list_hash, (void**) &list_iterator );
- if( (*list_iterator)->type == IS_STRING )
- stringList->append( Z_STRVAL_PP( list_iterator ) );
- else if ( (*list_iterator)->type == IS_OBJECT ) {
- smokephp_object* o = PHPQt::getSmokePHPObjectFromZval( (*list_iterator) );
- if( o && o->classId() == QSTRING_CLASSID )
- {
- QString* s = reinterpret_cast< QString*> ( o->mPtr() );
- stringList->append( *s );
- } else {
- pNotice() << "unsupported class " << o->className() << "in QStringList";
- }
- }
- zend_hash_move_forward( list_hash );
- }
+ if ( list->type != IS_ARRAY ) {
+ m->item().s_voidp = 0;
+ break;
+ }
+ HashTable* list_hash = HASH_OF( list );
+ zval **list_iterator;
+ zend_hash_internal_pointer_reset( list_hash );
+ while( zend_hash_has_more_elements( list_hash ) == SUCCESS )
+ {
+ zend_hash_get_current_key( list_hash, &assocKey, &numKey, 0 );
+ zend_hash_get_current_data( list_hash, (void**) &list_iterator );
+ if( (*list_iterator)->type == IS_STRING )
+ stringList->append( Z_STRVAL_PP( list_iterator ) );
+ else if ( (*list_iterator)->type == IS_OBJECT ) {
+ smokephp_object* o = PHPQt::getSmokePHPObjectFromZval( (*list_iterator) );
+ if( o && o->classId() == QSTRING_CLASSID )
+ {
+ QString* s = reinterpret_cast< QString*> ( o->mPtr() );
+ stringList->append( *s );
+ } else {
+ pNotice() << "unsupported class " << o->className() << "in QStringList";
+ }
+ }
+ zend_hash_move_forward( list_hash );
+ }
- m->item().s_voidp = stringList;
- m->next();
+ m->item().s_voidp = stringList;
+ m->next();
- // it might be changed if not const
+ // it might be changed if not const
if ( stringList != 0 && !m->type().isConst() ) {
- array_init( list );
+ array_init( list );
for(QStringList::Iterator it = stringList->begin(); it != stringList->end(); ++it)
- add_next_index_string( list , const_cast<char*>( (*it).toLatin1().constData() ), 0 );
+ add_next_index_string( list , (*it).toLatin1().data(), 0 );
}
+ if (m->cleanup()) {
+ delete stringList;
+ }
+ break;
+ }
+ case Marshall::ToZVAL:
+ {
+ QStringList *stringlist = static_cast<QStringList *>( m->item().s_voidp );
+ if ( !stringlist ) {
+ *(m->var()) = *Qnil;
+ break;
+ }
+ // TODO linking QStringList
+ zval* av;
+ MAKE_STD_ZVAL( av );
+ array_init( av );
+ for (QStringList::Iterator it = stringlist->begin(); it != stringlist->end(); ++it) {
+ add_next_index_string( av, estrdup( (*it).toAscii().data() ), 0 );
+ }
+ *(m->var()) = *av;
if (m->cleanup()) {
- delete stringList;
+ delete stringlist;
}
+ }
+ break;
+ default:
+ m->unsupported();
break;
- }
- case Marshall::ToZVAL:
- {
- QStringList *stringlist = static_cast<QStringList *>( m->item().s_voidp );
- if ( !stringlist ) {
- *(m->var()) = *Qnil;
- break;
- }
-
- // TODO linking QStringList
- zval* av;
- ALLOC_HASHTABLE( av->value.ht );
- zend_hash_init( av->value.ht, 0, NULL, ZVAL_PTR_DTOR, 0 );
- for (QStringList::Iterator it = stringlist->begin(); it != stringlist->end(); ++it) {
- add_next_index_string( av, const_cast<char*> ( (*it).toAscii().constData() ) , 1 );
- }
-
- *(m->var()) = *av;
-
- if (m->cleanup()) {
- delete stringlist;
- }
-
-
- }
- break;
- default:
- m->unsupported();
- break;
- }
+ }
}
TypeHandler Qt_handlers[] = {
More information about the Kde-bindings
mailing list