Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8230959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:18:51+00:00 2026-06-07T17:18:51+00:00

How can I process a va_list argument with Java, having received it from the

  • 0

How can I process a va_list argument with Java, having received it from the native library?

I am using a C library that facilitates logging through a callback function. The library is libghoto2 and I am using a JNA wrapper libgphoto2-java to access its features.
See the errordumper method in this C file for an example of how the logging should be done.

I’ve managed to add a Java-written callback function using the library’s gp_log_add_func. The only problem is, the callback function’s signature contains a va_list argument that I don’t know how to process.

As the C example from earlier shows, va_list args is passed directly into vfprintf. Reading the vfprintf manual it becomes clear that it is some sort of iterable data structure that has “been initialized with the va_start macro” and after iterating using va_arg a cleanup with va_end is required.
But the only way I found for keeping the JVM from crashing, is to make the args parameter of type com.sun.jna.Pointer while a String[] or Object[] would be more suitable.

How do I get the data out of this va_list?

N.B. In order to get access to gp_log_add_func, I added some Java code:

Additions to org.gphoto2.jna.GPhoto2Native:

int gp_log_add_func(int logLevel, LogFunc func, Pointer data);

Created org.gphoto2.jna.LogFunc:

public interface LogFunc extends Callback {
    public static final int GP_LOG_ERROR = 0;
    public static final int GP_LOG_VERBOSE = 1;
    public static final int GP_LOG_DEBUG = 2;
    public static final int GP_LOG_DATA = 3;
    public static final int GP_LOG_ALL = GP_LOG_DATA;

    //the args argument is a va_list 
    public void log(int logLevel, String domain, String format, Pointer args, Pointer data);
}

The implementation and usage of org.gphoto2.jna.LogFunc:

LogFunc callback = new LogFunc() {
        public void log(int logLevel, String domain, String format, Pointer args, Pointer data) {
            System.out.println("[" + domain + "] " + format);
            System.out.println(args.toString());
        }
};
GPhoto2Native.INSTANCE.gp_log_add_func(LogFunc.GP_LOG_ALL, callback, null);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T17:18:53+00:00Added an answer on June 7, 2026 at 5:18 pm

    Here is an example varargs implementation, with some hints about what the varargs macros are doing:

    int printf(const char* fmt, ...) {
      va_list argp;
    
      va_start(argp, fmt); // usually something like: argp = (char *)&fmt - sizeof(void *);
    
      int arg1 = va_arg(argp, int); // *(int *)argp; argp += sizeof(int);
      void *arg2 = va_arg(argp, void*); // *(void **)argp; argp += sizeof(void *);
      float arg3 = va_arg(argp, float); // *(float *)argp; argp += sizeof(float);
    
      va_end(argp); // no-op
    
    }
    

    So it’s basically a bunch of pointer arithmetic working with the stack pointer. The problematic piece w/r/t JNA is that you don’t have access to the stack pointer, and you’d probably need to extend JNA’s callback mechanism at the native level to specially handle variadic callbacks to provide the stack pointer.

    Even that is potentially problematic. As you can see from the above example, you actually need the address of the last named argument of the variadic function signature in order to access the variadic arguments. That would be very tricky to do generically.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been using argparse for a Python program that can -process , -upload or
In my iOS app I have several UIElement s that can process user input:
I have a callback url that gets called, and I can process it. However
how can i process all radio buttons from the page? <input type=radio name=radio_1 value=some
I know that in c# I can do: Process currentProcess = System.Diagnostics.Process.GetCurrentProcess(); currentProcess.Modules[0].BaseAddress currentProcess.Modules[0].EntryPointAddress
I have a defined number of servers that can locally process data in their
Is there a command-line program that can process pngs(and other formats) to make them
I have to make an iPhone project that can process video data in realtime.
I've created a factory assembly that can process any type of transaction (that supports
I would like to make a program that can process audio. How get an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.