Skip to content

Use 'static inline' for function definitions that are in header files. #863

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
73 changes: 73 additions & 0 deletions jerry-core/jrt/jrt.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/* Copyright 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.
* 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"

/**
* Read data from a specified buffer.
*
* Note:
* Offset is in-out and is incremented if the read operation completes successfully.
*
* @return true, if read was successful, i.e. offset + data_size doesn't exceed buffer size,
* false - otherwise.
*/
bool __attr_always_inline___
jrt_read_from_buffer_by_offset (const uint8_t *buffer_p, /**< buffer */
size_t buffer_size, /**< size of buffer */
size_t *in_out_buffer_offset_p, /**< in: offset to read from,
* out: offset, incremented on sizeof (T) */
void *out_data_p, /**< out: data */
size_t out_data_size) /**< size of the readable data */
{
if (*in_out_buffer_offset_p + out_data_size > buffer_size)
{
return false;
}

memcpy (out_data_p, buffer_p + *in_out_buffer_offset_p, out_data_size);
*in_out_buffer_offset_p += out_data_size;

return true;
} /* jrt_read_from_buffer_by_offset */

/**
* Write data to a specified buffer.
*
* Note:
* Offset is in-out and is incremented if the write operation completes successfully.
*
* @return true, if write was successful, i.e. offset + data_size doesn't exceed buffer size,
* false - otherwise.
*/
bool __attr_always_inline___
jrt_write_to_buffer_by_offset (uint8_t *buffer_p, /**< buffer */
size_t buffer_size, /**< size of buffer */
size_t *in_out_buffer_offset_p, /**< in: offset to read from,
* out: offset, incremented on sizeof (T) */
const void *data_p, /**< data */
size_t data_size) /**< size of the writable data */
{
if (*in_out_buffer_offset_p + data_size > buffer_size)
{
return false;
}

memcpy (buffer_p + *in_out_buffer_offset_p, data_p, data_size);
*in_out_buffer_offset_p += data_size;

return true;
} /* jrt_write_to_buffer_by_offset */
57 changes: 3 additions & 54 deletions jerry-core/jrt/jrt.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,60 +214,9 @@ extern void __noreturn jerry_fatal (jerry_fatal_code_t);
#define JERRY_MIN(v1, v2) ((v1 < v2) ? v1 : v2)
#define JERRY_MAX(v1, v2) ((v1 < v2) ? v2 : v1)

/**
* Read data from a specified buffer.
*
* Note:
* Offset is in-out and is incremented if the read operation completes successfully.
*
* @return true, if read was successful, i.e. offset + data_size doesn't exceed buffer size,
* false - otherwise.
*/
inline bool
jrt_read_from_buffer_by_offset (const uint8_t *buffer_p, /**< buffer */
size_t buffer_size, /**< size of buffer */
size_t *in_out_buffer_offset_p, /**< in: offset to read from,
* out: offset, incremented on sizeof (T) */
void *out_data_p, /**< out: data */
size_t out_data_size) /**< size of the readable data */
{
if (*in_out_buffer_offset_p + out_data_size > buffer_size)
{
return false;
}

memcpy (out_data_p, buffer_p + *in_out_buffer_offset_p, out_data_size);
*in_out_buffer_offset_p += out_data_size;

return true;
} /* jrt_read_from_buffer_by_offset */

/**
* Write data to a specified buffer.
*
* Note:
* Offset is in-out and is incremented if the write operation completes successfully.
*
* @return true, if write was successful, i.e. offset + data_size doesn't exceed buffer size,
* false - otherwise.
*/
inline bool
jrt_write_to_buffer_by_offset (uint8_t *buffer_p, /**< buffer */
size_t buffer_size, /**< size of buffer */
size_t *in_out_buffer_offset_p, /**< in: offset to read from,
* out: offset, incremented on sizeof (T) */
const void *data_p, /**< data */
size_t data_size) /**< size of the writable data */
{
if (*in_out_buffer_offset_p + data_size > buffer_size)
{
return false;
}

memcpy (buffer_p + *in_out_buffer_offset_p, data_p, data_size);
*in_out_buffer_offset_p += data_size;

return true;
} /* jrt_write_to_buffer_by_offset */
extern bool jrt_read_from_buffer_by_offset (const uint8_t *, size_t, size_t *, void *, size_t);

extern bool jrt_write_to_buffer_by_offset (uint8_t *, size_t, size_t *, const void *, size_t);

#endif /* !JERRY_GLOBALS_H */