Re: Euphoria JSON parser
- Posted by SDPringle Oct 16, 2015
- 2763 views
You know, it is funny, but I have been able to use c_func/c_proc interface without external dlls.
include std/unittest.e include std/dll.e include std/machine.e constant no_dll = -1 constant malloc_function = define_c_func(no_dll, "malloc", {C_INT}, C_POINTER) constant Emalloc = define_c_func(no_dll, "Emalloc", {C_UINT}, C_POINTER) test_true("Malloc function returns non-zero", malloc_function) test_true("EMalloc function returns non-zero", Emalloc) test_report()
You can link the C code with the rest into the "library" section, and then you use a Euphoria wrapper that you first can debug as an external dll while the team resists.
In the case of Regex, we didn't do this. Because of the way as Open Euphoria has integrated PCRE. Extra glue code in C via be_regex.c had to handle whether we pass a number implemented as an encoded pointer to a struct d or as a C integer. The code had to be written with great care to ensure people were not passing sequences where integers were expected. Initially, it did not do this.
Now, if you use the c_func/c_proc interface and compile the files into the library, you don't get external dependencies. And it is in the be_callc.c that makes sure your integers are converted into c integers when they need to and whether to error out. The EUPHORIA wrapper code has to be written correctly but it is less work in the end. This approach eliminates a need for a be_json.c which would be needed if you pass everything through machine_func/machine_proc.
Shawn