From 98fef199bdd4ad632aa201e3fa3ee753a56c4675 Mon Sep 17 00:00:00 2001 From: Costa Vitor Date: Mon, 1 Jun 2009 18:01:30 -0500 Subject: [PATCH] fix conflict in error handling (not supposed to be exported by SWI-Prolog.h add PL_eval_expression_to_int64_ex --- include/SWI-Prolog.h | 43 +---------------------- library/yap2swi/yap2swi.c | 69 ++++++++++++++++++++++++++++++++++++- packages/PLStream/pl-incl.h | 5 ++- packages/PLStream/pl-yap.c | 9 +++++ packages/PLStream/pl-yap.h | 40 +++++++++++++++++++++ packages/sgml/error.h | 1 + 6 files changed, 123 insertions(+), 44 deletions(-) diff --git a/include/SWI-Prolog.h b/include/SWI-Prolog.h index 3d5a7ca72..db212ae97 100644 --- a/include/SWI-Prolog.h +++ b/include/SWI-Prolog.h @@ -292,8 +292,6 @@ typedef struct foreign_context *control_t; #define PL_fail return FALSE /* fail */ #define PL_succeed return TRUE /* success */ -extern X_API void PL_free(void *); - extern X_API PL_agc_hook_t PL_agc_hook(PL_agc_hook_t); extern X_API char* PL_atom_chars(atom_t); extern X_API term_t PL_copy_term_ref(term_t); @@ -427,6 +425,7 @@ extern X_API void PL_erase(record_t); extern X_API int PL_action(int,...); extern X_API void *PL_malloc(int); extern X_API void PL_free(void *); +extern X_API int PL_eval_expression_to_int_64_ex(term_t t, int64_t *val); #define PL_register_foreign(name, arity, function, flags) PL_register_foreign_in_module(NULL, (name), (arity), (function), (flags)) @@ -467,46 +466,6 @@ extern X_API const char *PL_cwd(void); void swi_install(void); -#define ERR_NO_ERROR 0 -#define ERR_INSTANTIATION 1 /* void */ -#define ERR_TYPE 2 /* atom_t expected, term_t value */ -#define ERR_DOMAIN 3 /* atom_t domain, term_t value */ -#define ERR_REPRESENTATION 4 /* atom_t what */ -#define ERR_MODIFY_STATIC_PROC 5 /* predicate_t proc */ -#define ERR_EVALUATION 6 /* atom_t what */ -#define ERR_AR_TYPE 7 /* atom_t expected, Number value */ -#define ERR_NOT_EVALUABLE 8 /* functor_t func */ -#define ERR_DIV_BY_ZERO 9 /* void */ -#define ERR_FAILED 10 /* predicate_t proc */ -#define ERR_FILE_OPERATION 11 /* atom_t action, atom_t type, term_t */ -#define ERR_PERMISSION 12 /* atom_t type, atom_t op, term_t obj*/ -#define ERR_NOT_IMPLEMENTED 13 /* const char *what */ -#define ERR_EXISTENCE 14 /* atom_t type, term_t obj */ -#define ERR_STREAM_OP 15 /* atom_t action, term_t obj */ -#define ERR_RESOURCE 16 /* atom_t resource */ -#define ERR_NOMEM 17 /* void */ -#define ERR_SYSCALL 18 /* void */ -#define ERR_SHELL_FAILED 19 /* term_t command */ -#define ERR_SHELL_SIGNALLED 20 /* term_t command, int signal */ -#define ERR_AR_UNDEF 21 /* void */ -#define ERR_AR_OVERFLOW 22 /* void */ -#define ERR_AR_UNDERFLOW 23 /* void */ -#define ERR_UNDEFINED_PROC 24 /* Definition def */ -#define ERR_SIGNALLED 25 /* int sig, char *name */ -#define ERR_CLOSED_STREAM 26 /* IOSTREAM * */ -#define ERR_BUSY 27 /* mutexes */ -#define ERR_PERMISSION_PROC 28 /* op, type, Definition */ -#define ERR_DDE_OP 29 /* op, error */ -#define ERR_SYNTAX 30 /* what */ -#define ERR_SHARED_OBJECT_OP 31 /* op, error */ -#define ERR_TIMEOUT 32 /* op, object */ -#define ERR_NOT_IMPLEMENTED_PROC 33 /* name, arity */ -#define ERR_FORMAT 34 /* message */ -#define ERR_FORMAT_ARG 35 /* seq, term */ -#define ERR_OCCURS_CHECK 36 /* Word, Word */ -#define ERR_CHARS_TYPE 37 /* char *, term */ -#define ERR_MUST_BE_VAR 38 /* int argn, term_t term */ - X_API int PL_error(const char *pred, int arity, const char *msg, int id, ...); diff --git a/library/yap2swi/yap2swi.c b/library/yap2swi/yap2swi.c index 88919f80a..12ea73b0f 100644 --- a/library/yap2swi/yap2swi.c +++ b/library/yap2swi/yap2swi.c @@ -19,6 +19,7 @@ #include #include +#include #if HAVE_MATH_H #include @@ -425,7 +426,7 @@ X_API int PL_get_wchars(term_t l, size_t *len, wchar_t **wsp, unsigned flags) YAP: YAP_Functor YAP_FunctorOfTerm(Term) */ X_API int PL_get_functor(term_t ts, functor_t *f) { - YAP_Term t = Yap_GetFromSlot(ts); + Term t = Yap_GetFromSlot(ts); if ( IsAtomTerm(t)) { *f = t; } else { @@ -916,6 +917,46 @@ X_API int PL_raise_exception(term_t exception) #define FUNCTOR_timeout_error2 FunctorToSWIFunctor(FunctorTimeoutError) #define FUNCTOR_type_error2 FunctorToSWIFunctor(FunctorTypeError) +#define ERR_NO_ERROR 0 +#define ERR_INSTANTIATION 1 /* void */ +#define ERR_TYPE 2 /* atom_t expected, term_t value */ +#define ERR_DOMAIN 3 /* atom_t domain, term_t value */ +#define ERR_REPRESENTATION 4 /* atom_t what */ +#define ERR_MODIFY_STATIC_PROC 5 /* predicate_t proc */ +#define ERR_EVALUATION 6 /* atom_t what */ +#define ERR_AR_TYPE 7 /* atom_t expected, Number value */ +#define ERR_NOT_EVALUABLE 8 /* functor_t func */ +#define ERR_DIV_BY_ZERO 9 /* void */ +#define ERR_FAILED 10 /* predicate_t proc */ +#define ERR_FILE_OPERATION 11 /* atom_t action, atom_t type, term_t */ +#define ERR_PERMISSION 12 /* atom_t type, atom_t op, term_t obj*/ +#define ERR_NOT_IMPLEMENTED 13 /* const char *what */ +#define ERR_EXISTENCE 14 /* atom_t type, term_t obj */ +#define ERR_STREAM_OP 15 /* atom_t action, term_t obj */ +#define ERR_RESOURCE 16 /* atom_t resource */ +#define ERR_NOMEM 17 /* void */ +#define ERR_SYSCALL 18 /* void */ +#define ERR_SHELL_FAILED 19 /* term_t command */ +#define ERR_SHELL_SIGNALLED 20 /* term_t command, int signal */ +#define ERR_AR_UNDEF 21 /* void */ +#define ERR_AR_OVERFLOW 22 /* void */ +#define ERR_AR_UNDERFLOW 23 /* void */ +#define ERR_UNDEFINED_PROC 24 /* Definition def */ +#define ERR_SIGNALLED 25 /* int sig, char *name */ +#define ERR_CLOSED_STREAM 26 /* IOSTREAM * */ +#define ERR_BUSY 27 /* mutexes */ +#define ERR_PERMISSION_PROC 28 /* op, type, Definition */ +#define ERR_DDE_OP 29 /* op, error */ +#define ERR_SYNTAX 30 /* what */ +#define ERR_SHARED_OBJECT_OP 31 /* op, error */ +#define ERR_TIMEOUT 32 /* op, object */ +#define ERR_NOT_IMPLEMENTED_PROC 33 /* name, arity */ +#define ERR_FORMAT 34 /* message */ +#define ERR_FORMAT_ARG 35 /* seq, term */ +#define ERR_OCCURS_CHECK 36 /* Word, Word */ +#define ERR_CHARS_TYPE 37 /* char *, term */ +#define ERR_MUST_BE_VAR 38 /* int argn, term_t term */ + X_API int PL_error(const char *pred, int arity, const char *msg, int id, ...) { term_t formal, swi, predterm, msgterm, except; @@ -2127,6 +2168,32 @@ PL_free(void *obj) return YAP_FreeSpaceFromYap(obj); } +X_API int +PL_eval_expression_to_int_64_ex(term_t t, int64_t *val) +{ + Term res = Yap_Eval(Yap_GetFromSlot(t)); + if (!res) { + return FALSE; + } + if (IsIntegerTerm(res)) { + *val = IntegerOfTerm(res); + return TRUE; + } else if (YAP_IsBigNumTerm(res)) { + MP_INT g; + char s[64]; + + YAP_BigNumOfTerm(t, (void *)&g); + if (mpz_sizeinbase(&g,2) > 64) { + return PL_error(NULL,0,NULL, ERR_EVALUATION, AtomToSWIAtom(Yap_LookupAtom("int_overflow"))); + } + mpz_get_str (s, 10, &g); + sscanf(s, "%lld", (long long int *)val); + return 1; + } + PL_error(NULL,0,NULL, ERR_TYPE, AtomToSWIAtom(Yap_LookupAtom("integer_expression"))); + return FALSE; +} + static int SWI_ctime(void) diff --git a/packages/PLStream/pl-incl.h b/packages/PLStream/pl-incl.h index 31303ffe5..9b36f78f8 100644 --- a/packages/PLStream/pl-incl.h +++ b/packages/PLStream/pl-incl.h @@ -509,7 +509,6 @@ extern bool readLine(IOSTREAM *in, IOSTREAM *out, char *buffer); extern bool tellString(char **s, size_t *size, IOENC enc); extern bool tellString(char **s, size_t *size, IOENC enc); extern bool toldString(void); -ssize_t Sread_user(void *handle, char *buf, size_t size); extern int setupOutputRedirect(term_t to, redir_context *ctx, int redir); extern void discardOutputRedirect(redir_context *ctx); @@ -577,6 +576,10 @@ extern atom_t lookupUCSAtom(const pl_wchar_t *s, size_t len); extern int toIntegerNumber(Number n, int flags); extern int get_atom_ptr_text(Atom a, PL_chars_t *text); +/* empty stub */ +void setPrologFlag(const char *name, int flags, ...); +void PL_set_prolog_flag(const char *name, int flags, ...); + static inline word setBoolean(int *flag, term_t old, term_t new) { if ( !PL_unify_bool_ex(old, *flag) || diff --git a/packages/PLStream/pl-yap.c b/packages/PLStream/pl-yap.c index 4025d0557..76ba0d5cc 100644 --- a/packages/PLStream/pl-yap.c +++ b/packages/PLStream/pl-yap.c @@ -544,4 +544,13 @@ ok: } +void +setPrologFlag(const char *name, int flags, ...) +{ +} + +void +PL_set_prolog_flag(const char *name, int flags, ...) +{ +} diff --git a/packages/PLStream/pl-yap.h b/packages/PLStream/pl-yap.h index 22cf6f627..148f0d6cb 100644 --- a/packages/PLStream/pl-yap.h +++ b/packages/PLStream/pl-yap.h @@ -198,4 +198,44 @@ stripostfix(const char *s, const char *e) } #endif +#define ERR_NO_ERROR 0 +#define ERR_INSTANTIATION 1 /* void */ +#define ERR_TYPE 2 /* atom_t expected, term_t value */ +#define ERR_DOMAIN 3 /* atom_t domain, term_t value */ +#define ERR_REPRESENTATION 4 /* atom_t what */ +#define ERR_MODIFY_STATIC_PROC 5 /* predicate_t proc */ +#define ERR_EVALUATION 6 /* atom_t what */ +#define ERR_AR_TYPE 7 /* atom_t expected, Number value */ +#define ERR_NOT_EVALUABLE 8 /* functor_t func */ +#define ERR_DIV_BY_ZERO 9 /* void */ +#define ERR_FAILED 10 /* predicate_t proc */ +#define ERR_FILE_OPERATION 11 /* atom_t action, atom_t type, term_t */ +#define ERR_PERMISSION 12 /* atom_t type, atom_t op, term_t obj*/ +#define ERR_NOT_IMPLEMENTED 13 /* const char *what */ +#define ERR_EXISTENCE 14 /* atom_t type, term_t obj */ +#define ERR_STREAM_OP 15 /* atom_t action, term_t obj */ +#define ERR_RESOURCE 16 /* atom_t resource */ +#define ERR_NOMEM 17 /* void */ +#define ERR_SYSCALL 18 /* void */ +#define ERR_SHELL_FAILED 19 /* term_t command */ +#define ERR_SHELL_SIGNALLED 20 /* term_t command, int signal */ +#define ERR_AR_UNDEF 21 /* void */ +#define ERR_AR_OVERFLOW 22 /* void */ +#define ERR_AR_UNDERFLOW 23 /* void */ +#define ERR_UNDEFINED_PROC 24 /* Definition def */ +#define ERR_SIGNALLED 25 /* int sig, char *name */ +#define ERR_CLOSED_STREAM 26 /* IOSTREAM * */ +#define ERR_BUSY 27 /* mutexes */ +#define ERR_PERMISSION_PROC 28 /* op, type, Definition */ +#define ERR_DDE_OP 29 /* op, error */ +#define ERR_SYNTAX 30 /* what */ +#define ERR_SHARED_OBJECT_OP 31 /* op, error */ +#define ERR_TIMEOUT 32 /* op, object */ +#define ERR_NOT_IMPLEMENTED_PROC 33 /* name, arity */ +#define ERR_FORMAT 34 /* message */ +#define ERR_FORMAT_ARG 35 /* seq, term */ +#define ERR_OCCURS_CHECK 36 /* Word, Word */ +#define ERR_CHARS_TYPE 37 /* char *, term */ +#define ERR_MUST_BE_VAR 38 /* int argn, term_t term */ + #endif /* PL_YAP_H */ diff --git a/packages/sgml/error.h b/packages/sgml/error.h index e3c2d23f9..d691f6ee0 100644 --- a/packages/sgml/error.h +++ b/packages/sgml/error.h @@ -44,3 +44,4 @@ typedef enum int sgml2pl_error(plerrorid, ...); #endif /*H_ERROR_INCLUDED*/ +