Skip to content

Update jerry-port and jerry-ext #4907

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ IncludeBlocks: Regroup
IncludeCategories:
- Regex: '<windows.h>'
Priority: 0
- Regex: '<[-.a-z]*>'
- Regex: '<[-./a-z]*>'
Priority: 1
- Regex: '"jerryscript[-.a-z]*"'
Priority: 2
Expand Down
12 changes: 6 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ set(JERRY_CMDLINE ON CACHE BOOL "Build jerry command line tool?")
set(JERRY_CMDLINE_TEST OFF CACHE BOOL "Build jerry test command line tool?")
set(JERRY_CMDLINE_SNAPSHOT OFF CACHE BOOL "Build jerry snapshot command line tool?")
set(JERRY_LIBFUZZER OFF CACHE BOOL "Build jerry with libfuzzer support?")
set(JERRY_PORT_DEFAULT ON CACHE BOOL "Build default jerry port implementation?")
set(JERRY_PORT ON CACHE BOOL "Build default jerry port implementation?")
set(JERRY_EXT ON CACHE BOOL "Build jerry-ext?")
set(JERRY_MATH OFF CACHE BOOL "Build and use jerry-math?")
set(UNITTESTS OFF CACHE BOOL "Build unit tests?")
Expand All @@ -75,9 +75,9 @@ if(NOT USING_CLANG)
endif()

if(JERRY_CMDLINE OR JERRY_CMDLINE_TEST OR JERRY_CMDLINE_SNAPSHOT OR JERRY_LIBFUZZER OR UNITTESTS OR DOCTESTS)
set(JERRY_PORT_DEFAULT ON)
set(JERRY_PORT ON)

set(JERRY_PORT_DEFAULT_MESSAGE " (FORCED BY CMDLINE OR LIBFUZZER OR TESTS)")
set(JERRY_PORT_MESSAGE " (FORCED BY CMDLINE OR LIBFUZZER OR TESTS)")
endif()

if(JERRY_CMDLINE OR DOCTESTS)
Expand Down Expand Up @@ -138,7 +138,7 @@ message(STATUS "JERRY_CMDLINE " ${JERRY_CMDLINE} ${JERRY_CMDLIN
message(STATUS "JERRY_CMDLINE_TEST " ${JERRY_CMDLINE_TEST} ${JERRY_CMDLINE_TEST_MESSAGE})
message(STATUS "JERRY_CMDLINE_SNAPSHOT " ${JERRY_CMDLINE_SNAPSHOT} ${JERRY_CMDLINE_SNAPSHOT_MESSAGE})
message(STATUS "JERRY_LIBFUZZER " ${JERRY_LIBFUZZER} ${JERRY_LIBFUZZER_MESSAGE})
message(STATUS "JERRY_PORT_DEFAULT " ${JERRY_PORT_DEFAULT} ${JERRY_PORT_DEFAULT_MESSAGE})
message(STATUS "JERRY_PORT " ${JERRY_PORT} ${JERRY_PORT_MESSAGE})
message(STATUS "JERRY_EXT " ${JERRY_EXT} ${JERRY_EXT_MESSAGE})
message(STATUS "JERRY_MATH " ${JERRY_MATH} ${JERRY_MATH_MESSAGE})
message(STATUS "UNITTESTS " ${UNITTESTS})
Expand Down Expand Up @@ -278,8 +278,8 @@ if(JERRY_EXT)
endif()

# Jerry's default port implementation
if(JERRY_PORT_DEFAULT)
add_subdirectory(jerry-port/default)
if(JERRY_PORT)
add_subdirectory(jerry-port)
endif()

# Jerry command line tool
Expand Down
7 changes: 3 additions & 4 deletions docs/01.CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ in other projects. To achieve this, the following command can be executed to cre
into the `amalgam` directory:

```sh
$ python tools/amalgam.py --output-dir amalgam --jerry-core --jerry-port-default --jerry-math
$ python tools/amalgam.py --output-dir amalgam --jerry-core --jerry-port --jerry-math
```

(Note: In the example above, the command is executed from the project's root directory, but that is
Expand All @@ -310,8 +310,7 @@ The command creates the following files in the `amalgam` dir:
* `jerryscript.c`
* `jerryscript.h`
* `jerryscript-config.h`
* `jerryscript-port-default.c`
* `jerryscript-port-default.h`
* `jerryscript-port.c`
* `jerryscript-math.c`
* `math.h`

Expand All @@ -323,7 +322,7 @@ These files can be directly compiled with an application using the JerryScript A
E.g., using a command similar to the one below:

```sh
$ gcc -Wall -o demo_app demo_app.c amalgam/jerryscript.c amalgam/jerryscript-port-default.c amalgam/jerryscript-math.c -Iamalgam/
$ gcc -Wall -o demo_app demo_app.c amalgam/jerryscript.c amalgam/jerryscript-port.c amalgam/jerryscript-math.c -Iamalgam/
```

(Note: The headers must be available on the include path.)
Expand Down
102 changes: 2 additions & 100 deletions docs/02.API-REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6385,6 +6385,8 @@ jerry_bigint_digit_count (jerry_value_t value)
[doctest]: # ()

```c
#include <stdio.h>

#include "jerryscript.h"

int
Expand Down Expand Up @@ -10527,106 +10529,6 @@ void jerry_heap_free (void *mem_p, size_t size);
- [jerry_heap_alloc](#jerry_heap_alloc)


# External context functions

## jerry_context_alloc

**Summary**

Create an external JerryScript engine context.

**Prototype**

```c
jerry_context_t *
jerry_context_alloc (uint32_t heap_size,
jerry_context_alloc_t alloc,
void *cb_data_p);
```

- `heap_size` - requested heap size of the JerryScript context
- `alloc` - function for allocation
- `cb_data_p` - user data
- return value
- pointer to the newly created JerryScript context if success
- NULL otherwise.

*New in version 2.0*.

**Example**

[doctest]: # (test="compile", name="02.API-REFERENCE-create-context.c")

```c
#include <stdlib.h>
#include <pthread.h>

#include "jerryscript.h"
#include "jerryscript-port.h"

/* A different Thread Local Storage variable for each jerry context. */
__thread jerry_context_t *tls_context;

jerry_context_t *
jerry_port_get_current_context (void)
{
/* Returns the context assigned to the thread. */
return tls_context;
}

/* Allocate JerryScript heap for each thread. */
static void *
context_alloc_fn (size_t size, void *cb_data)
{
(void) cb_data;
return malloc (size);
}

static void *
thread_function (void *param)
{
tls_context = jerry_context_alloc (512 * 1024, context_alloc_fn, NULL);

jerry_init (JERRY_INIT_EMPTY);
/* Run JerryScript in the context (e.g.: jerry_parse & jerry_run) */
jerry_cleanup ();

/* Deallocate JerryScript context */
free (tls_context);

return NULL;
}

#define NUM_OF_THREADS 8

int
main (void)
{
pthread_t threads[NUM_OF_THREADS];

/* Create the threads. */
for (int i = 0; i < NUM_OF_THREADS; i++)
{
pthread_create (&threads[i], NULL, thread_function, (void *) (intptr_t) i);
}

/* Wait for the threads to complete, and release their resources. */
for (int i = 0; i < NUM_OF_THREADS; i++)
{
pthread_join (threads[i], NULL);
}

return 0;
}
```

**See also**

- [jerry_context_t](#jerry_context_t)
- [jerry_context_alloc_t](#jerry_context_alloc_t)
- [jerry_port_get_current_context](05.PORT-API.md#jerry_port_get_current_context)


# Snapshot functions

## jerry_generate_snapshot
Expand Down
Loading