Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
88102eae
Commit
88102eae
authored
Dec 12, 2017
by
Bo Yang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace private timelib_update_ts with public date_timestamp_get
parent
9f6aceaa
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
5 deletions
+31
-5
message.c
php/ext/google/protobuf/message.c
+19
-5
memory_leak_test.php
php/tests/memory_leak_test.php
+12
-0
No files found.
php/ext/google/protobuf/message.c
View file @
88102eae
...
...
@@ -1133,12 +1133,24 @@ PHP_METHOD(Timestamp, fromDateTime) {
return
;
}
php_date_obj
*
dateobj
=
UNBOX
(
php_date_obj
,
datetime
);
if
(
!
dateobj
->
time
->
sse_uptodate
)
{
timelib_update_ts
(
dateobj
->
time
,
NULL
);
// Get timestamp from Datetime object.
zval
*
retval_ptr
;
zval
*
function_name
;
int64_t
timestamp
;
MAKE_STD_ZVAL
(
retval_ptr
);
MAKE_STD_ZVAL
(
function_name
);
ZVAL_STRING
(
function_name
,
"date_timestamp_get"
,
1
);
if
(
call_user_function
(
EG
(
function_table
),
NULL
,
function_name
,
retval_ptr
,
1
,
&
datetime
TSRMLS_CC
)
==
SUCCESS
)
{
protobuf_convert_to_int64
(
retval_ptr
,
&
timestamp
);
}
int64_t
timestamp
=
dateobj
->
time
->
sse
;
zval_ptr_dtor
(
&
retval_ptr
);
zval_ptr_dtor
(
&
function_name
);
// Set seconds
MessageHeader
*
self
=
UNBOX
(
MessageHeader
,
getThis
());
...
...
@@ -1146,13 +1158,15 @@ PHP_METHOD(Timestamp, fromDateTime) {
upb_msgdef_ntofz
(
self
->
descriptor
->
msgdef
,
"seconds"
);
void
*
storage
=
message_data
(
self
);
void
*
memory
=
slot_memory
(
self
->
descriptor
->
layout
,
storage
,
field
);
*
(
int64_t
*
)
memory
=
dateobj
->
time
->
sse
;
*
(
int64_t
*
)
memory
=
timestamp
;
// Set nanos
field
=
upb_msgdef_ntofz
(
self
->
descriptor
->
msgdef
,
"nanos"
);
storage
=
message_data
(
self
);
memory
=
slot_memory
(
self
->
descriptor
->
layout
,
storage
,
field
);
*
(
int32_t
*
)
memory
=
0
;
RETURN_NULL
();
#else
zend_error
(
E_USER_ERROR
,
"fromDateTime needs date extension."
);
#endif
...
...
php/tests/memory_leak_test.php
View file @
88102eae
...
...
@@ -126,6 +126,18 @@ $from = new \Google\Protobuf\Timestamp();
$from
->
setSeconds
(
1
);
assert
(
1
,
$from
->
getSeconds
());
$timestamp
=
new
\Google\Protobuf\Timestamp
();
date_default_timezone_set
(
'UTC'
);
$from
=
new
DateTime
(
'2011-01-01T15:03:01.012345UTC'
);
$timestamp
->
fromDateTime
(
$from
);
assert
(
$from
->
format
(
'U'
),
$timestamp
->
getSeconds
());
assert
(
0
,
$timestamp
->
getNanos
());
$to
=
$timestamp
->
toDateTime
();
assert
(
\DateTime
::
class
,
get_class
(
$to
));
assert
(
$from
->
format
(
'U'
),
$to
->
format
(
'U'
));
$from
=
new
\Google\Protobuf\Value
();
$from
->
setNumberValue
(
1
);
assert
(
1
,
$from
->
getNumberValue
());
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment