Skip to content

remove the c++ syntax, struct::xxx #836

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

Closed

Conversation

jiangzidong
Copy link
Contributor

jerry now has the c++ syntax, struct_name:xxx and enum_name:xxx
such as sizeof (ecma_collection_chunk_t::data) and mem_block_length_type_t::GENERAL
those are not standard c syntax.

I convert them to JERRY_SIZE_OF_STRUCT_MEMBER (ecma_collection_chunk_t, data) and GENERAL

JERRY_SIZE_OF_STRUCT_MEMBER is a macro defined in jrt.h

@@ -38,7 +38,7 @@ ecma_new_values_collection (const ecma_value_t values_buffer[], /**< ecma-values
{
JERRY_ASSERT (values_buffer != NULL || values_number == 0);

const size_t values_in_chunk = sizeof (ecma_collection_chunk_t::data) / sizeof (ecma_value_t);
const size_t values_in_chunk = sizeof (((ecma_collection_chunk_t *)0)->data) / sizeof (ecma_value_t);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please do not use a hack for getting the size. Instead, you should use macros.

 lit_utf8_byte_t data[ sizeof (uint64_t) - sizeof (mem_cpointer_t) ];

For example:

#define ECMA_COLLECTION_DATA_COUNT (sizeof (uint64_t) - sizeof (mem_cpointer_t))
#define ECMA_COLLECTION_DATA_SIZE (sizeof (lit_utf8_byte_t) * ECMA_COLLECTION_DATA_COUNT)

lit_utf8_byte_t data[ ECMA_COLLECTION_DATA_COUNT ];
const size_t values_in_chunk = ECMA_COLLECTION_DATA_SIZE / sizeof (ecma_value_t);

As I wrote (#806 (comment)) I'm already eliminating the C++ features. So the current workflow is not the best because it results work duplication. The example that I show is my result for this problem.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could we talk on the jerryscript gitter about this topic? We can share our experience and current status :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rtakacs Should I close this PR and let you continue C-Convertion work? Of course we can talk on gitter. What about your 13:00 (GMT+1), which is my 20:00(GMT+8) today?

Copy link
Contributor

Choose a reason for hiding this comment

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

@jiangzidong It is not necessary. You spent time to do this like me, but you were faster to upload. Your solution is also good (the null pointer surprised me, I have never seen similar before). In my comment I just would like to symbolize that either work is unnecessary when we do this together (at the same time) without any conversation.

The time you recommended is good for me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rtakacs I don't think it's a hack. it is a well accepted method to get size of c struct member. (see http://stackoverflow.com/questions/3553296/c-sizeof-single-struct-member and http://stackoverflow.com/questions/3864583/sizeof-a-struct-member)

your solution directly calculated the size of ecma_collection_chunk_t::data

Copy link
Member

Choose a reason for hiding this comment

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

@jiangzidong It's not that nice to repeat the sizeof-null-deref logic all over the code. It'd be better to have it in a macro, as suggested in the linked stackoverflow post, e.g.,

#define member_size(type, member) sizeof(((type *)0)->member)

(If we choose to use this approach. There are some comments that it is either an undefined behaviour in old C, or needs C99 compiler at least.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@akiss77 @rtakacs I find that there already has the marco in jrt.h
line 191 #define JERRY_SIZE_OF_STRUCT_MEMBER(struct_name, member_name) sizeof (((struct_name *)NULL)->member_name)

I will fix my patch soon

@@ -349,7 +349,7 @@ mem_heap_init (void)
for (size_t i = 0; i < MEM_HEAP_CHUNKS_NUM; i++)
{
#ifndef JERRY_NDEBUG
JERRY_ASSERT (mem_heap_length_types[i] == mem_block_length_type_t::GENERAL);
JERRY_ASSERT (mem_heap_length_types[i] == GENERAL);
Copy link
Contributor

Choose a reason for hiding this comment

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

@jiangzidong, please rename GENERAL / ONE_CHUNKED to MEM_BLOCK_LENGTH_TYPE_GENERAL / MEM_BLOCK_LENGTH_TYPE_ONE_CHUNKED.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ruben-ayrapetyan updated, thanks

@@ -94,13 +94,13 @@ void mem_heap_valgrind_freya_mempool_request (void)
*/
typedef enum : uint8_t
{
GENERAL = 0, /**< general (may be multi-chunk) block
MEM_BLOCK_LENGTH_TYPE_GENERAL = 0, /**< general (may be multi-chunk) block
*
* Note:
Copy link
Contributor

Choose a reason for hiding this comment

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

@jiangzidong, please, fix indentation in the comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ruben-ayrapetyan
Copy link
Contributor

Looks good to me

JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
@zherczeg
Copy link
Member

zherczeg commented Feb 5, 2016

LGTM

@LaszloLango
Copy link
Contributor

Landed (9ab24b3)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants