help from *nix ruby users

A

Ara.T.Howard

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
===============================================================================
 
D

David Ross

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 said:
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
 
A

Ara.T.Howard

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
===============================================================================
 
L

Lothar Scholz

Hello Ara.T.Howard,

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.
 
D

David Ross

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 said:
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
 
A

Ara.T.Howard

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
===============================================================================
 
N

Nicholas Van Weerdenburg

Is there any difference between

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

and

ruby -e 'p PLATFORM'

Thanks,
Nick
 
N

nobu.nokada

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.
 
N

Nicholas Van Weerdenburg

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

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.
 
A

Ara.T.Howard

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.

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
===============================================================================
 
N

nobu.nokada

Hi,

At Thu, 5 Aug 2004 22:02:48 +0900,
Nicholas Van Weerdenburg wrote in [ruby-talk:108380]:
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).

Constants are not accessed with a method, so we don't have a
way to check about it. Only I think out is a trick using
const_missing.

class Object
class << self
depr = [:VERSION, :pLATFORM, :RELEASE_DATE]
define_method:)const_missing) do |i|
if depr.include?(i)
warn "#{caller(2)[0]}: #{i} is deprecated, use RUBY_#{i}"
const_get("RUBY_#{i}")
else
begin
super(i)
rescue NameError
$@[0,2] = nil
raise
end
end
end
depr
end.each(&method:)remove_const))
end
 
N

nobu.nokada

Hi,

At Thu, 5 Aug 2004 22:51:36 +0900,
Ara.T.Howard wrote in [ruby-talk:108383]:
so you reccomend using CONFIG['arch']? how about for #ifdefs in extenstions?

Platform/compiler specific macros are not concerned with ruby.
However, I'd prefer to test per feature in extconf.rb.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top