This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH v3] Provide a C++ version of iseqsig


On Tue, 14 Nov 2017, Florian Weimer wrote:

>On 11/14/2017 02:21 PM, Gabriel F. T. Gomes wrote:
>
>> +template<typename _T1, typename _T2>
>> +inline int
>> +iseqsig(_T1 __x, _T2 __y) throw()
>> +{
>> +#  if __cplusplus >= 201103L
>> +  typedef __decltype (__MATH_EVAL_FMT2 (__x, __y)) _T3;
>> +#  else
>> +  typedef __typeof (__MATH_EVAL_FMT2 (__x, __y)) _T3;
>> +#  endif
>> +  return __iseqsig_type<_T3>::__call(__x, __y);
>> +}
>
>Would these two expressions have the same types, assuming _T1 and _T2 
>are the template parameters from the iseqsig definition?
>
>   __MATH_EVAL_FMT2 (__x, __y)
>   __MATH_EVAL_FMT2 (_T1 (), _T2 ())
>
>I believe the second expression would be safe to evaluate, so it could 
>be used to select a suitable inline function.  This would then work with 
>any C++ version.

Do you mean that I should go back to the first version of the patch (that
worked with function overloading and had a third parameter)?

For instance:

template <typename _T1, typename _T2> inline int
__iseqsig_type (float, _T1 x, _T2 y)
{
  return __iseqsigf (x, y);
}

/* ...  Likewise for other types.  */

template <typename _T1, typename _T2> inline int
iseqsig (_T1 __x, _T2 __y)
{
  _T1 __w = _T1 ();
  _T2 __z = _T2 ();
  return __iseqsig_type (__MATH_EVAL_FMT2 (__w, __z), __x, __y);
}

I am asking it, because on the second and third versions of this patch,
the selection of the underlying function is through a template parameter,
so I think we need to use typeof or decltype (at least I think that the
template parameter requires it).

>Maybe use support_record_failure from <support/check.h> instead?

I already adapted locally to use this, but I'll wait for your answer to my
question above, before sending a new version.

>> +static void
>> +check (int actual, int expected, const char *actual_expr, int line)
>> +{
>> +  if (actual != expected)
>> +    {
>> +      errors = true;
>> +      printf ("%s:%d: error: %s\n", __FILE__, line, actual_expr);
>> +      printf ("%s:%d:   expected: %d\n", __FILE__, line, expected);
>> +      printf ("%s:%d:   actual: %d\n", __FILE__, line, actual);
>> +    }
>> +}
>> +
>> +#define CHECK(actual, expected) \
>> +  check ((actual), (expected), #actual, __LINE__)  
>
>I think my memory protection key patches contain a more general 
>implementation of this called TEST_COMPARE.  Adhemerval requested just a 
>minor documentation change, so I could commit that separately if you 
>want to use it.

I can wait for your changes to go in in their own timing, then I'd gladly
write a clean up to use them (here and in other similar tests).


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]