-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ffi][prefactor] add
kernel_utils
header in read_table example (#539)
moved out some pieces of `read_table.c` and put into `kernel_utils.h/c`. just some small README updates otherwise.
- Loading branch information
1 parent
f1f8a82
commit 7bfd119
Showing
9 changed files
with
134 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#include "arrow.h" | ||
#include "kernel_utils.h" | ||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#include <delta_kernel_ffi.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include "kernel_utils.h" | ||
|
||
// some diagnostic functions | ||
void print_diag(char* fmt, ...) | ||
{ | ||
#ifdef VERBOSE | ||
va_list args; | ||
va_start(args, fmt); | ||
vprintf(fmt, args); | ||
va_end(args); | ||
#else | ||
(void)(fmt); | ||
#endif | ||
} | ||
|
||
// Print out an error message, plus the code and kernel message of an error | ||
void print_error(const char* msg, Error* err) | ||
{ | ||
printf("[ERROR] %s\n", msg); | ||
printf(" Kernel Code: %i\n", err->etype.etype); | ||
printf(" Kernel Msg: %s\n", err->msg); | ||
} | ||
|
||
// free an error | ||
void free_error(Error* error) | ||
{ | ||
free(error->msg); | ||
free(error); | ||
} | ||
|
||
// kernel will call this to allocate our errors. This can be used to create an "engine native" type | ||
// error | ||
EngineError* allocate_error(KernelError etype, const KernelStringSlice msg) | ||
{ | ||
Error* error = malloc(sizeof(Error)); | ||
error->etype.etype = etype; | ||
char* charmsg = allocate_string(msg); | ||
error->msg = charmsg; | ||
return (EngineError*)error; | ||
} | ||
|
||
#ifdef WIN32 // windows doesn't have strndup | ||
char *strndup(const char *s, size_t n) { | ||
size_t len = strnlen(s, n); | ||
char *p = malloc(len + 1); | ||
if (p) { | ||
memcpy(p, s, len); | ||
p[len] = '\0'; | ||
} | ||
return p; | ||
} | ||
#endif | ||
|
||
// utility to turn a slice into a char* | ||
void* allocate_string(const KernelStringSlice slice) | ||
{ | ||
return strndup(slice.ptr, slice.len); | ||
} | ||
|
||
// utility function to convert key/val into slices and set them on a builder | ||
void set_builder_opt(EngineBuilder* engine_builder, char* key, char* val) | ||
{ | ||
KernelStringSlice key_slice = { key, strlen(key) }; | ||
KernelStringSlice val_slice = { val, strlen(val) }; | ||
set_builder_option(engine_builder, key_slice, val_slice); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#pragma once | ||
|
||
#include <delta_kernel_ffi.h> | ||
|
||
// This is how we represent our errors. The kernel will ask us to contruct this struct whenever it | ||
// enounters an error, and then return the contructed EngineError to us | ||
typedef struct Error | ||
{ | ||
struct EngineError etype; | ||
char* msg; | ||
} Error; | ||
|
||
void print_diag(char* fmt, ...); | ||
// Print out an error message, plus the code and kernel message of an error | ||
void print_error(const char* msg, Error* err); | ||
// free an error | ||
void free_error(Error* error); | ||
// create a char* from a KernelStringSlice | ||
void* allocate_string(const KernelStringSlice slice); | ||
// kernel will call this to allocate our errors. This can be used to create an "engine native" type | ||
// error | ||
EngineError* allocate_error(KernelError etype, const KernelStringSlice msg); | ||
// utility function to convert key/val into slices and set them on a builder | ||
void set_builder_opt(EngineBuilder* engine_builder, char* key, char* val); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
#include "delta_kernel_ffi.h" | ||
#include "read_table.h" | ||
#include "kernel_utils.h" | ||
#include <stdint.h> | ||
|
||
/** | ||
|