Skip to content

Commit 4f46860

Browse files
committed
Improve the jerry port api documents.
Notable changes: - Remove the comments in port impl, that's easily getting to in-consistence - Sync the jerryscript-port.h and 05.PORT-API.md - Fixes the invalid comment in port codes JerryScript-DCO-1.0-Signed-off-by: Yonggang Luo [email protected]
1 parent d00f481 commit 4f46860

File tree

18 files changed

+32
-279
lines changed

18 files changed

+32
-279
lines changed

docs/05.PORT-API.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ void jerry_port_context_free (void);
112112
*
113113
* The implementation can decide whether error and debug messages are logged to
114114
* the console, or saved to a database or to a file.
115+
*
116+
* @param message_p: the message to log.
115117
*/
116118
void jerry_port_log (const char *message_p);
117119
```

jerry-core/include/jerryscript-port.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ void jerry_port_context_free (void);
142142
*
143143
* The implementation can decide whether error and debug messages are logged to
144144
* the console, or saved to a database or to a file.
145+
*
146+
* @param message_p: the message to log.
145147
*/
146148
void jerry_port_log (const char *message_p);
147149

@@ -246,7 +248,7 @@ void jerry_port_path_free (jerry_char_t *path_p);
246248
jerry_size_t jerry_port_path_base (const jerry_char_t *path_p);
247249

248250
/**
249-
* Open a source file and read the content into a buffer.
251+
* Open a source file and read its contents into a buffer.
250252
*
251253
* When the source file is no longer needed by the caller, the returned pointer will be passed to
252254
* `jerry_port_source_free`, which can be used to finalize the buffer.

jerry-port/common/jerry-port-context.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,6 @@
2727
*/
2828
static jerry_context_t *current_context_p = NULL;
2929

30-
/**
31-
* Allocate a new external context.
32-
*
33-
* @param context_size: requested context size
34-
*
35-
* @return total allcoated size
36-
*/
3730
size_t JERRY_ATTR_WEAK
3831
jerry_port_context_alloc (size_t context_size)
3932
{
@@ -43,20 +36,12 @@ jerry_port_context_alloc (size_t context_size)
4336
return total_size;
4437
} /* jerry_port_context_alloc */
4538

46-
/**
47-
* Get the current context.
48-
*
49-
* @return the pointer to the current context
50-
*/
5139
jerry_context_t *JERRY_ATTR_WEAK
5240
jerry_port_context_get (void)
5341
{
5442
return current_context_p;
5543
} /* jerry_port_context_get */
5644

57-
/**
58-
* Free the currently allocated external context.
59-
*/
6045
void JERRY_ATTR_WEAK
6146
jerry_port_context_free (void)
6247
{

jerry-port/common/jerry-port-fs.c

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,8 @@ jerry_port_get_file_size (FILE *file_p) /**< opened file */
4141
return (jerry_size_t) size;
4242
} /* jerry_port_get_file_size */
4343

44-
/**
45-
* Opens file with the given path and reads its source.
46-
* @return the source of the file
47-
*/
4844
jerry_char_t *JERRY_ATTR_WEAK
49-
jerry_port_source_read (const char *file_name_p, /**< file name */
50-
jerry_size_t *out_size_p) /**< [out] read bytes */
45+
jerry_port_source_read (const char *file_name_p, jerry_size_t *out_size_p)
5146
{
5247
/* TODO(dbatyai): Temporary workaround for nuttx target
5348
* The nuttx target builds and copies the jerryscript libraries as a separate build step, which causes linking issues
@@ -92,11 +87,8 @@ jerry_port_source_read (const char *file_name_p, /**< file name */
9287
return buffer_p;
9388
} /* jerry_port_source_read */
9489

95-
/**
96-
* Release the previously opened file's content.
97-
*/
9890
void JERRY_ATTR_WEAK
99-
jerry_port_source_free (uint8_t *buffer_p) /**< buffer to free */
91+
jerry_port_source_free (uint8_t *buffer_p)
10092
{
10193
free (buffer_p);
10294
} /* jerry_port_source_free */
@@ -107,15 +99,8 @@ jerry_port_source_free (uint8_t *buffer_p) /**< buffer to free */
10799
*/
108100
#if defined(JERRY_WEAK_SYMBOL_SUPPORT) && !(defined(__unix__) || defined(__APPLE__) || defined(_WIN32))
109101

110-
/**
111-
* Normalize a file path.
112-
*
113-
* @return a newly allocated buffer with the normalized path if the operation is successful,
114-
* NULL otherwise
115-
*/
116102
jerry_char_t *JERRY_ATTR_WEAK
117-
jerry_port_path_normalize (const jerry_char_t *path_p, /**< input path */
118-
jerry_size_t path_size) /**< size of the path */
103+
jerry_port_path_normalize (const jerry_char_t *path_p, jerry_size_t path_size)
119104
{
120105
jerry_char_t *buffer_p = (jerry_char_t *) malloc (path_size + 1);
121106

@@ -128,26 +113,16 @@ jerry_port_path_normalize (const jerry_char_t *path_p, /**< input path */
128113
memcpy (buffer_p, path_p, path_size + 1);
129114

130115
return buffer_p;
131-
} /* jerry_port_normalize_path */
116+
} /* jerry_port_path_normalize */
132117

133-
/**
134-
* Free a path buffer returned by jerry_port_path_normalize.
135-
*
136-
* @param path_p: the path to free
137-
*/
138118
void JERRY_ATTR_WEAK
139119
jerry_port_path_free (jerry_char_t *path_p)
140120
{
141121
free (path_p);
142-
} /* jerry_port_normalize_path */
122+
} /* jerry_port_path_free */
143123

144-
/**
145-
* Computes the end of the directory part of a path.
146-
*
147-
* @return end of the directory part of a path.
148-
*/
149124
jerry_size_t JERRY_ATTR_WEAK
150-
jerry_port_path_base (const jerry_char_t *path_p) /**< path */
125+
jerry_port_path_base (const jerry_char_t *path_p)
151126
{
152127
const jerry_char_t *basename_p = (jerry_char_t *) strrchr ((char *) path_p, '/') + 1;
153128

@@ -157,6 +132,6 @@ jerry_port_path_base (const jerry_char_t *path_p) /**< path */
157132
}
158133

159134
return (jerry_size_t) (basename_p - path_p);
160-
} /* jerry_port_get_directory_end */
135+
} /* jerry_port_path_base */
161136

162137
#endif /* defined(JERRY_WEAK_SYMBOL_SUPPORT) && !(defined(__unix__) || defined(__APPLE__) || defined(_WIN32)) */

jerry-port/common/jerry-port-io.c

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,47 +19,27 @@
1919

2020
#include "jerryscript-port.h"
2121

22-
/**
23-
* Default implementation of jerry_port_log. Prints log messages to stderr.
24-
*/
2522
void JERRY_ATTR_WEAK
26-
jerry_port_log (const char *message_p) /**< message */
23+
jerry_port_log (const char *message_p)
2724
{
2825
fputs (message_p, stderr);
2926
} /* jerry_port_log */
3027

31-
/**
32-
* Default implementation of jerry_port_print_byte. Uses 'putchar' to
33-
* print a single character to standard output.
34-
*/
3528
void JERRY_ATTR_WEAK
36-
jerry_port_print_byte (jerry_char_t byte) /**< the character to print */
29+
jerry_port_print_byte (jerry_char_t byte)
3730
{
3831
putchar (byte);
3932
} /* jerry_port_print_byte */
4033

41-
/**
42-
* Default implementation of jerry_port_print_buffer. Uses 'jerry_port_print_byte' to
43-
* print characters of the input buffer.
44-
*/
4534
void JERRY_ATTR_WEAK
46-
jerry_port_print_buffer (const jerry_char_t *buffer_p, /**< string buffer */
47-
jerry_size_t buffer_size) /**< string size*/
35+
jerry_port_print_buffer (const jerry_char_t *buffer_p, jerry_size_t buffer_size)
4836
{
4937
for (jerry_size_t i = 0; i < buffer_size; i++)
5038
{
5139
jerry_port_print_byte (buffer_p[i]);
5240
}
53-
} /* jerry_port_print_byte */
41+
} /* jerry_port_print_buffer */
5442

55-
/**
56-
* Read a line from standard input as a zero-terminated string.
57-
*
58-
* @param out_size_p: length of the string
59-
*
60-
* @return pointer to the buffer storing the string,
61-
* or NULL if end of input
62-
*/
6343
jerry_char_t *JERRY_ATTR_WEAK
6444
jerry_port_line_read (jerry_size_t *out_size_p)
6545
{
@@ -94,11 +74,6 @@ jerry_port_line_read (jerry_size_t *out_size_p)
9474
}
9575
} /* jerry_port_line_read */
9676

97-
/**
98-
* Free a line buffer allocated by jerry_port_line_read
99-
*
100-
* @param buffer_p: buffer that has been allocated by jerry_port_line_read
101-
*/
10277
void JERRY_ATTR_WEAK
10378
jerry_port_line_free (jerry_char_t *buffer_p)
10479
{

jerry-port/common/jerry-port-process.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,8 @@
1717

1818
#include "jerryscript-port.h"
1919

20-
/**
21-
* Default implementation of jerry_port_fatal. Calls 'abort' if exit code is
22-
* non-zero, 'exit' otherwise.
23-
*/
2420
void JERRY_ATTR_WEAK
25-
jerry_port_fatal (jerry_fatal_code_t code) /**< cause of error */
21+
jerry_port_fatal (jerry_fatal_code_t code)
2622
{
2723
if (code != 0 && code != JERRY_FATAL_OUT_OF_MEMORY)
2824
{

jerry-port/unix/jerry-port-unix-date.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@
2020
#include <sys/time.h>
2121
#include <time.h>
2222

23-
/**
24-
* Default implementation of jerry_port_local_tza.
25-
*
26-
* @return offset between UTC and local time at the given unix timestamp, if
27-
* available. Otherwise, returns 0, assuming UTC time.
28-
*/
2923
int32_t
3024
jerry_port_local_tza (double unix_ms)
3125
{
@@ -53,11 +47,6 @@ jerry_port_local_tza (double unix_ms)
5347
#endif /* HAVE_TM_GMTOFF */
5448
} /* jerry_port_local_tza */
5549

56-
/**
57-
* Default implementation of jerry_port_current_time.
58-
*
59-
* @return milliseconds since Unix epoch
60-
*/
6150
double
6251
jerry_port_current_time (void)
6352
{

jerry-port/unix/jerry-port-unix-fs.c

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,44 +20,26 @@
2020
#include <stdlib.h>
2121
#include <string.h>
2222

23-
/**
24-
* Normalize a file path using realpath.
25-
*
26-
* @param path_p: input path
27-
* @param path_size: input path size
28-
*
29-
* @return a newly allocated buffer with the normalized path if the operation is successful,
30-
* NULL otherwise
31-
*/
3223
jerry_char_t *
33-
jerry_port_path_normalize (const jerry_char_t *path_p, /**< input path */
34-
jerry_size_t path_size) /**< size of the path */
24+
jerry_port_path_normalize (const jerry_char_t *path_p, jerry_size_t path_size)
3525
{
3626
(void) path_size;
3727

3828
return (jerry_char_t *) realpath ((char *) path_p, NULL);
3929
} /* jerry_port_path_normalize */
4030

41-
/**
42-
* Free a path buffer returned by jerry_port_path_normalize.
43-
*/
4431
void
4532
jerry_port_path_free (jerry_char_t *path_p)
4633
{
4734
free (path_p);
4835
} /* jerry_port_path_free */
4936

50-
/**
51-
* Computes the end of the directory part of a path.
52-
*
53-
* @return end of the directory part of a path.
54-
*/
5537
jerry_size_t JERRY_ATTR_WEAK
56-
jerry_port_path_base (const jerry_char_t *path_p) /**< path */
38+
jerry_port_path_base (const jerry_char_t *path_p)
5739
{
5840
const jerry_char_t *basename_p = (jerry_char_t *) strrchr ((char *) path_p, '/') + 1;
5941

6042
return (jerry_size_t) (basename_p - path_p);
61-
} /* jerry_port_get_directory_end */
43+
} /* jerry_port_path_base */
6244

6345
#endif /* defined(__unix__) || defined(__APPLE__) */

jerry-port/unix/jerry-port-unix-process.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,8 @@
2525

2626
#include <unistd.h>
2727

28-
/**
29-
* Default implementation of jerry_port_sleep, uses 'usleep'.
30-
*/
3128
void
32-
jerry_port_sleep (uint32_t sleep_time) /**< milliseconds to sleep */
29+
jerry_port_sleep (uint32_t sleep_time)
3330
{
3431
usleep ((useconds_t) sleep_time * 1000);
3532
} /* jerry_port_sleep */

jerry-port/win/jerry-port-win-date.c

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ unix_time_to_filetime (double t, LPFILETIME ft_p)
4444

4545
ft_p->dwLowDateTime = (DWORD) ll;
4646
ft_p->dwHighDateTime = (DWORD) (ll >> 32);
47-
} /* unix_time_to_file_time */
47+
} /* unix_time_to_filetime */
4848

4949
/**
5050
* Convert a FILETIME to a unix time value.
@@ -58,14 +58,8 @@ filetime_to_unix_time (LPFILETIME ft_p)
5858
date.HighPart = ft_p->dwHighDateTime;
5959
date.LowPart = ft_p->dwLowDateTime;
6060
return (double) (((LONGLONG) date.QuadPart - UNIX_EPOCH_IN_TICKS) / TICKS_PER_MS);
61-
} /* FileTimeToUnixTimeMs */
61+
} /* filetime_to_unix_time */
6262

63-
/**
64-
* Default implementation of jerry_port_local_tza.
65-
*
66-
* @return offset between UTC and local time at the given unix timestamp, if
67-
* available. Otherwise, returns 0, assuming UTC time.
68-
*/
6963
int32_t
7064
jerry_port_local_tza (double unix_ms)
7165
{
@@ -86,11 +80,6 @@ jerry_port_local_tza (double unix_ms)
8680
return 0;
8781
} /* jerry_port_local_tza */
8882

89-
/**
90-
* Default implementation of jerry_port_current_time.
91-
*
92-
* @return milliseconds since Unix epoch
93-
*/
9483
double
9584
jerry_port_current_time (void)
9685
{

jerry-port/win/jerry-port-win-fs.c

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,37 +20,20 @@
2020
#include <stdlib.h>
2121
#include <string.h>
2222

23-
/**
24-
* Normalize a file path.
25-
*
26-
* @return a newly allocated buffer with the normalized path if the operation is successful,
27-
* NULL otherwise
28-
*/
2923
jerry_char_t *
30-
jerry_port_path_normalize (const jerry_char_t *path_p, /**< input path */
31-
jerry_size_t path_size) /**< size of the path */
24+
jerry_port_path_normalize (const jerry_char_t *path_p, jerry_size_t path_size)
3225
{
3326
(void) path_size;
3427

3528
return (jerry_char_t *) _fullpath (NULL, path_p, _MAX_PATH);
3629
} /* jerry_port_path_normalize */
3730

38-
/**
39-
* Free a path buffer returned by jerry_port_path_normalize.
40-
*/
4131
void
4232
jerry_port_path_free (jerry_char_t *path_p)
4333
{
4434
free (path_p);
4535
} /* jerry_port_path_free */
4636

47-
/**
48-
* Get the end of the directory part of the input path.
49-
*
50-
* @param path_p: input zero-terminated path string
51-
*
52-
* @return offset of the directory end in the input path string
53-
*/
5437
jerry_size_t
5538
jerry_port_path_base (const jerry_char_t *path_p)
5639
{

jerry-port/win/jerry-port-win-process.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,8 @@
1818

1919
#include <windows.h>
2020

21-
/**
22-
* Default implementation of jerry_port_sleep, uses 'Sleep'.
23-
*/
2421
void
25-
jerry_port_sleep (uint32_t sleep_time) /**< milliseconds to sleep */
22+
jerry_port_sleep (uint32_t sleep_time)
2623
{
2724
Sleep (sleep_time);
2825
} /* jerry_port_sleep */

0 commit comments

Comments
 (0)