mypeb
mypeb copied to clipboard
arrays and strings/numbers
We have ones issue with this erlang bridge since it was invented, but today I've found this fork so I thought maybe I just post my issue again.
The problem occurs when the erlang server returns an array with numbers lower than 128. Then these numbers are converted to one single string. E.g. array {1,2,3,4,5} will not returned as an array, but instead it appears like a string with "char(1)+char(2)+char(3)" and so on. Not sure if this is intended, or can be fixed in any other way.. for us it is enough to just not decode it as string.
A fix for this is the following code (basically in _peb_decode case "ERL_STRING_EXT" I convert everything into an array):
case ERL_STRING_EXT:
buff = emalloc( size + 1 );
ei_decode_string( x->buff, & x->index, buff );
buff[ size ] = '\0';
// ZVAL_STRING(z, buff, 0);
array_init( z );
zval * z2;
for(i=0;i<size;i++)
{
#ifdef DEBUG_PRINTF
php_printf("%d / %d: %d (%c)\n",i,size,buff[i],buff[i]);
#endif
ALLOC_INIT_ZVAL(z2);
ZVAL_LONG(z2, buff[i]);
add_next_index_zval( z, z2);
}
add_next_index_zval( htable, z);
break;
patch for the current master branch:
# diff peb-old.c peb.c
1110c1110,1124
< ZVAL_STRING(z, buff, 0);
---
>
> // ZVAL_STRING(z, buff, 0);
> array_init( z );
>
> zval * z2;
> for(i=0;i<size;i++)
> {
> #ifdef DEBUG_PRINTF
> php_printf("%d / %d: %d (%c)\n",i,size,buff[i],buff[i]);
> #endif
> ALLOC_INIT_ZVAL(z2);
> ZVAL_LONG(z2, buff[i]);
> add_next_index_zval( z, z2);
> }
>
Maybe it's helpful for someone.
cheers, Simon