r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[!REBOL3 Extensions] REBOL 3 Extensions discussions

Maxim
8-Nov-2010
[1600x5]
this is what carl will be adding to the next host-kit.... 


//------------------
//-    #RXV_xxx
//
// REBOL EXTENSION GET Macros
//
// provide direct RXIARG access macros
// with these macros, the single argument should be an RXIARG *
//

// this is usefull when the RXIARG is NOT being used from an argument 
frame

// but as a single value, like when we use RL_Get_Field() or RL_Get_Value()
//
// if the argument is dynamically allocated, ex:
//    RXIARG arg = OS_MAKE(sizeof(RXIARG)); 
// then use the macros like so:
//     RXV_WORD(*(arg));
//------------------
#define RXV_INT64(a)		(a.int64)
#define RXV_INT32(a)		(i32)(a.int64)
#define RXV_INTEGER(a)	(a.int64) // maps to RXT_INTEGER
#define RXV_DEC64(a)		(a.dec64)
#define RXV_DECIMAL(a)	(a.dec64) // maps to RXT_DECIMAL
#define RXV_LOGIC(a)		(a.int32a)
#define RXV_CHAR(a)		(a.int32a)
#define RXV_TIME(a)		(a.int64)
#define RXV_DATE(a)		(a.int32a)
#define RXV_WORD(a)		(a.int32a)
#define RXV_PAIR(a)		(a.pair)
#define RXV_TUPLE(a)		(a.bytes)
#define RXV_SERIES(a)		(a.series)
#define RXV_BLOCK(a)		(a.series)
#define RXV_INDEX(a)		(a.index)
#define RXV_OBJECT(a)	(a.addr)
#define RXV_MODULE(a)	(a.addr)
#define RXV_HANDLE(a)	(a.addr)
#define RXV_IMAGE(a)		(a.image)
#define RXV_GOB(a)		(a.addr)
oh... sorry... posting this I just saw that the series don't use 
  .addr    but    .series

so you exxample would be:
//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);
                for (j = 0; j < strlen(item); ++j)
                    RL_SET_CHAR(s, j, item[i]);
                RL_SET_VALUE(b, i, arg, RXT_STRING);
            }
arrrhhh... sorry... darn CTRL-S got switched...
ignore above... not finished editing.
Andreas
8-Nov-2010
[1605]
Oldes, your number_options usage is wrong.
Oldes
8-Nov-2010
[1606x2]
it works:)
how?
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 ... :)