[pcre-dev] PCRE 7.6 Threading suggestion

Αρχική Σελίδα
Delete this message
Συντάκτης: Ted
Ημερομηνία:  
Προς: pcre-dev
Αντικείμενο: [pcre-dev] PCRE 7.6 Threading suggestion
One of the programs I am involved in beta testing for makes use of an older
version of the PCRE. The particular app is multithreaded and allows the
user to abort commands that aren't running right. This is occasionally a
problem when the command is running a bad regex supplied by a user. I took
it upon myself to build a dll of the most current PCRE (7.6) and thought it
would be a really good idea to add an abort into the matching code.

Being a Windows programmer I have no clue about Unix or even a more general
way to do this, but I thought I would suggest the idea to you and also
supply you with the code and way in which I did it. There are actually 2
aborts, one is done by a global variable that causes all usage of match to
abort. The other is a global variable that is compared against Windows
message queue and creates a thread specific abort.

In pcre.h add 2 lines for the additional functions
PCRE_EXP_DECL pcre_extra *pcre_study(const pcre *, int, const char **);
PCRE_EXP_DECL const char *pcre_version(void);
PCRE_EXP_DECL void RegisterAbortMSG(unsigned int msg);
PCRE_EXP_DECL void SetGlobalAbort(char Abort);

#ifdef __cplusplus
-------------
In pcre_exec 2 groups of changes:
add include for header that defines internal functions and global variable
#include "pcre_internal.h"
#include "abort.h"

/* Undefine some potentially clashing cpp symbols */
-------------
add line for checking in function match
complicated macro. It has to be used in one particular way. This shouldn't,
however, impact performance when true recursion is being used. */

if (GlobalAbort || CheckAbort()) RRETURN(PCRE_ERROR_ABORTED);

#ifdef SUPPORT_UTF8
utf8 = md->utf8;       /* Local copy of the flag */
-------------
Contents of abort.h
#include <windows.h>
extern int CheckAbort(void);
extern char GlobalAbort;
-------------
Contents of abort .c
UINT AbortMsg=0;
char GlobalAbort=0;


DLLIMPORT void RegisterAbortMSG(unsigned int msg) {
AbortMsg=msg;
}

DLLIMPORT void SetGlobalAbort(char Abort) {
GlobalAbort=Abort;
}

int CheckAbort(void) {
if (AbortMsg) {
MSG msg;
if (PeekMessage(&msg,NULL,AbortMsg,AbortMsg,PM_NOREMOVE)) return 1;
return 0;
} else return 0;
}
-------------

If you need any more details on the Windows specific code let me know.
Ted