• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tarantool / luajit / 8062004225

27 Feb 2024 08:41AM UTC coverage: 92.591% (-0.007%) from 92.598%
8062004225

push

github

Buristan
test: enable CLI-related lua-Harness tests back

Tarantool supports -b and -j options to use LuaJIT modules since the
commit bf8b76a4d ("lua: proxy -j and -b
flags"), so 241-standalone.t and 411-luajit.t tests in the lua-Harness
suite, disabled in the commit 39a4db500
("test: support Tarantool in lua-Harness"), can be enabled back.

However, the -O option is still not implemented in Tarantool, so the
related part in the 411-luajit.t test chunk is still disabled.

Follows up tarantool/tarantool#5541

Reviewed-by: Maxim Kokryashkin <m.kokryashkin@tarantool.org>
Reviewed-by: Sergey Kaplun <skaplun@tarantool.org>
Signed-off-by: Sergey Kaplun <skaplun@tarantool.org>
(cherry picked from commit e316cbf0d)

5657 of 6016 branches covered (94.03%)

Branch coverage included in aggregate %.

21588 of 23409 relevant lines covered (92.22%)

2817149.02 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

76.62
/src/lj_wbuf.c
1
/*
2
** Low-level writer for LuaJIT.
3
**
4
** Major portions taken verbatim or adapted from the LuaVela.
5
** Copyright (C) 2015-2019 IPONWEB Ltd.
6
*/
7

8
#define lj_wbuf_c
9
#define LUA_CORE
10

11
#include <errno.h>
12

13
#include "lj_obj.h"
14
#include "lj_wbuf.h"
15
#include "lj_utils.h"
16

17
static LJ_AINLINE void wbuf_set_flag(struct lj_wbuf *buf, uint8_t flag)
×
18
{
19
  buf->flags |= flag;
×
20
}
21

22
static LJ_AINLINE void wbuf_save_errno(struct lj_wbuf *buf)
×
23
{
24
  buf->saved_errno = errno;
×
25
}
×
26

27
static LJ_AINLINE size_t wbuf_len(const struct lj_wbuf *buf)
1,843,883✔
28
{
29
  return (size_t)(buf->pos - buf->buf);
1,843,883✔
30
}
31

32
static LJ_AINLINE size_t wbuf_left(const struct lj_wbuf *buf)
1,843,869✔
33
{
34
  return buf->size - wbuf_len(buf);
1,843,869✔
35
}
36

37
void lj_wbuf_init(struct lj_wbuf *buf, lj_wbuf_writer writer,
28✔
38
                  void *ctx, uint8_t *mem, size_t size)
39
{
40
  buf->ctx = ctx;
28✔
41
  buf->writer = writer;
28✔
42
  buf->buf = mem;
28✔
43
  buf->pos = mem;
28✔
44
  buf->size = size;
28✔
45
  buf->flags = 0;
28✔
46
  buf->saved_errno = 0;
28✔
47
}
14✔
48

49
void LJ_FASTCALL lj_wbuf_terminate(struct lj_wbuf *buf)
14✔
50
{
51
  lj_wbuf_init(buf, NULL, NULL, NULL, 0);
14✔
52
}
14✔
53

54
static LJ_AINLINE void wbuf_reserve(struct lj_wbuf *buf, size_t n)
1,843,869✔
55
{
56
  lj_assertX(n <= buf->size, "wbuf overflow");
1,843,869✔
57
  if (LJ_UNLIKELY(wbuf_left(buf) < n))
1,843,869✔
58
    lj_wbuf_flush(buf);
×
59
}
60

61
/* Writes a byte to the output buffer. */
62
void LJ_FASTCALL lj_wbuf_addbyte(struct lj_wbuf *buf, uint8_t b)
461,524✔
63
{
64
  if (LJ_UNLIKELY(lj_wbuf_test_flag(buf, STREAM_STOP)))
461,524✔
65
    return;
66
  wbuf_reserve(buf, sizeof(b));
461,524✔
67
  *buf->pos++ = b;
461,524✔
68
}
69

70
/* Writes an unsigned integer which is at most 64 bits long to the output. */
71
void LJ_FASTCALL lj_wbuf_addu64(struct lj_wbuf *buf, uint64_t n)
924,687✔
72
{
73
  if (LJ_UNLIKELY(lj_wbuf_test_flag(buf, STREAM_STOP)))
924,687✔
74
    return;
75
  wbuf_reserve(buf, LEB128_U64_MAXSIZE);
924,687✔
76
  buf->pos += (ptrdiff_t)lj_utils_write_uleb128(buf->pos, n);
924,687✔
77
}
78

79
/* Writes n bytes from an arbitrary buffer src to the buffer. */
80
void lj_wbuf_addn(struct lj_wbuf *buf, const void *src, size_t n)
457,658✔
81
{
82
  if (LJ_UNLIKELY(lj_wbuf_test_flag(buf, STREAM_STOP)))
457,658✔
83
    return;
84
  /*
85
  ** Very unlikely: We are told to write a large buffer at once.
86
  ** Buffer doesn't belong to us so we must to pump data
87
  ** through the buffer.
88
  */
89
  while (LJ_UNLIKELY(n > buf->size)) {
457,658✔
90
    const size_t left = wbuf_left(buf);
×
91
    memcpy(buf->pos, src, left);
×
92
    buf->pos += (ptrdiff_t)left;
×
93
    lj_wbuf_flush(buf);
×
94
    src = (uint8_t *)src + (ptrdiff_t)left;
×
95
    n -= left;
×
96
  }
97

98
  wbuf_reserve(buf, n);
457,658✔
99
  memcpy(buf->pos, src, n);
457,658✔
100
  buf->pos += (ptrdiff_t)n;
457,658✔
101
}
102

103
/* Writes a \0-terminated C string to the output buffer. */
104
void LJ_FASTCALL lj_wbuf_addstring(struct lj_wbuf *buf, const char *s)
457,630✔
105
{
106
  const size_t l = strlen(s);
457,630✔
107

108
  /* Check that profiling is still active is made in the callee's scope. */
109
  lj_wbuf_addu64(buf, (uint64_t)l);
457,630✔
110
  lj_wbuf_addn(buf, s, l);
457,630✔
111
}
457,630✔
112

113
void LJ_FASTCALL lj_wbuf_flush(struct lj_wbuf *buf)
14✔
114
{
115
  const size_t len = wbuf_len(buf);
14✔
116
  size_t written;
14✔
117

118
  if (LJ_UNLIKELY(lj_wbuf_test_flag(buf, STREAM_STOP)))
14✔
119
    return;
120

121
  written = buf->writer((const void **)&buf->buf, len, buf->ctx);
14✔
122

123
  if (LJ_UNLIKELY(written < len)) {
14✔
124
    wbuf_set_flag(buf, STREAM_ERRIO);
×
125
    wbuf_save_errno(buf);
×
126
  }
127
  if (LJ_UNLIKELY(buf->buf == NULL)) {
14✔
128
    wbuf_set_flag(buf, STREAM_STOP);
×
129
    wbuf_save_errno(buf);
×
130
  }
131
  buf->pos = buf->buf;
14✔
132
}
133

134
int LJ_FASTCALL lj_wbuf_test_flag(const struct lj_wbuf *buf, uint8_t flag)
1,847,523✔
135
{
136
  return buf->flags & flag;
1,843,883✔
137
}
138

139
int LJ_FASTCALL lj_wbuf_errno(const struct lj_wbuf *buf)
×
140
{
141
  return buf->saved_errno;
×
142
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc