]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Fix 2 errors in mod_spidermonkey on windows.
authorMichael Jerris <mike@jerris.com>
Mon, 23 Apr 2007 15:33:25 +0000 (15:33 +0000)
committerMichael Jerris <mike@jerris.com>
Mon, 23 Apr 2007 15:33:25 +0000 (15:33 +0000)
1. We need a pool for apr_stat.  Expand api and create a pool when necessary.
2. Don't use -1 value in enum for no reason as they can be signed or unsigned (compiler defined) so there is an int overflow.  This fixes an incorrect assert in the spidermonkey exception handling caused by an unsigned int overflow.

resolve http://jira.freeswitch.org/browse/MODLANG-7.

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5002 d0543943-73ff-0310-b7d9-9358b9ac24b2

libs/js/src/jspubtd.h
src/include/switch_apr.h
src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
src/mod/languages/mod_spidermonkey/mod_spidermonkey.h
src/switch_apr.c

index 05d7282fdfff80e0224b599372399b043c987686..02a9c1e574955d467bdf4fd63c82b89a8517ed05 100644 (file)
@@ -552,7 +552,7 @@ typedef void
  * JSEXN_NONE marks an unthrowable error.
  */
 typedef enum JSExnType {
-    JSEXN_NONE = -1,
+    JSEXN_NONE,
       JSEXN_ERR,
         JSEXN_INTERNALERR,
         JSEXN_EVALERR,
index 88d01e11ce854eb6ebfb15022e0bf4487f8cfb6e..ccf995e495aa326d1d32034d4f0adb661bcfdb55 100644 (file)
@@ -733,7 +733,7 @@ SWITCH_DECLARE(switch_status_t) switch_file_read(switch_file_t * thefile, void *
  */
 SWITCH_DECLARE(switch_status_t) switch_file_write(switch_file_t * thefile, const void *buf, switch_size_t *nbytes);
 
-SWITCH_DECLARE(switch_status_t) switch_file_exists(const char *filename);
+SWITCH_DECLARE(switch_status_t) switch_file_exists(const char *filename, switch_memory_pool_t *pool);
 
 /** @} */
 
index a9cc48d6109ee2b678e561812af1f053949e8bfc..8e499c6ca69cbc890909855da21ad3800d95c1fa 100644 (file)
@@ -2771,7 +2771,7 @@ static void  message_query_handler(switch_event_t *event)
                path  = switch_mprintf("%s%smwi.js", SWITCH_GLOBAL_dirs.script_dir, SWITCH_PATH_SEPARATOR);
                assert(path != NULL);
 
-               if (switch_file_exists(path) == SWITCH_STATUS_SUCCESS) {
+               if (switch_file_exists(path, NULL) == SWITCH_STATUS_SUCCESS) {
                        cmd = switch_mprintf("%s %s", path, account);
                        assert(cmd != NULL);
                        js_thread_launch(cmd);
index 24486d8339a9d5f996b58944274c5b73bcdbbc24..323d8bbb44ceb3962f359ad6c42dcd9234f5199b 100644 (file)
@@ -91,7 +91,7 @@ int eval_some_js(char *code, JSContext * cx, JSObject * obj, jsval * rval)
                        script_name = path;
                }
                if (script_name) {
-                       if (switch_file_exists(script_name) == SWITCH_STATUS_SUCCESS) {
+                       if (switch_file_exists(script_name, NULL) == SWITCH_STATUS_SUCCESS) {
                                script = JS_CompileFile(cx, obj, script_name);
                        } else {
                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Open File: %s\n", script_name);
index 7a25a9a3271a52289582809593d043647f27fdc5..076344bb3af393cb1ea7f5b5f6842d5bf07e0a17 100644 (file)
@@ -335,17 +335,31 @@ SWITCH_DECLARE(switch_status_t) switch_file_write(switch_file_t * thefile, const
        return apr_file_write(thefile, buf, nbytes);
 }
 
-SWITCH_DECLARE(switch_status_t) switch_file_exists(const char *filename)
+SWITCH_DECLARE(switch_status_t) switch_file_exists(const char *filename, switch_memory_pool_t *pool)
 {
        int32_t wanted = APR_FINFO_TYPE;
+       switch_memory_pool_t *our_pool = NULL;
+       switch_status_t status = SWITCH_STATUS_FALSE;
        apr_finfo_t info = { 0 };
+
+       if (!pool) {
+               if ((apr_pool_create(&our_pool, NULL)) != SWITCH_STATUS_SUCCESS) {
+                       return SWITCH_STATUS_MEMERR;
+               }
+       }
+
        if (filename) {
-               apr_stat(&info, filename, wanted, NULL);
+               apr_stat(&info, filename, wanted, pool ? pool : our_pool);
                if (info.filetype != APR_NOFILE) {
-                       return SWITCH_STATUS_SUCCESS;
+                       status =  SWITCH_STATUS_SUCCESS;
                }
        }
-       return SWITCH_STATUS_FALSE;
+
+       if (our_pool) {
+               apr_pool_destroy(our_pool);
+       }
+
+       return status;
 }
 
 /* thread stubs */