ICU-6149 Use traditional ICU C callback declarations.

X-SVN-Rev: 23481
This commit is contained in:
George Rhoten 2008-02-25 21:21:47 +00:00
parent c905bdfa76
commit fe7e42eace
4 changed files with 113 additions and 111 deletions

View File

@ -1207,7 +1207,7 @@ int32_t RegexMatcher::getStackLimit() const {
// setMatchCallback // setMatchCallback
// //
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
void RegexMatcher::setMatchCallback(URegexMatchCallback callback, void RegexMatcher::setMatchCallback(URegexMatchCallback *callback,
const void *context, const void *context,
UErrorCode &status) { UErrorCode &status) {
if (U_FAILURE(status)) { if (U_FAILURE(status)) {
@ -1223,7 +1223,7 @@ void RegexMatcher::setMatchCallback(URegexMatchCallback callback,
// getMatchCallback // getMatchCallback
// //
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
void RegexMatcher::getMatchCallback(URegexMatchCallback &callback, void RegexMatcher::getMatchCallback(URegexMatchCallback *&callback,
const void *&context, const void *&context,
UErrorCode &status) { UErrorCode &status) {
if (U_FAILURE(status)) { if (U_FAILURE(status)) {

View File

@ -1080,7 +1080,7 @@ public:
* @param status A reference to a UErrorCode to receive any errors. * @param status A reference to a UErrorCode to receive any errors.
* @draft ICU 4.0 * @draft ICU 4.0
*/ */
virtual void setMatchCallback(URegexMatchCallback callback, virtual void setMatchCallback(URegexMatchCallback *callback,
const void *context, const void *context,
UErrorCode &status); UErrorCode &status);
@ -1096,7 +1096,7 @@ public:
* @param status A reference to a UErrorCode to receive any errors. * @param status A reference to a UErrorCode to receive any errors.
* @draft ICU 4.0 * @draft ICU 4.0
*/ */
virtual void getMatchCallback(URegexMatchCallback &callback, virtual void getMatchCallback(URegexMatchCallback *&callback,
const void *&context, const void *&context,
UErrorCode &status); UErrorCode &status);
@ -1213,7 +1213,7 @@ private:
int32_t fStackLimit; // Maximum memory size to use for the backtrack int32_t fStackLimit; // Maximum memory size to use for the backtrack
// stack, in bytes. Zero for unlimited. // stack, in bytes. Zero for unlimited.
URegexMatchCallback fCallbackFn; // Pointer to match progress callback funct. URegexMatchCallback *fCallbackFn; // Pointer to match progress callback funct.
// NULL if there is no callback. // NULL if there is no callback.
const void *fCallbackContext; // User Context ptr for callback function. const void *fCallbackContext; // User Context ptr for callback function.

View File

@ -844,140 +844,142 @@ uregex_split( URegularExpression *regexp,
/** /**
* Set a processing time limit for match operations with this URegularExpression. * Set a processing time limit for match operations with this URegularExpression.
* *
* Some patterns, when matching certain strings, can run in exponential time. * Some patterns, when matching certain strings, can run in exponential time.
* For practical purposes, the match operation may appear to be in an * For practical purposes, the match operation may appear to be in an
* infinite loop. * infinite loop.
* When a limit is set a match operation will fail with an error if the * When a limit is set a match operation will fail with an error if the
* limit is exceeded. * limit is exceeded.
* <p> * <p>
* The units of the limit are steps of the match engine. * The units of the limit are steps of the match engine.
* Correspondence with actual processor time will depend on the speed * Correspondence with actual processor time will depend on the speed
* of the processor and the details of the specific pattern, but will * of the processor and the details of the specific pattern, but will
* typically be on the order of milliseconds. * typically be on the order of milliseconds.
* <p> * <p>
* By default, the matching time is not limited. * By default, the matching time is not limited.
* <p> * <p>
* *
* @param regexp The compiled regular expression. * @param regexp The compiled regular expression.
* @param limit The limit value, or 0 for no limit. * @param limit The limit value, or 0 for no limit.
* @param status A reference to a UErrorCode to receive any errors. * @param status A reference to a UErrorCode to receive any errors.
* @draft ICU 4.0 * @draft ICU 4.0
*/ */
U_DRAFT void U_EXPORT2 U_DRAFT void U_EXPORT2
uregex_setTimeLimit(URegularExpression *regexp, uregex_setTimeLimit(URegularExpression *regexp,
int32_t limit, int32_t limit,
UErrorCode *status); UErrorCode *status);
/** /**
* Get the time limit for for matches with this URegularExpression. * Get the time limit for for matches with this URegularExpression.
* A return value of zero indicates that there is no limit. * A return value of zero indicates that there is no limit.
* *
* @param regexp The compiled regular expression. * @param regexp The compiled regular expression.
* @param status A reference to a UErrorCode to receive any errors. * @param status A reference to a UErrorCode to receive any errors.
* @return the maximum allowed time for a match, in units of processing steps. * @return the maximum allowed time for a match, in units of processing steps.
* @draft ICU 4.0 * @draft ICU 4.0
*/ */
U_DRAFT int32_t U_EXPORT2 U_DRAFT int32_t U_EXPORT2
uregex_getTimeLimit(const URegularExpression *regexp, uregex_getTimeLimit(const URegularExpression *regexp,
UErrorCode *status); UErrorCode *status);
/** /**
* Set the amount of heap storage avaliable for use by the match backtracking stack. * Set the amount of heap storage avaliable for use by the match backtracking stack.
* <p> * <p>
* ICU uses a backtracking regular expression engine, with the backtrack stack * ICU uses a backtracking regular expression engine, with the backtrack stack
* maintained on the heap. This function sets the limit to the amount of memory * maintained on the heap. This function sets the limit to the amount of memory
* that can be used for this purpose. A backtracking stack overflow will * that can be used for this purpose. A backtracking stack overflow will
* result in an error from the match operation that caused it. * result in an error from the match operation that caused it.
* <p> * <p>
* A limit is desirable because a malicious or poorly designed pattern can use * A limit is desirable because a malicious or poorly designed pattern can use
* excessive memory, potentially crashing the process. A limit is enabled * excessive memory, potentially crashing the process. A limit is enabled
* by default. * by default.
* <p> * <p>
* @param regexp The compiled regular expression. * @param regexp The compiled regular expression.
* @param limit The maximum size, in bytes, of the matching backtrack stack. * @param limit The maximum size, in bytes, of the matching backtrack stack.
* A value of -1 means no limit. * A value of -1 means no limit.
* The limit must be greater than zero, or -1. * The limit must be greater than zero, or -1.
* @param status A reference to a UErrorCode to receive any errors. * @param status A reference to a UErrorCode to receive any errors.
* *
* @draft ICU 4.0 * @draft ICU 4.0
*/ */
U_DRAFT void U_EXPORT2 U_DRAFT void U_EXPORT2
uregex_setStackLimit(URegularExpression *regexp, uregex_setStackLimit(URegularExpression *regexp,
int32_t limit, int32_t limit,
UErrorCode *status); UErrorCode *status);
/** /**
* Get the size of the heap storage available for use by the back tracking stack. * Get the size of the heap storage available for use by the back tracking stack.
* *
* @return the maximum backtracking stack size, in bytes, or zero if the * @return the maximum backtracking stack size, in bytes, or zero if the
* stack size is unlimited. * stack size is unlimited.
* @draft ICU 4.0 * @draft ICU 4.0
*/ */
U_DRAFT int32_t U_EXPORT2 U_DRAFT int32_t U_EXPORT2
uregex_getStackLimit(const URegularExpression *regexp, uregex_getStackLimit(const URegularExpression *regexp,
UErrorCode *status); UErrorCode *status);
/** /**
* Function pointer for a regular expression matching callback function. * Function pointer for a regular expression matching callback function.
* When set, a callback function will be called periodically during matching * When set, a callback function will be called periodically during matching
* operations. If the call back function returns FALSE, the matching * operations. If the call back function returns FALSE, the matching
* operation will be terminated early. * operation will be terminated early.
* *
* Note: the callback function must not call other functions on this * Note: the callback function must not call other functions on this
* URegularExpression. * URegularExpression.
* *
* @param context context pointer. The callback function will be invoked * @param context context pointer. The callback function will be invoked
* with the context specified at the time that * with the context specified at the time that
* uregex_setMatchCallback() is called. * uregex_setMatchCallback() is called.
* @param steps the accumulated processing time, in match steps, * @param steps the accumulated processing time, in match steps,
* for this matching operation. * for this matching operation.
* @return TRUE to continue the matching operation. * @return TRUE to continue the matching operation.
* FALSE to terminate the matching operation. * FALSE to terminate the matching operation.
* @draft ICU 4.0 * @draft ICU 4.0
*/ */
typedef UBool (U_EXPORT2 *URegexMatchCallback) ( U_CDECL_BEGIN
typedef UBool U_CALLCONV URegexMatchCallback (
const void *context, const void *context,
int32_t steps); int32_t steps);
U_CDECL_END
/** /**
* Set a callback function for this URegularExpression. * Set a callback function for this URegularExpression.
* During matching operations the function will be called periodically, * During matching operations the function will be called periodically,
* giving the application the opportunity to terminate a long-running * giving the application the opportunity to terminate a long-running
* match. * match.
* *
* @param regexp The compiled regular expression. * @param regexp The compiled regular expression.
* @param callback A pointer to the user-supplied callback function. * @param callback A pointer to the user-supplied callback function.
* @param context User context pointer. The value supplied at the * @param context User context pointer. The value supplied at the
* time the callback function is set will be saved * time the callback function is set will be saved
* and passed to the callback each time that it is called. * and passed to the callback each time that it is called.
* @param status A reference to a UErrorCode to receive any errors. * @param status A reference to a UErrorCode to receive any errors.
* @draft ICU 4.0 * @draft ICU 4.0
*/ */
U_DRAFT void U_EXPORT2 U_DRAFT void U_EXPORT2
uregex_setMatchCallback(URegularExpression *regexp, uregex_setMatchCallback(URegularExpression *regexp,
URegexMatchCallback callback, URegexMatchCallback *callback,
const void *context, const void *context,
UErrorCode *status); UErrorCode *status);
/** /**
* Get the callback function for this URegularExpression. * Get the callback function for this URegularExpression.
* *
* @param regexp The compiled regular expression. * @param regexp The compiled regular expression.
* @param callback Out paramater, receives a pointer to the user-supplied * @param callback Out paramater, receives a pointer to the user-supplied
* callback function. * callback function.
* @param context Out parameter, receives the user context pointer that * @param context Out parameter, receives the user context pointer that
* was set when uregex_setMatchCallback() was called. * was set when uregex_setMatchCallback() was called.
* @param status A reference to a UErrorCode to receive any errors. * @param status A reference to a UErrorCode to receive any errors.
* @draft ICU 4.0 * @draft ICU 4.0
*/ */
U_DRAFT void U_EXPORT2 U_DRAFT void U_EXPORT2
uregex_getMatchCallback(const URegularExpression *regexp, uregex_getMatchCallback(const URegularExpression *regexp,
URegexMatchCallback *callback, URegexMatchCallback **callback,
const void **context, const void **context,
UErrorCode *status); UErrorCode *status);

View File

@ -2420,7 +2420,7 @@ void RegexTest::Callbacks() {
// The variables that the getter will fill in. // The variables that the getter will fill in.
// Init to non-null values so that the action of the getter can be seen. // Init to non-null values so that the action of the getter can be seen.
const void *returnedContext = &returnedContext; const void *returnedContext = &returnedContext;
URegexMatchCallback returnedFn = &testCallBackFn; URegexMatchCallback *returnedFn = &testCallBackFn;
UErrorCode status = U_ZERO_ERROR; UErrorCode status = U_ZERO_ERROR;
RegexMatcher matcher("x", 0, status); RegexMatcher matcher("x", 0, status);
@ -2435,7 +2435,7 @@ void RegexTest::Callbacks() {
// Set and Get work // Set and Get work
callBackContext cbInfo = {this, 0, 0, 0}; callBackContext cbInfo = {this, 0, 0, 0};
const void *returnedContext; const void *returnedContext;
URegexMatchCallback returnedFn; URegexMatchCallback *returnedFn;
UErrorCode status = U_ZERO_ERROR; UErrorCode status = U_ZERO_ERROR;
RegexMatcher matcher("((.)+\\2)+x", 0, status); // A pattern that can run long. RegexMatcher matcher("((.)+\\2)+x", 0, status); // A pattern that can run long.
REGEX_CHECK_STATUS; REGEX_CHECK_STATUS;
@ -2443,7 +2443,7 @@ void RegexTest::Callbacks() {
REGEX_CHECK_STATUS; REGEX_CHECK_STATUS;
matcher.getMatchCallback(returnedFn, returnedContext, status); matcher.getMatchCallback(returnedFn, returnedContext, status);
REGEX_CHECK_STATUS; REGEX_CHECK_STATUS;
REGEX_ASSERT(returnedFn == &testCallBackFn); REGEX_ASSERT(returnedFn == testCallBackFn);
REGEX_ASSERT(returnedContext == &cbInfo); REGEX_ASSERT(returnedContext == &cbInfo);
// A short-running match shouldn't invoke the callback // A short-running match shouldn't invoke the callback