MCPcopy Create free account
hub / github.com/apache/httpd / get_match_data

Function get_match_data

server/util_pcre.c:332–381  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

330#endif
331
332static match_data_pt get_match_data(apr_size_t size,
333 match_vector_pt small_vector,
334 int *to_free)
335{
336 apr_thread_t *current;
337 struct apreg_tls *tls = NULL;
338
339 /* Even though AP_HAS_THREAD_LOCAL, we may still be called by a
340 * native/non-apr thread, let's fall back to alloc/free in this case.
341 */
342 current = ap_thread_current();
343 if (!current) {
344 *to_free = 1;
345 return alloc_match_data(size, small_vector);
346 }
347
348 apr_thread_data_get((void **)&tls, "apreg", current);
349 if (!tls || tls->size < size) {
350 apr_pool_t *tp = apr_thread_pool_get(current);
351 if (!tls) {
352 tls = apr_pcalloc(tp, sizeof(*tls));
353#ifdef HAVE_PCRE2
354 apr_thread_data_set(tls, "apreg", apreg_tls_cleanup, current);
355#else
356 apr_thread_data_set(tls, "apreg", NULL, current);
357#endif
358 }
359
360 tls->size *= 2;
361 if (tls->size < size) {
362 tls->size = size;
363 if (tls->size < POSIX_MALLOC_THRESHOLD) {
364 tls->size = POSIX_MALLOC_THRESHOLD;
365 }
366 }
367
368#ifdef HAVE_PCRE2
369 pcre2_match_data_free(tls->data); /* NULL safe */
370 tls->data = pcre2_match_data_create(tls->size, NULL);
371 if (!tls->data) {
372 tls->size = 0;
373 return NULL;
374 }
375#else
376 tls->data = apr_palloc(tp, tls->size * sizeof(int) * 3);
377#endif
378 }
379
380 return tls->data;
381}
382
383#else /* AP_HAS_THREAD_LOCAL && !defined(APREG_NO_THREAD_LOCAL) */
384

Callers 1

ap_regexec_lenFunction · 0.85

Calls 2

ap_thread_currentFunction · 0.85
alloc_match_dataFunction · 0.85

Tested by

no test coverage detected