[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    translating linked list with SIP
From:       Marian Thomsen <marian.th () outlook ! de>
Date:       2021-02-25 12:59:14
Message-ID: AM0PR0502MB3764D717ED47722C2BABBC1D96CE0 () AM0PR0502MB3764 ! eurprd05 ! prod ! outlook ! com
[Download RAW message or body]

Hello,

I'm having difficulties translating linked list from given c++ API to pytho=
n.

I have a struct (DataType) holding some data (const unsigned char* data) an=
d the size of this data. Then I have a struct ListNode that has a void* dat=
a, that should point to a DataTypeObj.

Where I'm stuck:
DataType and ListNode can be translated with SIP, but I suspect something g=
oes wrong when passing the address of dataTypeObj to listNodeObj.data.
The address of dataTypeObj in hex format is the address the debugger shows =
me, therefore the ID should be right.
But the content is not. dataTypeObj.size accessed from listNodeObj is garba=
ge.

This is my header file:

typedef struct ListNode {

    void* data;
    struct ListNode *next;
    struct ListNode *prev;
}ListNode;


typedef struct DataType {

    const unsigned char *data;
    int   numocts;
}DataType;

// to debug
void displayDataType(DataType &dataType, void *dataTypePtr);
void displayListNode(ListNode &listNode);


and this is my .sip file:

struct ListNode {

%TypeHeaderCode
#include <llist.h>
%End

    void *data;
    struct ListNode *next;
    struct ListNode *prev;
} ;


struct DataType {

%TypeHeaderCode
#include <llist.h>
%End

   const unsigned char *data;
   int   numocts;
} ;

// to debug
void displayDataType(DataType &dataType, void *dataTypePtr);
void displayListNode(ListNode &listNode);


Does someone have and idea?

Thanks in advance!

M.T.

[Attachment #3 (text/html)]

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} \
</style> </head>
<body dir="ltr">
<div>Hello, </div>
<div><br>
</div>
<div>I'm having difficulties translating linked list from given c++ API to \
python.</div> <div><br>
</div>
<div>I have a struct (DataType) holding some data (const unsigned char* data) and the \
size of this data. Then I have a struct ListNode that has a void* data, that should \
point to a DataTypeObj.</div> <div><br>
</div>
<div>Where I'm stuck:</div>
<div>DataType and ListNode can be translated with SIP, but I suspect something goes \
wrong when passing the address of dataTypeObj to listNodeObj.data.</div> <div>The \
address of dataTypeObj in hex format is the address the debugger shows me, therefore \
the ID should be right.</div> <div>But the content is not. dataTypeObj.size accessed \
from listNodeObj is garbage.</div> <div><br>
</div>
<div>This is my header file:</div>
<div>
<pre style="background-color:#ffffff; color:#080808; font-family:'JetBrains \
Mono',monospace; font-size:9.8pt"><span style="color:#0033b3">typedef struct \
</span><span style="color:#008080">ListNode </span>{<br><br>&nbsp; &nbsp; <span \
style="color:#0033b3">void</span>* <span style="color:#660e7a">data</span>;<br>&nbsp; \
&nbsp; <span style="color:#0033b3">struct </span><span style="color:#008080">ListNode \
</span>*<span style="color:#660e7a">next</span>;<br>&nbsp; &nbsp; <span \
style="color:#0033b3">struct </span><span style="color:#008080">ListNode \
</span>*<span style="color:#660e7a">prev</span>;<br>}<span \
style="color:#371f80">ListNode</span>;<br><br><br><span style="color:#0033b3">typedef \
struct </span><span style="color:#008080">DataType </span>{<span \
style="color:#8c8c8c; font-style:italic"><br></span><span style="color:#8c8c8c; \
font-style:italic"><br></span><span style="color:#8c8c8c; font-style:italic">&nbsp; \
&nbsp; </span><span style="color:#0033b3">const unsigned char </span>*<span \
style="color:#660e7a">data</span>;<br>&nbsp; &nbsp; <span style="color:#0033b3">int \
&nbsp; </span><span style="color:#660e7a">numocts</span>;<br>}<span \
style="color:#371f80">DataType</span>;<br><br><span style="color:#8c8c8c; \
font-style:italic">// to debug<br></span><span style="color:#0033b3">void \
</span><span style="color:#00627a">displayDataType</span>(<span \
style="color:#371f80">DataType </span>&amp;dataType, <span style="color:#0033b3">void \
</span>*dataTypePtr);<br><span style="color:#0033b3">void </span><span \
style="color:#00627a">displayListNode</span>(<span style="color:#371f80">ListNode \
</span>&amp;listNode);</pre> <br>
</div>
<div><br>
</div>
<div>and this is my .sip file:</div>
<div>
<pre style="background-color:#ffffff; color:#080808; font-family:'JetBrains \
Mono',monospace; font-size:9.8pt"><span style="color:#0033b3">struct </span>ListNode \
{<br><br>%TypeHeaderCode<br><span style="color:#9e880d">#include </span><span \
style="color:#067d17">&lt;llist.h&gt;<br></span>%End<br><br>&nbsp; &nbsp; <span \
style="color:#0033b3">void </span>*data;<br>&nbsp; &nbsp; <span \
style="color:#0033b3">struct </span>ListNode *next;<br>&nbsp; &nbsp; <span \
style="color:#0033b3">struct </span>ListNode *prev;<br>} ;<br><br><br><span \
style="color:#0033b3">struct </span><span style="color:#008080">DataType \
</span>{<span style="color:#8c8c8c; font-style:italic"><br></span><span \
style="color:#8c8c8c; font-style:italic"><br></span>%TypeHeaderCode<br><span \
style="color:#9e880d">#include </span><span \
style="color:#067d17">&lt;llist.h&gt;<br></span>%End<br><br>&nbsp; &nbsp;<span \
style="color:#0033b3">const unsigned char </span>*data;<br>&nbsp; &nbsp;<span \
style="color:#0033b3">int &nbsp; </span><span \
style="color:#660e7a">numocts</span>;<br>} ;<br><br><span style="color:#8c8c8c; \
font-style:italic">// to debug<br></span><span style="color:#0033b3">void \
</span><span style="color:#00627a">displayDataType</span>(<span \
style="color:#008080">DataType </span>&amp;dataType, <span style="color:#0033b3">void \
</span>*dataTypePtr);<br><span style="color:#0033b3">void </span><span \
style="color:#00627a">displayListNode</span>(ListNode &amp;listNode);</pre> <br>
</div>
<div><br>
</div>
<div>Does someone have and idea?</div>
<div><br>
</div>
<div>Thanks in advance!</div>
<div><br>
</div>
<div>M.T.<br>
</div>
</body>
</html>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic