Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > help from *nix ruby users

Reply
Thread Tools

help from *nix ruby users

 
 
Ara.T.Howard
Guest
Posts: n/a
 
      08-03-2004

i have a bit of code that packs an flock struct

struct flock {
...
short l_type; /* Type of lock: F_RDLCK,
F_WRLCK, F_UNLCK */
short l_whence; /* How to interpret l_start:
SEEK_SET, SEEK_CUR, SEEK_END */
off_t l_start; /* Starting offset for lock */
off_t l_len; /* Number of bytes to lock */
pid_t l_pid; /* PID of process blocking our lock
(F_GETLK only) */
...
};

using 'ssqqi' (thanks to matz for this tip). this works for linux, but i'm
sure it won't for other *nixes with different flock layouts. if i understand
ruby dl there is no way to portably set the fields of a struct unless you
already know it's layout, so packing is just as good in this case (please
correct me if i'm wrong). what i'm asking for people on various *nixes to
post their struct flock definitions so i can add appropriate pack templates
for those.

this output of

ruby -r rbconfig -e 'p Config::CONFIG["arch"]'

would also be useful

if there is an easier way to do this - some online resource where i could find
this info - please let me know

thanks alot.

-a
--
================================================== =============================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| A flower falls, even though we love it;
| and a weed grows, even though we do not love it.
| --Dogen
================================================== =============================
 
Reply With Quote
 
 
 
 
David Ross
Guest
Posts: n/a
 
      08-03-2004


The output is from my DragonFlyBSD systems. It is the
same in FreeBSD4.x


> ruby -r rbconfig -e 'p Config::CONFIG["arch"]'

"i386-dragonfly1.1"


struct flock {
off_t l_start; /* starting offset */
off_t l_len; /* len = 0 means until
end of file */
pid_t l_pid; /* lock owner */
short l_type; /* lock type:
read/write, etc. */
short l_whence; /* type of l_start */
};




--- "Ara.T.Howard" <(E-Mail Removed)> wrote:

>
> i have a bit of code that packs an flock struct
>
> struct flock {
> ...
> short l_type; /* Type of lock: F_RDLCK,
> F_WRLCK, F_UNLCK */
> short l_whence; /* How to interpret l_start:
> SEEK_SET, SEEK_CUR,
> SEEK_END */
> off_t l_start; /* Starting offset for lock
> */
> off_t l_len; /* Number of bytes to lock */
> pid_t l_pid; /* PID of process blocking
> our lock
> (F_GETLK only) */
> ...
> };
>
> using 'ssqqi' (thanks to matz for this tip). this
> works for linux, but i'm
> sure it won't for other *nixes with different flock
> layouts. if i understand
> ruby dl there is no way to portably set the fields
> of a struct unless you
> already know it's layout, so packing is just as good
> in this case (please
> correct me if i'm wrong). what i'm asking for
> people on various *nixes to
> post their struct flock definitions so i can add
> appropriate pack templates
> for those.
>
> this output of
>
> ruby -r rbconfig -e 'p Config::CONFIG["arch"]'
>
> would also be useful
>
> if there is an easier way to do this - some online
> resource where i could find
> this info - please let me know
>
> thanks alot.
>
> -a
> --
>

================================================== =============================
> | EMAIL :: Ara [dot] T [dot] Howard [at] noaa
> [dot] gov
> | PHONE :: 303.497.6469
> | A flower falls, even though we love it;
> | and a weed grows, even though we do not love it.
> | --Dogen
>

================================================== =============================
>
>





__________________________________
Do you Yahoo!?
Yahoo! Mail Address AutoComplete - You start. We finish.
http://promotions.yahoo.com/new_mail


 
Reply With Quote
 
 
 
 
Ara.T.Howard
Guest
Posts: n/a
 
      08-03-2004
On Tue, 3 Aug 2004, David Ross wrote:

>
>
> The output is from my DragonFlyBSD systems. It is the
> same in FreeBSD4.x
>
>
>> ruby -r rbconfig -e 'p Config::CONFIG["arch"]'

> "i386-dragonfly1.1"
>
>
> struct flock {
> off_t l_start; /* starting offset */
> off_t l_len; /* len = 0 means until
> end of file */
> pid_t l_pid; /* lock owner */
> short l_type; /* lock type:
> read/write, etc. */
> short l_whence; /* type of l_start */
> };


wow - they just do it backwards (or linux does) - why can't they all just get
along ;-(

thanks - i'll add this one in!


-a
--
================================================== =============================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| A flower falls, even though we love it;
| and a weed grows, even though we do not love it.
| --Dogen
================================================== =============================
 
Reply With Quote
 
Lothar Scholz
Guest
Posts: n/a
 
      08-03-2004
Hello Ara.T.Howard,

ATH> On Tue, 3 Aug 2004, David Ross wrote:

>>
>>
>> The output is from my DragonFlyBSD systems. It is the
>> same in FreeBSD4.x
>>
>>
>>> ruby -r rbconfig -e 'p Config::CONFIG["arch"]'

>> "i386-dragonfly1.1"
>>
>>
>> struct flock {
>> off_t l_start; /* starting offset */
>> off_t l_len; /* len = 0 means until
>> end of file */
>> pid_t l_pid; /* lock owner */
>> short l_type; /* lock type:
>> read/write, etc. */
>> short l_whence; /* type of l_start */
>> };


ATH> wow - they just do it backwards (or linux does) - why can't they all just get
ATH> along ;-(

ATH> thanks - i'll add this one in!

Why don't you write a small C level function with "offset_of" to access the values.
You will always run in problems with different datasizes, different
compiler alignments, different struct's.

--
Best regards, emailto: scholz at scriptolutions dot com
Lothar Scholz http://www.ruby-ide.com
CTO Scriptolutions Ruby, PHP, Python IDE 's




 
Reply With Quote
 
David Ross
Guest
Posts: n/a
 
      08-03-2004
Its been like that since 1994 in FreeBSD
OpenBSD and NetBSD should have the same.. lemme
check..

NetBSD.. checked
OpenBSD. checked

They are all the same

--David Ross

--- "Ara.T.Howard" <(E-Mail Removed)> wrote:

> On Tue, 3 Aug 2004, David Ross wrote:
>
> >
> >
> > The output is from my DragonFlyBSD systems. It is

> the
> > same in FreeBSD4.x
> >
> >
> >> ruby -r rbconfig -e 'p Config::CONFIG["arch"]'

> > "i386-dragonfly1.1"
> >
> >
> > struct flock {
> > off_t l_start; /* starting offset

> */
> > off_t l_len; /* len = 0 means

> until
> > end of file */
> > pid_t l_pid; /* lock owner */
> > short l_type; /* lock type:
> > read/write, etc. */
> > short l_whence; /* type of l_start

> */
> > };

>
> wow - they just do it backwards (or linux does) -
> why can't they all just get
> along ;-(
>
> thanks - i'll add this one in!
>
>
> -a
> --
>

================================================== =============================
> | EMAIL :: Ara [dot] T [dot] Howard [at] noaa
> [dot] gov
> | PHONE :: 303.497.6469
> | A flower falls, even though we love it;
> | and a weed grows, even though we do not love it.
> | --Dogen
>

================================================== =============================
>
>





__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
http://promotions.yahoo.com/new_mail


 
Reply With Quote
 
Ara.T.Howard
Guest
Posts: n/a
 
      08-03-2004
On Wed, 4 Aug 2004, Lothar Scholz wrote:

> Why don't you write a small C level function with "offset_of" to access the
> values. You will always run in problems with different datasizes, different
> compiler alignments, different struct's.


lothar-

never knew about offset_of... nice macro. however, if i were writing it in C
i could just use the stuct members couldn't i? am i missing something here?
this should compile on any posix system:

struct flock flock;

flock.l_type = F_RDLCK;
flock.l_whence = SEEK_SET;
flock.l_start = 0;
flock.l_len = 0;

etc. since posix stipultes these members must exist (it just doesn't say where
or if there are others before or after!)

am i missing something?

regards.


-a
--
================================================== =============================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| A flower falls, even though we love it;
| and a weed grows, even though we do not love it.
| --Dogen
================================================== =============================
 
Reply With Quote
 
Nicholas Van Weerdenburg
Guest
Posts: n/a
 
      08-05-2004
Is there any difference between

ruby -r rbconfig -e 'p Config::CONFIG["arch"]'

and

ruby -e 'p PLATFORM'

Thanks,
Nick

Ara.T.Howard wrote:

>
> i have a bit of code that packs an flock struct
>
> struct flock {
> ...
> short l_type; /* Type of lock: F_RDLCK,
> F_WRLCK, F_UNLCK */
> short l_whence; /* How to interpret l_start:
> SEEK_SET, SEEK_CUR, SEEK_END */
> off_t l_start; /* Starting offset for lock */
> off_t l_len; /* Number of bytes to lock */
> pid_t l_pid; /* PID of process blocking our lock
> (F_GETLK only) */
> ...
> };
>
> using 'ssqqi' (thanks to matz for this tip). this works for linux,
> but i'm
> sure it won't for other *nixes with different flock layouts. if i
> understand
> ruby dl there is no way to portably set the fields of a struct unless you
> already know it's layout, so packing is just as good in this case (please
> correct me if i'm wrong). what i'm asking for people on various
> *nixes to
> post their struct flock definitions so i can add appropriate pack
> templates
> for those.
>
> this output of
>
> ruby -r rbconfig -e 'p Config::CONFIG["arch"]'
>
> would also be useful
>
> if there is an easier way to do this - some online resource where i
> could find
> this info - please let me know
>
> thanks alot.
>
> -a
> --
> ================================================== =============================
>
> | EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
> | PHONE :: 303.497.6469
> | A flower falls, even though we love it;
> | and a weed grows, even though we do not love it. | --Dogen
> ================================================== =============================
>
>



 
Reply With Quote
 
nobu.nokada@softhome.net
Guest
Posts: n/a
 
      08-05-2004
Hi,

At Thu, 5 Aug 2004 13:25:54 +0900,
Nicholas Van Weerdenburg wrote in [ruby-talk:108359]:
> Is there any difference between
>
> ruby -r rbconfig -e 'p Config::CONFIG["arch"]'
>
> and
>
> ruby -e 'p PLATFORM'


Almostly equal. But they can be different while cross
compiling.

Although many extension libraries (even ext/extmk.rb and
lib/mkmf.rb) uses RUBY_PLATFORM in their extconf.rb to determin
the target platform, I consider it shouldn't.

Moreover, PLATFORM, VERSION and RELEASE_DATE have been
deprecated long ago, so never use them.

--
Nobu Nakada


 
Reply With Quote
 
Nicholas Van Weerdenburg
Guest
Posts: n/a
 
      08-05-2004
Thanks.

How would I normally determine if something is deprecated in ruby? After
your email, I tried "ruby -w -e 'p PLATFORM'" but didn't see any
warnings of deprecation (if that would be one way to check).

Thanks,
Nick

http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

>Hi,
>
>At Thu, 5 Aug 2004 13:25:54 +0900,
>Nicholas Van Weerdenburg wrote in [ruby-talk:108359]:
>
>
>>Is there any difference between
>>
>>ruby -r rbconfig -e 'p Config::CONFIG["arch"]'
>>
>>and
>>
>>ruby -e 'p PLATFORM'
>>
>>

>
>Almostly equal. But they can be different while cross
>compiling.
>
>Although many extension libraries (even ext/extmk.rb and
>lib/mkmf.rb) uses RUBY_PLATFORM in their extconf.rb to determin
>the target platform, I consider it shouldn't.
>
>Moreover, PLATFORM, VERSION and RELEASE_DATE have been
>deprecated long ago, so never use them.
>
>
>



 
Reply With Quote
 
Ara.T.Howard
Guest
Posts: n/a
 
      08-05-2004
On Thu, 5 Aug 2004 (E-Mail Removed) wrote:

> Hi,
>
> At Thu, 5 Aug 2004 13:25:54 +0900,
> Nicholas Van Weerdenburg wrote in [ruby-talk:108359]:
>> Is there any difference between
>>
>> ruby -r rbconfig -e 'p Config::CONFIG["arch"]'
>>
>> and
>>
>> ruby -e 'p PLATFORM'

>
> Almostly equal. But they can be different while cross
> compiling.
>
> Although many extension libraries (even ext/extmk.rb and
> lib/mkmf.rb) uses RUBY_PLATFORM in their extconf.rb to determin
> the target platform, I consider it shouldn't.
>
> Moreover, PLATFORM, VERSION and RELEASE_DATE have been
> deprecated long ago, so never use them.
>
> --
> Nobu Nakada


so you reccomend using CONFIG['arch']? how about for #ifdefs in extenstions?


-a
--
================================================== =============================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| A flower falls, even though we love it;
| and a weed grows, even though we do not love it.
| --Dogen
================================================== =============================
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
#!/usr/bin/ruby , #!/usr/bin/ruby -w , #!/usr/bin/ruby -T?, #!/usr/bin/ruby -T1... anne001 Ruby 1 04-23-2006 03:02 PM
Help me in making users/deleting users in active directory Sara rafiee ASP .Net 3 10-04-2004 01:35 PM
Help me in making users/deleting users in active directory Sara rafiee ASP .Net Web Controls 1 10-04-2004 12:00 PM
BA-rb ( Bay Area Ruby Users Group ) - 'Generating Code in Ruby' by Jack Herrington. Grant Steinfeld Ruby 0 10-29-2003 07:52 PM
BA-rb ( Bay Area Ruby Users Group ) - 'Generating Code in Ruby' by Jack Herrington. Grant Steinfeld Ruby 0 10-28-2003 05:01 AM



Advertisments