Skip to content

Remove EXTERN_C macros and use block based solution #901

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
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
126 changes: 33 additions & 93 deletions jerry-core/jerry-api.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* Copyright 2015 Samsung Electronics Co., Ltd.
/* Copyright 2015-2016 Samsung Electronics Co., Ltd.
* Copyright 2016 University of Szeged.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,9 +23,8 @@
#include <sys/types.h>

#ifdef __cplusplus
# define EXTERN_C "C"
#else /* !__cplusplus */
# define EXTERN_C
extern "C"
{
#endif /* !__cplusplus */

/** \addtogroup jerry Jerry engine interface
Expand Down Expand Up @@ -147,47 +147,40 @@ typedef bool (*jerry_object_field_foreach_t) (const jerry_api_string_t *field_na
/**
* Returns whether the given jerry_api_value_t is void.
*/
extern EXTERN_C bool
jerry_api_value_is_void (const jerry_api_value_t *value_p);
bool jerry_api_value_is_void (const jerry_api_value_t *value_p);

/**
* Returns whether the given jerry_api_value_t is null.
*/
extern EXTERN_C bool
jerry_api_value_is_null (const jerry_api_value_t *value_p);
bool jerry_api_value_is_null (const jerry_api_value_t *value_p);

/**
* Returns whether the given jerry_api_value_t is undefined.
*/
extern EXTERN_C bool
jerry_api_value_is_undefined (const jerry_api_value_t *value_p);
bool jerry_api_value_is_undefined (const jerry_api_value_t *value_p);

/**
* Returns whether the given jerry_api_value_t has boolean type.
*/
extern EXTERN_C bool
jerry_api_value_is_boolean (const jerry_api_value_t *value_p);
bool jerry_api_value_is_boolean (const jerry_api_value_t *value_p);

/**
* Returns whether the given jerry_api_value_t is number.
*
* More specifically, returns true if the type is JERRY_API_DATA_TYPE_FLOAT32,
* JERRY_API_DATA_TYPE_FLOAT64 or JERRY_API_DATA_TYPE_UINT32, false otherwise.
*/
extern EXTERN_C bool
jerry_api_value_is_number (const jerry_api_value_t *value_p);
bool jerry_api_value_is_number (const jerry_api_value_t *value_p);

/**
* Returns whether the given jerry_api_value_t is string.
*/
extern EXTERN_C bool
jerry_api_value_is_string (const jerry_api_value_t *value_p);
bool jerry_api_value_is_string (const jerry_api_value_t *value_p);

/**
* Returns whether the given jerry_api_value_t is object.
*/
extern EXTERN_C bool
jerry_api_value_is_object (const jerry_api_value_t *value_p);
bool jerry_api_value_is_object (const jerry_api_value_t *value_p);

/**
* Returns whether the given jerry_api_value_t is a function object.
Expand All @@ -197,16 +190,14 @@ jerry_api_value_is_object (const jerry_api_value_t *value_p);
* jerry_api_is_function() functiron return true for its v_object member,
* otherwise false.
*/
extern EXTERN_C bool
jerry_api_value_is_function (const jerry_api_value_t *value_p);
bool jerry_api_value_is_function (const jerry_api_value_t *value_p);

/**
* Returns the boolean v_bool member of the given jerry_api_value_t structure.
* If the given jerry_api_value_t structure has type other than
* JERRY_API_DATA_TYPE_BOOLEAN, JERRY_ASSERT fails.
*/
extern EXTERN_C bool
jerry_api_get_boolean_value (const jerry_api_value_t *value_p);
bool jerry_api_get_boolean_value (const jerry_api_value_t *value_p);

/**
* Returns the number value of the given jerry_api_value_t structure
Expand All @@ -219,171 +210,120 @@ jerry_api_get_boolean_value (const jerry_api_value_t *value_p);
* JERRY_API_DATA_TYPE_FLOAT64 the function returns the v_float64 member.
* As long as the type is none of the above, JERRY_ASSERT falis.
*/
extern EXTERN_C double
jerry_api_get_number_value (const jerry_api_value_t *value_p);
double jerry_api_get_number_value (const jerry_api_value_t *value_p);

/**
* Returns the v_string member of the given jerry_api_value_t structure.
* If the given jerry_api_value_t structure has type other than
* JERRY_API_DATA_TYPE_STRING, JERRY_ASSERT fails.
*/
extern EXTERN_C jerry_api_string_t *
jerry_api_get_string_value (const jerry_api_value_t *value_p);
jerry_api_string_t *jerry_api_get_string_value (const jerry_api_value_t *value_p);

/**
* Returns the v_object member of the given jerry_api_value_t structure.
* If the given jerry_api_value_t structure has type other than
* JERRY_API_DATA_TYPE_OBJECT, JERRY_ASSERT fails.
*/
extern EXTERN_C jerry_api_object_t *
jerry_api_get_object_value (const jerry_api_value_t *value_p);
jerry_api_object_t *jerry_api_get_object_value (const jerry_api_value_t *value_p);

/**
* Creates and returns a jerry_api_value_t with type
* JERRY_API_DATA_TYPE_VOID.
*/
extern EXTERN_C jerry_api_value_t
jerry_api_create_void_value (void);
jerry_api_value_t jerry_api_create_void_value (void);

/**
* Creates and returns a jerry_api_value_t with type
* JERRY_API_DATA_TYPE_NULL.
*/
extern EXTERN_C jerry_api_value_t
jerry_api_create_null_value (void);
jerry_api_value_t jerry_api_create_null_value (void);

/**
* Creates and returns a jerry_api_value_t with type
* JERRY_API_DATA_TYPE_UNDEFINED.
*/
extern EXTERN_C jerry_api_value_t
jerry_api_create_undefined_value (void);
jerry_api_value_t jerry_api_create_undefined_value (void);

/**
* Creates a JERRY_API_DATA_TYPE_BOOLEAN jerry_api_value_t from the given
* boolean parameter and returns with it.
*/
extern EXTERN_C jerry_api_value_t
jerry_api_create_boolean_value (bool value);
jerry_api_value_t jerry_api_create_boolean_value (bool value);

/**
* Creates a jerry_api_value_t from the given double parameter and returns
* with it.
* The v_float64 member will be set and the will be JERRY_API_DATA_TYPE_FLOAT64.
*/
extern EXTERN_C jerry_api_value_t
jerry_api_create_number_value (double value);
jerry_api_value_t jerry_api_create_number_value (double value);

/**
* Creates a JERRY_API_DATA_TYPE_OBJECT type jerry_api_value_t from the
* given jerry_api_object_t *parameter and returns with it.
*/
extern EXTERN_C jerry_api_value_t
jerry_api_create_object_value (jerry_api_object_t *value);
jerry_api_value_t jerry_api_create_object_value (jerry_api_object_t *value);

/**
* Creates a JERRY_API_DATA_TYPE_STRING type jerry_api_value_t from the
* given jerry_api_string_t *parameter and returns with it.
*/
extern EXTERN_C jerry_api_value_t
jerry_api_create_string_value (jerry_api_string_t *value);
jerry_api_value_t jerry_api_create_string_value (jerry_api_string_t *value);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did the style change here? Above this point, return type was in a separate line, from this on, it's on the same line as the rest of the function declaration. It would be good to follow one style everywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with that we should use one style, but which one?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the public headers mostly use the same-line style, while internal headers mix it, sometimes even inside the same header. However, C sources use the return-type-on-separate-line style everywhere. So, I'm not sure... Happy to hear the opinion of others.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is easier to read when the return type is in the same line, so I prefer that.


extern EXTERN_C ssize_t
jerry_api_string_to_char_buffer (const jerry_api_string_t *, jerry_api_char_t *, ssize_t);
extern EXTERN_C
ssize_t jerry_api_string_to_char_buffer (const jerry_api_string_t *, jerry_api_char_t *, ssize_t);
jerry_api_string_t *jerry_api_acquire_string (jerry_api_string_t *);
extern EXTERN_C
void jerry_api_release_string (jerry_api_string_t *);

extern EXTERN_C
jerry_api_object_t *jerry_api_acquire_object (jerry_api_object_t *);
extern EXTERN_C
void jerry_api_release_object (jerry_api_object_t *);

extern EXTERN_C
void jerry_api_release_object (jerry_api_object_t *);
void jerry_api_release_string (jerry_api_string_t *);
void jerry_api_release_value (jerry_api_value_t *);

extern EXTERN_C
jerry_api_object_t *jerry_api_create_array_object (jerry_api_size_t);
jerry_api_object_t *jerry_api_create_object (void);
jerry_api_string_t *jerry_api_create_string (const jerry_api_char_t *);
extern EXTERN_C
jerry_api_string_t *jerry_api_create_string_sz (const jerry_api_char_t *, jerry_api_size_t);
extern EXTERN_C
jerry_api_object_t *jerry_api_create_object (void);

extern EXTERN_C
jerry_api_object_t *jerry_api_create_array_object (jerry_api_size_t);
extern EXTERN_C
bool jerry_api_set_array_index_value (jerry_api_object_t *, jerry_api_length_t, jerry_api_value_t *);
extern EXTERN_C
bool jerry_api_get_array_index_value (jerry_api_object_t *, jerry_api_length_t, jerry_api_value_t *);

extern EXTERN_C
jerry_api_object_t *jerry_api_create_error (jerry_api_error_t, const jerry_api_char_t *);
extern EXTERN_C
jerry_api_object_t *jerry_api_create_error_sz (jerry_api_error_t, const jerry_api_char_t *, jerry_api_size_t);
extern EXTERN_C
jerry_api_object_t *jerry_api_create_external_function (jerry_external_handler_t);

extern EXTERN_C
bool jerry_api_is_function (const jerry_api_object_t *);
extern EXTERN_C
bool jerry_api_is_constructor (const jerry_api_object_t *);
bool jerry_api_is_function (const jerry_api_object_t *);

extern EXTERN_C
bool jerry_api_add_object_field (jerry_api_object_t *, const jerry_api_char_t *, jerry_api_size_t,
const jerry_api_value_t *, bool);
extern EXTERN_C
bool jerry_api_delete_object_field (jerry_api_object_t *, const jerry_api_char_t *, jerry_api_size_t);
extern EXTERN_C
bool jerry_api_get_object_field_value (jerry_api_object_t *, const jerry_api_char_t *, jerry_api_value_t *);

extern EXTERN_C
bool jerry_api_get_object_field_value (jerry_api_object_t *, const jerry_api_char_t *, jerry_api_value_t *);
bool jerry_api_get_object_field_value_sz (jerry_api_object_t *, const jerry_api_char_t *, jerry_api_size_t,
jerry_api_value_t *);

extern EXTERN_C
bool jerry_api_set_object_field_value (jerry_api_object_t *, const jerry_api_char_t *, const jerry_api_value_t *);

extern EXTERN_C
bool jerry_api_set_object_field_value_sz (jerry_api_object_t *, const jerry_api_char_t *, jerry_api_size_t,
const jerry_api_value_t *);

extern EXTERN_C
bool jerry_api_foreach_object_field (jerry_api_object_t *, jerry_object_field_foreach_t, void *);

extern EXTERN_C
bool jerry_api_get_object_native_handle (jerry_api_object_t *, uintptr_t *);

extern EXTERN_C
void jerry_api_set_object_native_handle (jerry_api_object_t *, uintptr_t, jerry_object_free_callback_t);

extern EXTERN_C
bool jerry_api_call_function (jerry_api_object_t *, jerry_api_object_t *, jerry_api_value_t *,
const jerry_api_value_t[], uint16_t);

extern EXTERN_C
bool jerry_api_construct_object (jerry_api_object_t *, jerry_api_value_t *, const jerry_api_value_t[], uint16_t);

extern EXTERN_C
jerry_completion_code_t jerry_api_eval (const jerry_api_char_t *, size_t, bool, bool, jerry_api_value_t *);

extern EXTERN_C
jerry_api_object_t *jerry_api_get_global (void);

extern EXTERN_C
void jerry_api_gc (void);

extern EXTERN_C
void jerry_register_external_magic_strings (const jerry_api_char_ptr_t *, uint32_t, const jerry_api_length_t *);

extern EXTERN_C
size_t jerry_parse_and_save_snapshot (const jerry_api_char_t *, size_t, bool, uint8_t *, size_t);

extern EXTERN_C
jerry_completion_code_t jerry_exec_snapshot (const void *, size_t, bool, jerry_api_value_t *);

/**
* @}
*/

#ifdef __cplusplus
}
#endif /* !__cplusplus */
#endif /* !JERRY_API_H */
18 changes: 8 additions & 10 deletions jerry-core/jerry-port.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* Copyright 2015 Samsung Electronics Co., Ltd.
/* Copyright 2015-2016 Samsung Electronics Co., Ltd.
* Copyright 2016 University of Szeged.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,9 +20,8 @@
#include <stdio.h>

#ifdef __cplusplus
# define EXTERN_C "C"
#else /* !__cplusplus */
# define EXTERN_C
extern "C"
{
#endif /* !__cplusplus */

/** \addtogroup jerry_port Jerry engine port
Expand All @@ -31,17 +31,15 @@
/**
* Target port functions for console output
*/
extern EXTERN_C
int jerry_port_logmsg (FILE *stream, const char *format, ...);

extern EXTERN_C
int jerry_port_errormsg (const char *format, ...);

extern EXTERN_C
int jerry_port_putchar (int c);

/**
* @}
*/

#endif /* !JERRY_API_H */
#ifdef __cplusplus
}
#endif /* !__cplusplus */
#endif /* !JERRY_PORT_H */
Loading