GCC Code Coverage Report
Directory: emc/rs274ngc/ Exec Total Coverage
File: emc/rs274ngc/interp_base.cc Lines: 10 20 50.0 %
Date: 2016-10-27 Branches: 4 8 50.0 %

Line Exec Source
1
/*
2
 * Copyright (C) 2013 Jeff Epler <jepler@unpythonic.net>
3
 *
4
 *  This program is free software; you can redistribute it and/or
5
 *  modify it under the terms of the GNU General Public License
6
 *  as published by the Free Software Foundation; either version 2
7
 *  of the License, or (at your option) any later version.
8
 *
9
 *  This program is distributed in the hope that it will be useful,
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *  GNU General Public License for more details.
13
 *
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program; if not, write to the Free Software
16
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17
 */
18
#include "interp_base.hh"
19
#include <dlfcn.h>
20
#include <limits.h>
21
#include <config.h>
22
#include <stdio.h>
23
24
InterpBase::~InterpBase() {}
25
26
1
InterpBase *interp_from_shlib(const char *shlib) {
27
1
    fprintf(stderr, "interp_from_shlib(%s)\n", shlib);
28
1
    dlopen(NULL, RTLD_GLOBAL);
29
1
    void *interp_lib = dlopen(shlib, RTLD_NOW);
30
1
    if(!interp_lib) {
31
	fprintf(stderr, "emcTaskInit: could not open interpreter '%s': %s\n", shlib, dlerror());
32
	char relative_interp[PATH_MAX];
33
	snprintf(relative_interp, sizeof(relative_interp), "%s/%s",
34
	    EMC2_HOME "/lib/emc2", shlib);
35
	interp_lib = dlopen(relative_interp, RTLD_NOW);
36
    }
37
1
    if(!interp_lib) {
38
	fprintf(stderr, "emcTaskInit: could not open interpreter '%s': %s\n", shlib, dlerror());
39
	return 0;
40
    }
41
    typedef InterpBase* (*Constructor)();
42
1
    Constructor constructor = (Constructor)dlsym(interp_lib, "makeInterp");
43
1
    if(!constructor) {
44
	fprintf(stderr, "emcTaskInit: could not get symbol makeInterp from interpreter '%s': %s\n", shlib, dlerror());
45
	return 0;
46
    }
47
1
    InterpBase *pinterp = constructor();
48
1
    if(!pinterp) {
49
	fprintf(stderr, "emcTaskInit: makeInterp() returned NULL from interpreter '%s'\n", shlib);
50
	return 0;
51
    }
52
    return pinterp;
53
}