[Date Prev] [Date Next] [Thread Prev] [Thread Next] Date Index Thread Index Search archive:
Date:Mon Nov 26 11:51:00 2003 
Subject:accessing compound fields in external pointer class records ... 
From:bsl 
Volume-ID:1031126.01 


at least, I think that's what I am trying to do--the documentation is a
little difficult to follow.

I have some Pop code which calls the getrusage system call:

uses newexternal;

external declare resource in c;

    ;;; This is taken from the definition in /usr/include/bits/time.h and
    ;;; /usr/include/bits/types.h
    typedef struct timeval
    {
     long tv_sec;    /* seconds */
     long tv_usec;   /* microseconds */
    } timeval_t;
    
    typedef struct rusage 
    {
     timeval_t ru_utime; /* user time used */
     timeval_t ru_stime; /* system time used */
     long ru_maxrss;     /* maximum resident set size */
     long ru_ixrss;      /* integral shared memory size */
     long ru_idrss;      /* integral unshared data size */
     long ru_isrss;      /* integral unshared stack size */
     long ru_minflt;     /* page reclaims */
     long ru_majflt;     /* page faults */
     long ru_nswap;      /* swaps */
     long ru_inblock;    /* block input operations */
     long ru_oublock;    /* block output operations */
     long ru_msgsnd;     /* messages sent */
     long ru_msgrcv;     /* messages received */
     long ru_nsignals;   /* signals receiv4ed */
     long ru_nvcsw;      /* voluntary context switches */
     long ru_nivcsw;     /* involuntary context switches */
    } rusage_t;

    int getrusage(who, usage)
    int who;
    rusage_t *usage;
    {}

endexternal;

;;; Poplog thinks that -lc is /usr/lib/libc.so, but on Linux this is a 
;;; GNU ld script so we have to be explicit.
external load resource; 
    '/lib/libc.so.6'
endexternal;

This sort of works.  If I do:

vars r = initrusage_t(false); r =>

I get:

** struct rusage
	ru_utime -    <external_ptr>
	ru_stime -    <external_ptr>
	ru_maxrss -   0
	ru_ixrss -    0
	ru_idrss -    0
	ru_isrss -    0
	ru_minflt -   0
	ru_majflt -   0
	ru_nswap -    0
	ru_inblock -  0
	ru_oublock -  0
	ru_msgsnd -   0
	ru_msgrcv -   0
	ru_nsignals - 0
	ru_nvcsw -    0
	ru_nivcsw -   0 
:

and I can do, e.g.

r#:ru_maxrss =>

which gives:

** 0 

but if I try to access the fields of the ru_utime and ru_stime fields of the
rusage struct I get:

: r#:ru_utime#:tv_sec =>

;;; MISHAP - INVALID DATA TYPE FOR STRUCT ACCESS
;;; INVOLVING:  Type key - <key external_ptr> field name - tv_sec 
;;; DOING    :  struct_field_access pop_setpop_compiler 

However if I do: 

vars r1 = initrusage_t(false); r1 =>

I get:

** struct rusage
	ru_utime -    struct timeval
		tv_sec -  0
		tv_usec - 0
	ru_stime -    struct timeval
		tv_sec -  0
		tv_usec - 0
	ru_maxrss -   0
	ru_ixrss -    0
	ru_idrss -    0
	ru_isrss -    0
	ru_minflt -   0
	ru_majflt -   0
	ru_nswap -    0
	ru_inblock -  0
	ru_oublock -  0
	ru_msgsnd -   0
	ru_msgrcv -   0
	ru_nsignals - 0
	ru_nvcsw -    0
	ru_nivcsw -   0 
: 

and 

: r1#:ru_utime#:tv_sec =>

works

** 0 
: 

though

: r#:ru_utime#:tv_sec =>

still doesn't.

;;; MISHAP - INVALID DATA TYPE FOR STRUCT ACCESS
;;; INVOLVING:  Type key - <key external_ptr> field name - tv_sec 
;;; DOING    :  struct_field_access pop_setpop_compiler 

Can someone explain to me what is going on?

Thanks


-- Brian

  Brian Logan,  School of Computer Science & IT, University of Nottingham
 Email: bsl@cs.nott.ac.uk,  Phone: +44 115 846 6509, Fax: +44 115 951 4254