History

python/ext: simplify memory allocations, removed unneeded malloc/free calls

Paul Brossier committed 10 years ago

Commit 569b3631 parent a35db129 files · +75 −125Browse files

Showing the changes to python/lib/gen_code.py (1 of 9 files). Show all

Unified · Split

python/lib/gen_code.py+8−8
@@ -202,7 +202,9 @@ typedef struct{{ · 201 unmodified lines
202202 {output_results};
203203 }} Py_{shortname};
204204 """
205− return out.format(do_inputs_list = "; ".join(get_input_params(self.do_proto)), **self.__dict__)
205+ # fmat_t* / fvec_t* / cvec_t* inputs -> full fvec_t /.. struct in Py_{shortname}
206+ do_inputs_list = "; ".join(get_input_params(self.do_proto)).replace('fvec_t *','fvec_t').replace('fmat_t *', 'fmat_t').replace('cvec_t *', 'cvec_t')
207+ return out.format(do_inputs_list = do_inputs_list, **self.__dict__)
206208
207209 def gen_doc(self):
208210 out = """
@@ -310,9 +312,6 @@ Py_{shortname}_init (Py_{shortname} * self, PyObject * args, PyObject * kwds) · 101 unmodified lines
310312 out += """
311313 // TODO get internal params after actual object creation?
312314 """
313− for input_param in self.do_inputs:
314− out += """
315− self->{0} = ({1})malloc(sizeof({2}));""".format(input_param['name'], input_param['type'], input_param['type'][:-1])
316315 out += """
317316 // create outputs{output_create}
318317 """.format(output_create = output_create)
@@ -342,8 +341,9 @@ static void · 23 unmodified lines
342341 Py_{shortname}_del (Py_{shortname} * self, PyObject * unused)
343342 {{""".format(**self.__dict__)
344343 for input_param in self.do_inputs:
345− out += """
346− free(self->{0[name]});""".format(input_param)
344+ if input_param['type'] == 'fmat_t *':
345+ out += """
346+ free(self->{0[name]}.data);""".format(input_param)
347347 for o in self.outputs:
348348 name = o['name']
349349 del_out = delfromtype_fn[o['type']]
@@ -379,11 +379,11 @@ Py_{shortname}_do (Py_{shortname} * self, PyObject * args) · 29 unmodified lines
379379 }}""".format(refs = refs, pyparamtypes = pyparamtypes, **self.__dict__)
380380 for p in input_params:
381381 out += """
382− if (!{pytoaubio}(py_{0[name]}, self->{0[name]})) {{
382+ if (!{pytoaubio}(py_{0[name]}, &(self->{0[name]}))) {{
383383 return NULL;
384384 }}""".format(input_param, pytoaubio = pytoaubio_fn[input_param['type']])
385385 do_fn = get_name(self.do_proto)
386− inputs = ", ".join(['self->'+p['name'] for p in input_params])
386+ inputs = ", ".join(['&(self->'+p['name']+')' for p in input_params])
387387 outputs = ", ".join(["self->%s" % p['name'] for p in self.do_outputs])
388388 out += """
389389

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t