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
671c2459
Commit
671c2459
authored
Aug 28, 2019
by
Joshua Haberman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed crash bug and moved initialization into init method.
parent
3e3407af
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
14 deletions
+9
-14
message.c
ruby/ext/google/protobuf_c/message.c
+9
-12
storage.c
ruby/ext/google/protobuf_c/storage.c
+0
-2
No files found.
ruby/ext/google/protobuf_c/message.c
View file @
671c2459
...
...
@@ -62,26 +62,19 @@ VALUE Message_alloc(VALUE klass) {
Descriptor
*
desc
=
ruby_to_Descriptor
(
descriptor
);
MessageHeader
*
msg
;
VALUE
ret
;
size_t
size
;
if
(
desc
->
layout
==
NULL
)
{
create_layout
(
desc
);
}
msg
=
(
MessageHeader
*
)
ALLOC_N
(
uint8_t
,
sizeof
(
MessageHeader
)
+
desc
->
layout
->
size
);
// Required in case a GC happens before layout_init().
memset
(
msg
,
0
,
desc
->
layout
->
size
);
// We wrap first so that everything in the message object is GC-rooted in case
// a collection happens during object creation in layout_init().
ret
=
TypedData_Wrap_Struct
(
klass
,
&
Message_type
,
msg
);
msg
=
ALLOC_N
(
uint8_t
,
sizeof
(
MessageHeader
)
+
desc
->
layout
->
size
);
msg
->
descriptor
=
desc
;
rb_ivar_set
(
ret
,
descriptor_instancevar_interned
,
descriptor
);
msg
->
unknown_fields
=
NULL
;
memcpy
(
Message_data
(
msg
),
desc
->
layout
->
empty_template
,
desc
->
layout
->
size
);
layout_init
(
desc
->
layout
,
Message_data
(
msg
));
ret
=
TypedData_Wrap_Struct
(
klass
,
&
Message_type
,
msg
);
rb_ivar_set
(
ret
,
descriptor_instancevar_interned
,
descriptor
);
return
ret
;
}
...
...
@@ -473,7 +466,11 @@ int Message_initialize_kwarg(VALUE key, VALUE val, VALUE _self) {
* Message class are provided on each concrete message class.
*/
VALUE
Message_initialize
(
int
argc
,
VALUE
*
argv
,
VALUE
_self
)
{
MessageHeader
*
self
;
VALUE
hash_args
;
TypedData_Get_Struct
(
_self
,
MessageHeader
,
&
Message_type
,
self
);
layout_init
(
self
->
descriptor
->
layout
,
Message_data
(
self
));
if
(
argc
==
0
)
{
return
Qnil
;
...
...
ruby/ext/google/protobuf_c/storage.c
View file @
671c2459
...
...
@@ -947,8 +947,6 @@ void layout_init(MessageLayout* layout, void* storage) {
VALUE
*
value
=
(
VALUE
*
)
CHARPTR_AT
(
storage
,
layout
->
value_offset
);
int
i
;
memcpy
(
storage
,
layout
->
empty_template
,
layout
->
size
);
for
(
i
=
0
;
i
<
layout
->
repeated_count
;
i
++
,
value
++
)
{
*
value
=
RepeatedField_new_this_type
(
*
value
);
}
...
...
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