修一部分logbug

newsch
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/tests/speechtotext/thirdparty/sphinxbase
@git config --global --add safe.directory /sledge/runtime/thirdparty/http-parser @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/jsmn
@git config --global --add safe.directory /sledge/runtime/thirdparty/hashmap
@git config --global --add safe.directory /sledge/runtime/tests/C-Image-Manip @git config --global --add safe.directory /sledge/runtime/tests/C-Image-Manip
@git submodule update --init --recursive @git submodule update --init --recursive

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

@ -245,7 +245,7 @@ current_sandbox_start(void)
map_set(sandbox_req_map, cur_request_id, strlen(cur_request_id), sandbox_request, sizeof(struct sandbox_request *), false); map_set(sandbox_req_map, cur_request_id, strlen(cur_request_id), sandbox_request, sizeof(struct sandbox_request *), false);
}else }else
{ {
uint32_t rest_pre_count =*requet_id; uint32_t rest_pre_count = *requet_id;
assert(rest_pre_count >= 1); assert(rest_pre_count >= 1);
struct sandbox_request *sandbox_request = map_get(sandbox_req_map, cur_request_id, strlen(cur_request_id), &ret_value_len); struct sandbox_request *sandbox_request = map_get(sandbox_req_map, cur_request_id, strlen(cur_request_id), &ret_value_len);
@ -263,18 +263,19 @@ current_sandbox_start(void)
uint64_t enqueue_timestamp = __getcycles(); uint64_t enqueue_timestamp = __getcycles();
const char *previous_output = sandbox_request->previous_function_output ? sandbox_request->previous_function_output : ""; 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); char *new_output = (char *)malloc(new_output_length);
if (!new_output) { if (!new_output) {
fprintf(stderr, "Failed to allocate memory for the new output: %s\n", strerror(errno)); fprintf(stderr, "Failed to allocate memory for the new output: %s\n", strerror(errno));
free(pre_func_output); free(pre_func_output);
goto err; 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); free(sandbox_request->previous_function_output);
sandbox_request->previous_function_output = NULL;
sandbox_request->previous_function_output = new_output; sandbox_request->previous_function_output = new_output;
free(pre_func_output); free(pre_func_output);
sandbox_request->output_length +=output_length; sandbox_request->output_length = new_output_length;
rest_pre_count --; rest_pre_count --;
if (rest_pre_count != 0) if (rest_pre_count != 0)

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

Binary file not shown.
Loading…
Cancel
Save