Skip to content

Commit

Permalink
fix(util): deepcopy dicts instead
Browse files Browse the repository at this point in the history
It was possible for writes to happen in nested dicts, causing global
data to change and confuse the system.
Not that I wouldn't be aware of that danger, but apparently I didn't
see the recursiveness of the call tree :).
  • Loading branch information
Byron committed Mar 11, 2015
1 parent cf258bf commit efe56ad
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/mako/lib/schema.mako
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<%! from util import (schema_markers, rust_doc_comment, mangle_ident, to_rust_type, put_and,
IO_TYPES, activity_split, enclose_in, REQUEST_MARKER_TRAIT, mb_type)
IO_TYPES, activity_split, enclose_in, REQUEST_MARKER_TRAIT, mb_type, indent_all_but_first_by)
%>\
## Create new schema with everything.
## 's' contains the schema structure from json to build
###################################################################################################################
###################################################################################################################
<%def name="new(s, c)">\
<%
## assert s.type == "object"
assert s.type == "object"
markers = schema_markers(s, c)
%>\
<%block filter="rust_doc_comment">\
Expand All @@ -18,7 +18,7 @@ pub struct ${s.id}\
% if 'properties' in s:
{
% for pn, p in s.properties.iteritems():
${p.get('description', 'no description provided') | rust_doc_comment}
${p.get('description', 'no description provided') | rust_doc_comment, indent_all_but_first_by(1)}
pub ${mangle_ident(pn)}: ${to_rust_type(s.id, pn, p)},
% endfor
}
Expand Down
6 changes: 3 additions & 3 deletions src/mako/lib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
from random import (randint, random, choice, seed)
import collections
from copy import deepcopy

seed(1337)

Expand Down Expand Up @@ -271,7 +272,6 @@ def nested_type(nt):
else:
assert(is_nested_type_property(nt))
# It's a nested type - we take it literally like $ref, but generate a name for the type ourselves
# This of course assumes
return nested_type_name(sn, pn)
return to_rust_type(sn, pn, nt, allow_optionals=False)

Expand Down Expand Up @@ -331,7 +331,7 @@ def iter_nested_types(schemas):
def iter_nested_properties(prefix, properties):
for pn, p in properties.iteritems():
if is_nested_type_property(p):
ns = p.copy()
ns = deepcopy(p)
ns.id = nested_type_name(prefix, pn)
ns[NESTED_TYPE_MARKER] = True
if 'items' in p:
Expand Down Expand Up @@ -410,7 +410,7 @@ def method_params(m, required=None, location=None):
continue
if location is not None and p.get('location', '') != location:
continue
np = p.copy()
np = deepcopy(p)
np['name'] = pn
try:
# po = ['part', 'foo']
Expand Down

0 comments on commit efe56ad

Please sign in to comment.