caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Camlidl and order of include files
@ 2001-10-30 23:08 John Gerard Malecki
  2001-10-31 10:18 ` Dmitry Bely
  0 siblings, 1 reply; 4+ messages in thread
From: John Gerard Malecki @ 2001-10-30 23:08 UTC (permalink / raw)
  To: caml-list

Hi,

I just tried camlidl and am not sure if I am using it wrong or if I
have encountered a bug.  I want to access the (solaris) sysconf system
routine to find out how many processors on a machine.  I wrote this
idl file

  quote(C,"#include <unistd.h>")
  
  enum sysconf_names {
    SC_NPROCESSOR_ONLN = _SC_NPROCESSORS_ONLN
  };
  
  long sysconf([in] enum sysconf_names name);

I put this file in the camlidl-1.02/tests directory and executed 'make
sysconf.o' only to get

  ../compiler/camlidl -header sysconf.idl
  ocamlc -I ../lib -c sysconf.mli
  ocamlc -I ../lib -c sysconf.ml
  gcc -Wall -I.. -I/home/vtools/sun4os5/apps/ocaml-3.02/lib/ocaml -c sysconf.c
  In file included from sysconf.c:16:
  sysconf.h:17: `_SC_NPROCESSORS_ONLN' undeclared here (not in a function)
  sysconf.h:17: enumerator value for `SC_NPROCESSOR_ONLN' not integer constant

When I look in sysconf.c I notice

  #include "sysconf.h"
  
  #include <unistd.h>

If I change this order to

  #include <unistd.h>
  
  #include "sysconf.h"

The program now compiles and I am able to successfully use the code.

  :; cat test_sysconf.ml
  let _ =
    Printf.printf "sysconf ==> %d\n"
      (Sysconf.sysconf Sysconf.SC_NPROCESSOR_ONLN)
  :; ocamlc -c test_sysconf.ml 
  :; ocamlc -custom sysconf.cmo test_sysconf.cmo sysconf.o
  :; ./a.out
  sysconf ==> 2

Am I making proper use of camlidl?
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Camlidl and order of include files
  2001-10-30 23:08 [Caml-list] Camlidl and order of include files John Gerard Malecki
@ 2001-10-31 10:18 ` Dmitry Bely
  2001-10-31 15:19   ` John Gerard Malecki
  0 siblings, 1 reply; 4+ messages in thread
From: Dmitry Bely @ 2001-10-31 10:18 UTC (permalink / raw)
  To: caml-list

John Gerard Malecki <johnm@artisan.com> writes:

> I just tried camlidl and am not sure if I am using it wrong or if I
> have encountered a bug.  I want to access the (solaris) sysconf system
> routine to find out how many processors on a machine.  I wrote this
> idl file
> 
>   quote(C,"#include <unistd.h>")
>   
>   enum sysconf_names {
>     SC_NPROCESSOR_ONLN = _SC_NPROCESSORS_ONLN
>   };


Use quote(h,"#include <unistd.h>")

and then C stubs will compile, but your code still will be incorrect. How
the generated Caml part will know the value of _SC_NPROCESSORS_ONLN?
Obviously, it is not defined for Camlidl. It should generate an error
message here. It does not, and that's the bug in Camlidl (you can submit a
bug report). As for correct solution, you should either convert <unistd.h>
to IDL and then use

#include unistd.idl
   
enum sysconf_names {
   SC_NPROCESSOR_ONLN = _SC_NPROCESSORS_ONLN
};

or resolve _SC_NPROCESSORS_ONLN macro manually:

quote(C,"#include <unistd.h>")

enum sysconf_names {
   SC_NPROCESSOR_ONLN = 9
};

Hope to hear from you soon,
Dmitry


-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Camlidl and order of include files
  2001-10-31 10:18 ` Dmitry Bely
@ 2001-10-31 15:19   ` John Gerard Malecki
  2001-10-31 17:01     ` Dmitry Bely
  0 siblings, 1 reply; 4+ messages in thread
From: John Gerard Malecki @ 2001-10-31 15:19 UTC (permalink / raw)
  To: Dmitry Bely; +Cc: caml-list

Hi Dmitry,

I am satisfied with simply using 

  quote(h,"#include <unistd.h>")

Canlidl does not need to know the value of _SC_NPROCESSORS_ONLN only
that the type is (something like) an enum.

No need for a camlidl bug report but the manual could benefit from an
index of the keywords.

Thanks for you help.

Dmitry Bely wrote (2001-10-31T13:18:12+0300):
 > John Gerard Malecki <johnm@artisan.com> writes:
 > 
 > > I just tried camlidl and am not sure if I am using it wrong or if I
 > > have encountered a bug.  I want to access the (solaris) sysconf system
 > > routine to find out how many processors on a machine.  I wrote this
 > > idl file
 > > 
 > >   quote(C,"#include <unistd.h>")
 > >   
 > >   enum sysconf_names {
 > >     SC_NPROCESSOR_ONLN = _SC_NPROCESSORS_ONLN
 > >   };
 > 
 > 
 > Use quote(h,"#include <unistd.h>")
 > 
 > and then C stubs will compile, but your code still will be incorrect. How
 > the generated Caml part will know the value of _SC_NPROCESSORS_ONLN?
 > Obviously, it is not defined for Camlidl. It should generate an error
 > message here. It does not, and that's the bug in Camlidl (you can submit a
 > bug report). As for correct solution, you should either convert <unistd.h>
 > to IDL and then use
 > 
 > #include unistd.idl
 >    
 > enum sysconf_names {
 >    SC_NPROCESSOR_ONLN = _SC_NPROCESSORS_ONLN
 > };
 > 
 > or resolve _SC_NPROCESSORS_ONLN macro manually:
 > 
 > quote(C,"#include <unistd.h>")
 > 
 > enum sysconf_names {
 >    SC_NPROCESSOR_ONLN = 9
 > };
 > 
 > Hope to hear from you soon,
 > Dmitry
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Camlidl and order of include files
  2001-10-31 15:19   ` John Gerard Malecki
@ 2001-10-31 17:01     ` Dmitry Bely
  0 siblings, 0 replies; 4+ messages in thread
From: Dmitry Bely @ 2001-10-31 17:01 UTC (permalink / raw)
  To: caml-list

John Gerard Malecki <johnm@artisan.com> writes:

> Hi Dmitry,
> 
> I am satisfied with simply using 
> 
>   quote(h,"#include <unistd.h>")
> 
> Canlidl does not need to know the value of _SC_NPROCESSORS_ONLN only
> that the type is (something like) an enum.
> 
> No need for a camlidl bug report

Yes, you are right. The bug was in my head, not in Camlidl :-)

Hope to hear from you soon,
Dmitry


-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2001-10-31 17:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-10-30 23:08 [Caml-list] Camlidl and order of include files John Gerard Malecki
2001-10-31 10:18 ` Dmitry Bely
2001-10-31 15:19   ` John Gerard Malecki
2001-10-31 17:01     ` Dmitry Bely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).