@@ -1357,19 +1357,55 @@ Handle<Value> DLOpen(const v8::Arguments& args) {
13571357 return ThrowException (exception);
13581358 }
13591359
1360+ String::Utf8Value symbol (args[0 ]->ToString ());
1361+ char *symstr = NULL ;
1362+ {
1363+ char *sym = *symbol;
1364+ char *p = strrchr (sym, ' /' );
1365+ if (p != NULL ) {
1366+ sym = p+1 ;
1367+ }
1368+
1369+ p = strrchr (sym, ' .' );
1370+ if (p != NULL ) {
1371+ *p = NULL ;
1372+ }
1373+
1374+ size_t slen = strlen (sym);
1375+ symstr = static_cast <char *>(calloc (1 , slen + sizeof (" _module" ) + 1 ));
1376+ memcpy (symstr, sym, slen);
1377+ memcpy (symstr+slen, " _module" , sizeof (" _module" ) + 1 );
1378+ }
1379+
13601380 // Get the init() function from the dynamically shared object.
1361- void *init_handle = dlsym (handle, " init" );
1381+ node_module_struct *mod = static_cast <node_module_struct *>(dlsym (handle, symstr));
1382+ free (symstr);
13621383 // Error out if not found.
1363- if (init_handle == NULL ) {
1364- dlclose (handle);
1384+ if (mod == NULL ) {
1385+ /* Start Compatibility hack: Remove once everyone is using NODE_MODULE macro */
1386+ node_module_struct compat_mod;
1387+ mod = &compat_mod;
1388+ mod->version = NODE_MODULE_VERSION ;
1389+
1390+ void *init_handle = dlsym (handle, " init" );
1391+ if (init_handle == NULL ) {
1392+ dlclose (handle);
1393+ Local<Value> exception =
1394+ Exception::Error (String::New (" No module symbol found in module." ));
1395+ return ThrowException (exception);
1396+ }
1397+ mod->register_func = (extInit)(init_handle);
1398+ /* End Compatibility hack */
1399+ }
1400+
1401+ if (mod->version != NODE_MODULE_VERSION ) {
13651402 Local<Value> exception =
1366- Exception::Error (String::New (" No 'init' symbol found in module ." ));
1403+ Exception::Error (String::New (" Module version mismatch, refusing to load ." ));
13671404 return ThrowException (exception);
13681405 }
1369- extInit init = (extInit)(init_handle); // Cast
13701406
13711407 // Execute the C++ module
1372- init (target);
1408+ mod-> register_func (target);
13731409
13741410 // Tell coverity that 'handle' should not be freed when we return.
13751411 // coverity[leaked_storage]
0 commit comments