World: r3wp
[!REBOL3 Extensions] REBOL 3 Extensions discussions
older newer | first last |
Andreas 8-Nov-2010 [1608] | Should be: unsigned long number_options; MagickQueryConfigureOptions("*", &number_options); REBSER *b = RL_MAKE_BLOCK(number_options); |
Maxim 8-Nov-2010 [1609x3] | //I want: char **MagickQueryConfigureOptions(const char *pattern, unsigned long *number_options) //I have: unsigned long *number_options; char *item; char **list = MagickQueryConfigureOptions("*",number_options); REBSER *b = RL_MAKE_BLOCK(*number_options); RXA_SERIES(frm, 1) = b; RXA_INDEX(frm, 1) = 0; RXA_TYPE(frm, 1) = RXT_BLOCK; int i,j; for(i=0; i<*number_options; ++i) { RXIARG arg; item = list[i]; REBSER *s = RL_MAKE_STRING(strlen(item), 0); arg.series = s; for (j = 0; j < strlen(item); ++j) RL_SET_CHAR(s, j, item[i]); RL_SET_VALUE(b, i, arg, RXT_STRING); } |
hehe, yeah andreas... good catch. :-) | |
Oldes, without changes given by andreas, you will corrupt the executable's memory and will *eventually* have a memory acces failure. | |
Andreas 8-Nov-2010 [1612] | and of course `for (i=0; i<number_options; ++i)` as well |
Oldes 8-Nov-2010 [1613] | Just in the resuted string I'm missing first char |
Maxim 8-Nov-2010 [1614] | does j++ change anything? |
Andreas 8-Nov-2010 [1615] | you are missing the first character in all returned strings? |
Oldes 8-Nov-2010 [1616x3] | yes |
(now I'm missing all, don't know why:) | |
I must go to sleep, that's the sign:) | |
Maxim 8-Nov-2010 [1619] | post your current version so we might find a little typo... |
Oldes 8-Nov-2010 [1620] | unsigned long number_options; char *item; char **list = MagickQueryConfigureOptions("*",&number_options); REBSER *b = RL_MAKE_BLOCK(number_options); RXA_SERIES(frm, 1) = b; RXA_INDEX(frm, 1) = 0; RXA_TYPE(frm, 1) = RXT_BLOCK; int i,j; for(i=0; i<number_options; ++i) { RXIARG arg; item = list[i]; REBSER *s = RL_MAKE_STRING(strlen(item), 0); arg.series = s; for (j = 0; j < strlen(item); ++j) RL_SET_CHAR(s, j, item[i]); RL_SET_VALUE(b, i, arg, RXT_STRING); } |
Andreas 8-Nov-2010 [1621x2] | RL_SET_CHAR(s, j, item[i]); make that RL_SET_CHAR(s, j, item[j]); |
J instead of I | |
Oldes 8-Nov-2010 [1623x2] | Isn't it possible to debug it somehow? |
Still empty. | |
Andreas 8-Nov-2010 [1625] | That was a definitive bug. |
Maxim 8-Nov-2010 [1626] | the reason I use c and n for counters ;-) |
Andreas 8-Nov-2010 [1627] | The remaining bug will be somewhere in the interaction betweein RXIARG, arg.series and RL_SET_VALUE. |
Maxim 8-Nov-2010 [1628x5] | I'd start by printing the length of item... just to be sure its not the input which is the problem. RL_Print("%d, %s", i, list[i]); |
add a little newline there... RL_Print("%d, %s\n", i, list[i]); | |
also make sure you ASSIGN the return value of the command, as it may be garbage collected otherwise. but depending on the rebol code, this might not be the issue... its just good practice. | |
I think I found the bug. it could have worked earlier with your other memory access issues but will not work anymore. RXA_INDEX(frm, 1) = 0; AFAIK this effectively erases the assignment of: RXA_SERIES(frm, 1) = b; | |
darn, ignore the above. I think I'm tired... I continued searching the C code, and posted too quickly. | |
Oldes 9-Nov-2010 [1633x4] | I cannot use RL_print --> undefined reference to `_imp__RL_Print' btw.. here is my current (not working) version with (I hope all required files) - http://box.lebeda.ws/~hmm/temp/ext-wand.zip |
I can say, that the **list is filed correctly because when I for example use at the tail: REBSER *s = RL_MAKE_STRING(strlen(list[2]), 0); for (c = 0; c< strlen(list[2]); ++c) RL_SET_CHAR(s, c, list[2][c]); RXA_SERIES(frm, 1) = s; RXA_INDEX(frm, 1) = 0; RXA_TYPE(frm, 1) = RXT_STRING; return RXR_VALUE; I get the correct list[2] value. | |
The problem is with the block value definition. | |
Ok, so simple question, how to return a block with one string inside? | |
Maxim 9-Nov-2010 [1637x2] | using above code as reference... RXA_SERIES(frm, 1) = b; RXA_INDEX(frm, 1) = 0; // AFAIK this is 0 by default. RXA_TYPE(frm, 1) = RXT_BLOCK; return RXR_VALUE; |
obviously, you need to have set the first value of the block to a string. | |
Andreas 9-Nov-2010 [1639] | And then you've got to properly construct the block in b :) |
BrianH 9-Nov-2010 [1640] | And the string? |
Oldes 9-Nov-2010 [1641] | Maxim, the setting of the string value of the block is actually my problem and that's why I'm asking. I can even return block with empty strings:) So I should extend my queastion to return block with non emptz string:) |
Andreas 9-Nov-2010 [1642x2] | https://gist.github.com/0c6305d7c25e40742b31 |
This contains a minimal extension that returns a block containing a string. | |
Oldes 9-Nov-2010 [1644] | Is this working for you? Because with your code I get empty string inside as well. |
Andreas 9-Nov-2010 [1645x2] | Works for me, yes. |
What hostkit do you use? A110? | |
Oldes 9-Nov-2010 [1647] | yes |
Andreas 9-Nov-2010 [1648x2] | Ok, let me check what I use :) |
A110 to run, A107 to build. Well ... :) | |
Oldes 9-Nov-2010 [1650] | How can I get A107? Also you are on Linux, aren't you? |
Andreas 9-Nov-2010 [1651] | Yes, give me a minute. I'll check a full A110 on Windows. |
Oldes 9-Nov-2010 [1652] | oh.. it's too late here. I give you all day:) Thanks. |
Andreas 9-Nov-2010 [1653] | Does work for me on Linux A110, does not work for me on Win32 A110 either. |
Maxim 9-Nov-2010 [1654x2] | hum... so RL_SET_VALUE has bug in the A110 host-kit... |
but RL_GET_VALUE is working fine... this is strange. | |
Andreas 9-Nov-2010 [1656] | Interesting. Seems to make a difference whether I run a script which imports the extension or import the extension from the command line. |
Maxim 9-Nov-2010 [1657] | I had that reaction when I had an unstable CGR host-kit. |
older newer | first last |