[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Using blocks in C (with File.open

Jim Freeze

11/6/2003 3:26:00 PM

Hi:

I have written some code in Ruby to parse a file and yield
items inside the file. It looks something like this:


def each(file)_
File.open(file) { |f|
# Do work here
}
end

To speed this up, I have written this in C. However, my original
version had the File.open() {} code in Ruby.
I am now writing that in C, don't know how to use the block
methodology so the file will automatically close.

Below is what I currently have:

static VALUE
each(self, filename)
VALUE self, filename;
{
VALUE f = rb_file_open(filename, rb_str_new2("r"));

/* do work here */

rb_io_close(f);
}


Can someone provide sample code of how use File.open and
blocks in C?

Thanks
--
Jim Freeze
----------
Money is better than poverty, if only for financial reasons.

16 Answers

ts

11/6/2003 3:41:00 PM

0

>>>>> "J" == Jim Freeze <jim@freeze.org> writes:

J> Can someone provide sample code of how use File.open and
J> blocks in C?

static VALUE
do_work_here(file)
VALUE file;
{
/* do work here */
return Qnil;
}

J> static VALUE
J> each(self, filename)
J> VALUE self, filename;
J> {
J> VALUE f = rb_file_open(filename, rb_str_new2("r"));

return rb_ensure(do_work_here, f, rb_io_close, f);

J> }



Guy Decoux



Tom McDonald

7/5/2013 2:05:00 AM

0

On 7/4/2013 9:03 PM, Attila < wrote:
> On Thu, 04 Jul 2013 18:02:00 -0700, Jeanne Douglas
> <hlwdjsd2@NOSPAMgmail.com> in alt.abortion with message-id
> <hlwdjsd2-5B97B4.18020004072013@news.giganews.com> wrote:
>
>> In article <eqsat8tspcr6s03vn67nivqbi1s564hcc3@4ax.com>,
>> Attila <<prochoice@here.now> wrote:
>>
>>> On Thu, 4 Jul 2013 12:12:24 +0100, "Alex W." <ingilt@yahoo.co.uk> in
>>> alt.abortion with message-id
>>> <1kekwxk2u4an0$.1c9z2jptyeodf.dlg@40tude.net> wrote:
>>>
>>>> On Thu, 04 Jul 2013 06:44:21 -0400, Attila wrote:
>>>>
>>>>
>>>>> Why would you assume any armed person would shoot you (or anyone else)
>>>>> in the back absent a direct threat to do so?
>>>>
>>>> You are joking, right?
>>>
>>> No.
>>>
>>>> Have you seen any homicide stats recently?
>>>
>>> Irrelevant. Do you think all legally armed men go about looking for
>>> someone to shoot in the back?
>>
>> I'd be suspicious of any person I didn't know who was carrying a gun.
>
>
> Why? Are you doing something wrong?
>
> Do you think everyone who carries a gun is looking for someone to
> shoot?
>
Some are. That's the point I took from Jeanne's statement. I know it's
what I wonder when I see someone, especially a civilian I don't know,
carrying.

Jeanne Douglas

7/5/2013 2:13:00 AM

0

In article <k7act899t70t3ves4dkik6lekcojgirmt1@4ax.com>,
Attila <<prochoice@here.now> wrote:

> On Thu, 04 Jul 2013 18:02:00 -0700, Jeanne Douglas
> <hlwdjsd2@NOSPAMgmail.com> in alt.abortion with message-id
> <hlwdjsd2-5B97B4.18020004072013@news.giganews.com> wrote:
>
> >In article <eqsat8tspcr6s03vn67nivqbi1s564hcc3@4ax.com>,
> > Attila <<prochoice@here.now> wrote:
> >
> >> On Thu, 4 Jul 2013 12:12:24 +0100, "Alex W." <ingilt@yahoo.co.uk> in
> >> alt.abortion with message-id
> >> <1kekwxk2u4an0$.1c9z2jptyeodf.dlg@40tude.net> wrote:
> >>
> >> >On Thu, 04 Jul 2013 06:44:21 -0400, Attila wrote:
> >> >
> >> >
> >> >> Why would you assume any armed person would shoot you (or anyone else)
> >> >> in the back absent a direct threat to do so?
> >> >
> >> >You are joking, right?
> >>
> >> No.
> >>
> >> >Have you seen any homicide stats recently?
> >>
> >> Irrelevant. Do you think all legally armed men go about looking for
> >> someone to shoot in the back?
> >
> >I'd be suspicious of any person I didn't know who was carrying a gun.
>
>
> Why? Are you doing something wrong?
>
> Do you think everyone who carries a gun is looking for someone to
> shoot?

If I don't know the person, I'd have no reason to think I'm safe around
them.

--

JD

"Osama Bin Laden is dead and GM is alive."--VP Joseph Biden

Jason

7/5/2013 2:35:00 AM

0

In article <kr59ao$env$1@dont-email.me>, Tom McDonald <kiltmac@gmail.com> wrote:

> On 7/4/2013 9:03 PM, Attila < wrote:
> > On Thu, 04 Jul 2013 18:02:00 -0700, Jeanne Douglas
> > <hlwdjsd2@NOSPAMgmail.com> in alt.abortion with message-id
> > <hlwdjsd2-5B97B4.18020004072013@news.giganews.com> wrote:
> >
> >> In article <eqsat8tspcr6s03vn67nivqbi1s564hcc3@4ax.com>,
> >> Attila <<prochoice@here.now> wrote:
> >>
> >>> On Thu, 4 Jul 2013 12:12:24 +0100, "Alex W." <ingilt@yahoo.co.uk> in
> >>> alt.abortion with message-id
> >>> <1kekwxk2u4an0$.1c9z2jptyeodf.dlg@40tude.net> wrote:
> >>>
> >>>> On Thu, 04 Jul 2013 06:44:21 -0400, Attila wrote:
> >>>>
> >>>>
> >>>>> Why would you assume any armed person would shoot you (or anyone else)
> >>>>> in the back absent a direct threat to do so?
> >>>>
> >>>> You are joking, right?
> >>>
> >>> No.
> >>>
> >>>> Have you seen any homicide stats recently?
> >>>
> >>> Irrelevant. Do you think all legally armed men go about looking for
> >>> someone to shoot in the back?
> >>
> >> I'd be suspicious of any person I didn't know who was carrying a gun.
> >
> >
> > Why? Are you doing something wrong?
> >
> > Do you think everyone who carries a gun is looking for someone to
> > shoot?
> >
> Some are. That's the point I took from Jeanne's statement. I know it's
> what I wonder when I see someone, especially a civilian I don't know,
> carrying.

Most normal people that have carry permits don't display their guns. I
kept my gun totally concealed.


Attila <

7/5/2013 3:18:00 AM

0

On Thu, 04 Jul 2013 21:05:16 -0500, Tom McDonald <kiltmac@gmail.com>
in alt.abortion with message-id <kr59ao$env$1@dont-email.me> wrote:

>On 7/4/2013 9:03 PM, Attila < wrote:
>> On Thu, 04 Jul 2013 18:02:00 -0700, Jeanne Douglas
>> <hlwdjsd2@NOSPAMgmail.com> in alt.abortion with message-id
>> <hlwdjsd2-5B97B4.18020004072013@news.giganews.com> wrote:
>>
>>> In article <eqsat8tspcr6s03vn67nivqbi1s564hcc3@4ax.com>,
>>> Attila <<prochoice@here.now> wrote:
>>>
>>>> On Thu, 4 Jul 2013 12:12:24 +0100, "Alex W." <ingilt@yahoo.co.uk> in
>>>> alt.abortion with message-id
>>>> <1kekwxk2u4an0$.1c9z2jptyeodf.dlg@40tude.net> wrote:
>>>>
>>>>> On Thu, 04 Jul 2013 06:44:21 -0400, Attila wrote:
>>>>>
>>>>>
>>>>>> Why would you assume any armed person would shoot you (or anyone else)
>>>>>> in the back absent a direct threat to do so?
>>>>>
>>>>> You are joking, right?
>>>>
>>>> No.
>>>>
>>>>> Have you seen any homicide stats recently?
>>>>
>>>> Irrelevant. Do you think all legally armed men go about looking for
>>>> someone to shoot in the back?
>>>
>>> I'd be suspicious of any person I didn't know who was carrying a gun.
>>
>>
>> Why? Are you doing something wrong?
>>
>> Do you think everyone who carries a gun is looking for someone to
>> shoot?
>>
>Some are.

In which case they probably have already found someone to shoot. The
odds of your being followed by a new gun carrier looking for a target
is rather small. A lot smaller than being run down by a car.


>That's the point I took from Jeanne's statement. I know it's
>what I wonder when I see someone, especially a civilian I don't know,
>carrying.

That sounds like a personal problem. Carry permits are quite common,
quite legal, and most guns are hidden. I once lived in a state that
did not require a permit to carry a non-concealed weapon, and I have
seen people on the street with a shoulder holster.

No big deal. I frequently did not even notice what they had.


--
Pro-Choice is Pro-Freedom

Every illegal alien is a criminal.
No amnesty or work permit under any name or for any reason.
Deportation upon identification as the only option.

Religion is the worst monstrosity ever fostered upon the
human species. Only mental defectives would pay the
slightest attention to it.

Why should any religion be considered a foreign nation
with Ambassadors and diplomatic immunity?

Any day now I expect some liberal to demand a government
guaranteed above average income for every person.

You are more likely to by kicked to death than to be killed
by a rifle or a shotgun in the US.

Attila <

7/5/2013 3:21:00 AM

0

On Thu, 04 Jul 2013 19:12:48 -0700, Jeanne Douglas
<hlwdjsd2@NOSPAMgmail.com> in alt.abortion with message-id
<hlwdjsd2-863E39.19124804072013@news.giganews.com> wrote:

>In article <k7act899t70t3ves4dkik6lekcojgirmt1@4ax.com>,
> Attila <<prochoice@here.now> wrote:
>
>> On Thu, 04 Jul 2013 18:02:00 -0700, Jeanne Douglas
>> <hlwdjsd2@NOSPAMgmail.com> in alt.abortion with message-id
>> <hlwdjsd2-5B97B4.18020004072013@news.giganews.com> wrote:
>>
>> >In article <eqsat8tspcr6s03vn67nivqbi1s564hcc3@4ax.com>,
>> > Attila <<prochoice@here.now> wrote:
>> >
>> >> On Thu, 4 Jul 2013 12:12:24 +0100, "Alex W." <ingilt@yahoo.co.uk> in
>> >> alt.abortion with message-id
>> >> <1kekwxk2u4an0$.1c9z2jptyeodf.dlg@40tude.net> wrote:
>> >>
>> >> >On Thu, 04 Jul 2013 06:44:21 -0400, Attila wrote:
>> >> >
>> >> >
>> >> >> Why would you assume any armed person would shoot you (or anyone else)
>> >> >> in the back absent a direct threat to do so?
>> >> >
>> >> >You are joking, right?
>> >>
>> >> No.
>> >>
>> >> >Have you seen any homicide stats recently?
>> >>
>> >> Irrelevant. Do you think all legally armed men go about looking for
>> >> someone to shoot in the back?
>> >
>> >I'd be suspicious of any person I didn't know who was carrying a gun.
>>
>>
>> Why? Are you doing something wrong?
>>
>> Do you think everyone who carries a gun is looking for someone to
>> shoot?
>
>If I don't know the person, I'd have no reason to think I'm safe around
>them.

You must be scared a lot, or only stay around people you know.

Since most guns are concealed, and you have no idea if a person is
armed you should properly be terrified of everyone you don't know.

--
Pro-Choice is Pro-Freedom

Every illegal alien is a criminal.
No amnesty or work permit under any name or for any reason.
Deportation upon identification as the only option.

Religion is the worst monstrosity ever fostered upon the
human species. Only mental defectives would pay the
slightest attention to it.

Why should any religion be considered a foreign nation
with Ambassadors and diplomatic immunity?

Any day now I expect some liberal to demand a government
guaranteed above average income for every person.

You are more likely to by kicked to death than to be killed
by a rifle or a shotgun in the US.

Jason

7/5/2013 5:27:00 AM

0

In article <hlwdjsd2-863E39.19124804072013@news.giganews.com>, Jeanne
Douglas <hlwdjsd2@NOSPAMgmail.com> wrote:

> In article <k7act899t70t3ves4dkik6lekcojgirmt1@4ax.com>,
> Attila <<prochoice@here.now> wrote:
>
> > On Thu, 04 Jul 2013 18:02:00 -0700, Jeanne Douglas
> > <hlwdjsd2@NOSPAMgmail.com> in alt.abortion with message-id
> > <hlwdjsd2-5B97B4.18020004072013@news.giganews.com> wrote:
> >
> > >In article <eqsat8tspcr6s03vn67nivqbi1s564hcc3@4ax.com>,
> > > Attila <<prochoice@here.now> wrote:
> > >
> > >> On Thu, 4 Jul 2013 12:12:24 +0100, "Alex W." <ingilt@yahoo.co.uk> in
> > >> alt.abortion with message-id
> > >> <1kekwxk2u4an0$.1c9z2jptyeodf.dlg@40tude.net> wrote:
> > >>
> > >> >On Thu, 04 Jul 2013 06:44:21 -0400, Attila wrote:
> > >> >
> > >> >
> > >> >> Why would you assume any armed person would shoot you (or anyone else)
> > >> >> in the back absent a direct threat to do so?
> > >> >
> > >> >You are joking, right?
> > >>
> > >> No.
> > >>
> > >> >Have you seen any homicide stats recently?
> > >>
> > >> Irrelevant. Do you think all legally armed men go about looking for
> > >> someone to shoot in the back?
> > >
> > >I'd be suspicious of any person I didn't know who was carrying a gun.
> >
> >
> > Why? Are you doing something wrong?
> >
> > Do you think everyone who carries a gun is looking for someone to
> > shoot?
>
> If I don't know the person, I'd have no reason to think I'm safe around
> them.

You have probably been around people carrying concealed firearms and did
not even know it. I carried a concealed firearm when in public for several
years and doubt that anyone knew it since I kept it concealed.


Jeanne Douglas

7/5/2013 6:28:00 AM

0

In article
<Jason-0407132227030001@66-53-210-153.lsan.mdsg-pacwest.com>,
Jason@nospam.com (Jason) wrote:

> In article <hlwdjsd2-863E39.19124804072013@news.giganews.com>, Jeanne
> Douglas <hlwdjsd2@NOSPAMgmail.com> wrote:
>
> > In article <k7act899t70t3ves4dkik6lekcojgirmt1@4ax.com>,
> > Attila <<prochoice@here.now> wrote:
> >
> > > On Thu, 04 Jul 2013 18:02:00 -0700, Jeanne Douglas
> > > <hlwdjsd2@NOSPAMgmail.com> in alt.abortion with message-id
> > > <hlwdjsd2-5B97B4.18020004072013@news.giganews.com> wrote:
> > >
> > > >In article <eqsat8tspcr6s03vn67nivqbi1s564hcc3@4ax.com>,
> > > > Attila <<prochoice@here.now> wrote:
> > > >
> > > >> On Thu, 4 Jul 2013 12:12:24 +0100, "Alex W." <ingilt@yahoo.co.uk> in
> > > >> alt.abortion with message-id
> > > >> <1kekwxk2u4an0$.1c9z2jptyeodf.dlg@40tude.net> wrote:
> > > >>
> > > >> >On Thu, 04 Jul 2013 06:44:21 -0400, Attila wrote:
> > > >> >
> > > >> >
> > > >> >> Why would you assume any armed person would shoot you (or anyone
> > > >> >> else)
> > > >> >> in the back absent a direct threat to do so?
> > > >> >
> > > >> >You are joking, right?
> > > >>
> > > >> No.
> > > >>
> > > >> >Have you seen any homicide stats recently?
> > > >>
> > > >> Irrelevant. Do you think all legally armed men go about looking for
> > > >> someone to shoot in the back?
> > > >
> > > >I'd be suspicious of any person I didn't know who was carrying a gun.
> > >
> > >
> > > Why? Are you doing something wrong?
> > >
> > > Do you think everyone who carries a gun is looking for someone to
> > > shoot?
> >
> > If I don't know the person, I'd have no reason to think I'm safe around
> > them.
>
> You have probably been around people carrying concealed firearms and did
> not even know it. I carried a concealed firearm when in public for several
> years and doubt that anyone knew it since I kept it concealed.

Then I wouldn't be afraid of what they might do, now would I?

--

JD

"Osama Bin Laden is dead and GM is alive."--VP Joseph Biden

%

7/5/2013 6:40:00 AM

0

Jeanne Douglas wrote:
> In article
> <Jason-0407132227030001@66-53-210-153.lsan.mdsg-pacwest.com>,
> Jason@nospam.com (Jason) wrote:
>
>> In article <hlwdjsd2-863E39.19124804072013@news.giganews.com>, Jeanne
>> Douglas <hlwdjsd2@NOSPAMgmail.com> wrote:
>>
>>> In article <k7act899t70t3ves4dkik6lekcojgirmt1@4ax.com>,
>>> Attila <<prochoice@here.now> wrote:
>>>
>>>> On Thu, 04 Jul 2013 18:02:00 -0700, Jeanne Douglas
>>>> <hlwdjsd2@NOSPAMgmail.com> in alt.abortion with message-id
>>>> <hlwdjsd2-5B97B4.18020004072013@news.giganews.com> wrote:
>>>>
>>>>> In article <eqsat8tspcr6s03vn67nivqbi1s564hcc3@4ax.com>,
>>>>> Attila <<prochoice@here.now> wrote:
>>>>>
>>>>>> On Thu, 4 Jul 2013 12:12:24 +0100, "Alex W."
>>>>>> <ingilt@yahoo.co.uk> in alt.abortion with message-id
>>>>>> <1kekwxk2u4an0$.1c9z2jptyeodf.dlg@40tude.net> wrote:
>>>>>>
>>>>>>> On Thu, 04 Jul 2013 06:44:21 -0400, Attila wrote:
>>>>>>>
>>>>>>>
>>>>>>>> Why would you assume any armed person would shoot you (or
>>>>>>>> anyone else)
>>>>>>>> in the back absent a direct threat to do so?
>>>>>>>
>>>>>>> You are joking, right?
>>>>>>
>>>>>> No.
>>>>>>
>>>>>>> Have you seen any homicide stats recently?
>>>>>>
>>>>>> Irrelevant. Do you think all legally armed men go about looking
>>>>>> for someone to shoot in the back?
>>>>>
>>>>> I'd be suspicious of any person I didn't know who was carrying a
>>>>> gun.
>>>>
>>>>
>>>> Why? Are you doing something wrong?
>>>>
>>>> Do you think everyone who carries a gun is looking for someone to
>>>> shoot?
>>>
>>> If I don't know the person, I'd have no reason to think I'm safe
>>> around them.
>>
>> You have probably been around people carrying concealed firearms and
>> did not even know it. I carried a concealed firearm when in public
>> for several years and doubt that anyone knew it since I kept it
>> concealed.
>
> Then I wouldn't be afraid of what they might do, now would I?

could you please explain to her how long you've known me , and its not
> likely i am a sock of anyone's

I've only met you once in person, ten years ago, when you offered me a
frisbee full of mushrooms. Man I got so hallucinatory I said my name
backwards one thousand times.

Other than that, I don't think we can really say we know each other.
Most of your followups to me are that you don't care or that I am
obsessing about you, so I guess you just don't want to be friends anymore.

--

Jason

7/5/2013 7:02:00 AM

0

In article <hlwdjsd2-A39C79.23275004072013@news.giganews.com>, Jeanne
Douglas <hlwdjsd2@NOSPAMgmail.com> wrote:

> In article
> <Jason-0407132227030001@66-53-210-153.lsan.mdsg-pacwest.com>,
> Jason@nospam.com (Jason) wrote:
>
> > In article <hlwdjsd2-863E39.19124804072013@news.giganews.com>, Jeanne
> > Douglas <hlwdjsd2@NOSPAMgmail.com> wrote:
> >
> > > In article <k7act899t70t3ves4dkik6lekcojgirmt1@4ax.com>,
> > > Attila <<prochoice@here.now> wrote:
> > >
> > > > On Thu, 04 Jul 2013 18:02:00 -0700, Jeanne Douglas
> > > > <hlwdjsd2@NOSPAMgmail.com> in alt.abortion with message-id
> > > > <hlwdjsd2-5B97B4.18020004072013@news.giganews.com> wrote:
> > > >
> > > > >In article <eqsat8tspcr6s03vn67nivqbi1s564hcc3@4ax.com>,
> > > > > Attila <<prochoice@here.now> wrote:
> > > > >
> > > > >> On Thu, 4 Jul 2013 12:12:24 +0100, "Alex W." <ingilt@yahoo.co.uk> in
> > > > >> alt.abortion with message-id
> > > > >> <1kekwxk2u4an0$.1c9z2jptyeodf.dlg@40tude.net> wrote:
> > > > >>
> > > > >> >On Thu, 04 Jul 2013 06:44:21 -0400, Attila wrote:
> > > > >> >
> > > > >> >
> > > > >> >> Why would you assume any armed person would shoot you (or anyone
> > > > >> >> else)
> > > > >> >> in the back absent a direct threat to do so?
> > > > >> >
> > > > >> >You are joking, right?
> > > > >>
> > > > >> No.
> > > > >>
> > > > >> >Have you seen any homicide stats recently?
> > > > >>
> > > > >> Irrelevant. Do you think all legally armed men go about looking for
> > > > >> someone to shoot in the back?
> > > > >
> > > > >I'd be suspicious of any person I didn't know who was carrying a gun.
> > > >
> > > >
> > > > Why? Are you doing something wrong?
> > > >
> > > > Do you think everyone who carries a gun is looking for someone to
> > > > shoot?
> > >
> > > If I don't know the person, I'd have no reason to think I'm safe around
> > > them.
> >
> > You have probably been around people carrying concealed firearms and did
> > not even know it. I carried a concealed firearm when in public for several
> > years and doubt that anyone knew it since I kept it concealed.
>
> Then I wouldn't be afraid of what they might do, now would I?

That's a valid point.