Skip to content
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

Getting files C++ compilable #12499

Merged
merged 3 commits into from
Sep 13, 2017
Merged

Getting files C++ compilable #12499

merged 3 commits into from
Sep 13, 2017

Conversation

yashykt
Copy link
Member

@yashykt yashykt commented Sep 12, 2017

Getting files C++ compilable - Adding pointer conversions, changing variable and type names.

@yashykt
Copy link
Member Author

yashykt commented Sep 12, 2017

Jenkins: test this please

Copy link
Member

@vjpai vjpai left a comment

Choose a reason for hiding this comment

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

In general, check if the things that you are typecasting have already been typecast the desired way.

@@ -130,9 +130,9 @@ static void fd_global_shutdown(void);
* Pollset Declarations
*/

typedef enum { UNKICKED, KICKED, DESIGNATED_POLLER } kick_state;
typedef enum { UNKICKED, KICKED, DESIGNATED_POLLER } kick_state_t;
Copy link
Member

Choose a reason for hiding this comment

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

Just curious, what was the motivation for going from kick_state to kick_state_t ? Is this a style guide rule?

Copy link
Member

Choose a reason for hiding this comment

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

And likewise with the other places where _t is getting appended to struct or enum names.

Copy link
Member Author

Choose a reason for hiding this comment

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

C++ does not allow same type and variable names. There were cases such as :
kick_state kick_state;
Adding a _t seemed like the easiest way to solve them.

Copy link
Member

Choose a reason for hiding this comment

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

Very neat.

@@ -22,6 +22,8 @@
#include "src/core/lib/iomgr/pollset.h"
#include "src/core/lib/iomgr/pollset_set.h"

typedef enum pops_tag { POPS_NONE, POPS_POLLSET, POPS_POLLSET_SET } pops_tag;
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, this abbreviation isn't obvious to me. I think stylistically, non-obvious abbrevations shouldn't be used.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've just brought it outside the struct, since C++ does not allow using enum which are inside a struct.

Copy link
Member

@vjpai vjpai Sep 12, 2017

Choose a reason for hiding this comment

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

Ah, ok, this is uglier then. Since this is in a header and lives outside of a struct, it is polluting the global namespace. (FWIW, this was probably true even before since C doesn't have the concept of local names afaik, but we didn't particularly notice it for some reason.) Anything in the global namespace needs to be prefixed grpc_ . But I meant that the enum names are ugly. And even these enums should be prefixed GRPC_ .

Copy link
Member Author

Choose a reason for hiding this comment

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

The grpc_ prefix is for functions as per https://github.com/grpc/grpc/blob/master/doc/c-style-guide.md. But it might make sense ti add I guess we can substitute it with
typedef enum pollset_tag {POLLS_NONE, POLLS_POLLSET, POLLS_POLLSET_SET} pollset_tag;
or
typedef enum grpc_pollset_tag {GRPC_POLLS_NONE, GRPC_POLLS_POLLSET, GRPC_POLLS_POLLSET_SET} grpc_pollset_tag;

Copy link
Member

Choose a reason for hiding this comment

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

Then this is a defect in our C style guide. In practice, all the structs/enums declared in header files have the typename prefixed with grpc_ and all the enum names are also prefixed with GRPC_ . You should go ahead and fix this as typedef enum grpc_pollset_tag .... etc (your 2nd option above)

Copy link
Member

Choose a reason for hiding this comment

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

I'll fix the style guide.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks Vijay! Done

Copy link
Member

Choose a reason for hiding this comment

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

I have sent in PR #12519 to fix the style guide (as well as a few places where we weren't actually following the rules)

@@ -549,8 +549,8 @@ static void destroy_call(grpc_exec_ctx *exec_ctx, void *call,
GRPC_CQ_INTERNAL_UNREF(exec_ctx, c->cq, "bind");
}

get_final_status(call, set_status_value_directly, &c->final_info.final_status,
NULL);
get_final_status((grpc_call *)call, set_status_value_directly,
Copy link
Member

Choose a reason for hiding this comment

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

Wait, this has already been typecasted to a call as c above (in line 527)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. Good eye!

@@ -1474,7 +1475,7 @@ static void receiving_stream_ready(grpc_exec_ctx *exec_ctx, void *bctlp,
* acq_load is in receiving_initial_metadata_ready() */
if (error != GRPC_ERROR_NONE || call->receiving_stream == NULL ||
!gpr_atm_rel_cas(&call->recv_state, RECV_NONE, (gpr_atm)bctlp)) {
process_data_after_md(exec_ctx, bctlp);
process_data_after_md(exec_ctx, (batch_control *)bctlp);
Copy link
Member

Choose a reason for hiding this comment

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

bctl , right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup

Copy link
Member

@vjpai vjpai left a comment

Choose a reason for hiding this comment

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

Please address the comments in my previous review...

@grpc-kokoro
Copy link

[trickle] No significant performance differences

@grpc-kokoro
Copy link

[microbenchmarks] No significant performance differences

@vjpai
Copy link
Member

vjpai commented Sep 12, 2017

BTW, what are the strange commits at the top of this PR? There seem to be commits from Mark and others that are unrelated. Looks to me like your branch base is questionable; can you rebase this to master?

@yashykt
Copy link
Member Author

yashykt commented Sep 12, 2017

I was trying out git rebase -i. So it intermingled some of the merges. Fixed it.

Copy link
Member

@vjpai vjpai left a comment

Choose a reason for hiding this comment

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

LGTM

@grpc-kokoro
Copy link

[trickle] No significant performance differences

@grpc-kokoro
Copy link

[microbenchmarks] No significant performance differences

@yashykt
Copy link
Member Author

yashykt commented Sep 13, 2017

Known issues : #11737, (also the fixed INT_MAX issue in flow_control.c)

@yashykt yashykt merged commit 22e89a8 into grpc:master Sep 13, 2017
@ctiller
Copy link
Member

ctiller commented Sep 13, 2017

_t names are reserved for the language and system libraries afaik... Can we change this to use something else?

@yashykt
Copy link
Member Author

yashykt commented Sep 13, 2017

Can change it to explicitly use _type or _enum or something else. What do you suggest?

@ctiller
Copy link
Member

ctiller commented Sep 13, 2017 via email

@yashykt
Copy link
Member Author

yashykt commented Sep 13, 2017

Created PR #12545 to change _t to _type

@yashykt yashykt deleted the ctocc3 branch March 14, 2018 22:12
@lock lock bot locked as resolved and limited conversation to collaborators Jan 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants