Fix 2 errors in mod_spidermonkey on windows.

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
This commit is contained in:
Michael Jerris 2007-04-23 15:33:25 +00:00
parent deb4972610
commit ae1a6184e2
5 changed files with 24 additions and 10 deletions

View 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,

View 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);
/** @} */

View 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);

View 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);

View 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 (filename) {
apr_stat(&info, filename, wanted, NULL);
if (info.filetype != APR_NOFILE) {
return SWITCH_STATUS_SUCCESS;
if (!pool) {
if ((apr_pool_create(&our_pool, NULL)) != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_MEMERR;
}
}
return SWITCH_STATUS_FALSE;
if (filename) {
apr_stat(&info, filename, wanted, pool ? pool : our_pool);
if (info.filetype != APR_NOFILE) {
status = SWITCH_STATUS_SUCCESS;
}
}
if (our_pool) {
apr_pool_destroy(our_pool);
}
return status;
}
/* thread stubs */