Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

camlidl generated .h headers in C++ mode #2829

Closed
vicuna opened this issue Jul 9, 2001 · 1 comment
Closed

camlidl generated .h headers in C++ mode #2829

vicuna opened this issue Jul 9, 2001 · 1 comment

Comments

@vicuna
Copy link

vicuna commented Jul 9, 2001

Original bug ID: 426
Reporter: administrator
Status: closed
Resolution: fixed
Priority: normal
Severity: minor
Category: -for CamlIDL use https://github.com/xavierleroy/camlidl/issues

Bug description

Full_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---]

@vicuna
Copy link
Author

vicuna commented Jul 30, 2001

Comment author: administrator

Suggested patch applied 2001-07-30 by XL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant