Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0001234OCamlCamlIDLpublic2002-07-13 20:092004-07-08 11:48
Reporteradministrator 
Assigned To 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionfixed 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0001234: OS exception while initializing Ocaml COM DLL
DescriptionOcaml: 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


TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0000088)
administrator (administrator)
2004-07-08 11:48

Fixed as suggested 2004-07-08 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