Skip to content

Commit 4f7efdf

Browse files
committed
inc: New TRE (regex) binding
Besides updating binding for a more up-to-date TRE version, this also fixes an issue where regex.bi used the libtre API/ABI but linked to glibc's implementation of the reg*() functions, which are not ABI-compatible, which caused the TRE examples to crash on Linux. The new binding avoids this issue by using libtre's tre_reg*() functions - thanks to the tre_* prefix, there is no collision with glibc's plain functions anymore. In fact it seems like libtre doesn't expose plain functions itself anymore, but only ones with the tre_* prefix, so I think the old binding couldn't even have worked anymore on Win32 with the latest libtre version.
1 parent f5b1815 commit 4f7efdf

File tree

4 files changed

+178
-117
lines changed

4 files changed

+178
-117
lines changed

Diff for: changelog.txt

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Version 1.02.0
2424
GNU libiconv 1.14
2525
fontconfig 2.11.1
2626
Allegro 5.0.11
27+
TRE 0.8.0 as tre/tre.bi and tre/regex.bi. For backwards-compatibility, the "plain" regex.bi still exists, but now just redirects to tre/regex.bi.
2728

2829
[fixed]
2930
- Potential bad code generation for dynamic array field copying

Diff for: inc/regex.bi

+1-117
Original file line numberDiff line numberDiff line change
@@ -1,117 +1 @@
1-
''
2-
''
3-
'' regex -- POSIX.2 compatible regexp interface and TRE extensions
4-
'' (header translated with help of SWIG FB wrapper)
5-
''
6-
'' NOTICE: This file is part of the FreeBASIC Compiler package and can't
7-
'' be included in other distributions without authorization.
8-
''
9-
''
10-
#ifndef __regex_bi__
11-
#define __regex_bi__
12-
13-
#inclib "tre"
14-
15-
type regoff_t as integer
16-
17-
type regex_t
18-
re_nsub as integer
19-
value as any ptr
20-
end type
21-
22-
type regmatch_t
23-
rm_so as regoff_t
24-
rm_eo as regoff_t
25-
end type
26-
27-
enum reg_errcode_t
28-
REG_OK = 0
29-
REG_NOMATCH
30-
REG_BADPAT
31-
REG_ECOLLATE
32-
REG_ECTYPE
33-
REG_EESCAPE
34-
REG_ESUBREG
35-
REG_EBRACK
36-
REG_EPAREN
37-
REG_EBRACE
38-
REG_BADBR
39-
REG_ERANGE
40-
REG_ESPACE
41-
REG_BADRPT
42-
end enum
43-
44-
#define REG_EXTENDED 1
45-
#define REG_ICASE (REG_EXTENDED shl 1)
46-
#define REG_NEWLINE (REG_ICASE shl 1)
47-
#define REG_NOSUB (REG_NEWLINE shl 1)
48-
#define REG_BASIC 0
49-
#define REG_LITERAL (REG_NOSUB shl 1)
50-
#define REG_RIGHT_ASSOC (REG_LITERAL shl 1)
51-
#define REG_NOTBOL 1
52-
#define REG_NOTEOL (REG_NOTBOL shl 1)
53-
#define REG_APPROX_MATCHER (REG_NOTEOL shl 1)
54-
#define REG_BACKTRACKING_MATCHER (REG_APPROX_MATCHER shl 1)
55-
#ifdef REG_LITERAL
56-
# define REG_NOSPEC REG_LITERAL
57-
#elseif defined(REG_NOSPEC)
58-
# define REG_LITERAL REG_NOSPEC
59-
#endif
60-
#define RE_DUP_MAX 255
61-
62-
declare function regcomp cdecl alias "regcomp" (byval preg as regex_t ptr, byval regex as zstring ptr, byval cflags as integer) as integer
63-
declare function regexec cdecl alias "regexec" (byval preg as regex_t ptr, byval string as zstring ptr, byval nmatch as integer, byval pmatch as regmatch_t ptr, byval eflags as integer) as integer
64-
declare function regerror cdecl alias "regerror" (byval errcode as integer, byval preg as regex_t ptr, byval errbuf as zstring ptr, byval errbuf_size as integer) as integer
65-
declare sub regfree cdecl alias "regfree" (byval preg as regex_t ptr)
66-
declare function regncomp cdecl alias "regncomp" (byval preg as regex_t ptr, byval regex as zstring ptr, byval len as integer, byval cflags as integer) as integer
67-
declare function regnexec cdecl alias "regnexec" (byval preg as regex_t ptr, byval string as zstring ptr, byval len as integer, byval nmatch as integer, byval pmatch as regmatch_t ptr, byval eflags as integer) as integer
68-
69-
type regaparams_t
70-
cost_ins as integer
71-
cost_del as integer
72-
cost_subst as integer
73-
max_cost as integer
74-
max_ins as integer
75-
max_del as integer
76-
max_subst as integer
77-
max_err as integer
78-
end type
79-
80-
type regamatch_t
81-
nmatch as integer
82-
pmatch as regmatch_t ptr
83-
cost as integer
84-
num_ins as integer
85-
num_del as integer
86-
num_subst as integer
87-
end type
88-
89-
declare function regaexec cdecl alias "regaexec" (byval preg as regex_t ptr, byval string as zstring ptr, byval match as regamatch_t ptr, byval params as regaparams_t, byval eflags as integer) as integer
90-
declare function reganexec cdecl alias "reganexec" (byval preg as regex_t ptr, byval string as zstring ptr, byval len as integer, byval match as regamatch_t ptr, byval params as regaparams_t, byval eflags as integer) as integer
91-
declare sub regaparams_default cdecl alias "regaparams_default" (byval params as regaparams_t ptr)
92-
93-
type tre_char_t as ubyte
94-
95-
type tre_str_source
96-
get_next_char as function cdecl(byval as tre_char_t ptr, byval as uinteger ptr, byval as any ptr) as integer
97-
rewind as sub cdecl(byval as integer, byval as any ptr)
98-
compare as function cdecl(byval as integer, byval as integer, byval as integer, byval as any ptr) as integer
99-
context as any ptr
100-
end type
101-
102-
declare function reguexec cdecl alias "reguexec" (byval preg as regex_t ptr, byval string as tre_str_source ptr, byval nmatch as integer, byval pmatch as regmatch_t ptr, byval eflags as integer) as integer
103-
declare function tre_version cdecl alias "tre_version" () as zstring ptr
104-
declare function tre_config cdecl alias "tre_config" (byval query as integer, byval result as any ptr) as integer
105-
106-
enum
107-
TRE_CONFIG_APPROX
108-
TRE_CONFIG_WCHAR
109-
TRE_CONFIG_MULTIBYTE
110-
TRE_CONFIG_SYSTEM_ABI
111-
TRE_CONFIG_VERSION
112-
end enum
113-
114-
declare function tre_have_backrefs cdecl alias "tre_have_backrefs" (byval preg as regex_t ptr) as integer
115-
declare function tre_have_approx cdecl alias "tre_have_approx" (byval preg as regex_t ptr) as integer
116-
117-
#endif
1+
#include once "tre/regex.bi"

