Changeset 569b363 for python/lib


Ignore:
Timestamp:
Apr 24, 2016, 6:23:14 PM (8 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
Children:
51b9c83
Parents:
a35db12
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/lib/gen_code.py

    ra35db12 r569b363  
    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):
     
    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}
     
    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']
     
    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 += """
Note: See TracChangeset for help on using the changeset viewer.