[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Embedded socket error

Nathan Whitney

7/26/2006 7:36:00 PM

I am running the following code in a C++ app:

int _tmain(int argc, _TCHAR* argv[])
{
NtInitialize(&argc, &argv);
ruby_init();
ruby_init_loadpath();
ruby_script("embedded");
rb_load_file( "embr.rb" );
ruby_run();
return 0;
}

with embr.rb of:
require 'socket'

I get:
************
Embed\rubyEmbed>Debug\rubyEmbed.exe
/socket.so: [BUG] Segmentation fault
ruby 1.8.2 (2004-12-25) [i386-mswin32]


This application has requested the Runtime to terminate it in an unusual
way.
Please contact the application's support team for more information.
*********

Any ideas?

Nathan


--
Posted via http://www.ruby-....

79 Answers

ts

7/27/2006 8:25:00 AM

0

>>>>> "N" == Nathan Whitney <laserwhit@gmail.com> writes:

N> ruby_init();
N> ruby_init_loadpath();
N> ruby_script("embedded");
N> rb_load_file( "embr.rb" );
N> ruby_run();

N> Embed\rubyEmbed>Debug\rubyEmbed.exe
N> /socket.so: [BUG] Segmentation fault
N> ruby 1.8.2 (2004-12-25) [i386-mswin32]

it's normal.

When you write an embedded application, you have the responsibility to
protect your application against the error that ruby can raise. In your
case, rb_load_file() can raise an exception (file not found, ...) and it
must be called inside a call to rb_protect() to give you the possibility
to test the error.

It's also best if you use a more recent ruby.

--

Guy Decoux

Nathan Whitney

7/27/2006 4:14:00 PM

0

So I installed 1.8.4 and couldn't compile until I changed the
C:\ruby\lib\ruby\1.8\i386-mswin32\config.h to accept _MSC_VER > 1200. I
then changed my code to:

rubyEmbeded.cpp:
*******************

#include "stdafx.h"
#include "ruby.h"
#include "win32\win32.h"

static VALUE wrap_run( VALUE arg1 ) {
rb_load_file( StringValueCStr( arg1 ) );
return Qnil;
}

static VALUE protected_run( VALUE script ) {
int error;
VALUE args[1];
VALUE result;

args[0] = script;

result = rb_protect( wrap_run, (VALUE)args, &error );
return error ? Qnil : result;
}

int _tmain(int argc, _TCHAR* argv[])
{
NtInitialize(&argc, &argv);
ruby_init();
ruby_init_loadpath();
ruby_script("embedded");

VALUE script = rb_str_new( "embr.rb", strlen("embr.rb") );
protected_run( script );

ruby_run();

return 0;
}
*********************

embr.rb:
*********************

require 'socket'

*********************

My results are still:

Embed\rubyEmbed>Debug\rubyEmbed.exe
embedded: [BUG] Segmentation fault
ruby 1.8.4 (2006-04-14) [i386-mswin32]


This application has requested the Runtime to terminate it in an unusual
way.
Please contact the application's support team for more information.

Any more thoughts? I'm not sure how I'm supposed to debug this. By the
way thanks for you help so far.

Nathan

--
Posted via http://www.ruby-....

ts

7/27/2006 4:47:00 PM

0

>>>>> "N" == Nathan Whitney <laserwhit@gmail.com> writes:

N> static VALUE wrap_run( VALUE arg1 ) {
^^^^^^^^^^
N> rb_load_file( StringValueCStr( arg1 ) );
^^^^
N> return Qnil;
N> }

N> static VALUE protected_run( VALUE script ) {
N> int error;
N> VALUE args[1];
^^^^^^^^^^^^^
N> VALUE result;

N> args[0] = script;
^^^^^^^

N> result = rb_protect( wrap_run, (VALUE)args, &error );
^^^^
N> return error ? Qnil : result;
N> }

You give a C array to wrap_run() and then inside wrap_run() you interpret
it as a VALUE.

Now if you want to do something similar to "load 'embed.rb'", you have
the function

void rb_load_protect(VALUE fname, int wrap, int *state);

which call rb_load() inside the equivalent of rb_protect()


Guy Decoux

William Black

2/3/2008 7:40:00 AM

0


"Renia" <renia@DELETEotenet.gr> wrote in message
news:fo3pfh$sl6$1@mouse.otenet.gr...
> William Black wrote:
>
>>
>> Do I sniff a 'Daily Mail' story somewhere here?
>
> Good for the Daily Mail if it is their story.
>
> At least one British newspaper is standing up for British values. You
> should be grateful. Or don't you have British values?

What exactly are 'British values'?

There was a leading article in The Times of India a few months ago about
this one that pulled the whole idea to pieces.

The idea that a country that was busy repressing a third of the world just
over half a century ago has the cheek to say their unique fundamental values
included democracy and freedom of the press is actually laughable.

A country that requires ISPs to record all transactions and correspondence
of all customers for half a decade on the grounds that some of them may
commit a crime at some point in the future is not a beacon of freedom
either...

Traditional British values are about the repression and exploitation of the
poor, wherever they can be found...

"Any liberties that have been won in Great Britain have been wrenched from
the ruling elite by the blood stained hands of the people"

(Who knows who said it?)

--
William Black


I've seen things you people wouldn't believe.
Barbeques on fire by the chalets past the castle headland
I watched the gift shops glitter in the darkness off the Newborough gate
All these moments will be lost in time, like icecream on the beach
Time for tea.


Nebulous

2/3/2008 8:29:00 AM

0


"William Black" <william.black@hotmail.co.uk> wrote in message
news:fo3nop$605

New Gem of the day courtesy of Hines
Edinburgh
Beautiful city of Edinburgh!
Where the tourist can drown his sorrow
By viewing your monuments and statues fine
During the lovely summer-time.
I'm sure it will his spirits cheer
As Sir Walter Scott's monument he draws near,
That stands in East Prince's Street
Amongst flowery gardens, fine and neat.

And Edinburgh Castle is magnificent to be seen
With its beautiful walks and trees so green,
Which seems like a fairy dell;
And near by its rocky basement is St Margaret's Well,
Where the tourist can drink at when he feels dry,
And view the castle from beneath so very high,
Which seems almost towering to the sky.

Then as for Nelson's monument that stands on Calton Hill,
As the tourist gazes thereon, with wonder his heart does fill
As he thinks on Admiral Nelson who did the Frenchmen kill,
Then, as for Salisbury Crags, they are most beautiful to be seen,
Especially in the month of June, when the grass is green;
There numerous mole-hills can be seen,
And the busy little creatures howking away,
Searching for worms among the clay;
And as the tourist's eye does wander to and fro
From the south side of Salisbury Crags below,
His bosom with admiration feels all aglow
As he views the beautiful scenery in the valley below;
And if, with an observant eye, the little loch beneath he scans,
He can see the wild ducks about and beautiful white swans.

Then, as for Arthur's Seat, I'm sure it is a treat
Most worthy to be seen, with its rugged rocks and pastures green,
And the sheep browsing on its sides
To and fro, with slow-paced strides,
And the little lambkins at play
During the livelong summer day,
Beautiful city of Edinburgh! the truth to express,
Your beauties are matchless I must confess,
And which no one dare gainsay,
But that you are the grandest city in Scotland at the present day!


Nebulous

2/3/2008 8:30:00 AM

0


"William Black" <william.black@hotmail.co.uk> wrote in message
news:fo3r41$hh9

New Gem of the day courtesy of Hines
Edinburgh
Beautiful city of Edinburgh!
Where the tourist can drown his sorrow
By viewing your monuments and statues fine
During the lovely summer-time.
I'm sure it will his spirits cheer
As Sir Walter Scott's monument he draws near,
That stands in East Prince's Street
Amongst flowery gardens, fine and neat.

And Edinburgh Castle is magnificent to be seen
With its beautiful walks and trees so green,
Which seems like a fairy dell;
And near by its rocky basement is St Margaret's Well,
Where the tourist can drink at when he feels dry,
And view the castle from beneath so very high,
Which seems almost towering to the sky.

Then as for Nelson's monument that stands on Calton Hill,
As the tourist gazes thereon, with wonder his heart does fill
As he thinks on Admiral Nelson who did the Frenchmen kill,
Then, as for Salisbury Crags, they are most beautiful to be seen,
Especially in the month of June, when the grass is green;
There numerous mole-hills can be seen,
And the busy little creatures howking away,
Searching for worms among the clay;
And as the tourist's eye does wander to and fro
From the south side of Salisbury Crags below,
His bosom with admiration feels all aglow
As he views the beautiful scenery in the valley below;
And if, with an observant eye, the little loch beneath he scans,
He can see the wild ducks about and beautiful white swans.

Then, as for Arthur's Seat, I'm sure it is a treat
Most worthy to be seen, with its rugged rocks and pastures green,
And the sheep browsing on its sides
To and fro, with slow-paced strides,
And the little lambkins at play
During the livelong summer day,
Beautiful city of Edinburgh! the truth to express,
Your beauties are matchless I must confess,
And which no one dare gainsay,
But that you are the grandest city in Scotland at the present day!


Nebulous

2/3/2008 8:30:00 AM

0


"Renia" <renia@DELETEotenet.gr> wrote in message
news:fo3pfh$sl6$1@mouse.otenet.gr...

New Gem of the day courtesy of Hines
Edinburgh
Beautiful city of Edinburgh!
Where the tourist can drown his sorrow
By viewing your monuments and statues fine
During the lovely summer-time.
I'm sure it will his spirits cheer
As Sir Walter Scott's monument he draws near,
That stands in East Prince's Street
Amongst flowery gardens, fine and neat.

And Edinburgh Castle is magnificent to be seen
With its beautiful walks and trees so green,
Which seems like a fairy dell;
And near by its rocky basement is St Margaret's Well,
Where the tourist can drink at when he feels dry,
And view the castle from beneath so very high,
Which seems almost towering to the sky.

Then as for Nelson's monument that stands on Calton Hill,
As the tourist gazes thereon, with wonder his heart does fill
As he thinks on Admiral Nelson who did the Frenchmen kill,
Then, as for Salisbury Crags, they are most beautiful to be seen,
Especially in the month of June, when the grass is green;
There numerous mole-hills can be seen,
And the busy little creatures howking away,
Searching for worms among the clay;
And as the tourist's eye does wander to and fro
From the south side of Salisbury Crags below,
His bosom with admiration feels all aglow
As he views the beautiful scenery in the valley below;
And if, with an observant eye, the little loch beneath he scans,
He can see the wild ducks about and beautiful white swans.

Then, as for Arthur's Seat, I'm sure it is a treat
Most worthy to be seen, with its rugged rocks and pastures green,
And the sheep browsing on its sides
To and fro, with slow-paced strides,
And the little lambkins at play
During the livelong summer day,
Beautiful city of Edinburgh! the truth to express,
Your beauties are matchless I must confess,
And which no one dare gainsay,
But that you are the grandest city in Scotland at the present day!


Renia

2/3/2008 8:56:00 AM

0

William Black wrote:

>
> "Renia" <renia@DELETEotenet.gr> wrote in message
> news:fo3pfh$sl6$1@mouse.otenet.gr...
>
>> William Black wrote:
>>
>>>
>>> Do I sniff a 'Daily Mail' story somewhere here?
>>
>>
>> Good for the Daily Mail if it is their story.
>>
>> At least one British newspaper is standing up for British values. You
>> should be grateful. Or don't you have British values?
>
>
> What exactly are 'British values'?

Toleration, religious freedom, stiff upper lip and never complaining,
sense of humour in adversity.

Time for the stiff upper lip to start wobbling. Complain, England.
You're being trodden to death.


>
> There was a leading article in The Times of India a few months ago about
> this one that pulled the whole idea to pieces.

The Times of India. Right.


> The idea that a country that was busy repressing a third of the world
> just over half a century ago has the cheek to say their unique
> fundamental values included democracy and freedom of the press is
> actually laughable.

India has no agenda?

How would India have developed without British intervention? It's not a
comment or judgement, it's a serious question.


> A country that requires ISPs to record all transactions and
> correspondence of all customers for half a decade on the grounds that
> some of them may commit a crime at some point in the future is not a
> beacon of freedom either...

Sorry, ISP?

> Traditional British values are about the repression and exploitation of
> the poor, wherever they can be found...


Total crap. That's the politically correct spin of the red-brick
universities awash with Social Science and guilt.


> "Any liberties that have been won in Great Britain have been wrenched
> from the ruling elite by the blood stained hands of the people"
>
> (Who knows who said it?)

You have been gullibly taken in by the Sociology bridgade who have no
concept of history. You can't change history and you can't put today's
moralistic and politically correct ideals on to yesterday's events. Even
today's politically correct events will be seen as a moralistic sell-out
in the future. Every era makes the mistake of judging other societies in
comparison to its own. No society is perfect.

You are on a dreadful guilt trip for some reason and you blame England
for it.

William Black

2/3/2008 9:57:00 AM

0


"Renia" <renia@DELETEotenet.gr> wrote in message
news:fo3vjr$v8c$1@mouse.otenet.gr...
> William Black wrote:
>
>>
>> "Renia" <renia@DELETEotenet.gr> wrote in message
>> news:fo3pfh$sl6$1@mouse.otenet.gr...
>>
>>> William Black wrote:
>>>
>>>>
>>>> Do I sniff a 'Daily Mail' story somewhere here?
>>>
>>>
>>> Good for the Daily Mail if it is their story.
>>>
>>> At least one British newspaper is standing up for British values. You
>>> should be grateful. Or don't you have British values?
>>
>>
>> What exactly are 'British values'?
>
> Toleration, religious freedom, stiff upper lip and never complaining,
> sense of humour in adversity.
>
> Time for the stiff upper lip to start wobbling. Complain, England. You're
> being trodden to death.

British values!

They've just caught the cops bugging an MP.

In direct contravention of rules laid down decades ago.

Nobody will get the sack, nobody will even get punished

British values?


>> There was a leading article in The Times of India a few months ago about
>> this one that pulled the whole idea to pieces.
>
> The Times of India. Right.
>
>
>> The idea that a country that was busy repressing a third of the world
>> just over half a century ago has the cheek to say their unique
>> fundamental values included democracy and freedom of the press is
>> actually laughable.
>
> India has no agenda?

India may have, however it also has a free press...

> How would India have developed without British intervention? It's not a
> comment or judgement, it's a serious question.

Gandhi's 'Constructive Programme' of 1941 gives some idea

I assume you've read it.

>> A country that requires ISPs to record all transactions and
>> correspondence of all customers for half a decade on the grounds that
>> some of them may commit a crime at some point in the future is not a
>> beacon of freedom either...
>
> Sorry, ISP?

Oh dear.

Internet service provider.

You don't even know that your own government requires the people you pay to
provide you with a service use your own money to spy on you...

>> Traditional British values are about the repression and exploitation of
>> the poor, wherever they can be found...
>
>
> Total crap. That's the politically correct spin of the red-brick
> universities awash with Social Science and guilt.

Lack of content noted...

>
>
>> "Any liberties that have been won in Great Britain have been wrenched
>> from the ruling elite by the blood stained hands of the people"
>>
>> (Who knows who said it?)
>
> You have been gullibly

<snip of bollocks>

So you don't know then...

Look...

We are Perfidious Albion, our murderous popinjays and gilded assassins
stalk the night bringing fear and death in equal measure.

We care not that they hate us so long as they fear us.

--
William Black


I've seen things you people wouldn't believe.
Barbeques on fire by the chalets past the castle headland
I watched the gift shops glitter in the darkness off the Newborough gate
All these moments will be lost in time, like icecream on the beach
Time for tea.

a.spencer3

2/3/2008 11:08:00 AM

0


"William Black" <william.black@hotmail.co.uk> wrote in message
news:fo3r41$hh9$1@registered.motzarella.org...
>
> "Renia" <renia@DELETEotenet.gr> wrote in message
> news:fo3pfh$sl6$1@mouse.otenet.gr...
> > William Black wrote:
> >
> >>
> >> Do I sniff a 'Daily Mail' story somewhere here?
> >
> > Good for the Daily Mail if it is their story.
> >
> > At least one British newspaper is standing up for British values. You
> > should be grateful. Or don't you have British values?
>
> What exactly are 'British values'?
>
> There was a leading article in The Times of India a few months ago about
> this one that pulled the whole idea to pieces.
>
> The idea that a country that was busy repressing a third of the world just
> over half a century ago has the cheek to say their unique fundamental
values
> included democracy and freedom of the press is actually laughable.
>
> A country that requires ISPs to record all transactions and correspondence
> of all customers for half a decade on the grounds that some of them may
> commit a crime at some point in the future is not a beacon of freedom
> either...
>
> Traditional British values are about the repression and exploitation of
the
> poor, wherever they can be found...
>
> "Any liberties that have been won in Great Britain have been wrenched from
> the ruling elite by the blood stained hands of the people"
>

What blood?

Surreyman