From: Marcelo M. <mm...@ac...> - 2006-01-19 23:27:30
|
Kevin Ruland wrote: > Marcelo Matus wrote: > >>> Excellent. I did have to stub the %set_constant method because >>> PHP's constant mechanism is type specific. I'm going to leave the >>> current implementation in place. BTW - the current PHP code >>> generator uses "consttab" typemaps - not the constcode typemaps used >>> in UTL. >> >> >> the consttab is really fragile, for that reason in the UTL we use >> the constcode. but, the >> transition is easy, in the current php module you must have some code >> that does the >> translation from consttab to real "const code", either inside >> php4.cxx or in the *.g files. > > > php4.cxx might be handling consttab differently than other modules. I > don't really know. Depending on the type of the constant, you need to > use different PHP methods to declare/define the constant. For > example, the const int a = 42; becomes: > > REGISTER_LONG_CONSTANT("a",42, 0, CONST_CS | CONST_PERSISTENT); > > There are different calls for DOUBLE and STRING constants as well. > > Is there a way to do this with the UTL? if you look at the php/const.i file, the last type has the code needed to define %set_constant, ie: %typemap(consttab) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] { // This actually registers it as a global variable and constant. I don't like it, but I can't figure out // the zend_constant code... zval *z_var; MAKE_STD_ZVAL(z_var); SWIG_SetPointerZval(z_var, (void*)$value, $1_descriptor, 0); //zend_hash_add(&EG(symbol_table), "$1", strlen("$1")+1, (void *)&z_var,sizeof(zval *), NULL); zend_constant c; c.value = *z_var; zval_copy_ctor(&c.value); size_t len = strlen("$1"); c.name = zend_strndup( "$1", len ); c.name_len = len+1; c.flags = CONST_CS | CONST_PERSISTENT; c.module_number = module_number; zend_register_constant( &c TSRMLS_CC ); } is just matter of replace zval *z_var; MAKE_STD_ZVAL(z_var); SWIG_SetPointerZval(z_var, (void*)$value, $1_descriptor, 0); with the proper argument I guess. Marcelo >>> >>> But this does bring up another question. The SWIG_AsVal( unsigned >>> long ) is identical in implemenation to SWIG_AsVal( long ) (PHP >>> doesn't have the unsigned distinction.) What magic incantation can >>> I use in order to not repeat the fragment? I'm trying this: >>> >>> %fragment( SWIG_AsVal_frag(unsigned long), "header", >>> fragment=SWIG_AsVal_frag(long) { >>> %define_as(SWIG_AsVal_dec(unsigned long), SWIG_AsVal_dec(long) >>> } >>> >> >> except you need to check for the sign. remember that php could not >> support the type, but C++ >> does it. So, just copy the same fragment for 'long' you have and add >> an extra line for checking >> if the number is possitive or not. >> >> > Yes, I thought of this just after sending the email. They are > different because of the little cast needed. > > > > ------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. Do you grep through log > files > for problems? Stop! Download the new AJAX search engine that makes > searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642 > _______________________________________________ > Swig-devel mailing list > Swi...@li... > https://lists.sourceforge.net/lists/listinfo/swig-devel |