File: sv_regex_global_pos.c.inc

package info (click to toggle)
libterm-termkey-perl 0.19-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 232 kB
  • sloc: perl: 370; makefile: 5
file content (42 lines) | stat: -rw-r--r-- 1,206 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/* vi: set ft=c : */

#ifndef SV_POSBYTES

/* any value will do; it's just for our own purposes */
#define SV_POSBYTES (1<<0)

/* Before perl 5.41.10, the only way to access the regex global `pos` position
 * was direct interaction with the PERL_MAGIC_regex_global magic's mg_len
 * field.
 */

#define sv_regex_global_pos_get(sv, posp, flags)  S_sv_regex_global_pos_get(aTHX_ sv, posp, flags)
static bool S_sv_regex_global_pos_get(pTHX_ SV *sv, STRLEN *posp, U32 flags)
{
  /* TODO: This implementation only supports SV_POSBYTES, not zero flags */
  assert(flags & SV_POSBYTES);

  if(SvTYPE(sv) < SVt_PVMG || !SvMAGIC(sv))
    return FALSE;

  MAGIC *mg = mg_find(sv, PERL_MAGIC_regex_global);
  if(!mg || mg->mg_len == (STRLEN)-1)
    return FALSE;

  *posp = mg->mg_len;
  return TRUE;
}

#define sv_regex_global_pos_set(sv, pos, flags)  S_sv_regex_global_pos_set(aTHX_ sv, pos, flags)
static void S_sv_regex_global_pos_set(pTHX_ SV *sv, STRLEN pos, U32 flags)
{
  assert(flags & SV_POSBYTES);

  MAGIC *mg = SvTYPE(sv) >= SVt_PVMG ? mg_find(sv, PERL_MAGIC_regex_global) : NULL;
  if(!mg)
    mg = sv_magicext(sv, NULL, PERL_MAGIC_regex_global, &PL_vtbl_mglob, NULL, 0);

  mg->mg_len = pos;
}

#endif