[OpenSER-Devel] SF.net SVN: openser: [2662] trunk/modules

Henning Westerholt henning.westerholt at 1und1.de
Mon Sep 3 14:17:18 CEST 2007


On Monday 03 September 2007, you wrote:
> Henning,
>
> I think that the way these helper functions were separated is not the best
> approach, because the test for the param_no shouldn't be done by the
> generic helper function. 

Hello Dan,

thank you for pointing out this problem, you're right. I fixed the issue for 
the textops module, now the t_check_status function in tm misses a warning 
for param_no = 2. And for the str2int the same issue exists. Certainly not 
ideal.

> Else you will have to write helper functions for 
> every parameter combination out there, or people will start implementing
> their own versions of these again. For example if you consider only
> functions with integer arguments, you will have to write 3 helpers for
> str2int alone.
>
> IMO the helper functions should simply convert from one type to another
> and leave the test for the param_no to be done by a wrapper in the
> module. The module is the only one that knows which argument is of which
> type and how should it be converted.
>
> What I have in mind is something like this (as a wrapper in a module):
>
> fix_arguments(void **param, int param_no)
> {
>     if (param_no == 1) {
>         fixup_str2int(param);
>     } else if (param_no == 2) {
>         something_other_conversion(param);
>     }
> }
>
> and the fixup_str2int should do the conversion without any check on the
> param_no argument.

Well, i don't think introducing a wrapper function for all fixup functions is 
really pretty. Perhaps we can introduce a additional parameter to the 
function interface? E.g.:

fixup_str2int(void ** param, int param_no, int expected_param_no)
and return an error if param_no > expected_param?

But this is also not really nice. The param_no information is in the module 
interface present, is there any possiblity to evaluate this at the startup, 
perhaps in sr_module.c? This way we could remove these checks in the fixup 
functions at all.

Cheers,

Henning



More information about the Devel mailing list