修一部分logbug

sledge_graph
hwwang 4 months ago
parent 7abc07445d
commit 0b1fb6c5d7

@ -150,6 +150,7 @@ fetch:
@git config --global --add safe.directory /sledge/runtime/tests/speechtotext/thirdparty/sphinxbase
@git config --global --add safe.directory /sledge/runtime/thirdparty/http-parser
@git config --global --add safe.directory /sledge/runtime/thirdparty/jsmn
@git config --global --add safe.directory /sledge/runtime/thirdparty/hashmap
@git config --global --add safe.directory /sledge/runtime/tests/C-Image-Manip
@git submodule update --init --recursive

@ -16,7 +16,7 @@
struct map_node {
struct map_node *next;
void *key;
char *key;
void *value;
uint32_t key_len;
uint32_t value_len;
@ -44,13 +44,12 @@ map_init(struct hashmap *restrict map)
/* See https://en.wikipedia.org/wiki/Jenkins_hash_function */
static inline uint32_t
jenkins_hash(void *key, uint32_t key_len)
jenkins_hash(char *key, uint32_t key_len)
{
uint32_t i = 0;
uint32_t hash = 0;
unsigned char *data = (unsigned char *)key;
while (i != key_len) {
hash += data[i++];
hash += key[i++];
hash += hash << 10;
hash ^= hash >> 6;
}
@ -61,7 +60,7 @@ jenkins_hash(void *key, uint32_t key_len)
}
static inline void *
map_get(struct hashmap *map, void *key, uint32_t key_len, uint32_t *ret_value_len)
map_get(struct hashmap *map, char *key, uint32_t key_len, uint32_t *ret_value_len)
{
void *value = NULL;
@ -86,7 +85,7 @@ DONE:
}
static inline bool
map_set(struct hashmap *map, void *key, uint32_t key_len, void *value, uint32_t value_len, bool manage_mvalue)
map_set(struct hashmap *map, char *key, uint32_t key_len, void *value, uint32_t value_len, bool manage_mvalue)
{
bool did_set = false;
@ -127,7 +126,7 @@ DONE:
* @returns boolean if node was deleted or not
*/
static inline bool
map_delete(struct hashmap *map, void *key, uint32_t key_len)
map_delete(struct hashmap *map, char *key, uint32_t key_len)
{
bool did_delete = false;
@ -164,7 +163,7 @@ DONE:
}
static inline void
map_upsert(struct hashmap *map, void *key, uint32_t key_len, void *value, uint32_t value_len)
map_upsert(struct hashmap *map, char *key, uint32_t key_len, void *value, uint32_t value_len)
{
uint32_t hash = MAP_HASH(key, key_len);
struct map_bucket *bucket = &map->buckets[hash % MAP_BUCKET_COUNT];

@ -263,18 +263,19 @@ current_sandbox_start(void)
uint64_t enqueue_timestamp = __getcycles();
const char *previous_output = sandbox_request->previous_function_output ? sandbox_request->previous_function_output : "";
int new_output_length = strlen(previous_output) + output_length + 1;
ssize_t new_output_length = sandbox_request->output_length + output_length + 2;
char *new_output = (char *)malloc(new_output_length);
if (!new_output) {
fprintf(stderr, "Failed to allocate memory for the new output: %s\n", strerror(errno));
free(pre_func_output);
goto err;
}
snprintf(new_output, new_output_length, "%s+%s", previous_output, pre_func_output);
snprintf(new_output, new_output_length, "%s&%s", previous_output, pre_func_output);
free(sandbox_request->previous_function_output);
sandbox_request->previous_function_output = NULL;
sandbox_request->previous_function_output = new_output;
free(pre_func_output);
sandbox_request->output_length +=output_length;
sandbox_request->output_length = new_output_length;
rest_pre_count --;
if (rest_pre_count != 0)

@ -93,6 +93,7 @@ mem_log(char const * fmt, ...)
} else {
/* Write Success */
log_obj.offset += n;
// dump_log_to_file(log_obj);
}
}

Binary file not shown.

@ -1,8 +1,9 @@
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
// 假设的 Fibonacci 函数实现
unsigned long int fib(unsigned long int n) {
if (n <= 1) return n;
return fib(n - 1) + fib(n - 2);
@ -17,28 +18,29 @@ int main() {
perror("Error reading input");
return 1;
}
buffer[bytes_read] = '\0'; // Null-terminate the string
buffer[bytes_read] = '\0';
// Variables to store the two numbers
unsigned long int num1, num2;
// Split the input into two parts based on newline and parse them
char *line = strtok(buffer, "+");
if (line != NULL && sscanf(line, "%lu", &num1) == 1) {
line = strtok(NULL, "\n");
if (line != NULL && sscanf(line, "%lu", &num2) == 1) {
char *line = strtok(buffer, "&");
char *second_part = strtok(NULL, "\0"); // Assume the rest of the string is the second number
if (line && sscanf(line, "%lu", &num1) == 1 &&
second_part && sscanf(second_part, "%lu", &num2) == 1) {
// Calculate Fibonacci numbers and their sum
unsigned long int fib1 = fib(num1);
unsigned long int fib2 = fib(num2);
unsigned long int sum = fib1 + fib2;
printf("Fibonacci(%lu) + Fibonacci(%lu) = %lu + %lu = %lu\n", num1, num2, fib1, fib2, sum);
} else {
printf("Invalid input. Please enter two numbers on separate lines.\n");
return 1;
}
// Prepare output string
char output[1024];
int len = snprintf(output, sizeof(output), "Fibonacci(%lu) + Fibonacci(%lu) = %lu + %lu = %lu\n", num1, num2, fib1, fib2, sum);
// Write to stdout
write(1, output, len);
} else {
printf("Invalid input. Please enter two numbers on separate lines.\n");
const char *error_msg = "Invalid input. Please enter two numbers separated by .\n";
write(1, error_msg, strlen(error_msg));
return 1;
}

Binary file not shown.
Loading…
Cancel
Save