annotate Lib/fftw-3.2.1/api/.svn/text-base/export-wisdom-to-string.c.svn-base @ 9:262e084a15a9

Vectorised everything and made use of unique_ptr so there should be no more memory leaks. Hurrah for RAII
author Geogaddi\David <d.m.ronan@qmul.ac.uk>
date Wed, 12 Aug 2015 22:25:06 +0100
parents 25bf17994ef1
children
rev   line source
d@0 1 /*
d@0 2 * Copyright (c) 2003, 2007-8 Matteo Frigo
d@0 3 * Copyright (c) 2003, 2007-8 Massachusetts Institute of Technology
d@0 4 *
d@0 5 * This program is free software; you can redistribute it and/or modify
d@0 6 * it under the terms of the GNU General Public License as published by
d@0 7 * the Free Software Foundation; either version 2 of the License, or
d@0 8 * (at your option) any later version.
d@0 9 *
d@0 10 * This program is distributed in the hope that it will be useful,
d@0 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d@0 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d@0 13 * GNU General Public License for more details.
d@0 14 *
d@0 15 * You should have received a copy of the GNU General Public License
d@0 16 * along with this program; if not, write to the Free Software
d@0 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
d@0 18 *
d@0 19 */
d@0 20
d@0 21 #include "api.h"
d@0 22
d@0 23 typedef struct {
d@0 24 printer super;
d@0 25 int *cnt;
d@0 26 } P_cnt;
d@0 27
d@0 28 static void putchr_cnt(printer * p_, char c)
d@0 29 {
d@0 30 P_cnt *p = (P_cnt *) p_;
d@0 31 UNUSED(c);
d@0 32 ++*p->cnt;
d@0 33 }
d@0 34
d@0 35 static printer *mkprinter_cnt(int *cnt)
d@0 36 {
d@0 37 P_cnt *p = (P_cnt *) X(mkprinter)(sizeof(P_cnt), putchr_cnt, 0);
d@0 38 p->cnt = cnt;
d@0 39 *cnt = 0;
d@0 40 return &p->super;
d@0 41 }
d@0 42
d@0 43 typedef struct {
d@0 44 printer super;
d@0 45 char *s;
d@0 46 } P_str;
d@0 47
d@0 48 static void putchr_str(printer * p_, char c)
d@0 49 {
d@0 50 P_str *p = (P_str *) p_;
d@0 51 *p->s++ = c;
d@0 52 *p->s = 0;
d@0 53 }
d@0 54
d@0 55 static printer *mkprinter_str(char *s)
d@0 56 {
d@0 57 P_str *p = (P_str *) X(mkprinter)(sizeof(P_str), putchr_str, 0);
d@0 58 p->s = s;
d@0 59 *s = 0;
d@0 60 return &p->super;
d@0 61 }
d@0 62
d@0 63 char *X(export_wisdom_to_string)(void)
d@0 64 {
d@0 65 printer *p;
d@0 66 planner *plnr = X(the_planner)();
d@0 67 int cnt;
d@0 68 char *s;
d@0 69
d@0 70 p = mkprinter_cnt(&cnt);
d@0 71 plnr->adt->exprt(plnr, p);
d@0 72 X(printer_destroy)(p);
d@0 73
d@0 74 s = (char *) NATIVE_MALLOC(sizeof(char) * (cnt + 1), OTHER);
d@0 75 if (s) {
d@0 76 p = mkprinter_str(s);
d@0 77 plnr->adt->exprt(plnr, p);
d@0 78 X(printer_destroy)(p);
d@0 79 }
d@0 80
d@0 81 return s;
d@0 82 }