From 175b00797c9d688ce5c9a9ccf3da424dfeb8a1e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Lindqvist?= Date: Fri, 29 Nov 2013 15:52:30 +0100 Subject: [PATCH] pcre: pcre-config throws bad-option on error --- extra/pcre/ffi/ffi.factor | 29 +---------------------------- extra/pcre/pcre-tests.factor | 18 +++++++++++++----- extra/pcre/pcre.factor | 14 +++++--------- 3 files changed, 19 insertions(+), 42 deletions(-) diff --git a/extra/pcre/ffi/ffi.factor b/extra/pcre/ffi/ffi.factor index 772486373b..8a7882479d 100644 --- a/extra/pcre/ffi/ffi.factor +++ b/extra/pcre/ffi/ffi.factor @@ -75,33 +75,6 @@ ENUM: PCRE_ERRORS { PCRE_ERROR_BADOFFSET -24 } { PCRE_ERROR_SHORTUTF8 -25 } ; -CONSTANT: PCRE_ERROR_NOMATCH -1 -CONSTANT: PCRE_ERROR_NULL -2 -CONSTANT: PCRE_ERROR_BADOPTION -3 -CONSTANT: PCRE_ERROR_BADMAGIC -4 -CONSTANT: PCRE_ERROR_UNKNOWN_OPCODE -5 -CONSTANT: PCRE_ERROR_UNKNOWN_NODE -5 -CONSTANT: PCRE_ERROR_NOMEMORY -6 -CONSTANT: PCRE_ERROR_NOSUBSTRING -7 -CONSTANT: PCRE_ERROR_MATCHLIMIT -8 -CONSTANT: PCRE_ERROR_CALLOUT -9 -CONSTANT: PCRE_ERROR_BADUTF8 -10 -CONSTANT: PCRE_ERROR_BADUTF8_OFFSET -11 -CONSTANT: PCRE_ERROR_PARTIAL -12 -CONSTANT: PCRE_ERROR_BADPARTIAL -13 -CONSTANT: PCRE_ERROR_INTERNAL -14 -CONSTANT: PCRE_ERROR_BADCOUNT -15 -CONSTANT: PCRE_ERROR_DFA_UITEM -16 -CONSTANT: PCRE_ERROR_DFA_UCOND -17 -CONSTANT: PCRE_ERROR_DFA_UMLIMIT -18 -CONSTANT: PCRE_ERROR_DFA_WSSIZE -19 -CONSTANT: PCRE_ERROR_DFA_RECURSE -20 -CONSTANT: PCRE_ERROR_RECURSIONLIMIT -21 -CONSTANT: PCRE_ERROR_NULLWSLIMIT -22 -CONSTANT: PCRE_ERROR_BADNEWLINE -23 -CONSTANT: PCRE_ERROR_BADOFFSET -24 -CONSTANT: PCRE_ERROR_SHORTUTF8 -25 - CONSTANT: PCRE_INFO_OPTIONS 0 CONSTANT: PCRE_INFO_SIZE 1 CONSTANT: PCRE_INFO_CAPTURECOUNT 2 @@ -144,7 +117,7 @@ STRUCT: pcre_extra { mark uchar** } { executable_jit void* } ; -FUNCTION: void pcre_config ( int what, void* where ) ; +FUNCTION: int pcre_config ( int what, void* where ) ; FUNCTION: void* pcre_compile ( c-string pattern, int options, diff --git a/extra/pcre/pcre-tests.factor b/extra/pcre/pcre-tests.factor index fc0a56483f..96cd03cbe7 100644 --- a/extra/pcre/pcre-tests.factor +++ b/extra/pcre/pcre-tests.factor @@ -1,5 +1,6 @@ -USING: accessors arrays assocs http.client kernel math.ranges -pcre pcre.ffi pcre.private random sequences system tools.test ; +USING: accessors arrays assocs continuations http.client kernel +literals math.ranges pcre pcre.ffi pcre.private random sequences +system tools.test ; QUALIFIED: regexp IN: pcre.tests @@ -34,9 +35,16 @@ os unix? [ [ 10 ] [ PCRE_CONFIG_NEWLINE pcre-config ] unit-test ] when [ 1 ] [ PCRE_CONFIG_UNICODE_PROPERTIES pcre-config ] unit-test -! libpcre must not support 16 or 32 bit code points. -[ 0 ] [ PCRE_CONFIG_UTF16 pcre-config ] unit-test -[ 0 ] [ PCRE_CONFIG_UTF32 pcre-config ] unit-test +! Ok if these options throw if the pcre library is to old to support +! these configuration parameters. +[ t ] [ + [ PCRE_CONFIG_UTF16 pcre-config ] [ what>> ] recover + { 0 $ PCRE_CONFIG_UTF16 } member? +] unit-test +[ t ] [ + [ PCRE_CONFIG_UTF32 pcre-config ] [ what>> ] recover + { 0 $ PCRE_CONFIG_UTF32 } member? +] unit-test ! Tests for findall [ diff --git a/extra/pcre/pcre.factor b/extra/pcre/pcre.factor index 461f03ddda..585ab4743e 100644 --- a/extra/pcre/pcre.factor +++ b/extra/pcre/pcre.factor @@ -8,6 +8,8 @@ math.bitwise pcre.ffi sequences splitting strings ; QUALIFIED: regexp IN: pcre +ERROR: bad-option what ; + ERROR: malformed-regexp expr error ; ERROR: pcre-error value ; @@ -32,14 +34,8 @@ ERROR: pcre-error value ; ] [ 2drop f ] if* ; : pcre-config ( what -- value ) - dup { - PCRE_CONFIG_MATCH_LIMIT - PCRE_CONFIG_MATCH_LIMIT_RECURSION - } member? [ - { long } [ pcre_config ] with-out-parameters - ] [ - { int } [ pcre_config ] with-out-parameters - ] if dup PCRE_ERROR_BADOPTION = [ pcre-error ] when ; + [ { long } [ pcre_config ] with-out-parameters ] keep + rot 0 = [ drop ] [ bad-option ] if ; : pcre-fullinfo ( pcre extra what -- obj ) { int } [ pcre_fullinfo ] with-out-parameters nip ; @@ -59,7 +55,7 @@ ERROR: pcre-error value ; : name-table-entry ( addr -- group-index group-name ) [ 1 alien-unsigned-1 ] - [ 2 + utf8 alien>string ] bi ; + [ 2 + utf8 alien>string ] bi ; : name-table-entries ( pcre extra -- addrs ) [ name-table ] [ name-entry-size ] [ name-count ] 2tri