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 6953355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:28:03+00:00 2026-05-27T14:28:03+00:00

I’m trying to figure out what SWIG Interface file change is needed in order

  • 0

I’m trying to figure out what SWIG Interface file change is needed in order to handle the getFoo returns a pointer that points to an array of a custom structure (sender_id_t). Without any special SWIG Interface code, I get just the pointer on the Java side. How can I turn that pointer into something I can loop or iterate over (in Java) so that I can get each sender_id_t id value? Appreciate any suggestions.

C Structure:

typedef unsigned char id_v1_t[32];
typedef id_v1_t id_t;
%rename (Sample) sender_id_t_;
struct sender_id_t_ {
    id_t       id;
    uint32_t   phy_idx;
};

C Function:

//This will return a pointer to an array of sender_id_t data.  The number of elements is retrieved from a separate call. 
sender_id_t* getFoo(resultset_t* resultset);

Exception:

 [exec] test_wrap.c: In function `new_foo_array':
 [exec] test_wrap.c:785: error: invalid application of `sizeof' to incomplete type `sender_id_t_' 
 [exec] test_wrap.c: At top level:
 [exec] test_wrap.c:792: error: return type is an incomplete type
 [exec] test_wrap.c: In function `foo_array_getitem':
 [exec] test_wrap.c:793: error: invalid use of undefined type `struct sender_id_t_'
 [exec] test_wrap.c:793: error: dereferencing pointer to incomplete type
 [exec] test_wrap.c:793: warning: `return' with a value, in function returning void
 [exec] test_wrap.c: At top level:
 [exec] test_wrap.c:795: error: parameter `value' has incomplete type
 [exec] test_wrap.c: In function `foo_array_setitem':
  • 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-05-27T14:28:04+00:00Added an answer on May 27, 2026 at 2:28 pm

    The simplest solution to this doesn’t involve writing any JNI at all – in effect it’s method 2. So what I did was use carrays.i to expose a very basic interface and then written a small bit of Java to make the public view of it more usable/intuitive. The key thing is you need to supply a way of bringing together the knowledge of the array and the length of it. I’ve put together a minimal complete example to illustrate, it returns a Java array, but it could equally work for an ArrayList or any collection you like.

    Firstly a header file, with an inline implementation for compactness:

    #ifndef TEST_H
    #define TEST_H
    
    struct Foo {
       int v;
    };
    
    inline static struct Foo *getFoo() {
      static struct Foo r[] = {{0},{1},{2}};
      return r;
    }
    
    inline static unsigned short numFoo() {
      return 3;
    }
    
    #endif
    

    This is then wrapped with:

    %module test
    
    %{
    #include "test.h"
    %}
    
    %include <carrays.i>
    %array_functions(struct Foo, foo_array);
    
    %rename(getFooImpl) getFoo;
    %javamethodmodifiers getFoo() "private";
    %javamethodmodifiers numFoo() "private";
    %include "test.h"
    
    %pragma(java) modulecode=%{
      public static Foo[] getFoo() {
        final int num = numFoo();
        Foo ret[] = new Foo[num];
        Foo result = getFooImpl();
        for (int i = 0; i < num; ++i) {
          ret[i] = foo_array_getitem(result, i);
        }
        return ret;
      }  
    %}
    

    Where we make rename the getFoo() from the header file and make it and the corresponding numFoo() private, i.e. implementation details.

    Using these two private functions we can then write a real, public Foo[] getFoo(), that calls these two and then copies the results into an actual array of known size.

    I tested this with:

    public class main {
      public static void main(String[] argv) {
        System.loadLibrary("test");
        Foo[] foos = test.getFoo();
        System.out.println(foos[2].getV());
      }
    }
    

    In my view this solution is cleaner than the corresponding JNI based example – it’s simpler to write and harder to introduce bugs which makes it more maintainable. Any Java or C programmer that looks at it can pretty much see what’s going on. It’s probably not much worse in terms of performance and probably not going to be a big chunk of time on some critical path – if benchmarks show it to be a problem then it’s still easy to go down the JNI road later.

    For completeness on the “making it private” aspect you might also want to do something like:

    %javamethodmodifiers foo_array_getitem "private";
    %ignore foo_array_setitem;
    %ignore delete_foo_array;
    %ignore new_foo_array;
    %include <carrays.i>
    %array_functions(struct Foo, foo_array);
    

    To hide all of the functions which get generated by the %array_functions macro.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.