Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am triptec on github.
  • I am triptec (https://keybase.io/triptec) on keybase.
  • I have a public key ASBMWfQ3zsbyzoTzg3SnzX-7R_AHYnRFltZoZcd5wY80Pwo

To claim this, I am signing this object:

@triptec
triptec / rust_dynamic_va_call.md
Last active February 22, 2019 08:31
Calling a variadic function dynamically from rust

So I need to create a function wrapping a variadic c function (https://jcupitt.github.io/libvips/API/current/libvips-resample.html#vips-thumbnail) in rust.
This function takes some arguments and lastly a "NULL-terminated list of optional named arguments".
c function:

int vips_thumbnail (const char *filename, VipsImage **out, int width, ...); 

example calling it from rust with a optional height parameter:

vips_thumbnail(some_path.as_ptr(), &mut out_ptr, width as i32, "height\0".as_ptr(), height as i32, null() as *const c_char);
#0 0x00007ffff616fddf in std::__detail::_List_node_base::_M_hook(std::__detail::_List_node_base*) () at /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#1 0x00007ffff7bacee5 in std::__cxx11::list<vips::VOption::Pair*, std::allocator<vips::VOption::Pair*> >::_M_insert<vips::VOption::Pair* const&>(std::_List_iterator<vips::VOption::Pair*>, vips::VOption::Pair* const&) (__position=..., this=0x7fffffffd488) at /usr/include/c++/7/bits/stl_list.h:1802
#2 0x00007ffff7bacee5 in std::__cxx11::list<vips::VOption::Pair*, std::allocator<vips::VOption::Pair*> >::push_back(vips::VOption::Pair* const&) (__x=<synthetic pointer>: <optimized out>, this=0x7fffffffd488) at /usr/include/c++/7/bits/stl_list.h:1118
#3 0x00007ffff7bacee5 in vips::VOption::set(char const*, int) (this=0x7fffffffd480, name=<optimized out>, value=0) at VImage.cpp:138
#4 0x000055555555a006 in vips_cpp_sys::bindings::root::vips::VOption::set1 (self=0x7fffffffd480, name=0x5555557aec90 "access", value=0) at /home/ubuntu/Development/vips-workspace/vips-cpp-sys
> vips-ffi@0.2.0 test /var/task/node_modules/vips-ffi
> semistandard && nyc --reporter=lcov --branches=99 mocha --slow=5000 --timeout=60000 ./test/unit/*.js
Image arithmetic
(banana:706): GLib-CRITICAL **: g_datalist_id_dup_data: assertion `key_id != 0' failed
#[macro_use]
extern crate actix;
extern crate actix_web;
extern crate bytes;
extern crate futures;
#[macro_use]
extern crate log;
extern crate env_logger;