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

OS exception while initializing Ocaml COM DLL #3425

Closed
vicuna opened this Issue Jul 13, 2002 · 1 comment

Comments

Projects
None yet
1 participant
@vicuna
Copy link
Collaborator

vicuna commented Jul 13, 2002

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

Bug description

Ocaml: CVS version
camlidl: CVS version
OS: Windows 2000

The problem is that DllMain() in runtime/cfactory.cpp sets argv[0]
(executable name) to NULL:

BOOL APIENTRY DllMain(HANDLE module, DWORD reason, void *reserved)
{
char * argv[1];

switch(reason) {
case DLL_PROCESS_ATTACH:
argv[0] = NULL; //********** executable name **********
camlidl_module_handle = (HMODULE) module;
#if 0
int fd = open("/tmp/camllog", O_RDWR|O_TRUNC|O_CREAT, _S_IWRITE|_S_IREAD);
dup2(fd, 1);
dup2(fd, 2);
close(fd);
#endif
caml_startup(argv);
break;
/* TODO: free all memory when DLL detached */
}
return TRUE;
}

but this NULL is not acceptable by Sys module startup code:

CAMLprim value sys_get_argv(value unit)
{
CAMLparam0 (); /* unit is unused /
CAMLlocal3 (exe_name, argv, res);
exe_name = copy_string(caml_exe_name); //
********* caml_exe_names == NULL **********
argv = copy_string_array((char const **) caml_main_argv);
res = alloc_small(2, 0);
Field(res, 0) = exe_name;
Field(res, 1) = argv;
CAMLreturn(res);
}

CAMLexport value copy_string(char const *s)
{
int len;
value res;

len = strlen(s); //********** s == NULL here, so the function fails **********
res = alloc_string(len);
memmove(String_val(res), s, len);
return res;
}

Here is the fix:

Index: cfactory.cpp

RCS file: /caml/bazar-ocaml/camlidl/runtime/cfactory.cpp,v
retrieving revision 1.8
diff -u -r1.8 cfactory.cpp
--- cfactory.cpp 2001/07/30 14:05:17 1.8
+++ cfactory.cpp 2002/07/13 16:06:59
@@ -26,6 +26,11 @@
#include "comstuff.h"
#include "registry.h"

+#ifdef CYGWIN32
+#include <sys/param.h>
+#define _MAX_PATH MAXPATHLEN
+#endif
+
/* Count of server locks */
static long camlidl_num_server_locks = 0;

@@ -173,13 +178,17 @@

/* DLL entry point */

+extern "C"
BOOL APIENTRY DllMain(HANDLE module, DWORD reason, void *reserved)
{

  • char * argv[1];
  • char * argv[2];

  • char dll_path[_MAX_PATH];

    switch(reason) {
    case DLL_PROCESS_ATTACH:

  • argv[0] = NULL;
  • GetModuleFileName( (HMODULE) module, dll_path, _MAX_PATH );
  • argv[0] = dll_path;
  • argv[1] = NULL;
    camlidl_module_handle = (HMODULE) module;
    #if 0
    int fd = open("/tmp/camllog", O_RDWR|O_TRUNC|O_CREAT, _S_IWRITE|_S_IREAD);

Strange enough that the error only appears in the native code DLLs and that
I did not observed it before.

Hope to hear from you soon,
Dmitry

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

vicuna commented Jul 8, 2004

Comment author: administrator

Fixed as suggested 2004-07-08 XL

@vicuna vicuna closed this Jul 8, 2004

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.