Swig update: typemaps
Merry Christmas everyone!
This patch updates the typemaps to add booleans, interfaces, context, and char** (for context_to_string). I really don't know what I'm doing here with those typemaps, so I would appreciate if someone (Joshua?) can look over. I was just following the pattern, with minor changes, and it seems to work for a port list function that I wrote for the semanage tool.
libsemanage/src/semanageswig.i +83 -1
@@ -51,7 +51,13 @@ } semanage_port_t *semanage_port_by_idx(semanage_port_t **list, int n) { return list[n]; - } + } + semanage_iface_t *semanage_iface_by_idx(semanage_iface_t **list, int n) { + return list[n]; + } + semanage_bool_t *semanage_bool_by_idx(semanage_bool_t **list, int n) { + return list[n]; + } char *char_by_idx(char **list, int n) { return list[n]; }
@@ -67,6 +73,14 @@ %apply int *OUTPUT { int * }; %apply int *OUTPUT { size_t * }; +%typemap(in, numinputs=0) char **(char *temp) { + $1 = &temp; +} + +%typemap(argout) char** { + $result = t_output_helper($result, SWIG_FromCharPtr(*$1)); +} + %typemap(in, numinputs=0) char ***(char **temp) { $1 = &temp; }
@@ -87,6 +101,74 @@ $result = t_output_helper($result, SWIG_NewPointerObj(*$1, SWIGTYPE_p_semanage_module_info, 0)); } +/** context typemaps **/ + +/* the wrapper will setup this parameter for passing... the resulting python functions + will not take the semanage_context_t ** parameter */ +%typemap(in, numinputs=0) semanage_context_t **(semanage_context_t *temp) { + $1 = &temp; +} + +%typemap(argout) semanage_context_t** { + $result = t_output_helper($result, SWIG_NewPointerObj(*$1, SWIGTYPE_p_semanage_context, 0)); +} + +/** boolean typemaps **/ + +/* the wrapper will setup this parameter for passing... the resulting python functions + will not take the semanage_bool_t *** parameter */ +%typemap(in, numinputs=0) semanage_bool_t ***(semanage_bool_t **temp) { + $1 = &temp; +} + +%typemap(argout) semanage_bool_t *** { + $result = t_output_helper($result, SWIG_NewPointerObj(*$1, SWIGTYPE_p_p_semanage_bool, 0)); +} + +%typemap(in, numinputs=0) semanage_bool_t **(semanage_bool_t *temp) { + $1 = &temp; +} + +%typemap(argout) semanage_bool_t ** { + $result = t_output_helper($result, SWIG_NewPointerObj(*$1, SWIGTYPE_p_semanage_bool, 0)); +} + +%typemap(argout) semanage_bool_key_t ** { + $result = t_output_helper($result, SWIG_NewPointerObj(*$1, SWIGTYPE_p_semanage_bool_key, 0)); +} + +%typemap(in, numinputs=0) semanage_bool_key_t **(semanage_bool_key_t *temp) { + $1 = &temp; +} + +/** interface typemaps **/ + +/* the wrapper will setup this parameter for passing... the resulting python functions + will not take the semanage_iface_t *** parameter */ +%typemap(in, numinputs=0) semanage_iface_t ***(semanage_iface_t **temp) { + $1 = &temp; +} + +%typemap(argout) semanage_iface_t *** { + $result = t_output_helper($result, SWIG_NewPointerObj(*$1, SWIGTYPE_p_p_semanage_iface, 0)); +} + +%typemap(in, numinputs=0) semanage_iface_t **(semanage_iface_t *temp) { + $1 = &temp; +} + +%typemap(argout) semanage_iface_t ** { + $result = t_output_helper($result, SWIG_NewPointerObj(*$1, SWIGTYPE_p_semanage_iface, 0)); +} + +%typemap(argout) semanage_iface_key_t ** { + $result = t_output_helper($result, SWIG_NewPointerObj(*$1, SWIGTYPE_p_semanage_iface_key, 0)); +} + +%typemap(in, numinputs=0) semanage_iface_key_t **(semanage_iface_key_t *temp) { + $1 = &temp; +} + /** seuser typemaps **/ /* the wrapper will setup this parameter for passing... the resulting python functions
Quoted 16 lines · Ivan Gyurdiev
Merry Christmas everyone!
This patch updates the typemaps to add booleans, interfaces, context, and char** (for
context_to_string). I really don't know what I'm doing here with those typemaps, so I would appreciate if someone (Joshua?) can look over. I was just following the pattern, with minor changes, and it seems to work for a port list function that I wrote for the semanage tool.------------------------------------------------------------------------
diff -Naurp --exclude-from excludes old/libsemanage/src/semanageswig.i new/libsemanage/src/semanageswig.i
libsemanage/src/semanageswig.i +0
-1@@ -51,7 +51,13 @@ } semanage_port_t *semanage_port_by_idx(semanage_port_t **list, int n) { return list[n]; - }
libsemanage/src/semanageswig.i line 63
Quoted 10 lines
libsemanage/src/semanageswig.i +7
-0+ } + semanage_iface_t *semanage_iface_by_idx(semanage_iface_t **list, int n) { + return list[n]; + } + semanage_bool_t *semanage_bool_by_idx(semanage_bool_t **list, int n) { + return list[n]; + } char *char_by_idx(char **list, int n) { return list[n]; }
Man.. adding that first semanage_*_by_idx was just a quick hack to get something working, we should probably move those into the proper libsemanage API instead of just adding them to the wrapper (they are clearly useful)
libsemanage/src/semanageswig.i line 83
Quoted 12 lines
libsemanage/src/semanageswig.i +8
-0@@ -67,6 +73,14 @@ %apply int *OUTPUT { int * }; %apply int *OUTPUT { size_t * }; +%typemap(in, numinputs=0) char **(char *temp) { + $1 = &temp; +} + +%typemap(argout) char** { + $result = t_output_helper($result, SWIG_FromCharPtr(*$1)); +} +
Have to be careful with this one, you don't want it messing with other char**. Did you run all the tests in pywrap-test after rebuilding this to make sure it didn't interrupt anything else?
The rest look fine.
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 2 lines · Joshua Brindle
Ivan Gyurdiev wrote:
<snip>
Quoted 16 lines
libsemanage/src/semanageswig.i line 83
Quoted 12 lines
libsemanage/src/semanageswig.i +8
-0@@ -67,6 +73,14 @@ %apply int *OUTPUT { int * }; %apply int *OUTPUT { size_t * }; +%typemap(in, numinputs=0) char **(char *temp) { + $1 = &temp; +} + +%typemap(argout) char** { + $result = t_output_helper($result, SWIG_FromCharPtr(*$1)); +} +Have to be careful with this one, you don't want it messing with other char**. Did you run all the tests in pywrap-test after rebuilding this to make sure it didn't interrupt anything else?
Quoted 2 lines
The rest look fine.
Speaking of which. Anytime you add anything to the wrapper please add the corresponding tests to pywrap-test. I'd like it if there was always a test for anything in mainline (I think Steve would too)
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 9 lines
Quoted 7 lines
Have to be careful with this one, you don't want it messing with other char**. Did you run all the tests in pywrap-test after rebuilding this to make sure it didn't interrupt anything else?
The rest look fine.
Speaking of which. Anytime you add anything to the wrapper please add the corresponding tests to pywrap-test. I'd like it if there was always a test for anything in mainline (I think Steve would too)
I have my own set of tests in C that I run (with valgrind). They're probably more detailed than what you have, but in terms of code are an awful mess, so I can't really submit them to use.
No, I didn't run pywrap-test. Does this work:
Testing users...
Query status (0 is good): 124 User list size: 4 User name: system_u
User mls level: s0
User mls range: s0-s0:c0.c255
User number of roles: 1
User roles:
system_r
User name: user_u
User mls level: s0
User mls range: s0-s0:c0.c255
User number of roles: 3
User roles:
system_r
sysadm_r
user_r
User name: root
User mls level: s0
User mls range: s0-s0:c0.c255
User number of roles: 3
User roles:
system_r
sysadm_r
user_r
User name: Ivan
User mls level: s0
User mls range: s0-s0:c1.c4,c55
User number of roles: 1
User roles:
staff_r
Testing seusers...
Query status (0 is good): 124 SEUser list size: 2 seuser name: root
seuser mls range: s0
seuser sename: root
seuser name: default
seuser mls range: s0
seuser sename: user_u
Testing modules...
Transaction number: 124 Module list size: 0
No modules installed!
This is not necessarily a test failure.
Testing user write...
Starting transaction...
Commit status (transaction number): 0
Removing user...
Commit status (transaction number): 0
Testing seuser write...
Starting transaction...
Commit status (transaction number): 0
Removing seuser...
Commit status (transaction number): 0
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 5 lines · Ivan Gyurdiev
Quoted 5 lines
Quoted 5 lines
Have to be careful with this one, you don't want it messing with other char**. Did you run all the tests in pywrap-test after rebuilding this to make sure it didn't interrupt anything else?
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
The rest look fine.
Speaking of which. Anytime you add anything to the wrapper please add the corresponding tests to pywrap-test. I'd like it if there was always a test for anything in mainline (I think Steve would too)
I have my own set of tests in C that I run (with valgrind). They're probably more detailed than what you have, but in terms of code are an awful mess, so I can't really submit them to use.
That is fine but there should be tests for the wrappers upstream. I consider this a requirement for adding wrappers.
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.