Fix layering violation in applications

Apps that use jerry should not (must not!) include and rely on its
internal headers. Typical issue is the use of "jrt/jrt.h". Fixing
`main-{unix,mcu}.c`, and speculatively the apps under the `targets`
directory as well.

(Note: a fix can be either including "jerry-port.h" and using
functions declared there, e.g., `jerry_port_errormsg`, or simply
using standard libc function like `printf`. Both approaches occur
in this patch.)

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
This commit is contained in:
Akos Kiss
2016-04-15 07:01:41 +02:00
parent 40e4d2638b
commit bb665336d4
4 changed files with 48 additions and 49 deletions
+1 -2
View File
@@ -17,7 +17,6 @@
#include <stdio.h>
#include "jerry-core/jerry.h"
#include "jerry-core/jrt/jrt.h" /* for JERRY_ERROR_MSG */
#include "jerry_extapi.h"
#include "native_esp8266.h"
@@ -52,7 +51,7 @@ DELCARE_HANDLER(assert) {
printf (">> Jerry assert true\r\n");
return true;
}
JERRY_ERROR_MSG ("Script assertion failed\n");
printf ("Script assertion failed\n");
exit (JERRY_STANDALONE_EXIT_CODE_FAIL);
return false;
}
+15 -15
View File
@@ -18,7 +18,7 @@
#include <stdlib.h>
#include "jerry.h"
#include "jrt/jrt.h"
#include "jerry-port.h"
/**
* The module interface routine
@@ -53,14 +53,14 @@ static char* read_sources (const char *script_file_names[],
file = fopen (script_file_name, "r");
if (file == NULL)
{
JERRY_ERROR_MSG ("Failed to fopen [%s]\n", script_file_name);
jerry_port_errormsg ("Failed to fopen [%s]\n", script_file_name);
return NULL;
}
int fseek_status = fseek (file, 0, SEEK_END);
if (fseek_status != 0)
{
JERRY_ERROR_MSG ("Failed to fseek fseek_status(%d)\n", fseek_status);
jerry_port_errormsg ("Failed to fseek fseek_status(%d)\n", fseek_status);
fclose (file);
return NULL;
}
@@ -68,7 +68,7 @@ static char* read_sources (const char *script_file_names[],
long script_len = ftell (file);
if (script_len < 0)
{
JERRY_ERROR_MSG ("Failed to ftell script_len(%ld)\n", script_len);
jerry_port_errormsg ("Failed to ftell script_len(%ld)\n", script_len);
fclose (file);
break;
}
@@ -81,14 +81,14 @@ static char* read_sources (const char *script_file_names[],
if (total_length <= 0)
{
JERRY_ERROR_MSG ("Theres noting to read\n");
jerry_port_errormsg ("Theres noting to read\n");
return NULL;
}
source_buffer = (char*)malloc(total_length);
if (source_buffer == NULL)
{
JERRY_ERROR_MSG ("Out of memory error\n");
jerry_port_errormsg ("Out of memory error\n");
return NULL;
}
memset(source_buffer, 0, sizeof(char)*total_length);
@@ -101,21 +101,21 @@ static char* read_sources (const char *script_file_names[],
if (file == NULL)
{
JERRY_ERROR_MSG ("Failed to fopen [%s]\n", script_file_name);
jerry_port_errormsg ("Failed to fopen [%s]\n", script_file_name);
break;
}
int fseek_status = fseek (file, 0, SEEK_END);
if (fseek_status != 0)
{
JERRY_ERROR_MSG ("Failed to fseek fseek_status(%d)\n", fseek_status);
jerry_port_errormsg ("Failed to fseek fseek_status(%d)\n", fseek_status);
break;
}
long script_len = ftell (file);
if (script_len < 0)
{
JERRY_ERROR_MSG ("Failed to ftell script_len(%ld)\n", script_len);
jerry_port_errormsg ("Failed to ftell script_len(%ld)\n", script_len);
break;
}
@@ -125,7 +125,7 @@ static char* read_sources (const char *script_file_names[],
size_t bytes_read = fread (source_buffer_tail, 1, current_source_size, file);
if (bytes_read < current_source_size)
{
JERRY_ERROR_MSG ("Failed to fread bytes_read(%d)\n", bytes_read);
jerry_port_errormsg ("Failed to fread bytes_read(%d)\n", bytes_read);
break;
}
@@ -142,7 +142,7 @@ static char* read_sources (const char *script_file_names[],
if (i < files_count)
{
JERRY_ERROR_MSG ("Failed to read script N%d\n", i + 1);
jerry_port_errormsg ("Failed to read script N%d\n", i + 1);
free(source_buffer);
return NULL;
}
@@ -156,8 +156,8 @@ int jerryscript_entry (int argc, char *argv[])
{
if (argc >= JERRY_MAX_COMMAND_LINE_ARGS)
{
JERRY_ERROR_MSG ("Too many command line arguments. Current maximum is %d\n",
JERRY_MAX_COMMAND_LINE_ARGS);
jerry_port_errormsg ("Too many command line arguments. Current maximum is %d\n",
JERRY_MAX_COMMAND_LINE_ARGS);
return JERRY_STANDALONE_EXIT_CODE_FAIL;
}
@@ -212,7 +212,7 @@ int jerryscript_entry (int argc, char *argv[])
}
else
{
JERRY_ERROR_MSG ("Error: wrong format or invalid argument\n");
jerry_port_errormsg ("Error: wrong format or invalid argument\n");
return JERRY_STANDALONE_EXIT_CODE_FAIL;
}
}
@@ -233,7 +233,7 @@ int jerryscript_entry (int argc, char *argv[])
if (source_p == NULL)
{
JERRY_ERROR_MSG ("JERRY_STANDALONE_EXIT_CODE_FAIL\n");
jerry_port_errormsg ("JERRY_STANDALONE_EXIT_CODE_FAIL\n");
return JERRY_STANDALONE_EXIT_CODE_FAIL;
}