Refinement of completion status codes and fatal error handlers.

This commit is contained in:
Ruben Ayrapetyan
2015-02-11 20:53:14 +03:00
parent 398501afeb
commit 17f51e0ba6
17 changed files with 237 additions and 347 deletions
-125
View File
@@ -1,125 +0,0 @@
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Implementation of exit with specified status code.
*/
#include "jrt.h"
#include "jerry-libc.h"
/*
* Exit with specified status code.
*
* If !JERRY_NDEBUG and code != 0, print status code with description
* and call assertion fail handler.
*/
void __noreturn
jerry_exit (jerry_err_t code) /**< status code */
{
#ifndef JERRY_NDEBUG
if (code != ERR_OK)
{
__printf ("Error: ");
switch (code)
{
case ERR_OK:
{
JERRY_UNREACHABLE();
break;
}
case ERR_IO:
{
__printf ("ERR_IO\n");
break;
}
case ERR_BUFFER_SIZE:
{
__printf ("ERR_BUFFER_SIZE\n");
break;
}
case ERR_SEVERAL_FILES:
{
__printf ("ERR_SEVERAL_FILES\n");
break;
}
case ERR_NO_FILES:
{
__printf ("ERR_NO_FILES\n");
break;
}
case ERR_NON_CHAR:
{
__printf ("ERR_NON_CHAR\n");
break;
}
case ERR_UNCLOSED:
{
__printf ("ERR_UNCLOSED\n");
break;
}
case ERR_INT_LITERAL:
{
__printf ("ERR_INT_LITERAL\n");
break;
}
case ERR_STRING:
{
__printf ("ERR_STRING\n");
break;
}
case ERR_PARSER:
{
__printf ("ERR_PARSER\n");
break;
}
case ERR_OUT_OF_MEMORY:
{
__printf ("ERR_OUT_OF_MEMORY\n");
break;
}
case ERR_SYSCALL:
{
JERRY_UNREACHABLE();
break;
}
case ERR_UNHANDLED_EXCEPTION:
{
__printf ("ERR_UNHANDLED_EXCEPTION\n");
break;
}
case ERR_UNIMPLEMENTED_CASE:
{
__printf ("ERR_UNIMPLEMENTED_CASE\n");
break;
}
case ERR_FAILED_ASSERTION_IN_SCRIPT:
{
__printf ("ERR_FAILED_ASSERTION_IN_SCRIPT\n");
break;
}
case ERR_FAILED_INTERNAL_ASSERTION:
{
__printf ("ERR_FAILED_INTERNAL_ASSERTION\n");
break;
}
}
}
#endif /* !JERRY_NDEBUG */
__exit (-code);
} /* jerry_exit */
@@ -13,9 +13,58 @@
* limitations under the License.
*/
/**
* Implementation of exit with specified status code.
*/
#include "jrt.h"
#include "jerry-libc.h"
/*
* Exit with specified status code.
*
* If !JERRY_NDEBUG and code != 0, print status code with description
* and call assertion fail handler.
*/
void __noreturn
jerry_fatal (jerry_fatal_code_t code) /**< status code */
{
#ifndef JERRY_NDEBUG
__printf ("Error: ");
switch (code)
{
case ERR_OUT_OF_MEMORY:
{
__printf ("ERR_OUT_OF_MEMORY\n");
break;
}
case ERR_SYSCALL:
{
/* print nothing as it may invoke syscall recursively */
break;
}
case ERR_PARSER:
{
__printf ("ERR_PARSER\n");
break;
}
case ERR_UNIMPLEMENTED_CASE:
{
__printf ("ERR_UNIMPLEMENTED_CASE\n");
break;
}
case ERR_FAILED_INTERNAL_ASSERTION:
{
__printf ("ERR_FAILED_INTERNAL_ASSERTION\n");
break;
}
}
#endif /* !JERRY_NDEBUG */
__exit (code);
} /* jerry_fatal */
/**
* Handle failed assertion
*/
@@ -35,7 +84,7 @@ jerry_assert_fail (const char *assertion, /**< assertion condition string */
(void) line;
#endif /* JERRY_NDEBUG */
__exit (-ERR_FAILED_INTERNAL_ASSERTION);
jerry_fatal (ERR_FAILED_INTERNAL_ASSERTION);
} /* jerry_assert_fail */
/**
@@ -62,7 +111,7 @@ jerry_unreachable (const char *comment, /**< comment to unreachable mark if exis
}
__printf (".\n");
__exit (-ERR_FAILED_INTERNAL_ASSERTION);
jerry_fatal (ERR_FAILED_INTERNAL_ASSERTION);
} /* jerry_unreachable */
/**
@@ -89,5 +138,5 @@ jerry_unimplemented (const char *comment, /**< comment to unimplemented mark if
}
__printf (".\n");
__exit (-ERR_UNIMPLEMENTED_CASE);
jerry_fatal (ERR_UNIMPLEMENTED_CASE);
} /* jerry_unimplemented */
+5 -23
View File
@@ -16,6 +16,7 @@
#ifndef JERRY_GLOBALS_H
#define JERRY_GLOBALS_H
#include "jerry.h"
#include "jrt_types.h"
/**
@@ -43,29 +44,10 @@
#define JERRY_BITSINBYTE 8
/**
* Error codes
*
* TODO: Move to jerry.h
* Standalone Jerry exit codes
*/
typedef enum
{
ERR_OK = 0,
ERR_IO = -1,
ERR_BUFFER_SIZE = -2,
ERR_SEVERAL_FILES = -3,
ERR_NO_FILES = -4,
ERR_NON_CHAR = -5,
ERR_UNCLOSED = -6,
ERR_INT_LITERAL = -7,
ERR_STRING = -8,
ERR_PARSER = -9,
ERR_OUT_OF_MEMORY = -10,
ERR_SYSCALL = -11,
ERR_UNHANDLED_EXCEPTION = -12,
ERR_UNIMPLEMENTED_CASE = -118,
ERR_FAILED_ASSERTION_IN_SCRIPT = -119,
ERR_FAILED_INTERNAL_ASSERTION = -120,
} jerry_err_t;
#define JERRY_STANDALONE_EXIT_CODE_OK (0)
#define JERRY_STANDALONE_EXIT_CODE_FAIL (1)
/**
* Asserts
@@ -175,7 +157,7 @@ template<typename... values> extern void jerry_ref_unused_variables (const value
/**
* Exit
*/
extern void __noreturn jerry_exit (jerry_err_t code);
extern void __noreturn jerry_fatal (jerry_fatal_code_t code);
/**
* sizeof, offsetof, ...
+1 -1
View File
@@ -53,7 +53,7 @@ FIXME (/* Include linux/fs.h */)
#define LIBC_EXIT_ON_ERROR(syscall_ret_val) \
if (unlikely ((syscall_ret_val) < 0)) \
{ \
__exit (-ERR_SYSCALL); \
jerry_fatal (ERR_SYSCALL); \
}
static long int syscall_1 (long int syscall_no, long int arg1);
-55
View File
@@ -1,55 +0,0 @@
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "jrt.h"
#include "jerry-libc.h"
/**
* Handle failed assertion
*/
void __noreturn
jerry_assert_fail (const char *assertion __unused, /**< assertion condition string */
const char *file __unused, /**< file name */
const char *function __unused, /**< function name */
const uint32_t line __unused) /** line */
{
__exit (-ERR_FAILED_INTERNAL_ASSERTION);
} /* jerry_assert_fail */
/**
* Handle execution of control path that should be unreachable
*/
void __noreturn
jerry_unreachable (const char *comment __unused, /**< comment to unreachable mark if exists,
NULL - otherwise */
const char *file __unused, /**< file name */
const char *function __unused, /**< function name */
const uint32_t line __unused) /**< line */
{
__exit (-ERR_FAILED_INTERNAL_ASSERTION);
} /* jerry_unreachable */
/**
* Handle unimplemented case execution
*/
void __noreturn
jerry_unimplemented (const char *comment __unused, /**< comment to unimplemented mark if exists,
NULL - otherwise */
const char *file __unused, /**< file name */
const char *function __unused, /**< function name */
const uint32_t line __unused) /**< line */
{
__exit (-ERR_UNIMPLEMENTED_CASE);
} /* jerry_unimplemented */
-55
View File
@@ -1,55 +0,0 @@
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "jrt.h"
#include "jerry-libc.h"
/**
* Handle failed assertion
*/
void __noreturn
jerry_assert_fail (const char *assertion __unused, /**< assertion condition string */
const char *file __unused, /**< file name */
const char *function __unused, /**< function name */
const uint32_t line __unused) /** line */
{
__exit (-ERR_FAILED_INTERNAL_ASSERTION);
} /* jerry_assert_fail */
/**
* Handle execution of control path that should be unreachable
*/
void __noreturn
jerry_unreachable (const char *comment __unused, /**< comment to unreachable mark if exists,
NULL - otherwise */
const char *file __unused, /**< file name */
const char *function __unused, /**< function name */
const uint32_t line __unused) /**< line */
{
__exit (-ERR_FAILED_INTERNAL_ASSERTION);
} /* jerry_unreachable */
/**
* Handle unimplemented case execution
*/
void __noreturn
jerry_unimplemented (const char *comment __unused, /**< comment to unimplemented mark if exists,
NULL - otherwise */
const char *file __unused, /**< file name */
const char *function __unused, /**< function name */
const uint32_t line __unused) /**< line */
{
__exit (-ERR_UNIMPLEMENTED_CASE);
} /* jerry_unimplemented */