Skip to content

Commit d3770d3

Browse files
committedApr 10, 2023
Resync qtermwidget with version 1.2.0
1 parent bf97c4a commit d3770d3

File tree

129 files changed

+13290
-4027
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+13290
-4027
lines changed
 

‎src/plugins/grass/qtermwidget/BlockArray.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,10 @@
2727
#include "BlockArray.h"
2828

2929
// System
30-
#include <assert.h>
3130
#include <sys/mman.h>
3231
#include <sys/param.h>
3332
#include <unistd.h>
34-
#include <stdio.h>
33+
#include <cstdio>
3534

3635

3736
using namespace Konsole;
@@ -42,9 +41,9 @@ BlockArray::BlockArray()
4241
: size(0),
4342
current(size_t(-1)),
4443
index(size_t(-1)),
45-
lastmap(0),
44+
lastmap(nullptr),
4645
lastmap_index(size_t(-1)),
47-
lastblock(0), ion(-1),
46+
lastblock(nullptr), ion(-1),
4847
length(0)
4948
{
5049
// lastmap_index = index = current = size_t(-1);
@@ -57,7 +56,7 @@ BlockArray::BlockArray()
5756
BlockArray::~BlockArray()
5857
{
5958
setHistorySize(0);
60-
assert(!lastblock);
59+
Q_ASSERT(!lastblock);
6160
}
6261

6362
size_t BlockArray::append(Block * block)
@@ -139,7 +138,7 @@ const Block * BlockArray::at(size_t i)
139138

140139
if (i > index) {
141140
qDebug() << "BlockArray::at() i > index\n";
142-
return 0;
141+
return nullptr;
143142
}
144143

145144
// if (index - i >= length) {
@@ -149,14 +148,14 @@ const Block * BlockArray::at(size_t i)
149148

150149
size_t j = i; // (current - (index - i) + (index/size+1)*size) % size ;
151150

152-
assert(j < size);
151+
Q_ASSERT(j < size);
153152
unmap();
154153

155-
Block * block = (Block *)mmap(0, blocksize, PROT_READ, MAP_PRIVATE, ion, j * blocksize);
154+
Block * block = (Block *)mmap(nullptr, blocksize, PROT_READ, MAP_PRIVATE, ion, j * blocksize);
156155

157156
if (block == (Block *)-1) {
158157
perror("mmap");
159-
return 0;
158+
return nullptr;
160159
}
161160

162161
lastmap = block;
@@ -173,7 +172,7 @@ void BlockArray::unmap()
173172
perror("munmap");
174173
}
175174
}
176-
lastmap = 0;
175+
lastmap = nullptr;
177176
lastmap_index = size_t(-1);
178177
}
179178

@@ -194,7 +193,7 @@ bool BlockArray::setHistorySize(size_t newsize)
194193

195194
if (!newsize) {
196195
delete lastblock;
197-
lastblock = 0;
196+
lastblock = nullptr;
198197
if (ion >= 0) {
199198
close(ion);
200199
}
@@ -218,7 +217,7 @@ bool BlockArray::setHistorySize(size_t newsize)
218217
return false;
219218
}
220219

221-
assert(!lastblock);
220+
Q_ASSERT(!lastblock);
222221

223222
lastblock = new Block();
224223
size = newsize;
@@ -231,7 +230,7 @@ bool BlockArray::setHistorySize(size_t newsize)
231230
return false;
232231
} else {
233232
decreaseBuffer(newsize);
234-
(void) ftruncate(ion, length*blocksize);
233+
ftruncate(ion, length*blocksize);
235234
size = newsize;
236235

237236
return true;
@@ -272,7 +271,7 @@ void BlockArray::decreaseBuffer(size_t newsize)
272271
return;
273272
}
274273

275-
// The Block constructor could do somthing in future...
274+
// The Block constructor could do something in future...
276275
char * buffer1 = new char[blocksize];
277276

278277
FILE * fion = fdopen(dup(ion), "w+b");
@@ -320,7 +319,7 @@ void BlockArray::increaseBuffer()
320319
return;
321320
}
322321

323-
// The Block constructor could do somthing in future...
322+
// The Block constructor could do something in future...
324323
char * buffer1 = new char[blocksize];
325324
char * buffer2 = new char[blocksize];
326325

‎src/plugins/grass/qtermwidget/BlockArray.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,20 @@
2727

2828
//#error Do not use in KDE 2.1
2929

30-
#define BlockSize (1 << 12)
31-
#define ENTRIES ((BlockSize - sizeof(size_t) ))
30+
#define QTERMWIDGET_BLOCKSIZE (1 << 12)
31+
#define ENTRIES ((QTERMWIDGET_BLOCKSIZE - sizeof(size_t) ) / sizeof(unsigned char))
3232

3333
namespace Konsole {
3434

3535
struct Block {
36-
unsigned char data[ENTRIES] = {};
37-
size_t size = 0;
36+
Block() {
37+
size = 0;
38+
}
39+
unsigned char data[ENTRIES];
40+
size_t size;
3841
};
3942

43+
// ///////////////////////////////////////////////////////
4044

4145
class BlockArray {
4246
public:
@@ -55,7 +59,7 @@ class BlockArray {
5559
* adds the Block at the end of history.
5660
* This may drop other blocks.
5761
*
58-
* The ownership on the block is transfered.
62+
* The ownership on the block is transferred.
5963
* An unique index number is returned for accessing
6064
* it later (if not yet dropped then)
6165
*
@@ -69,7 +73,7 @@ class BlockArray {
6973
* 0 if the block isn't available any more.
7074
*
7175
* The returned block is strictly readonly as only
72-
* maped in memory - and will be invalid on the next
76+
* mapped in memory - and will be invalid on the next
7377
* operation on this class.
7478
*/
7579
const Block * at(size_t index);

0 commit comments

Comments
 (0)
Please sign in to comment.