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

a memory leak occurs when createing a new type #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions pyros_schemas/ros/schemagic.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def create(ros_msg_class,

members_types = _get_rosmsg_fields_as_dict(ros_msg_class)
members = {}
schema_instance = RosSchema()
for s, stype in members_types.iteritems():
# Note here we rely entirely on _opt_slots from the class to be set properly
# for both Nested or List representation of optional fields
Expand Down Expand Up @@ -80,28 +81,24 @@ def create(ros_msg_class,
ros_schema_inst = RosNested(create(stype)) # we need to nest the next (Ros)Schema

members.setdefault(s, ros_schema_inst)
schema_instance.declared_fields[s] = ros_schema_inst
schema_instance.fields[s] = ros_schema_inst

# supporting extra customization of the serialization
if pre_load_fun:
members['_helper_pre_load'] = pre_load(pre_load_fun)
schema_instance.declared_fields['_helper_pre_load'] = pre_load(pre_load_fun)
if post_load_fun:
members['_helper_post_load'] = post_load(post_load_fun)
schema_instance.declared_fields['_helper_post_load'] = post_load(post_load_fun)
if pre_dump_fun:
members['_helper_pre_dump'] = pre_dump(pre_dump_fun)
schema_instance.declared_fields['_helper_pre_dump'] = pre_dump(pre_dump_fun)
if post_dump_fun:
members['_helper_post_dump'] = post_dump(post_dump_fun)
schema_instance.declared_fields['_helper_post_dump'] = post_dump(post_dump_fun)

# adding extra members if needed
for k, v in kwargs:
members[k] = v
schema_instance.declared_fields[k] = v

members['_valid_ros_msgtype'] = ros_msg_class
members['_generated_ros_msgtype'] = ros_msg_class

MsgSchema = type(ros_msg_class.__name__ + 'Schema', (RosSchema,), members)

# Generating the schema instance
# TODO : nicer way ?
schema_instance = MsgSchema()
schema_instance._valid_ros_msgtype = ros_msg_class
schema_instance._generated_ros_msgtype = ros_msg_class

return schema_instance