Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0000426OCamlCamlIDLpublic2001-07-09 16:122001-07-30 16:33
Reporteradministrator 
Assigned To 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionfixed 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0000426: camlidl generated .h headers in C++ mode
DescriptionFull_Name: Dmitry Bely
Version: camlidl current cvs
OS: Windows NT 4.0
Submission from: d227.p3.col.ru (195.210.132.227)


Let's consider the following example:

[---cut---]
void f();

[object]
interface ITest: IUnknown
{
    void method();
}
[---cut---]

It produces cplusplus.h file which we are going to use in C++ mode:

[---cut---]
/* File generated from cplusplus.idl */

#ifndef _CAMLIDL_CPLUSPLUS_H
#define _CAMLIDL_CPLUSPLUS_H

extern void f(void); /* (1) */

struct ITest;
#ifdef __cplusplus
struct ITest {
  virtual HRESULT (STDMETHODCALLTYPE *QueryInterface)(IID *, void **);
  virtual ULONG (STDMETHODCALLTYPE *AddRef)();
  virtual ULONG (STDMETHODCALLTYPE *Release)();
  virtual void (STDMETHODCALLTYPE *method)(); /* (2) */
};
#else
struct ITestVtbl {
  DECLARE_VTBL_PADDING
  HRESULT (STDMETHODCALLTYPE *QueryInterface)(struct ITest *, IID *, void **);
  ULONG (STDMETHODCALLTYPE *AddRef)(struct ITest *);
  ULONG (STDMETHODCALLTYPE *Release)(struct ITest *);
  void (STDMETHODCALLTYPE *method)(struct ITest * self);
};
struct ITest {
  struct ITestVtbl * lpVtbl;
};
#endif
extern IID IID_ITest; /* (3) */

#endif /* !_CAMLIDL_CPLUSPLUS_H */
[---cut---]

(1,3) Extern variables and functions should be declared as 'extern "C"' in c++
mode.
(2) Syntax error -- should be "virtual void STDMETHODCALLTYPE method();"

Also when we generate code for Win32, proper COM-compatible alignment should be
specified.

So the following path is proposed:

[---cut---]
Index: compiler/file.ml
===================================================================
RCS file: /caml/bazar-ocaml/camlidl/compiler/file.ml,v
retrieving revision 1.16
diff -u -r1.16 file.ml
--- compiler/file.ml 2001/06/15 16:53:45 1.16
+++ compiler/file.ml 2001/07/09 13:43:25
@@ -216,8 +216,21 @@
   fprintf oc "\
     #ifndef %s\n\
     #define %s\n\n" symbname symbname;
+ fprintf oc "\
+ #ifdef __cplusplus\n\
+ #define _CAMLIDL_EXTERN_C extern \"C\"\n\
+ #else\n\
+ #define _CAMLIDL_EXTERN_C extern\n\
+ #endif\n\n\
+ #ifdef _WIN32\n\
+ #pragma pack(push,8) /* is necessary for COM interfaces */\n\
+ #endif\n\n";
   (* Emit the definitions *)
   List.iter (process_definition oc) intf;
+ fprintf oc "\
+ #ifdef _WIN32\n\
+ #pragma pack(pop)\n\
+ #endif\n\n";
   fprintf oc "\n\
     #endif /* !%s */\n" symbname
 
Index: compiler/funct.ml
===================================================================
RCS file: /caml/bazar-ocaml/camlidl/compiler/funct.ml,v
retrieving revision 1.25
diff -u -r1.25 funct.ml
--- compiler/funct.ml 2001/06/17 10:50:25 1.25
+++ compiler/funct.ml 2001/07/09 13:43:27
@@ -114,7 +114,7 @@
 (* Generate the C declaration for a function *)
 
 let c_declaration oc fundecl =
- fprintf oc "extern %a(" out_c_decl (fundecl.fun_name, fundecl.fun_res);
+ fprintf oc "_CAMLIDL_EXTERN_C %a(" out_c_decl (fundecl.fun_name,
fundecl.fun_res);
   begin match fundecl.fun_params with
     [] -> fprintf oc "void"
   | p1 :: pl ->
Index: compiler/intf.ml
===================================================================
RCS file: /caml/bazar-ocaml/camlidl/compiler/intf.ml,v
retrieving revision 1.20
diff -u -r1.20 intf.ml
--- compiler/intf.ml 2001/06/17 10:50:25 1.20
+++ compiler/intf.ml 2001/07/09 13:43:31
@@ -122,7 +122,7 @@
     List.iter
       (fun m ->
         iprintf oc "virtual %a("
- out_c_decl (sprintf "(STDMETHODCALLTYPE *%s)" m.fun_name,
+ out_c_decl (sprintf "STDMETHODCALLTYPE %s" m.fun_name,
                                m.fun_res);
         let first = ref true in
         List.iter
@@ -153,7 +153,7 @@
     fprintf oc " struct %sVtbl * lpVtbl;\n" intf.intf_name;
     fprintf oc "};\n";
     fprintf oc "#endif\n";
- fprintf oc "extern IID IID_%s;\n\n" intf.intf_name
+ fprintf oc "_CAMLIDL_EXTERN_C IID IID_%s;\n\n" intf.intf_name
   end
 
 (* Define the wrapper classes *)
[---cut---]

and now we have

[---cut---]
/* File generated from cplusplus.idl */

#ifndef _CAMLIDL_CPLUSPLUS_H
#define _CAMLIDL_CPLUSPLUS_H

#ifdef __cplusplus
#define _CAMLIDL_EXTERN_C extern "C"
#else
#define _CAMLIDL_EXTERN_C extern
#endif

#ifdef _WIN32
#pragma pack(push,8) /* is necessary for COM interfaces */
#endif

_CAMLIDL_EXTERN_C void f(void);

struct ITest;
#ifdef __cplusplus
struct ITest {
  virtual HRESULT STDMETHODCALLTYPE QueryInterface(IID *, void **);
  virtual ULONG STDMETHODCALLTYPE AddRef();
  virtual ULONG STDMETHODCALLTYPE Release();
  virtual void STDMETHODCALLTYPE method();
};
#else
struct ITestVtbl {
  DECLARE_VTBL_PADDING
  HRESULT (STDMETHODCALLTYPE *QueryInterface)(struct ITest *, IID *, void **);
  ULONG (STDMETHODCALLTYPE *AddRef)(struct ITest *);
  ULONG (STDMETHODCALLTYPE *Release)(struct ITest *);
  void (STDMETHODCALLTYPE *method)(struct ITest * self);
};
struct ITest {
  struct ITestVtbl * lpVtbl;
};
#endif
_CAMLIDL_EXTERN_C IID IID_ITest;

#ifdef _WIN32
#pragma pack(pop)
#endif


#endif /* !_CAMLIDL_CPLUSPLUS_H */
[---cut---]

TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0000051)
administrator (administrator)
2001-07-30 16:33

Suggested patch applied 2001-07-30 by XL.

- Issue History
Date Modified Username Field Change
2005-11-18 10:13 administrator New Issue


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker