Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

perl XS and C struct (works)

by kopolov (Acolyte)
on Mar 20, 2016 at 09:08 UTC ( [id://1158350]=perlquestion: print w/replies, xml ) Need Help??

kopolov has asked for the wisdom of the Perl Monks concerning the following question:

Hi there, I'm a newbie to perlXS. I have a C code which contains different structs
typedef struct { EntryType type; EntryIndex index; } TM_TranslationEntry; typedef struct { u64 EA, VA, RA; u8 pageSize; u32 numOfEntries; TM_TranslationEntry* entries; u32 modificationSet; } TM_PageTranslation; typedef struct { TM_InMemoryEntry* entries; u32 numOfEntries; } TM_InMemoryEntries; typedef struct { u64 slbee; u64 slbev; } TM_SlbEntry;
This is my typemap file:
TYPEMAP PageTranslation T_PTROBJ TM_InMemoryEntries T_PTROBJ TM_SlbEntry T_PTROBJ TM_TranslationEntry T_PTROBJ U64 T_UV
This is my trans.xs file header:
#include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "ppport.h" #include "TM_TranslationAPI.h" <--- include for the C code typedef struct TM_PageTranslation * PageTranslation typedef struct TM_InMemoryEntries * InMemoryEntries typedef struct TM_SlbEntry * SlbEntry typedef struct TM_TranslationEntry * TranslationEntry MODULE = trans PACKAGE = trans PROTOTYPES: ENABLE
and I have these functions inside the XS file which fails (only a sample):
InMemoryEntries selectMemoryEntriesSet(type) U64 type InMemoryEntries getEntryByType(pageTranslation, entryType) PageTranslation pageTranslation U64 entryType SlbEntry getSlbEntry(pageTranslation) PageTranslation pageTranslation
failing line:
Error: 'InMemoryEntries' not in typemap in trans.xs, line 167 Error: 'InMemoryEntries' not in typemap in trans.xs, line 172 Error: 'SlbEntry' not in typemap in trans.xs, line 176
I want to note one thing: prior to the functions which fails due to typemap issues, there are functions with PageTranslation which seems to pass (compiler does not give any errors/warning about them). As you can see, PageTranslation is also defined in the typemap. What am I doing wrong? **** update - found my mistake typemap naming should contain the names I chose for the struct and not the struct themselves (InMemoryEntries instead of TM_InMemoryEntries)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1158350]
Approved by Laurent_R
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-25 19:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found