Diff for: inc/tre/regex.bi

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#pragma once
2+
3+
#include once "tre.bi"
4+
5+
const TRE_REGEX_H = 1
6+
7+
#ifndef TRE_USE_SYSTEM_REGEX_H
8+
#define regcomp tre_regcomp
9+
#define regerror tre_regerror
10+
#define regexec tre_regexec
11+
#define regfree tre_regfree
12+
#endif
13+
14+
#define regacomp tre_regacomp
15+
#define regaexec tre_regaexec
16+
#define regancomp tre_regancomp
17+
#define reganexec tre_reganexec
18+
#define regawncomp tre_regawncomp
19+
#define regawnexec tre_regawnexec
20+
#define regncomp tre_regncomp
21+
#define regnexec tre_regnexec
22+
#define regwcomp tre_regwcomp
23+
#define regwexec tre_regwexec
24+
#define regwncomp tre_regwncomp
25+
#define regwnexec tre_regwnexec

Diff for: inc/tre/tre.bi

+151
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
#pragma once
2+
3+
#inclib "tre"
4+
5+
#include once "crt/sys/types.bi"
6+
7+
#ifdef TRE_USE_SYSTEM_REGEX_H
8+
#include once "crt/regex.bi"
9+
#endif
10+
11+
#include once "crt/wchar.bi"
12+
13+
extern "C"
14+
15+
const TRE_H = 1
16+
17+
#ifdef TRE_USE_SYSTEM_REGEX_H
18+
#define tre_regcomp regcomp
19+
#define tre_regexec regexec
20+
#define tre_regerror regerror
21+
#define tre_regfree regfree
22+
const REG_OK = 0
23+
type reg_errcode_t as long
24+
const REG_LITERAL = &h1000
25+
#else
26+
type regoff_t as long
27+
28+
type regex_t
29+
re_nsub as uinteger
30+
value as any ptr
31+
end type
32+
33+
type regmatch_t
34+
rm_so as regoff_t
35+
rm_eo as regoff_t
36+
end type
37+
38+
type reg_errcode_t as long
39+
enum
40+
REG_OK = 0
41+
REG_NOMATCH
42+
REG_BADPAT
43+
REG_ECOLLATE
44+
REG_ECTYPE
45+
REG_EESCAPE
46+
REG_ESUBREG
47+
REG_EBRACK
48+
REG_EPAREN
49+
REG_EBRACE
50+
REG_BADBR
51+
REG_ERANGE
52+
REG_ESPACE
53+
REG_BADRPT
54+
end enum
55+
56+
const REG_EXTENDED = 1
57+
#define REG_ICASE (REG_EXTENDED shl 1)
58+
#define REG_NEWLINE (REG_ICASE shl 1)
59+
#define REG_NOSUB (REG_NEWLINE shl 1)
60+
#endif
61+
62+
const REG_BASIC = 0
63+
64+
#ifndef TRE_USE_SYSTEM_REGEX_H
65+
#define REG_LITERAL (REG_NOSUB shl 1)
66+
#endif
67+
68+
#define REG_RIGHT_ASSOC (REG_LITERAL shl 1)
69+
#define REG_UNGREEDY (REG_RIGHT_ASSOC shl 1)
70+
71+
#ifdef TRE_USE_SYSTEM_REGEX_H
72+
const REG_APPROX_MATCHER = &h1000
73+
#else
74+
const REG_NOTBOL = 1
75+
#define REG_NOTEOL (REG_NOTBOL shl 1)
76+
#define REG_APPROX_MATCHER (REG_NOTEOL shl 1)
77+
#endif
78+
79+
#define REG_BACKTRACKING_MATCHER (REG_APPROX_MATCHER shl 1)
80+
#define REG_NOSPEC REG_LITERAL
81+
const RE_DUP_MAX = 255
82+
83+
#ifdef TRE_USE_SYSTEM_REGEX_H
84+
declare function regcomp(byval preg as regex_t ptr, byval regex as const zstring ptr, byval cflags as long) as long
85+
declare function regexec(byval preg as const regex_t ptr, byval string as const zstring ptr, byval nmatch as uinteger, byval pmatch as regmatch_t ptr, byval eflags as long) as long
86+
declare function regerror(byval errcode as long, byval preg as const regex_t ptr, byval errbuf as zstring ptr, byval errbuf_size as uinteger) as uinteger
87+
declare sub regfree(byval preg as regex_t ptr)
88+
#else
89+
declare function tre_regcomp(byval preg as regex_t ptr, byval regex as const zstring ptr, byval cflags as long) as long
90+
declare function tre_regexec(byval preg as const regex_t ptr, byval string as const zstring ptr, byval nmatch as uinteger, byval pmatch as regmatch_t ptr, byval eflags as long) as long
91+
declare function tre_regerror(byval errcode as long, byval preg as const regex_t ptr, byval errbuf as zstring ptr, byval errbuf_size as uinteger) as uinteger
92+
declare sub tre_regfree(byval preg as regex_t ptr)
93+
#endif
94+
95+
declare function tre_regwcomp(byval preg as regex_t ptr, byval regex as const wstring ptr, byval cflags as long) as long
96+
declare function tre_regwexec(byval preg as const regex_t ptr, byval string as const wstring ptr, byval nmatch as uinteger, byval pmatch as regmatch_t ptr, byval eflags as long) as long
97+
declare function tre_regncomp(byval preg as regex_t ptr, byval regex as const zstring ptr, byval len as uinteger, byval cflags as long) as long
98+
declare function tre_regnexec(byval preg as const regex_t ptr, byval string as const zstring ptr, byval len as uinteger, byval nmatch as uinteger, byval pmatch as regmatch_t ptr, byval eflags as long) as long
99+
declare function tre_regwncomp(byval preg as regex_t ptr, byval regex as const wstring ptr, byval len as uinteger, byval cflags as long) as long
100+
declare function tre_regwnexec(byval preg as const regex_t ptr, byval string as const wstring ptr, byval len as uinteger, byval nmatch as uinteger, byval pmatch as regmatch_t ptr, byval eflags as long) as long
101+
102+
type regaparams_t
103+
cost_ins as long
104+
cost_del as long
105+
cost_subst as long
106+
max_cost as long
107+
max_ins as long
108+
max_del as long
109+
max_subst as long
110+
max_err as long
111+
end type
112+
113+
type regamatch_t
114+
nmatch as uinteger
115+
pmatch as regmatch_t ptr
116+
cost as long
117+
num_ins as long
118+
num_del as long
119+
num_subst as long
120+
end type
121+
122+
declare function tre_regaexec(byval preg as const regex_t ptr, byval string as const zstring ptr, byval match as regamatch_t ptr, byval params as regaparams_t, byval eflags as long) as long
123+
declare function tre_reganexec(byval preg as const regex_t ptr, byval string as const zstring ptr, byval len as uinteger, byval match as regamatch_t ptr, byval params as regaparams_t, byval eflags as long) as long
124+
declare function tre_regawexec(byval preg as const regex_t ptr, byval string as const wstring ptr, byval match as regamatch_t ptr, byval params as regaparams_t, byval eflags as long) as long
125+
declare function tre_regawnexec(byval preg as const regex_t ptr, byval string as const wstring ptr, byval len as uinteger, byval match as regamatch_t ptr, byval params as regaparams_t, byval eflags as long) as long
126+
declare sub tre_regaparams_default(byval params as regaparams_t ptr)
127+
type tre_char_t as wstring
128+
129+
type tre_str_source
130+
get_next_char as function(byval c as wstring ptr, byval pos_add as ulong ptr, byval context as any ptr) as long
131+
rewind as sub(byval pos as uinteger, byval context as any ptr)
132+
compare as function(byval pos1 as uinteger, byval pos2 as uinteger, byval len as uinteger, byval context as any ptr) as long
133+
context as any ptr
134+
end type
135+
136+
declare function tre_reguexec(byval preg as const regex_t ptr, byval string as const tre_str_source ptr, byval nmatch as uinteger, byval pmatch as regmatch_t ptr, byval eflags as long) as long
137+
declare function tre_version() as zstring ptr
138+
declare function tre_config(byval query as long, byval result as any ptr) as long
139+
140+
enum
141+
TRE_CONFIG_APPROX
142+
TRE_CONFIG_WCHAR
143+
TRE_CONFIG_MULTIBYTE
144+
TRE_CONFIG_SYSTEM_ABI
145+
TRE_CONFIG_VERSION
146+
end enum
147+
148+
declare function tre_have_backrefs(byval preg as const regex_t ptr) as long
149+
declare function tre_have_approx(byval preg as const regex_t ptr) as long
150+
151+
end extern

0 commit comments

Comments
 (0)