• Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r4wp

[#Red] Red language group

kensingleton
7-Jul-2013
[9362]
I am trying to learn Red/System but I have a strange result. When 
I enter this code all works fine, the input line is printed correctly:

#import [
	LIBC-File cdecl [
		get-line: "gets" [
			line	[c-string!]
			return:	[c-string!]
		]
	]
]

foo: ""
get-line foo            ; when run I enter: this is a test
print newline
print foo                  ; Correctly outputs: this is a test


but if I do this;

foo: ""
boo: ""
get-line foo          ; when run I enter: this is a test
boo: foo
print newline
print boo

then I get             ; "thisX @"

or if I enter: hello
it prints out: hellX @


It seems that something in the process of binding foo to boo is messing 
up, but I have no clue what it might be.
Any ideas?
DocKimbel
7-Jul-2013
[9363]
gets() requires you to allocate a buffer of adequate size. Empty 
c-string! literals ("") will statically allocate an empty string, 
unsuitable for use with gets(), resulting in buffer overflows ('boo 
is allocated just after 'foo). Try rather: 

foo:  allocate 100
boo: allocate 100


This will dynamically allocate 100 bytes for each c-string!. You 
need to ensure that gets() won't overflow those buffers (which in 
practice is impossible, so one should just avoid using gets() in 
production code).
kensingleton
7-Jul-2013
[9364x2]
Thanks Doc. What then would your recommend for getting console input 
into Red/System if not gets()?
The allocate did not work because of a type mismatch but using long 
empty string literals did.
DocKimbel
7-Jul-2013
[9366]
Have a look the Red/Sysme parts of Red's console:

https://github.com/dockimbel/Red/blob/master/red/tests/console.red


These are not the only ways to securely read inputs from user, fgets() 
is the main safe alternative:

http://stackoverflow.com/questions/4309746/safe-alternative-to-gets
kensingleton
7-Jul-2013
[9367]
Thanks Doc.
DocKimbel
7-Jul-2013
[9368]
Type mismatch: you can fix it easily with a simple type casting and 
proper string initialization.

foo: as c-string! allocate 100
boo: as c-string! allocate 100
kensingleton
7-Jul-2013
[9369]
Great, thanks Doc, worked a treat!
Kaj
7-Jul-2013
[9370x2]
Here is the first Red/System driver, a minimal Hello World kernel 
driver for Windows:
Red/System []

#import ["ntoskrnl.exe" stdcall [

 log-error: "DbgPrint" [				"Print formatted message to debug log."
		[variadic]
		; format		[c-string!]
		;	value		[variant!]
		;	...
	]
]]

