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
php: Added nanosecond support for Timestamp #3972
Conversation
Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure. |
1 similar comment
Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure. |
230b912
to
6655f4c
Compare
@TeBoring Could you please take a look at this ticket or assign it to someone? 🙂 |
Could you check the c extension also works? https://github.com/google/protobuf/tree/master/php/ext/google/protobuf |
8663105
to
59efdd5
Compare
@TeBoring You're right: The Can you run kokoro on this again? I tried my best converting my PHP logic into C and also improving the existing C code a little bit (e.g. by not relying on the flaky But if possible someone more experienced in PHP extensions has to look over this PR as I was basically only poking around in the dark here (I really don't have any clue how to write PHP extensions). |
If you run:
You will get:
|
#endif | ||
|
||
PHP_PROTO_ZVAL_STRING(&function_name, "date_format", 1); | ||
PHP_PROTO_ZVAL_STRING(&format_string, "u", 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You forget to call zval_dtor(&format_string);
which causes memory leak.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
}; | ||
|
||
if (call_user_function(EG(function_table), NULL, &function_name, &retval, | ||
ARRAY_SIZE(params), params TSRMLS_CC) == FAILURE) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using ARRAY_SZIE, why not using actual number?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my explanation for ARRAY_SIZE
below. 🙂
Should I change it back?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation. ARRAY_SIZE looks good to me.
@@ -42,6 +42,10 @@ | |||
#define MAX_LENGTH_OF_INT64 20 | |||
#define SIZEOF_INT64 8 | |||
|
|||
/* From Chromium. */ | |||
#define ARRAY_SIZE(x) \ | |||
((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x]))))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why ARRAY_SIZE
is like this? Is it related to implementation detail of php runtime?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've taken that macro from here: https://github.com/google/protobuf/blob/3beb19945b599d448c2524666effe1acdf29165f/php/ext/google/protobuf/upb.c#L8107-L8109
It's a classical macro to determine the size of constant-sized arrays in C.
For instance if you have a char foo[25]
then ARRAY_SIZE(foo)
will evaluate to 25
.
You can find an explanation here: https://stackoverflow.com/a/4415646
Since such a macro is much safer than hardcoding the size of arrays I've started replacing these hardcoded numbers in any PHP-extension code I touched, but I'd recommend using that macro in other places as well as soon as possible. It will probably reduce accidential mistakes in future PRs. 🙂
You probably also need to fix the memory_leak_test. |
any update? |
@TeBoring Sorry, I'm pretty busy at the moment and forgot about this PR for the last few days. |
The broken test is not about memory anymore. You can just run it with php.
…On Thu, Jul 12, 2018 at 11:16 Leonard Hecker ***@***.***> wrote:
@TeBoring <https://github.com/TeBoring> Sorry I'm pretty busy at the
moment and forgot about this PR for the last few days.
I "allocated" myself some time tomorrow though to finish up the remaining
issues in this PR. 🙂
(It'd be nice if I can get valgrind running on macOS though. 🤔)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3972 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AE9H5ZzlVxTMi8zJw1LQl6gFTsqehCF0ks5uF5KVgaJpZM4QunPT>
.
|
@TeBoring I fixed this one remaining issue just now. Sorry that you had to wait that long. 🙂 |
For php 7.1, c extension test:
|
@TeBoring You (or Kokoro) seem to have made a mistake when testing my PR: Proof for my "accusation":
is generated by phpunit's
If I'm correct this means that you're trying to test the changed C extension using the old test code, which is not possible in this case. |
I doubt it's our compatibility test. |
@TeBoring My fork was out of date and would've resulted in a merge conflict if I touch that file. I also sadly didn't quite understand your last comment. I feel like this solution is possibly a bit like shooting sparrows with cannons, but I didn't had any better idea. Do you happen to have one? |
@lhecker Thanks for the fix. There were some incorrect test. When we update the against compatibility tests, we will have the correct test. Before that, we just manually disable them. I think your approach is acceptable, because that test is truly not correct. |
@TeBoring Thanks for merging this and helping me ironing out all these issues in my PR. 🙂🎉 |
This PR adds support for the nanoseconds field of the wellknown
Timestamp
type for PHP 5.6 and later.The accuracy will be in the order of microseconds though, as that's the highest resolution PHP supports.
I hope this PR fullfills all necessary preconditions to be merged, but if it doesn't (e.g. because the
Timestamp
class is generated automatically), I'd be glad to help get this feature implemented whatever is necessary for that to happen. 🙂