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

World: r3wp

[!REBOL3 Extensions] REBOL 3 Extensions discussions

jocko
8-Nov-2010
[1583]
Maxim, yes, I have seen bindings to other languages, but I am still 
not convinced that its much simpler than coding directly in C or 
C++

Oldes, I did not know im-min.r. It's a nice work. I have not enough 
experience in Extensions to do such work, as the input-output methods 
of R3 extensions are a little tricky.
Maxim
8-Nov-2010
[1584x3]
the images are pointers, so the data doesn't need to be copied if 
you are just manipulating it.   though it seems there was some image 
bugs in the A107 (not sure where) which AFAIK are fixed but not yet 
released in current host-kit (cyphre knows for sure).
the images are pointers
 ....   more precisely:  


R3 image! datatypes are pointers in the extension, so you can access 
them as arrays directly.
though it does require usually thread safety and might require GC 
protection depending on what you are doing.
Oldes
8-Nov-2010
[1587]
How to free the extension?
Maxim
8-Nov-2010
[1588]
AFAIK we can't currently unload extensions.  


The extension interface actually is designed to support it, but right 
now, I think its never called and there is no way to trigger it from 
the REBOL code AFAIK.
Oldes
8-Nov-2010
[1589x4]
What I'm doing wrong here:
//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)    {
                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, s, RXT_STRING);
            }
but with error:

wand.c:81: error: incompatible type for argument 3 of indirect function 
call
where line 81 is:  RL_SET_VALUE(b, i, s, RXT_STRING);
Maxim
8-Nov-2010
[1593x2]
you should be using RL_SET_CHAR for starters...
oh sorry... you are  ;-)
Oldes
8-Nov-2010
[1595]
it requires RXIARG but how to get it from the REBSER?
Maxim
8-Nov-2010
[1596x9]
hehe I was going to say it required RXIARG.
REBSER is a type of RXIARG, you build the RXIARG like so:
RXIARG arg;
arg.addr = s;


in the next host-kit version, Carl will be adding macros for this 
exact situation... an oversight of his.
note that when you provide the arg, you must then give it directly 
using: 

RL_SET_VALUE(b, i, arg, RXT_STRING);
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.