annotate Lib/fftw-3.2.1/api/.svn/text-base/import-wisdom-from-file.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 #include <stdio.h>
d@0 23
d@0 24 /* getc()/putc() are *unbelievably* slow on linux. Looks like glibc
d@0 25 is grabbing a lock for each call to getc()/putc(), or something
d@0 26 like that. You pay the price for these idiotic posix threads
d@0 27 whether you use them or not.
d@0 28
d@0 29 So, we do our own buffering. This completely defeats the purpose
d@0 30 of having stdio in the first place, of course.
d@0 31 */
d@0 32
d@0 33 #define BUFSZ 256
d@0 34
d@0 35 typedef struct {
d@0 36 scanner super;
d@0 37 FILE *f;
d@0 38 char buf[BUFSZ];
d@0 39 char *bufr, *bufw;
d@0 40 } S;
d@0 41
d@0 42 static int getchr_file(scanner * sc_)
d@0 43 {
d@0 44 S *sc = (S *) sc_;
d@0 45
d@0 46 if (sc->bufr >= sc->bufw) {
d@0 47 sc->bufr = sc->buf;
d@0 48 sc->bufw = sc->buf + fread(sc->buf, 1, BUFSZ, sc->f);
d@0 49 if (sc->bufr >= sc->bufw)
d@0 50 return EOF;
d@0 51 }
d@0 52
d@0 53 return *(sc->bufr++);
d@0 54 }
d@0 55
d@0 56 static scanner *mkscanner_file(FILE *f)
d@0 57 {
d@0 58 S *sc = (S *) X(mkscanner)(sizeof(S), getchr_file);
d@0 59 sc->f = f;
d@0 60 sc->bufr = sc->bufw = sc->buf;
d@0 61 return &sc->super;
d@0 62 }
d@0 63
d@0 64 int X(import_wisdom_from_file)(FILE *input_file)
d@0 65 {
d@0 66 scanner *s = mkscanner_file(input_file);
d@0 67 planner *plnr = X(the_planner)();
d@0 68 int ret = plnr->adt->imprt(plnr, s);
d@0 69 X(scanner_destroy)(s);
d@0 70 return ret;
d@0 71 }