on-load: function ["DriverEntry"
	DriverObject	[driver-object!]
	RegistryPath 	[byte-ptr!]
	return:			[integer!]
][
	log-error "Hello Red/System from Windows kernel driver!"
	0
]
Bo
7-Jul-2013
[9372]
Great news!
Paul
9-Jul-2013
[9373]
Can the RED compiler generate PDB files?
Pekr
9-Jul-2013
[9374x2]
So, I gave my new BeagleBone Black (BBB) a quick test. With latest 
Arngstrom Linux, I was able to upload Red ARM tests (generated using 
%build-arm-tests.r). All tests pass, except %function-test, which 
crashes with Runtime Error 1: Access violation ....
The above mentioned script also fails at it tries to make a directory. 
Maybe it needs make-dir/deep %runnable/arm-tests, or simply to remove 
%runnable ....
Kaj
9-Jul-2013
[9376]
Doc said PDB is undocumented and too complex
Paul
9-Jul-2013
[9377]
I didn't know it wasn't documented.
Kaj
9-Jul-2013
[9378]
Early results were that PE format is less complex than ELF, but if 
you count in debug extensions, it's the other way around
Paul
9-Jul-2013
[9379]
I have a technet subscription so I'm combing the database right now.
Pekr
9-Jul-2013
[9380]
Ah, just found out, that above access violation is present even with 
Windows version of the function-test.exe
Kaj
9-Jul-2013
[9381]
I think Doc would be interested
DocKimbel
9-Jul-2013
[9382x2]
Function-test: it's a test that rely on unimplemeted feature that 
cause the crash, it should be disabled until  we get that supported.
PDB Paul if you can get me all the required documentation, I'll be 
glad to add PDB generation to Red toolchain.
Pekr
9-Jul-2013
[9384]
OK, got news posted to FB profile anyway ;-)
DocKimbel
9-Jul-2013
[9385]
Pekr: does the Red console works fine on the BeagleBone?
Paul
9-Jul-2013
[9386]
Does look to be a bit closely guarded but here are some links that 
may get you going for PDB output  -> http://ccimetadata.codeplex.com/wiki/search?tab=Home&SearchText=pdb
DocKimbel
9-Jul-2013
[9387]
You could cross-post it also on the Red ML and Tweeter (I'll retweet 
it).
Paul
9-Jul-2013
[9388x2]
Is there a RD
Sorry a RED Facebook?
Pekr
9-Jul-2013
[9390x3]
DocKimbel - so I tried it, and yes, it works ...
As for news channels - if there is anything new, and my time and 
skills permit, I do post. It is a pity, it is not reposted to your 
blog, it looks really dated with latest 0.3.2 Repl release :-( I 
find it a bad strategy, the project seems a bit stalled, at least 
Git get propagated there ....
as for Red ML, AFAIK, I am not there ... Any activity there?
DocKimbel
9-Jul-2013
[9393]
Paul: no much usable info there it seems. What I really need is a 
PDB file specification.
Pekr
9-Jul-2013
[9394]
Doc - I noticed Carl mentioned he is getting BBB for his HW purposes. 
When you will try to hook him into Red, just mention, that we are 
already there too :-)
DocKimbel
9-Jul-2013
[9395x2]
There are Twitter and Github for day to day news.
Pekr: will do. ;-)
Pekr
9-Jul-2013
[9397]
FB has component to display news, twitter too. As for FB, I would 
not put it into your website, but maybe twitter could be corrected
DocKimbel
9-Jul-2013
[9398]
If you think about the Twitter plugins on Blogger, they seem all 
dead. Anyway, I would be glad to get rid of Blogger and switch to 
something else, Blogger is horribly bad and outdated.
Pekr
9-Jul-2013
[9399x2]
Well, it works, no? Not sure what other blogging sites/domains are 
available. Twitter kind of removed possibility to freely display 
content via JS code. You can do it, but inside your twitter profile, 
in Settings/Widgets, you can create new display widget. But customisation/design 
options are limited - basically dark/bright theme, number of tweets, 
some other formatting, and that's it. It spits out a little code 
you add to your site, and done ... maybe worth the effort, dunno 
- not sure about minimal width though - more info here https://dev.twitter.com/docs/embedded-timelines
the question is, if you want to loose your time with such stuff .....
DocKimbel
9-Jul-2013
[9401x3]
I tried it once IIRC, and couldn't use it for Red site as it was 
requiring too much horizontal space.
I certainly don't want to loose my time with that, but I need anyway 
to search for an alternative in order to be ready to switch when 
the right time comes.
Pekr: if you don't have a Twitter account, it would be a good idea 
to make one and post news about the Rebol and Red world from there. 
We need a stronger presence on Twitter.
Pekr
9-Jul-2013
[9404x5]
I have 3 twitter account :-)
I just did not know, that I could post to anyone's other account 
...
Tried to write a tweet on Red Lang, it disappeared, maybe waiting 
for your approval? You can eventually remove it, not good at referring 
to other sites, etc.
ah, it was posted to my twee channel ... sucks ...
OK, so tweeted with the reference to #BeagleBoneBlack and #Red_lang 
... feel free to retweet ...
DocKimbel
9-Jul-2013
[9409]
You should rather use @red_lang, so it will appear directly. With 
a simple hashtag, I won't notice it unless  I search for it.
Pekr
9-Jul-2013
[9410x2]
ok, will tweet again ...
well, should I let there even @BeagleBoneBlack? Will not the other 
community mind?