kxsystems / ffi Goto Github PK
View Code? Open in Web Editor NEWFFI for kdb+
Home Page: https://code.kx.com/q/interfaces
License: Apache License 2.0
FFI for kdb+
Home Page: https://code.kx.com/q/interfaces
License: Apache License 2.0
extern "C" void g(void* ptr)
{
printf("%s: (%p)\n", PRETTY_FUNCTION, ptr);
K k = static_cast(ptr);
printf("k = %p\n", k);
printf("%p->t = %d\n", k, k->t);
printf("%p->n = %lld\n", k, k->n);
printf("---\n");
For some reason n is coming as some nonsensical number. The type t is correct. I would expect n to be 10 or 1 if it is the number of columns.
Is there a way of passing the raw k object using ffi?
I had some troubles building this library, and with help from Simon managed to get it built by adding the below to CMakeLists.txt. This should probably be included by default when I clone the repo.
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -D_GNU_SOURCE")
I'm having a pickle of a time trying to call execve. I can't for the life of me figure out the right way to construct and pass the argv and envp arguments to the function so that they are arrays of pointers.
Is this possible? How are you supposed to build the array of character pointers?
Hi,
Whenever the q function bound to isConnected() function from this c++ project is called for the second time, q crashes with segmentation fault error:
$ q
KDB+ 3.6 2018.06.14 Copyright (C) 1993-2018 Kx Systems
l64/ 16(16)core 64537MB dk s110519 208.110.70.170 EXPIRE 2019.11.06 daniel.krizian@gmail.com KOD #4162453
q)\l ffi.q;
q)lib:{`qib.0.0.1.so,x};
q)bind:{[f;a;r] '[.ffi.bind[ lib f;a;r],[;::]::;enlist]};
q)isConnected:bind[ ;"";"b"] `$"_ZNK7EClient11isConnectedEv";
q)isConnected[]
0b
q)isConnected[]
Sorry, this application or an associated library has encountered a fatal error and will exit.
If known, please email the steps to reproduce this error to tech@kx.com
with a copy of the kdb+ startup banner and the info printed below.
Thank you.
SIGSEGV: Fault address 0x40
/opt/conda/envs/q/q/l64/q() [0x48483b]
/lib/x86_64-linux-gnu/libpthread.so.0(+0xf890) [0x7f1a752a9890]
/usr/lib/qib.0.0.1.so(_ZNK7EClient11isConnectedEv+0) [0x7f1a75fa1400]
/opt/conda/envs/q/q/l64/../../lib/libffi.so.6(ffi_call_unix64+0x4c) [0x7f1a6e949ec0]
/opt/conda/envs/q/q/l64/../../lib/libffi.so.6(ffi_call+0x22d) [0x7f1a6e94987d]
/opt/conda/envs/q/q/l64/ffi.so(call+0x296) [0x7f1a6eb4ef67]
/opt/conda/envs/q/q/l64/q() [0x483bf9]
/opt/conda/envs/q/q/l64/q() [0x4441a6]
/opt/conda/envs/q/q/l64/q() [0x444185]
/opt/conda/envs/q/q/l64/q() [0x4445d5]
/opt/conda/envs/q/q/l64/q() [0x41da94]
/opt/conda/envs/q/q/l64/q() [0x443eee]
/opt/conda/envs/q/q/l64/q() [0x4445d5]
/opt/conda/envs/q/q/l64/q() [0x41da94]
/opt/conda/envs/q/q/l64/q() [0x443eee]
/opt/conda/envs/q/bin/q: line 3: 22054 Segmentation fault numactl --physcpubind=0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 $QHOME/l64/q "$@"
qib.0.0.1.so
library is compiled from this source (https://github.com/danielkrizian/qib/), which is latest version of the Interactive Brokers TWS API.
Note: _ZNK7EClient11isConnectedEv
is mangled c++ symbol of the function EClient::isConnected()
:
$ nm /usr/lib/qib.0.0.1.so | c++filt | grep isConnected
0000000000017400 T EClient::isConnected() const
$ nm /usr/lib/qib.0.0.1.so | grep _ZNK7EClient11isConnectedEv
0000000000017400 T _ZNK7EClient11isConnectedEv
Snippet from my CMakeCache.txt
:
//CXX compiler
CMAKE_CXX_COMPILER:FILEPATH=/opt/conda/envs/q/bin/x86_64-conda_cos6-linux-gnu-c++
//Flags used by the CXX compiler during all build types.
CMAKE_CXX_FLAGS:STRING=-fvisibility-inlines-hidden -std=c++17 -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe
//C compiler
CMAKE_C_COMPILER:FILEPATH=/opt/conda/envs/q/bin/x86_64-conda_cos6-linux-gnu-cc
//Flags used by the C compiler during all build types.
CMAKE_C_FLAGS:STRING=-march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe
//Flags used by the linker during all build types.
CMAKE_EXE_LINKER_FLAGS:STRING=-Wl,-O2 -Wl,--sort-common -Wl,--as-needed -Wl,-z,relro -Wl,-z,now -Wl,--disable-new-dtags -Wl,--gc-sections
//Flags used by the linker during the creation of shared libraries
// during all build types.
CMAKE_SHARED_LINKER_FLAGS:STRING=-Wl,-O2 -Wl,--sort-common -Wl,--as-needed -Wl,-z,relro -Wl,-z,now -Wl,--disable-new-dtags -Wl,--gc-sections
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.