fix queue overpop

This commit is contained in:
lyon 2022-01-26 08:38:02 +08:00
parent 76075564a2
commit 797607bccf
3 changed files with 33 additions and 29 deletions

View File

@ -21,7 +21,7 @@
// "--gtest_filter=parser.__set__",
// "--gtest_filter=parser.__get__",
// "--gtest_filter=pikaMain.print_with_enter",
"--gtest_filter=pikaMain.str_fun",
// "--gtest_filter=pikaMain.str_fun",
// "--gtest_filter=pikaMain.str_add",
// "--gtest_filter=content*",
// "--gtest_filter=pikaMain.print_in_def",

View File

@ -532,33 +532,33 @@ TEST(pikaMain, for_in_dict) {
}
// TEST(pikaMain, str_add) {
// /* init */
// pikaMemInfo.heapUsedMax = 0;
// PikaObj* pikaMain = newRootObj((char*)"pikaMain", New_PikaMain);
// /* run */
// obj_run(pikaMain, (char*)
// "a = 'a'\n"
// "b = 'b'\n"
// "c = a + b\n"
// "d = 1\n"
// "e = 1.2\n"
// "g = c + str(d)\n"
// "h = c + str(d) + str(e)\n"
// "\n"
// );
// /* collect */
// char* c = obj_getStr(pikaMain, (char*)"c");
// char* g = obj_getStr(pikaMain, (char*)"g");
// char* h = obj_getStr(pikaMain, (char*)"h");
// /* assert */
// EXPECT_STREQ(c, (char*)"ab");
// EXPECT_STREQ(g, (char*)"ab1");
// EXPECT_STREQ(h, (char*)"ab11.200000");
// /* deinit */
// obj_deinit(pikaMain);
// EXPECT_EQ(pikaMemNow(), 0);
// }
TEST(pikaMain, str_add) {
/* init */
pikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj((char*)"pikaMain", New_PikaMain);
/* run */
obj_run(pikaMain, (char*)
"a = 'a'\n"
"b = 'b'\n"
"c = a + b\n"
"d = 1\n"
"e = 1.2\n"
"g = c + str(d)\n"
"h = c + str(d) + str(e)\n"
"\n"
);
/* collect */
char* c = obj_getStr(pikaMain, (char*)"c");
char* g = obj_getStr(pikaMain, (char*)"g");
char* h = obj_getStr(pikaMain, (char*)"h");
/* assert */
EXPECT_STREQ(c, (char*)"ab");
EXPECT_STREQ(g, (char*)"ab1");
EXPECT_STREQ(h, (char*)"ab11.200000");
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(pikaMain, str_add_print) {
/* init */

View File

@ -26,8 +26,8 @@
*/
#include "dataQueue.h"
#include "dataArgs.h"
#include "PikaPlatform.h"
#include "dataArgs.h"
Queue* New_queue(void) {
Args* args = New_args(NULL);
@ -55,7 +55,11 @@ int32_t queue_pushArg(Queue* queue, Arg* arg) {
Arg* queue_popArg(Queue* queue) {
Args* args = queue;
uint64_t top = args_getInt(args, "__t");
uint64_t bottom = args_getInt(args, "__b");
if (top - bottom < 1) {
return NULL;
}
/* add bottom */
args_setInt(args, "__b", bottom + 1);
char buff[11];