I am using SWIG to generate a PHP extension that calls into a 'c' shared lib. I am able to get most things to work except the following situation...
In my 'c' code I declare a function as (Please note that structure and function names have been changed to protect the innocent):
int getAllThePortInfo(EthernetPort *ports);
In this case, the parameter ports is actually an array of EthernetPort structures. In another 'c' program, I could have called it like this...
EthernetPort ports[4];
int rval = getAllThePortInfo(ports);
<etc>
<etc>
This works fine. Then I run SWIG, generate my shared lib, and all builds well. I get php code that I can call...
$ports = new_ethernetport();
$rval = getAllThePortInfo($ports);
This causes PHP to throw the following error : php: free(): invalid pointer: 0x099cb610
So, I tried to do something like...
$ports = array(new_ethernetport(), new_ethernetport(), new_ethernetport(), new_ethernetport());
$rval = getAllThePortInfo($ports);
But then PHP complained... PHP Fatal error: Type error in argument 1 of getAllThePortInfo. Expected SWIGTYPE_p_EthernetPort
What I think is happening is that PHP (and SWIG) do not differentiate between pointers and arrays, and in the wrapper, it is thinking 'pointer to a single structure', when, in reality, it is an array of structures.
Is there something in PHP I can do? Allocate a chunk of memory that I can use as a space to store more than one structure?
Is there something with SWIG I can do to make my wrapper understand my intentions better?
I truly would appreciate any suggestions. Thanks.