Merge branch 'omega-hotfix' into omega-dev

This commit is contained in:
Quentin
2020-04-16 14:24:47 +02:00
335 changed files with 2114 additions and 1706 deletions

View File

@@ -3,6 +3,7 @@
#include "script.h"
#include "variable_box_controller.h"
#include <apps/i18n.h>
#include <algorithm>
#include <assert.h>
#include <escher/metric.h>
#include <poincare/preferences.h>
@@ -16,8 +17,6 @@ extern "C" {
namespace Code {
static inline int minInt(int x, int y) { return x < y ? x : y; }
static const char * sStandardPromptText = ">>> ";
ConsoleController::ConsoleController(Responder * parentResponder, App * pythonDelegate, ScriptStore * scriptStore
@@ -488,7 +487,7 @@ void ConsoleController::autoImportScript(Script script, bool force) {
/* Copy the script name without the extension ".py". The '.' is overwritten
* by the null terminating char. */
int copySizeWithNullTerminatingZero = minInt(k_maxImportCommandSize - currentChar, strlen(scriptName) - strlen(ScriptStore::k_scriptExtension));
int copySizeWithNullTerminatingZero = std::min(k_maxImportCommandSize - currentChar, strlen(scriptName) - strlen(ScriptStore::k_scriptExtension));
assert(copySizeWithNullTerminatingZero >= 0);
assert(copySizeWithNullTerminatingZero <= k_maxImportCommandSize - currentChar);
strlcpy(command+currentChar, scriptName, copySizeWithNullTerminatingZero);

View File

@@ -4,11 +4,10 @@
#include <apps/i18n.h>
#include <apps/global_preferences.h>
#include <assert.h>
#include <algorithm>
namespace Code {
static inline int minInt(int x, int y) { return x < y ? x : y; }
ConsoleEditCell::ConsoleEditCell(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, TextFieldDelegate * delegate) :
HighlightCell(),
Responder(parentResponder),
@@ -70,7 +69,7 @@ const char * ConsoleEditCell::shiftCurrentTextAndClear() {
char * textFieldBuffer = const_cast<char *>(m_textField.text());
char * newTextPosition = textFieldBuffer + 1;
assert(previousBufferSize > 0);
size_t copyLength = minInt(previousBufferSize - 1, strlen(textFieldBuffer));
size_t copyLength = std::min(previousBufferSize - 1, strlen(textFieldBuffer));
memmove(newTextPosition, textFieldBuffer, copyLength);
newTextPosition[copyLength] = 0;
textFieldBuffer[0] = 0;

View File

@@ -1,10 +1,9 @@
#include "console_store.h"
#include <string.h>
#include <algorithm>
namespace Code {
static inline int minInt(int x, int y) { return x < y ? x : y; }
void ConsoleStore::startNewSession() {
if (k_historySize < 1) {
return;
@@ -12,7 +11,7 @@ void ConsoleStore::startNewSession() {
m_history[0] = makePrevious(m_history[0]);
for (int i = 0; i < k_historySize - 1; i++) {
for (size_t i = 0; i < k_historySize - 1; i++) {
if (m_history[i] == 0) {
if (m_history[i+1] == 0) {
return ;
@@ -25,7 +24,7 @@ void ConsoleStore::startNewSession() {
ConsoleLine ConsoleStore::lineAtIndex(int i) const {
assert(i >= 0 && i < numberOfLines());
int currentLineIndex = 0;
for (int j=0; j<k_historySize; j++) {
for (size_t j=0; j<k_historySize; j++) {
if (m_history[j] == 0) {
currentLineIndex++;
j++;
@@ -43,7 +42,7 @@ int ConsoleStore::numberOfLines() const {
return 0;
}
int result = 0;
for (int i = 0; i < k_historySize - 1; i++) {
for (size_t i = 0; i < k_historySize - 1; i++) {
if (m_history[i] == 0) {
result++;
if (m_history[i+1] == 0) {
@@ -96,14 +95,14 @@ const char * ConsoleStore::push(const char marker, const char * text) {
if (ConsoleLine::sizeOfConsoleLine(textLength) > k_historySize - 1) {
textLength = k_historySize - 1 - 1 - 1; // Marker, null termination and null marker.
}
int i = indexOfNullMarker();
size_t i = indexOfNullMarker();
// If needed, make room for the text we want to push.
while (i + ConsoleLine::sizeOfConsoleLine(textLength) > k_historySize - 1) {
deleteFirstLine();
i = indexOfNullMarker();
}
m_history[i] = marker;
strlcpy(&m_history[i+1], text, minInt(k_historySize-(i+1),textLength+1));
strlcpy(&m_history[i+1], text, std::min(k_historySize-(i+1),textLength+1));
m_history[i+1+textLength+1] = 0;
return &m_history[i+1];
}
@@ -113,11 +112,11 @@ ConsoleLine::Type ConsoleStore::lineTypeForMarker(char marker) const {
return static_cast<ConsoleLine::Type>(marker-1);
}
int ConsoleStore::indexOfNullMarker() const {
size_t ConsoleStore::indexOfNullMarker() const {
if (m_history[0] == 0) {
return 0;
}
for (int i=0; i<k_historySize; i++) {
for (size_t i=0; i<k_historySize; i++) {
if (m_history[i] == 0 && m_history[i+1] == 0) {
return (i+1);
}
@@ -129,13 +128,13 @@ int ConsoleStore::indexOfNullMarker() const {
void ConsoleStore::deleteLineAtIndex(int index) {
assert(index >=0 && index < numberOfLines());
int currentLineIndex = 0;
for (int i = 0; i < k_historySize - 1; i++) {
for (size_t i = 0; i < k_historySize - 1; i++) {
if (m_history[i] == 0) {
currentLineIndex++;
continue;
}
if (currentLineIndex == index) {
int nextLineStart = i;
size_t nextLineStart = i;
while (m_history[nextLineStart] != 0 && nextLineStart < k_historySize - 2) {
nextLineStart++;
}
@@ -158,7 +157,7 @@ void ConsoleStore::deleteFirstLine() {
secondLineMarkerIndex++;
}
secondLineMarkerIndex++;
for (int i=0; i<k_historySize - secondLineMarkerIndex; i++) {
for (size_t i=0; i<k_historySize - secondLineMarkerIndex; i++) {
m_history[i] = m_history[secondLineMarkerIndex+i];
}
}
@@ -174,7 +173,7 @@ void ConsoleStore::deleteLastLine() {
}
int currentLineIndex = 1;
int lastLineMarkerIndex = 0;
for (int i=0; i<k_historySize; i++) {
for (size_t i=0; i<k_historySize; i++) {
if (m_history[i] == 0) {
currentLineIndex++;
if (currentLineIndex == lineCount) {

View File

@@ -23,7 +23,7 @@ private:
static constexpr char CurrentSessionResultMarker = 0x02;
static constexpr char PreviousSessionCommandMarker = 0x03;
static constexpr char PreviousSessionResultMarker = 0x04;
static constexpr int k_historySize = 1024;
static constexpr size_t k_historySize = 1024;
static char makePrevious(char marker) {
if (marker == CurrentSessionCommandMarker || marker == CurrentSessionResultMarker) {
return marker + 0x02;
@@ -32,7 +32,7 @@ private:
}
const char * push(const char marker, const char * text);
ConsoleLine::Type lineTypeForMarker(char marker) const;
int indexOfNullMarker() const;
size_t indexOfNullMarker() const;
void deleteLineAtIndex(int index);
void deleteFirstLine();
/* When there is no room left to store a new ConsoleLine, we have to delete

View File

@@ -9,6 +9,7 @@ extern "C" {
#include "py/lexer.h"
}
#include <stdlib.h>
#include <algorithm>
namespace Code {
@@ -21,8 +22,6 @@ constexpr KDColor StringColor = Palette::CodeString;
constexpr KDColor BackgroundColor = Palette::CodeBackground;
constexpr KDColor HighlightColor = Palette::CodeBackgroundSelected;
static inline const char * minPointer(const char * x, const char * y) { return x < y ? x : y; }
static inline KDColor TokenColor(mp_token_kind_t tokenKind) {
if (tokenKind == MP_TOKEN_STRING) {
return StringColor;
@@ -84,7 +83,7 @@ void PythonTextArea::ContentView::drawLine(KDContext * ctx, int line, const char
line,
fromColumn,
lineStart,
minPointer(text + byteLength, lineEnd) - lineStart,
std::min(text + byteLength, lineEnd) - lineStart,
StringColor,
BackgroundColor,
selectionStart,
@@ -107,7 +106,7 @@ void PythonTextArea::ContentView::drawLine(KDContext * ctx, int line, const char
line,
fromColumn,
spacesStart,
minPointer(text + byteLength, firstNonSpace) - spacesStart,
std::min(text + byteLength, firstNonSpace) - spacesStart,
StringColor,
BackgroundColor,
selectionStart,
@@ -135,7 +134,7 @@ void PythonTextArea::ContentView::drawLine(KDContext * ctx, int line, const char
line,
UTF8Helper::GlyphOffsetAtCodePoint(text, tokenEnd),
tokenEnd,
minPointer(text + byteLength, tokenFrom) - tokenEnd,
std::min(text + byteLength, tokenFrom) - tokenEnd,
StringColor,
BackgroundColor,
selectionStart,