language-binding

ctypes segfault on OSX only

瘦欲@ 提交于 2021-01-28 02:51:04
问题 I created a very simple C library binding in Python using ctypes. All it does is accept a string and return a string. I did the development on Ubuntu, and everything looked fine. Unfortunately, on OSX the exact same code fails. I'm completely stumped. I've put together a minimal case showing the issue I'm having. main.py import ctypes # Compile for: # Linux: `gcc -fPIC -shared hello.c -o hello.so` # OSX: `gcc -shared hello.c -o hello.so` lib = ctypes.cdll.LoadLibrary('./hello.so') # Call the

What kinds of C++ functions can be placed in a C function pointer?

∥☆過路亽.° 提交于 2020-06-11 22:33:01
问题 I have a C library that uses a struct of function pointers for callbacks. The callbacks will be called from C code. extern "C" { typedef struct callbacks_t { void (*foo) (const char*); int (*bar) (int); } callbacks_t; }// extern C What kinds of C++ functions can I safely place in those function pointers to be called from the C library? Static member functions? Fully specified template functions? Non-capturing Lambdas? g++ seemingly lets me use all of the above, but I question the safety when

What kinds of C++ functions can be placed in a C function pointer?

不羁岁月 提交于 2020-06-11 22:32:34
问题 I have a C library that uses a struct of function pointers for callbacks. The callbacks will be called from C code. extern "C" { typedef struct callbacks_t { void (*foo) (const char*); int (*bar) (int); } callbacks_t; }// extern C What kinds of C++ functions can I safely place in those function pointers to be called from the C library? Static member functions? Fully specified template functions? Non-capturing Lambdas? g++ seemingly lets me use all of the above, but I question the safety when

What kinds of C++ functions can be placed in a C function pointer?

南楼画角 提交于 2020-06-11 22:32:30
问题 I have a C library that uses a struct of function pointers for callbacks. The callbacks will be called from C code. extern "C" { typedef struct callbacks_t { void (*foo) (const char*); int (*bar) (int); } callbacks_t; }// extern C What kinds of C++ functions can I safely place in those function pointers to be called from the C library? Static member functions? Fully specified template functions? Non-capturing Lambdas? g++ seemingly lets me use all of the above, but I question the safety when

What kinds of C++ functions can be placed in a C function pointer?

匆匆过客 提交于 2020-06-11 22:32:11
问题 I have a C library that uses a struct of function pointers for callbacks. The callbacks will be called from C code. extern "C" { typedef struct callbacks_t { void (*foo) (const char*); int (*bar) (int); } callbacks_t; }// extern C What kinds of C++ functions can I safely place in those function pointers to be called from the C library? Static member functions? Fully specified template functions? Non-capturing Lambdas? g++ seemingly lets me use all of the above, but I question the safety when

extending 'incomplete' types (SWIG)

女生的网名这么多〃 提交于 2019-12-18 09:20:46
问题 I'm looking for a way to extend (i.e. add new members to a type using the %extend directive) a type that is defined in the library file itself while the header files of the library provide only a forward declaration for the type. Treating the type as if its definition is known at compile time, leads to the following warning: Warning 303: %extend defined for an undeclared class [name of the type]. Is anyone aware of a solution or a workaround for this problem? I'm sure there is one, since SWIG

C/Python binding: pointer address modification

吃可爱长大的小学妹 提交于 2019-12-11 03:41:27
问题 Source C++ extern "C" { Service* create_service( int port ) { Settings settings; settings.set_port( port ); auto service = new Service( settings ); std::cout << "create_service returning pointer address: " << service << std::endl; return service; } void release_service( Service* service ) { std::cout << "release_service consuming pointer address: " << service << std::endl; delete service; } } Python from ctypes import * library = cdll.LoadLibrary('distribution/library/libhelpers.dylib') class

Iterating over std::map in PHP with SWIG

房东的猫 提交于 2019-12-04 21:55:38
问题 I am using SWIG to wrap a function that returns an std::map in PHP. In the PHP code, I need to iterate over the elements of the map. Thw SWIG library provides support for std::map with the std_map.i interface file, but only the following methods are wrapped: clear() del($key) get($key) has_key($key) is_empty() set($key, $x) size() How can I iterate over the elements of the map? Would I need to extend the std_map.i file with some sort of wrappers for iterators and begin() and end() ? 回答1: As

CUDA for .net?

一世执手 提交于 2019-12-03 04:14:28
问题 I know that there are a lot of CUDA language bindings, such as PyCUDA, but are there any good bindings for .Net? The only one I've seen is this one, but I'd like to know if there are any others. 回答1: Here's another library: http://sourceforge.net/projects/brahma-fx/ Edit : I've been looking at the documentation for the project you initially listed, and can say that the interface makes me think: what is the point of using .Net. The project I've listed has a cleaner interface but no

What is a language binding?

痞子三分冷 提交于 2019-12-03 02:14:38
问题 My good friend, Wikipedia, didn't give me a very good response to that question. So: What are language bindings? How do they work? Specifically accessing functions from code written in language X of a library written in language Y. 回答1: Let's say you create a C library to post stuff to stackoverflow. Now you want to be able to use the same library from Python. In this case, you will write Python bindings for your library. Also see SWIG: http://www.swig.org 回答2: In the context of code