static char *prolog_cerrar(modulo_t *modulo) { prolog_dato_t *prolog = (prolog_dato_t*)modulo->m_dato; PL_discard_foreign_frame(prolog->m_fid); PL_cleanup(0); free(prolog); free(modulo); return "cerrado"; }
void release_prolog(pTHX_ pMY_CXT) { if (c_prolog_ok && c_prolog_init) { #ifdef MULTIPLICITY /* warn ("destroying Prolog engine"); */ PL_thread_destroy_engine(); #else warn ("Prolog cleanup"); PL_cleanup(0); #endif c_prolog_init=0; c_prolog_ok=0; } }
/************************* * prolog_exit *************************/ PROLOG_API void prolog_exit(void) { if (!initialized) return; if (PL_is_initialised(NULL, NULL)) PL_cleanup(0); libprolog_free_predicates(); libprolog_trace_exit(); initialized = FALSE; }
/************************* * prolog_init *************************/ PROLOG_API int prolog_init(char *argv0, int lsize, int gsize, int tsize, int asize, char *bootfile) { char **argv; int argc, status; (void)argv0; if (initialized) return EBUSY; /* * Notes: * * PL_initialise wants to know the path to the binary that has libpl.a * linked into. It tries to load the binary as a prolog resource file. * If this fails it will practically skip parsing most of the command * line, including our options to silence output and limit the size of * the various stacks. * * In our case, libpl.a is linked to libprolog.so and not to the main * binary. Hence we first need to find the path to libprolog.so and then * pass this in as argv[0] to PL_initialise. Ugly, I know... but necessary * unless we link statically. * * * Notes #2: * * This is unarguably a linux-specific hack. An alternative would be * a GLIBC-specific hack using dl_iterate_phdr(3) to iterate directly * through the list of shared objects loaded into us. This would have * the benefit of not needing to open and parse /proc entries. * * Notes #3: * * Stand-alone precompiled prolog files include a copy of the interpreter * itself. Using one could be an alternative to avoid this problem * altogether. */ #if 0 setenv("SWI_HOME_DIR", PROLOG_HOME, TRUE); /* hmm... is this needed ? */ #endif snprintf(lstack, sizeof(lstack), "-L%dk", lsize ?: 16); snprintf(gstack, sizeof(gstack), "-G%dk", gsize ?: 16); snprintf(tstack, sizeof(tstack), "-T%dk", tsize ?: 16); snprintf(astack, sizeof(astack), "-A%dk", asize ?: 16); if (bootfile != NULL) argv = pl_argv; else argv = pl_argv + 2; /* skip { "-x", bootfile } */ argv[argc=0] = shlib_path(LIBPROLOG_SO, libprolog_so, sizeof(libprolog_so)); if (bootfile != NULL) { pl_argv[++argc] = "-x"; /* must be argv[1] */ pl_argv[++argc] = bootfile; /* and argv[2] */ } argc += NUM_FIXED_ARGS; pl_argv[++argc] = lstack; pl_argv[++argc] = gstack; pl_argv[++argc] = tstack; pl_argv[++argc] = astack; libprolog_clear_errors(); if ((status = libprolog_trace_init()) != 0) return status; if ((status = register_predicates()) != 0) return status; if (!PL_initialise(argc + 1, argv)) { PL_cleanup(0); return EINVAL; } /* libprolog.pl assumed to be part of boot file, otherwise load it */ if (bootfile == NULL) { if (!libprolog_load_file(libprolog_pl, FALSE)) { PL_cleanup(0); return EINVAL; } } initialized = TRUE; return status; }
// Destructor SWIPLContainer::~SWIPLContainer() { qDebug() << "Cleaning up Prolog engine..."; PL_cleanup(0); qDebug() << "Prolog successfully cleaned up!"; }