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

World: r3wp

[Core] Discuss core issues

Pekr
9-Nov-2006
[6149x2]
so it should work correctly, expecting zero terminator in C level?
maybe it would be better to see your wrapper
Maxim
9-Nov-2006
[6151]
hum... I think I understand something... because the call, is not 
returning a string!, but filling up a buffer, REBOL has no means 
to know that it should fix the string! and resize it to the zero 
terminator, right?
Graham
9-Nov-2006
[6152x2]
don't  you define in your wrapper call what the function returns?
You don't pass a string as a bit of memory to be filled ...
Maxim
9-Nov-2006
[6154x2]
yes it returns success, but fills up the buffer I send it... it does 
not return the buffer itself...
well many C calls expect a buffer as an argument... what's the prefered 
method then?
Pekr
9-Nov-2006
[6156x2]
it would be good to see original C function spec. Because - e.g. 
when I was wrapping one function (trying to investigate red-icons 
problem IIRC), the function was clearly expecting chars (certain 
amount), but it did not work, untill Ladislav came in and changed 
it to struct for that part of function.
I just hope, that for R3, more automatic wrapping will be possible.
Maxim
9-Nov-2006
[6158x3]
yeah... like .h file loading ;-)  we can always dream  ;-)
my routine spec:

		username: make routine! [
			"Get the current logon name of thread which launched REBOL"
			buffer [char*]
			count [string!]
			return: [integer!]
		] libinfo "GetUserNameA"
C spec:

BOOL GetUserName(
  LPTSTR lpBuffer,
  LPDWORD lpnSize
);
Gabriele
9-Nov-2006
[6161]
about [<] - I think I have reported the problem like 5 years ago. 
In my scripts I use to lit-word! "<".
Pekr
9-Nov-2006
[6162]
is double word correctly specified as a string? (count). Should not 
it be an integer?
Rebolek
9-Nov-2006
[6163]
Five years ago? OK, why do I care:)))
Maxim
9-Nov-2006
[6164x2]
pekr:  its actually a word pointer  and  MS example look like so:
GetUserName( infoBuf, &bufCharCount )
which is why I supplied a string, so that the get user name would 
receive a pointer instead of a number.
Pekr
9-Nov-2006
[6166]
pointer is a number
Maxim
9-Nov-2006
[6167]
&bufCharCount  asks to get the pointer to the word, not the value 
of the word... no?
Pekr
9-Nov-2006
[6168x2]
what about trying putting struct instead of buffer [char] in there? 
:-), with first element being a string? Struct itself will be represented 
as a pointer
well, maybe better wait for someone like Ladislav or Anton or Gabriele 
or anyone else more experience than me. I always work by guess, try, 
change aproach, till it works (or it does not :-))
Maxim
9-Nov-2006
[6170]
just one question, how many bytes is a double word (in MS) supposed 
to have 4 or 8?
Pekr
9-Nov-2006
[6171x3]
16?
sorry, mixed bytes and bits :-)
bit, byte=8bit, nibble=4bit, word=32bit=4bytes, double=64bit=8bytes?
Maxim
9-Nov-2006
[6174]
k thanks, just wanted to confirm.. I've just not been thinking in 
those terms for soo long.
Pekr
9-Nov-2006
[6175x2]
my friend suggests me, that it can't be said - it depends upon platform. 
Typically it is good to use sizeo(word) to get the idea ...
sizeof
Maxim
9-Nov-2006
[6177]
I think that is more a problem with the use of int and long.
Pekr
9-Nov-2006
[6178]
try wikipedia - some good entries there ...
Maxim
9-Nov-2006
[6179x2]
but... anyhow... thanks... by chatting with you I realized why my 
string was staying at 0 length, while its actually filled with the 
data.
yesss... I do more and more... computer sciences are very well explained 
on it.
Pekr
9-Nov-2006
[6181]
so what actuall you realized?
Maxim
9-Nov-2006
[6182x6]
string! have an internal size and an external size.  using a string 
within rebol, will always update the size, so that it returns the 
current amount of the string! which has been "filled"
which is why 
>>  make string 100
== {}
internally, its 100 bytes long, but externally, it hasn't been filled 
so its still length? 0
now the external call dumps chars directly in the string and add 
a null termination.
but obviously, since REBOL didn't fill it... it still thinks it length? 
0  ... but its internal buffer really does contain data!
so prefilling the string to 100 chars of anything, will at least 
allow you to acces the whole buffer afterwards...
Pekr
9-Nov-2006
[6188x2]
there are two cases - when external function returns string and expects 
your struct for it, and second, when external function allocates 
its own buffer and provides you with a pointer
that is strange a bit then .... feels like close to cause a crash 
:-)
Maxim
9-Nov-2006
[6190x3]
yep, but in a case where rebol returns the value, its smart enough 
to look it up and find the null terminator for you  :-)
and adjust the external size counter.
in this case, rebol never really manipulates the string...
Pekr
9-Nov-2006
[6193]
well, that's true - doing make string! 100 does not mean length? 
should return 100 .... maybe we should have size-of?
Maxim
9-Nov-2006
[6194x2]
all I need to do is :
value: copy/part  buf  find  buf  #"^@"
good idea!
Pekr
9-Nov-2006
[6196]
wouldn't it be enought to just value: copy buff?
Maxim
9-Nov-2006
[6197]
hum... nope, tried it, it copies the whole string past the terminator... 
and it actually should, otherwise we could not parse binary data...
Ladislav
9-Nov-2006
[6198]
Max: to-logic "false" how about using something like to-logic "1 
+ 3 < 2" then?