help request: php array

php.internals

netcat

22 years ago
Hi internals. After looking at "Zend/zend_hash.h" e.t.c and haven't realizing how should i do that,i'm asking for your help. It should be really simple for you .... Have the following function: it should recursively convert data from rep_XXX to php data It does that for string and numbers for now. It's time to ad an array and hash. The question is near "???". (and another one - how this would look like for adding hash elements (excluding the rep_XXX stuff of course)) int rep_data_converter(repv in,zval *return_value) { if(rep_STRINGP(in)) { //printf("REP Will return string\n"); RETVAL_STRING (rep_STR(in),1); return 1; } if(rep_INTP(in)) { RETURN_LONG (rep_INT(in)); return 1; } if(rep_LONG_INTP(in)) { RETURN_LONG (rep_LONG_INT(in)); return 1; } // hadle array if(rep_CONSP(in)) { zval php_array; //zend_hash_init(&php_array,100, repv i,t; for(i=in;i!=Qnil;i=rep_CDR(i)) { printf("REP FWD to next element\n"); rep_data_converter(rep_CAR(i),&t); /* ??? add t to array php_array */ } } RETVAL_STRING("REP: Unsupported type yet\n",1); return 0; } Thanks in advance.
-- NetCat -------------------------------------------------- FREE 10MB Email + Antivirus + POP3 + more... Get it at http://www.doal.co.il:81/free/?c=antivirus

Wez Furlong

22 years ago
Try something like this: if (rep_CONSP(in)) { array_init(return_value); /* sets it up as an array */ for (i = in; i != Qnil; i = rep_CDR(i)) { zval *tmp; MAKE_STD_ZVAL(tmp); rep_data_converter(rep_CAR(i), tmp); add_next_index_zval(return_value, tmp); /* equivalent to $ret[] = $tmp */ } }

netcat

22 years ago
Wez Furlong wrote:
>Try something like this: > >if (rep_CONSP(in)) { > array_init(return_value); /* sets it up as an array */ > > for (i = in; i != Qnil; i = rep_CDR(i)) { > zval *tmp; > > MAKE_STD_ZVAL(tmp); > rep_data_converter(rep_CAR(i), tmp); > add_next_index_zval(return_value, tmp); /* equivalent to $ret[] = $tmp >*/ > } >} > > > > >> if(rep_CONSP(in)) { >> zval php_array; >> //zend_hash_init(&php_array,100, >> repv i,t; >> for(i=in;i!=Qnil;i=rep_CDR(i)) { >> printf("REP FWD to next element\n"); >> rep_data_converter(rep_CAR(i),&t); >> /* ??? add t to array php_array */ >> } >> } >> >> > > > > >
I guess it almost works : if(rep_CONSP(in)) { repv i; for(i=in;i!=Qnil;i=rep_CDR(i)) { zval *t; MAKE_STD_ZVAL(t); printf("REP FWD to next element PT1\n"); rep_data_converter(rep_CAR(i),t); printf("REP FWD to next element PT2\n"); add_next_index_zval(return_value, t); printf("REP FWD to next element PT3\n"); /* ??? add t to array() */ } } ---8<--- REP FWD to next element PT1 REP FWD to next element PT2 rep: received fatal signal: Segmentation fault struct debug_buf common: Backtrace in `fatal_signal_handler': <(null)+1107463240> <add_next_index_zval+28> <rep_data_converter+215> <zif_rep_eval+201> <execute+7234> <zend_execute_scripts+107> <php_execute_script+316> <main+1629> Lisp backtrace: Segmentation fault ---8<--- Is that rep's or php's problem? May be t should be duplicated? If yes, how?
-- NetCat ------------------------------------------------------ SPAM-Free 10mb Free email + Antivirus + POP3 + more... Get it at http://www.doal.co.il:81/free/?c=all-spam

Wez Furlong

22 years ago
That backtrace isn't useful (running windows?) Try a debug build, under unix if you have access to it. Chances are that it is your code that is at fault :-) --Wez.

netcat

22 years ago
Wez Furlong wrote:
>That backtrace isn't useful (running windows?) > >
Yuck... never... windows cannot (must not) live outside VmWare :)
>Try a debug build, under unix if you have access to it. > >
Will look for that. How fast it became not nice to me ....
>Chances are that it is your code that is at fault :-) > >
It's 99.9%. The question should be rephrased: I work wrong with PHP code or I work wrong with REP code ? Thanks a lot.
>--Wez. > > > >>Backtrace in `fatal_signal_handler': >> <(null)+1107463240> >> <add_next_index_zval+28> >> <rep_data_converter+215> >> <zif_rep_eval+201> >> <execute+7234> >> <zend_execute_scripts+107> >> <php_execute_script+316> >> <main+1629> >> >>Lisp backtrace: >> >>Segmentation fault >>---8<--- >> >>Is that rep's or php's problem? >>May be t should be duplicated? >>If yes, how? >> >> > > >
-- NetCat --------------------------------------------------- FREE 10MB Email + AntiSpam + POP3 + more. Get it at http://www.doal.co.il:81/free/?c=antispam

netcat

22 years ago
Wez Furlong wrote:
>That backtrace isn't useful (running windows?) >Try a debug build, under unix if you have access to it. > >Chances are that it is your code that is at fault :-) > >
Yep. It looked strange to me adding items to zval without even mentioning it's array. So I looked in other places .... array_init(return_value); solved the problem. Than i looked back into your letter. I just missed this one in your letter,sorry.... Thanks again.
>--Wez. > > > >>Backtrace in `fatal_signal_handler': >> <(null)+1107463240> >> <add_next_index_zval+28> >> <rep_data_converter+215> >> <zif_rep_eval+201> >> <execute+7234> >> <zend_execute_scripts+107> >> <php_execute_script+316> >> <main+1629> >> >>Lisp backtrace: >> >>Segmentation fault >>---8<--- >> >>Is that rep's or php's problem? >>May be t should be duplicated? >>If yes, how? >> >> > > >
-- NetCat --------------------------------------------------- FREE 10MB Email + AntiSpam + POP3 + more. Get it at http://www.doal.co.il:81/free/?c=antispam