help from *nix ruby users

Discussion in 'Ruby' started by Ara.T.Howard, Aug 3, 2004.

  1. Ara.T.Howard

    Ara.T.Howard Guest

    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
    ===============================================================================
     
    Ara.T.Howard, Aug 3, 2004
    #1
    1. Advertising

  2. Ara.T.Howard

    David Ross Guest

    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" <> 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
     
    David Ross, Aug 3, 2004
    #2
    1. Advertising

  3. Ara.T.Howard

    Ara.T.Howard Guest

    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
    ===============================================================================
     
    Ara.T.Howard, Aug 3, 2004
    #3
  4. 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
     
    Lothar Scholz, Aug 3, 2004
    #4
  5. Ara.T.Howard

    David Ross Guest

    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" <> 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
     
    David Ross, Aug 3, 2004
    #5
  6. Ara.T.Howard

    Ara.T.Howard Guest

    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
    ===============================================================================
     
    Ara.T.Howard, Aug 3, 2004
    #6
  7. 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
    > ===============================================================================
    >
    >
     
    Nicholas Van Weerdenburg, Aug 5, 2004
    #7
  8. Ara.T.Howard

    Guest

    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
     
    , Aug 5, 2004
    #8
  9. 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

    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.
    >
    >
    >
     
    Nicholas Van Weerdenburg, Aug 5, 2004
    #9
  10. Ara.T.Howard

    Ara.T.Howard Guest

    On Thu, 5 Aug 2004 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
    ===============================================================================
     
    Ara.T.Howard, Aug 5, 2004
    #10
  11. Ara.T.Howard

    Guest

    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

    --
    Nobu Nakada
     
    , Aug 6, 2004
    #11
  12. Ara.T.Howard

    Guest

    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.

    --
    Nobu Nakada
     
    , Aug 6, 2004
    #12
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    13
    Views:
    639
    Bryan Castillo
    Oct 28, 2004
  2. Andrew Thompson
    Replies:
    4
    Views:
    389
    Andrew Thompson
    Nov 8, 2004
  3. Christian Wilcox

    RE: Help, *.CHM, etc -> *nix .chm viewer

    Christian Wilcox, Jan 21, 2004, in forum: Python
    Replies:
    1
    Views:
    418
    Markus Wankus
    Jan 21, 2004
  4. Martin DeMello

    *nix binaries not linked from ruby-lang

    Martin DeMello, Jan 14, 2004, in forum: Ruby
    Replies:
    0
    Views:
    80
    Martin DeMello
    Jan 14, 2004
  5. Ben Zealley

    Ruby and *NIX environment variables

    Ben Zealley, Jul 25, 2006, in forum: Ruby
    Replies:
    8
    Views:
    135
    Ben Zealley
    Jul 26, 2006
Loading...

Share This Page