问:
AVX2 support in GCC 5 and later
I wrote the following class "T" to accelerate manipulations of
"sets of characters" using AVX2. Then I found that it doesn't work in
gcc 5 and later when I use "-O3".
Can anyone help me trace this down to some programming construct that
is known not to work on the latest compilers/systems?

How this code works: The underlying structure ("_bits") is a block of 256 bytes (aligned and allocated for AVX2), which can be accessed either as char[256] or AVX2 elements, depending on whether an element is accessed or the whole thing is used in a vector operation. Seems like it should work perfectly well on the AVX2 platform. No?

This is really hard to debug, because "valgrind" says it's clean,
and I can't use a debugger (due to the problem disappearing when
I remove "-O3"). But I am not happy with just going with the "|="
workaround because if this code is really wrong, then I'm probably
making the same mistake in other places and screwing up everything
I develop!

It is interesting to note that the "|" operator has the problem but the
"|=" does not. Could the problem be related to returning a struct from
a function? But I thought that returning a struct has worked since 1990
or something.

```<code>// g++ -std=c++11 -mavx2 -O3 gcc_fail.cpp

#include "assert.h"
#include "immintrin.h" // AVX

class T {
public:
  __m256i _bits[8];
  inline bool& operator[](unsigned char c)       {return ((bool*)_bits)[c];}
  inline bool  operator[](unsigned char c) const {return ((bool*)_bits)[c];}
  inline          T()                   {}
  inline explicit T(char const*);
  inline T     operator| (T const& b) const;
  inline T &   operator|=(T const& b);
  inline bool  operator! ()           const;
};

T::T(char const* s)
{
  _bits[0] = _bits[1] = _bits[2] = _bits[3] = _mm256_set1_epi32(0);
  _bits[4] = _bits[5] = _bits[6] = _bits[7] = _mm256_set1_epi32(0);
  char c;
  while ((c = *s++))
    (*this)[c] = true;
}

T T::operator| (T const& b) const
{
  T res;
  for (int i = 0; i < 8; i++)
    res._bits[i] = _mm256_or_si256(_bits[i], b._bits[i]);

  // FIXME why does the above code fail with -O3 in new gcc?
  for (int i=0; i<256; i++)
    assert(res[i] == ((*this)[i] || b[i]));
  // gcc 4.7.0 - PASS
  // gcc 4.7.2 - PASS
  // gcc 4.8.0 - PASS
  // gcc 4.9.2 - PASS
  // gcc 5.2.0 - FAIL
  // gcc 5.3.0 - FAIL
  // gcc 5.3.1 - FAIL
  // gcc 6.1.0 - FAIL

  return res;
}

T & T::operator|=(T const& b)
{
  for (int i = 0; i < 8; i++)
    _bits[i] = _mm256_or_si256(_bits[i], b._bits[i]);
  return *this;
}

bool T::operator! () const
{
  for (int i = 0; i < 8; i++)
    if (!_mm256_testz_si256(_bits[i], _bits[i]))
      return false;
  return true;
}

int Main()
{
  T sep (" ,\t\n");
  T end ("");
  return !(sep|end);
}

int main()
{
  return Main();
}
</code>```

答:
Your code's problem is the use of bool* when you should have been using unsigned char*, which allowed GCC 5 to proceed with a pointer alias optimization.

The two dumps of the machine code for function Main(), produced both by GCC 4.8.5 and 5.3.1, are at the end of this answer in appendix for reference.

Looking at the code:

Decompilation

After the prologue, T sep's _bits are initialized to zero...

```<code>  _bits[0] = _bits[1] = _bits[2] = _bits[3] = _mm256_set1_epi32(0);
  _bits[4] = _bits[5] = _bits[6] = _bits[7] = _mm256_set1_epi32(0);

  40063d:       c5 fd 7f 44 24 60               vmovdqa %ymm0,0x60(%rsp)
  400643:       c5 fd 7f 44 24 40               vmovdqa %ymm0,0x40(%rsp)
  400649:       c5 fd 7f 44 24 20               vmovdqa %ymm0,0x20(%rsp)
  40064f:       c5 fd 7f 04 24                  vmovdqa %ymm0,(%rsp)
  400654:       c5 fd 7f 84 24 e0 00 00 00      vmovdqa %ymm0,0xe0(%rsp)
  40065d:       c5 fd 7f 84 24 c0 00 00 00      vmovdqa %ymm0,0xc0(%rsp)
  400666:       c5 fd 7f 84 24 a0 00 00 00      vmovdqa %ymm0,0xa0(%rsp)
  40066f:       c5 fd 7f 84 24 80 00 00 00      vmovdqa %ymm0,0x80(%rsp)
</code>```

and then written to in a loop based on char* s.

```<code>  char c;
  while ((c = *s++))
    (*this)[c] = true;

  400680:       48 83 c2 01                     add    $0x1,%rdx
  400684:       c6 04 04 01                     movb   $0x1,(%rsp,%rax,1)
  400688:       0f b6 42 ff                     movzbl -0x1(%rdx),%eax
  40068c:       84 c0                           test   %al,%al
  40068e:       75 f0                           jne    400680 <_Z4Mainv+0x60>
</code>```

Both compilers then initialize T end to 0s:

```<code>  400690:       c5 f9 ef c0                     vpxor  %xmm0,%xmm0,%xmm0
  400694:       31 c0                           xor    %eax,%eax
  400696:       c5 fd 7f 84 24 60 01 00 00      vmovdqa %ymm0,0x160(%rsp)
  40069f:       c5 fd 7f 84 24 40 01 00 00      vmovdqa %ymm0,0x140(%rsp)
  4006a8:       c5 fd 7f 84 24 20 01 00 00      vmovdqa %ymm0,0x120(%rsp)
  4006b1:       c5 fd 7f 84 24 00 01 00 00      vmovdqa %ymm0,0x100(%rsp)
  4006ba:       c5 fd 7f 84 24 e0 01 00 00      vmovdqa %ymm0,0x1e0(%rsp)
  4006c3:       c5 fd 7f 84 24 c0 01 00 00      vmovdqa %ymm0,0x1c0(%rsp)
  4006cc:       c5 fd 7f 84 24 a0 01 00 00      vmovdqa %ymm0,0x1a0(%rsp)
  4006d5:       c5 fd 7f 84 24 80 01 00 00      vmovdqa %ymm0,0x180(%rsp)
</code>```

Both compilers then optimize out the _mm256_or_si256() operations because T end is known to be 0. But then, GCC 4.8.5 copies from T sep to T res (which is computationally what happens when you OR anything into a zero variable), while GCC 5.3.1 initializes T res to 0. It's entitled to do that because in your operator [] method you cast a pointer of type __m256i* to bool*, and the compiler is permitted to assume the pointers do not alias. Thus in GCC 4.8.5 you see

```<code>  4006de:       c5 fd 6f 04 24                  vmovdqa (%rsp),%ymm0
  4006e3:       c5 fd 7f 84 24 00 02 00 00      vmovdqa %ymm0,0x200(%rsp)
  4006ec:       c5 fd 6f 44 24 20               vmovdqa 0x20(%rsp),%ymm0
  4006f2:       c5 fd 7f 84 24 20 02 00 00      vmovdqa %ymm0,0x220(%rsp)
  4006fb:       c5 fd 6f 44 24 40               vmovdqa 0x40(%rsp),%ymm0
  400701:       c5 fd 7f 84 24 40 02 00 00      vmovdqa %ymm0,0x240(%rsp)
  40070a:       c5 fd 6f 44 24 60               vmovdqa 0x60(%rsp),%ymm0
  400710:       c5 fd 7f 84 24 60 02 00 00      vmovdqa %ymm0,0x260(%rsp)
  400719:       c5 fd 6f 84 24 80 00 00 00      vmovdqa 0x80(%rsp),%ymm0
  400722:       c5 fd 7f 84 24 80 02 00 00      vmovdqa %ymm0,0x280(%rsp)
  40072b:       c5 fd 6f 84 24 a0 00 00 00      vmovdqa 0xa0(%rsp),%ymm0
  400734:       c5 fd 7f 84 24 a0 02 00 00      vmovdqa %ymm0,0x2a0(%rsp)
  40073d:       c5 fd 6f 84 24 c0 00 00 00      vmovdqa 0xc0(%rsp),%ymm0
  400746:       c5 fd 7f 84 24 c0 02 00 00      vmovdqa %ymm0,0x2c0(%rsp)
  40074f:       c5 fd 6f 84 24 e0 00 00 00      vmovdqa 0xe0(%rsp),%ymm0
  400758:       c5 fd 7f 84 24 e0 02 00 00      vmovdqa %ymm0,0x2e0(%rsp)
</code>```

while in GCC 5.3.1 you see

```<code>  4006fa:       c5 fd 7f 85 f0 fe ff ff         vmovdqa %ymm0,-0x110(%rbp)
  400702:       c5 fd 7f 85 10 ff ff ff         vmovdqa %ymm0,-0xf0(%rbp)
  40070a:       c5 fd 7f 85 30 ff ff ff         vmovdqa %ymm0,-0xd0(%rbp)
  400712:       c5 fd 7f 85 50 ff ff ff         vmovdqa %ymm0,-0xb0(%rbp)
  40071a:       c5 fd 7f 85 70 ff ff ff         vmovdqa %ymm0,-0x90(%rbp)
  400722:       c5 fd 7f 45 90                  vmovdqa %ymm0,-0x70(%rbp)
  400727:       c5 fd 7f 45 b0                  vmovdqa %ymm0,-0x50(%rbp)
  40072c:       c5 fd 7f 45 d0                  vmovdqa %ymm0,-0x30(%rbp)
</code>```

Whereupon the reads for the assert() then fail.

The Standard's Ruling on Pointer Aliasing:

ISO C++11 refers to aliasing under the following section, which makes clear that variables of type __m256i* cannot be accessed using bool*, but may be accessed with a char*/unsigned char*:

§ 3.10 Lvalues and rvalues [basic.lval]

[...]

If a program attempts to access the stored value of an object through a glvalue of other than one of the following types the behavior is undefined: [52]

the dynamic type of the object,

a cv-qualified version of the dynamic type of the object,

a type similar (as defined in 4.4) to the dynamic type of the object,

a type that is the signed or unsigned type corresponding to the dynamic type of the object,

a type that is the signed or unsigned type corresponding to a cv-qualified version of the dynamic type of the object,

an aggregate or union type that includes one of the aforementioned types among its elements or non-static data members (including, recursively, an element or non-static data member of a subaggregate or contained union),

a type that is a (possibly cv-qualified) base class type of the dynamic type of the object,

a char or unsigned char type.

52) The intent of this list is to specify those circumstances in which an object may or may not be aliased.

Appendix

GCC 4.8.5:

```<code>0000000000400620 <_Z4Mainv>:
  400620:       55                              push   %rbp
  400621:       c5 f9 ef c0                     vpxor  %xmm0,%xmm0,%xmm0
  400625:       ba e5 08 40 00                  mov    $0x4008e5,%edx
  40062a:       b8 20 00 00 00                  mov    $0x20,%eax
  40062f:       48 89 e5                        mov    %rsp,%rbp
  400632:       48 83 e4 e0                     and    $0xffffffffffffffe0,%rsp
  400636:       48 81 ec 00 03 00 00            sub    $0x300,%rsp
  40063d:       c5 fd 7f 44 24 60               vmovdqa %ymm0,0x60(%rsp)
  400643:       c5 fd 7f 44 24 40               vmovdqa %ymm0,0x40(%rsp)
  400649:       c5 fd 7f 44 24 20               vmovdqa %ymm0,0x20(%rsp)
  40064f:       c5 fd 7f 04 24                  vmovdqa %ymm0,(%rsp)
  400654:       c5 fd 7f 84 24 e0 00 00 00      vmovdqa %ymm0,0xe0(%rsp)
  40065d:       c5 fd 7f 84 24 c0 00 00 00      vmovdqa %ymm0,0xc0(%rsp)
  400666:       c5 fd 7f 84 24 a0 00 00 00      vmovdqa %ymm0,0xa0(%rsp)
  40066f:       c5 fd 7f 84 24 80 00 00 00      vmovdqa %ymm0,0x80(%rsp)
  400678:       0f 1f 84 00 00 00 00 00         nopl   0x0(%rax,%rax,1)
  400680:       48 83 c2 01                     add    $0x1,%rdx
  400684:       c6 04 04 01                     movb   $0x1,(%rsp,%rax,1)
  400688:       0f b6 42 ff                     movzbl -0x1(%rdx),%eax
  40068c:       84 c0                           test   %al,%al
  40068e:       75 f0                           jne    400680 <_Z4Mainv+0x60>
  400690:       c5 f9 ef c0                     vpxor  %xmm0,%xmm0,%xmm0
  400694:       31 c0                           xor    %eax,%eax
  400696:       c5 fd 7f 84 24 60 01 00 00      vmovdqa %ymm0,0x160(%rsp)
  40069f:       c5 fd 7f 84 24 40 01 00 00      vmovdqa %ymm0,0x140(%rsp)
  4006a8:       c5 fd 7f 84 24 20 01 00 00      vmovdqa %ymm0,0x120(%rsp)
  4006b1:       c5 fd 7f 84 24 00 01 00 00      vmovdqa %ymm0,0x100(%rsp)
  4006ba:       c5 fd 7f 84 24 e0 01 00 00      vmovdqa %ymm0,0x1e0(%rsp)
  4006c3:       c5 fd 7f 84 24 c0 01 00 00      vmovdqa %ymm0,0x1c0(%rsp)
  4006cc:       c5 fd 7f 84 24 a0 01 00 00      vmovdqa %ymm0,0x1a0(%rsp)
  4006d5:       c5 fd 7f 84 24 80 01 00 00      vmovdqa %ymm0,0x180(%rsp)
  4006de:       c5 fd 6f 04 24                  vmovdqa (%rsp),%ymm0
  4006e3:       c5 fd 7f 84 24 00 02 00 00      vmovdqa %ymm0,0x200(%rsp)
  4006ec:       c5 fd 6f 44 24 20               vmovdqa 0x20(%rsp),%ymm0
  4006f2:       c5 fd 7f 84 24 20 02 00 00      vmovdqa %ymm0,0x220(%rsp)
  4006fb:       c5 fd 6f 44 24 40               vmovdqa 0x40(%rsp),%ymm0
  400701:       c5 fd 7f 84 24 40 02 00 00      vmovdqa %ymm0,0x240(%rsp)
  40070a:       c5 fd 6f 44 24 60               vmovdqa 0x60(%rsp),%ymm0
  400710:       c5 fd 7f 84 24 60 02 00 00      vmovdqa %ymm0,0x260(%rsp)
  400719:       c5 fd 6f 84 24 80 00 00 00      vmovdqa 0x80(%rsp),%ymm0
  400722:       c5 fd 7f 84 24 80 02 00 00      vmovdqa %ymm0,0x280(%rsp)
  40072b:       c5 fd 6f 84 24 a0 00 00 00      vmovdqa 0xa0(%rsp),%ymm0
  400734:       c5 fd 7f 84 24 a0 02 00 00      vmovdqa %ymm0,0x2a0(%rsp)
  40073d:       c5 fd 6f 84 24 c0 00 00 00      vmovdqa 0xc0(%rsp),%ymm0
  400746:       c5 fd 7f 84 24 c0 02 00 00      vmovdqa %ymm0,0x2c0(%rsp)
  40074f:       c5 fd 6f 84 24 e0 00 00 00      vmovdqa 0xe0(%rsp),%ymm0
  400758:       c5 fd 7f 84 24 e0 02 00 00      vmovdqa %ymm0,0x2e0(%rsp)
  400761:       0f 1f 80 00 00 00 00            nopl   0x0(%rax)
  400768:       80 3c 04 00                     cmpb   $0x0,(%rsp,%rax,1)
  40076c:       0f b6 8c 04 00 02 00 00         movzbl 0x200(%rsp,%rax,1),%ecx
  400774:       ba 01 00 00 00                  mov    $0x1,%edx
  400779:       75 08                           jne    400783 <_Z4Mainv+0x163>
  40077b:       0f b6 94 04 00 01 00 00         movzbl 0x100(%rsp,%rax,1),%edx
  400783:       38 d1                           cmp    %dl,%cl
  400785:       0f 85 b2 00 00 00               jne    40083d <_Z4Mainv+0x21d>
  40078b:       48 83 c0 01                     add    $0x1,%rax
  40078f:       48 3d 00 01 00 00               cmp    $0x100,%rax
  400795:       75 d1                           jne    400768 <_Z4Mainv+0x148>
  400797:       c5 fd 6f 8c 24 00 02 00 00      vmovdqa 0x200(%rsp),%ymm1
  4007a0:       31 c0                           xor    %eax,%eax
  4007a2:       c4 e2 7d 17 c9                  vptest %ymm1,%ymm1
  4007a7:       0f 94 c0                        sete   %al
  4007aa:       0f 85 88 00 00 00               jne    400838 <_Z4Mainv+0x218>
  4007b0:       c5 fd 6f 8c 24 20 02 00 00      vmovdqa 0x220(%rsp),%ymm1
  4007b9:       31 c0                           xor    %eax,%eax
  4007bb:       c4 e2 7d 17 c9                  vptest %ymm1,%ymm1
  4007c0:       0f 94 c0                        sete   %al
  4007c3:       75 73                           jne    400838 <_Z4Mainv+0x218>
  4007c5:       c5 fd 6f 8c 24 40 02 00 00      vmovdqa 0x240(%rsp),%ymm1
  4007ce:       31 c0                           xor    %eax,%eax
  4007d0:       c4 e2 7d 17 c9                  vptest %ymm1,%ymm1
  4007d5:       0f 94 c0                        sete   %al
  4007d8:       75 5e                           jne    400838 <_Z4Mainv+0x218>
  4007da:       c5 fd 6f 8c 24 60 02 00 00      vmovdqa 0x260(%rsp),%ymm1
  4007e3:       31 c0                           xor    %eax,%eax
  4007e5:       c4 e2 7d 17 c9                  vptest %ymm1,%ymm1
  4007ea:       0f 94 c0                        sete   %al
  4007ed:       75 49                           jne    400838 <_Z4Mainv+0x218>
  4007ef:       c5 fd 6f 8c 24 80 02 00 00      vmovdqa 0x280(%rsp),%ymm1
  4007f8:       31 c0                           xor    %eax,%eax
  4007fa:       c4 e2 7d 17 c9                  vptest %ymm1,%ymm1
  4007ff:       0f 94 c0                        sete   %al
  400802:       75 34                           jne    400838 <_Z4Mainv+0x218>
  400804:       c5 fd 6f 8c 24 a0 02 00 00      vmovdqa 0x2a0(%rsp),%ymm1
  40080d:       31 c0                           xor    %eax,%eax
  40080f:       c4 e2 7d 17 c9                  vptest %ymm1,%ymm1
  400814:       0f 94 c0                        sete   %al
  400817:       75 1f                           jne    400838 <_Z4Mainv+0x218>
  400819:       c5 fd 6f 8c 24 c0 02 00 00      vmovdqa 0x2c0(%rsp),%ymm1
  400822:       31 c0                           xor    %eax,%eax
  400824:       c4 e2 7d 17 c9                  vptest %ymm1,%ymm1
  400829:       0f 94 c0                        sete   %al
  40082c:       75 0a                           jne    400838 <_Z4Mainv+0x218>
  40082e:       31 c0                           xor    %eax,%eax
  400830:       c4 e2 7d 17 c0                  vptest %ymm0,%ymm0
  400835:       0f 94 c0                        sete   %al
  400838:       c5 f8 77                        vzeroupper
  40083b:       c9                              leaveq
  40083c:       c3                              retq
  40083d:       b9 20 09 40 00                  mov    $0x400920,%ecx
  400842:       ba 26 00 00 00                  mov    $0x26,%edx
  400847:       be e9 08 40 00                  mov    $0x4008e9,%esi
  40084c:       bf f8 08 40 00                  mov    $0x4008f8,%edi
  400851:       c5 f8 77                        vzeroupper
  400854:       e8 97 fc ff ff                  callq  4004f0 <__assert_fail@plt>
  400859:       0f 1f 80 00 00 00 00            nopl   0x0(%rax)
</code>```

GCC 5:

```<code>0000000000400630 <_Z4Mainv>:
  400630:       4c 8d 54 24 08                  lea    0x8(%rsp),%r10
  400635:       48 83 e4 e0                     and    $0xffffffffffffffe0,%rsp
  400639:       b8 20 00 00 00                  mov    $0x20,%eax
  40063e:       c5 f9 ef c0                     vpxor  %xmm0,%xmm0,%xmm0
  400642:       ba 25 08 40 00                  mov    $0x400825,%edx
  400647:       41 ff 72 f8                     pushq  -0x8(%r10)
  40064b:       55                              push   %rbp
  40064c:       48 89 e5                        mov    %rsp,%rbp
  40064f:       41 52                           push   %r10
  400651:       48 81 ec 08 03 00 00            sub    $0x308,%rsp
  400658:       c5 fd 7f 85 50 fd ff ff         vmovdqa %ymm0,-0x2b0(%rbp)
  400660:       c5 fd 7f 85 30 fd ff ff         vmovdqa %ymm0,-0x2d0(%rbp)
  400668:       c5 fd 7f 85 10 fd ff ff         vmovdqa %ymm0,-0x2f0(%rbp)
  400670:       c5 fd 7f 85 f0 fc ff ff         vmovdqa %ymm0,-0x310(%rbp)
  400678:       c5 fd 7f 85 d0 fd ff ff         vmovdqa %ymm0,-0x230(%rbp)
  400680:       c5 fd 7f 85 b0 fd ff ff         vmovdqa %ymm0,-0x250(%rbp)
  400688:       c5 fd 7f 85 90 fd ff ff         vmovdqa %ymm0,-0x270(%rbp)
  400690:       c5 fd 7f 85 70 fd ff ff         vmovdqa %ymm0,-0x290(%rbp)
  400698:       0f 1f 84 00 00 00 00 00         nopl   0x0(%rax,%rax,1)
  4006a0:       48 83 c2 01                     add    $0x1,%rdx
  4006a4:       c6 84 05 f0 fc ff ff 01         movb   $0x1,-0x310(%rbp,%rax,1)
  4006ac:       0f b6 42 ff                     movzbl -0x1(%rdx),%eax
  4006b0:       84 c0                           test   %al,%al
  4006b2:       75 ec                           jne    4006a0 <_Z4Mainv+0x70>
  4006b4:       c5 f9 ef c0                     vpxor  %xmm0,%xmm0,%xmm0
  4006b8:       31 c0                           xor    %eax,%eax
  4006ba:       c5 fd 7f 85 50 fe ff ff         vmovdqa %ymm0,-0x1b0(%rbp)
  4006c2:       c5 fd 7f 85 30 fe ff ff         vmovdqa %ymm0,-0x1d0(%rbp)
  4006ca:       c5 fd 7f 85 10 fe ff ff         vmovdqa %ymm0,-0x1f0(%rbp)
  4006d2:       c5 fd 7f 85 f0 fd ff ff         vmovdqa %ymm0,-0x210(%rbp)
  4006da:       c5 fd 7f 85 d0 fe ff ff         vmovdqa %ymm0,-0x130(%rbp)
  4006e2:       c5 fd 7f 85 b0 fe ff ff         vmovdqa %ymm0,-0x150(%rbp)
  4006ea:       c5 fd 7f 85 90 fe ff ff         vmovdqa %ymm0,-0x170(%rbp)
  4006f2:       c5 fd 7f 85 70 fe ff ff         vmovdqa %ymm0,-0x190(%rbp)
  4006fa:       c5 fd 7f 85 f0 fe ff ff         vmovdqa %ymm0,-0x110(%rbp)
  400702:       c5 fd 7f 85 10 ff ff ff         vmovdqa %ymm0,-0xf0(%rbp)
  40070a:       c5 fd 7f 85 30 ff ff ff         vmovdqa %ymm0,-0xd0(%rbp)
  400712:       c5 fd 7f 85 50 ff ff ff         vmovdqa %ymm0,-0xb0(%rbp)
  40071a:       c5 fd 7f 85 70 ff ff ff         vmovdqa %ymm0,-0x90(%rbp)
  400722:       c5 fd 7f 45 90                  vmovdqa %ymm0,-0x70(%rbp)
  400727:       c5 fd 7f 45 b0                  vmovdqa %ymm0,-0x50(%rbp)
  40072c:       c5 fd 7f 45 d0                  vmovdqa %ymm0,-0x30(%rbp)
  400731:       0f 1f 80 00 00 00 00            nopl   0x0(%rax)
  400738:       0f b6 94 05 f0 fc ff ff         movzbl -0x310(%rbp,%rax,1),%edx
  400740:       0f b6 8c 05 f0 fe ff ff         movzbl -0x110(%rbp,%rax,1),%ecx
  400748:       84 d2                           test   %dl,%dl
  40074a:       75 08                           jne    400754 <_Z4Mainv+0x124>
  40074c:       0f b6 94 05 f0 fd ff ff         movzbl -0x210(%rbp,%rax,1),%edx
  400754:       38 d1                           cmp    %dl,%cl
  400756:       75 2c                           jne    400784 <_Z4Mainv+0x154>
  400758:       48 83 c0 01                     add    $0x1,%rax
  40075c:       48 3d 00 01 00 00               cmp    $0x100,%rax
  400762:       75 d4                           jne    400738 <_Z4Mainv+0x108>
  400764:       c5 f9 ef c0                     vpxor  %xmm0,%xmm0,%xmm0
  400768:       31 c0                           xor    %eax,%eax
  40076a:       c4 e2 7d 17 c0                  vptest %ymm0,%ymm0
  40076f:       0f 94 c0                        sete   %al
  400772:       c5 f8 77                        vzeroupper
  400775:       48 81 c4 08 03 00 00            add    $0x308,%rsp
  40077c:       41 5a                           pop    %r10
  40077e:       5d                              pop    %rbp
  40077f:       49 8d 62 f8                     lea    -0x8(%r10),%rsp
  400783:       c3                              retq
  400784:       b9 60 08 40 00                  mov    $0x400860,%ecx
  400789:       ba 26 00 00 00                  mov    $0x26,%edx
  40078e:       be 29 08 40 00                  mov    $0x400829,%esi
  400793:       bf 38 08 40 00                  mov    $0x400838,%edi
  400798:       c5 f8 77                        vzeroupper
  40079b:       e8 50 fd ff ff                  callq  4004f0 <__assert_fail@plt>
</code>```

Title: AVX2 support in GCC 5 and later

Body:
I wrote the following class "T" to accelerate manipulations of
"sets of characters" using AVX2. Then I found that it doesn't work in
gcc 5 and later when I use "-O3".
Can anyone help me trace this down to some programming construct that
is known not to work on the latest compilers/systems?

How this code works: The underlying structure ("_bits") is a block of 256 bytes (aligned and allocated for AVX2), which can be accessed either as char[256] or AVX2 elements, depending on whether an element is accessed or the whole thing is used in a vector operation. Seems like it should work perfectly well on the AVX2 platform. No?

This is really hard to debug, because "valgrind" says it's clean,
and I can't use a debugger (due to the problem disappearing when
I remove "-O3"). But I am not happy with just going with the "|="
workaround because if this code is really wrong, then I'm probably
making the same mistake in other places and screwing up everything
I develop!

It is interesting to note that the "|" operator has the problem but the
"|=" does not. Could the problem be related to returning a struct from
a function? But I thought that returning a struct has worked since 1990
or something.

// g++ -std=c++11 -mavx2 -O3 gcc_fail.cpp

#include "assert.h"
#include "immintrin.h" // AVX

class T {
public:
  __m256i _bits[8];
  inline bool& operator[](unsigned char c)       {return ((bool*)_bits)[c];}
  inline bool  operator[](unsigned char c) const {return ((bool*)_bits)[c];}
  inline          T()                   {}
  inline explicit T(char const*);
  inline T     operator| (T const& b) const;
  inline T &   operator|=(T const& b);
  inline bool  operator! ()           const;
};

T::T(char const* s)
{
  _bits[0] = _bits[1] = _bits[2] = _bits[3] = _mm256_set1_epi32(0);
  _bits[4] = _bits[5] = _bits[6] = _bits[7] = _mm256_set1_epi32(0);
  char c;
  while ((c = *s++))
    (*this)[c] = true;
}

T T::operator| (T const& b) const
{
  T res;
  for (int i = 0; i < 8; i++)
    res._bits[i] = _mm256_or_si256(_bits[i], b._bits[i]);

  // FIXME why does the above code fail with -O3 in new gcc?
  for (int i=0; i<256; i++)
    assert(res[i] == ((*this)[i] || b[i]));
  // gcc 4.7.0 - PASS
  // gcc 4.7.2 - PASS
  // gcc 4.8.0 - PASS
  // gcc 4.9.2 - PASS
  // gcc 5.2.0 - FAIL
  // gcc 5.3.0 - FAIL
  // gcc 5.3.1 - FAIL
  // gcc 6.1.0 - FAIL

  return res;
}

T & T::operator|=(T const& b)
{
  for (int i = 0; i < 8; i++)
    _bits[i] = _mm256_or_si256(_bits[i], b._bits[i]);
  return *this;
}

bool T::operator! () const
{
  for (int i = 0; i < 8; i++)
    if (!_mm256_testz_si256(_bits[i], _bits[i]))
      return false;
  return true;
}

int Main()
{
  T sep (" ,\t\n");
  T end ("");
  return !(sep|end);
}

int main()
{
  return Main();
}

Body:
Your code's problem is the use of bool* when you should have been using unsigned char*, which allowed GCC 5 to proceed with a pointer alias optimization.

The two dumps of the machine code for function Main(), produced both by GCC 4.8.5 and 5.3.1, are at the end of this answer in appendix for reference.

Looking at the code:

Decompilation

After the prologue, T sep's _bits are initialized to zero...

  _bits[0] = _bits[1] = _bits[2] = _bits[3] = _mm256_set1_epi32(0);
  _bits[4] = _bits[5] = _bits[6] = _bits[7] = _mm256_set1_epi32(0);

  40063d:       c5 fd 7f 44 24 60               vmovdqa %ymm0,0x60(%rsp)
  400643:       c5 fd 7f 44 24 40               vmovdqa %ymm0,0x40(%rsp)
  400649:       c5 fd 7f 44 24 20               vmovdqa %ymm0,0x20(%rsp)
  40064f:       c5 fd 7f 04 24                  vmovdqa %ymm0,(%rsp)
  400654:       c5 fd 7f 84 24 e0 00 00 00      vmovdqa %ymm0,0xe0(%rsp)
  40065d:       c5 fd 7f 84 24 c0 00 00 00      vmovdqa %ymm0,0xc0(%rsp)
  400666:       c5 fd 7f 84 24 a0 00 00 00      vmovdqa %ymm0,0xa0(%rsp)
  40066f:       c5 fd 7f 84 24 80 00 00 00      vmovdqa %ymm0,0x80(%rsp)

and then written to in a loop based on char* s.

  char c;
  while ((c = *s++))
    (*this)[c] = true;

  400680:       48 83 c2 01                     add    $0x1,%rdx
  400684:       c6 04 04 01                     movb   $0x1,(%rsp,%rax,1)
  400688:       0f b6 42 ff                     movzbl -0x1(%rdx),%eax
  40068c:       84 c0                           test   %al,%al
  40068e:       75 f0                           jne    400680 <_Z4Mainv+0x60>

Both compilers then initialize T end to 0s:

  400690:       c5 f9 ef c0                     vpxor  %xmm0,%xmm0,%xmm0
  400694:       31 c0                           xor    %eax,%eax
  400696:       c5 fd 7f 84 24 60 01 00 00      vmovdqa %ymm0,0x160(%rsp)
  40069f:       c5 fd 7f 84 24 40 01 00 00      vmovdqa %ymm0,0x140(%rsp)
  4006a8:       c5 fd 7f 84 24 20 01 00 00      vmovdqa %ymm0,0x120(%rsp)
  4006b1:       c5 fd 7f 84 24 00 01 00 00      vmovdqa %ymm0,0x100(%rsp)
  4006ba:       c5 fd 7f 84 24 e0 01 00 00      vmovdqa %ymm0,0x1e0(%rsp)
  4006c3:       c5 fd 7f 84 24 c0 01 00 00      vmovdqa %ymm0,0x1c0(%rsp)
  4006cc:       c5 fd 7f 84 24 a0 01 00 00      vmovdqa %ymm0,0x1a0(%rsp)
  4006d5:       c5 fd 7f 84 24 80 01 00 00      vmovdqa %ymm0,0x180(%rsp)

Both compilers then optimize out the _mm256_or_si256() operations because T end is known to be 0. But then, GCC 4.8.5 copies from T sep to T res (which is computationally what happens when you OR anything into a zero variable), while GCC 5.3.1 initializes T res to 0. It's entitled to do that because in your operator [] method you cast a pointer of type __m256i* to bool*, and the compiler is permitted to assume the pointers do not alias. Thus in GCC 4.8.5 you see

  4006de:       c5 fd 6f 04 24                  vmovdqa (%rsp),%ymm0
  4006e3:       c5 fd 7f 84 24 00 02 00 00      vmovdqa %ymm0,0x200(%rsp)
  4006ec:       c5 fd 6f 44 24 20               vmovdqa 0x20(%rsp),%ymm0
  4006f2:       c5 fd 7f 84 24 20 02 00 00      vmovdqa %ymm0,0x220(%rsp)
  4006fb:       c5 fd 6f 44 24 40               vmovdqa 0x40(%rsp),%ymm0
  400701:       c5 fd 7f 84 24 40 02 00 00      vmovdqa %ymm0,0x240(%rsp)
  40070a:       c5 fd 6f 44 24 60               vmovdqa 0x60(%rsp),%ymm0
  400710:       c5 fd 7f 84 24 60 02 00 00      vmovdqa %ymm0,0x260(%rsp)
  400719:       c5 fd 6f 84 24 80 00 00 00      vmovdqa 0x80(%rsp),%ymm0
  400722:       c5 fd 7f 84 24 80 02 00 00      vmovdqa %ymm0,0x280(%rsp)
  40072b:       c5 fd 6f 84 24 a0 00 00 00      vmovdqa 0xa0(%rsp),%ymm0
  400734:       c5 fd 7f 84 24 a0 02 00 00      vmovdqa %ymm0,0x2a0(%rsp)
  40073d:       c5 fd 6f 84 24 c0 00 00 00      vmovdqa 0xc0(%rsp),%ymm0
  400746:       c5 fd 7f 84 24 c0 02 00 00      vmovdqa %ymm0,0x2c0(%rsp)
  40074f:       c5 fd 6f 84 24 e0 00 00 00      vmovdqa 0xe0(%rsp),%ymm0
  400758:       c5 fd 7f 84 24 e0 02 00 00      vmovdqa %ymm0,0x2e0(%rsp)

while in GCC 5.3.1 you see

  4006fa:       c5 fd 7f 85 f0 fe ff ff         vmovdqa %ymm0,-0x110(%rbp)
  400702:       c5 fd 7f 85 10 ff ff ff         vmovdqa %ymm0,-0xf0(%rbp)
  40070a:       c5 fd 7f 85 30 ff ff ff         vmovdqa %ymm0,-0xd0(%rbp)
  400712:       c5 fd 7f 85 50 ff ff ff         vmovdqa %ymm0,-0xb0(%rbp)
  40071a:       c5 fd 7f 85 70 ff ff ff         vmovdqa %ymm0,-0x90(%rbp)
  400722:       c5 fd 7f 45 90                  vmovdqa %ymm0,-0x70(%rbp)
  400727:       c5 fd 7f 45 b0                  vmovdqa %ymm0,-0x50(%rbp)
  40072c:       c5 fd 7f 45 d0                  vmovdqa %ymm0,-0x30(%rbp)

Whereupon the reads for the assert() then fail.

The Standard's Ruling on Pointer Aliasing:

ISO C++11 refers to aliasing under the following section, which makes clear that variables of type __m256i* cannot be accessed using bool*, but may be accessed with a char*/unsigned char*:

§ 3.10 Lvalues and rvalues [basic.lval]

[...]

If a program attempts to access the stored value of an object through a glvalue of other than one of the following types the behavior is undefined: [52]

the dynamic type of the object,

a cv-qualified version of the dynamic type of the object,

a type similar (as defined in 4.4) to the dynamic type of the object,

a type that is the signed or unsigned type corresponding to the dynamic type of the object,

a type that is the signed or unsigned type corresponding to a cv-qualified version of the dynamic type of the object,

an aggregate or union type that includes one of the aforementioned types among its elements or non-static data members (including, recursively, an element or non-static data member of a subaggregate or contained union),

a type that is a (possibly cv-qualified) base class type of the dynamic type of the object,

a char or unsigned char type.

52) The intent of this list is to specify those circumstances in which an object may or may not be aliased.

Appendix

GCC 4.8.5:

0000000000400620 <_Z4Mainv>:
  400620:       55                              push   %rbp
  400621:       c5 f9 ef c0                     vpxor  %xmm0,%xmm0,%xmm0
  400625:       ba e5 08 40 00                  mov    $0x4008e5,%edx
  40062a:       b8 20 00 00 00                  mov    $0x20,%eax
  40062f:       48 89 e5                        mov    %rsp,%rbp
  400632:       48 83 e4 e0                     and    $0xffffffffffffffe0,%rsp
  400636:       48 81 ec 00 03 00 00            sub    $0x300,%rsp
  40063d:       c5 fd 7f 44 24 60               vmovdqa %ymm0,0x60(%rsp)
  400643:       c5 fd 7f 44 24 40               vmovdqa %ymm0,0x40(%rsp)
  400649:       c5 fd 7f 44 24 20               vmovdqa %ymm0,0x20(%rsp)
  40064f:       c5 fd 7f 04 24                  vmovdqa %ymm0,(%rsp)
  400654:       c5 fd 7f 84 24 e0 00 00 00      vmovdqa %ymm0,0xe0(%rsp)
  40065d:       c5 fd 7f 84 24 c0 00 00 00      vmovdqa %ymm0,0xc0(%rsp)
  400666:       c5 fd 7f 84 24 a0 00 00 00      vmovdqa %ymm0,0xa0(%rsp)
  40066f:       c5 fd 7f 84 24 80 00 00 00      vmovdqa %ymm0,0x80(%rsp)
  400678:       0f 1f 84 00 00 00 00 00         nopl   0x0(%rax,%rax,1)
  400680:       48 83 c2 01                     add    $0x1,%rdx
  400684:       c6 04 04 01                     movb   $0x1,(%rsp,%rax,1)
  400688:       0f b6 42 ff                     movzbl -0x1(%rdx),%eax
  40068c:       84 c0                           test   %al,%al
  40068e:       75 f0                           jne    400680 <_Z4Mainv+0x60>
  400690:       c5 f9 ef c0                     vpxor  %xmm0,%xmm0,%xmm0
  400694:       31 c0                           xor    %eax,%eax
  400696:       c5 fd 7f 84 24 60 01 00 00      vmovdqa %ymm0,0x160(%rsp)
  40069f:       c5 fd 7f 84 24 40 01 00 00      vmovdqa %ymm0,0x140(%rsp)
  4006a8:       c5 fd 7f 84 24 20 01 00 00      vmovdqa %ymm0,0x120(%rsp)
  4006b1:       c5 fd 7f 84 24 00 01 00 00      vmovdqa %ymm0,0x100(%rsp)
  4006ba:       c5 fd 7f 84 24 e0 01 00 00      vmovdqa %ymm0,0x1e0(%rsp)
  4006c3:       c5 fd 7f 84 24 c0 01 00 00      vmovdqa %ymm0,0x1c0(%rsp)
  4006cc:       c5 fd 7f 84 24 a0 01 00 00      vmovdqa %ymm0,0x1a0(%rsp)
  4006d5:       c5 fd 7f 84 24 80 01 00 00      vmovdqa %ymm0,0x180(%rsp)
  4006de:       c5 fd 6f 04 24                  vmovdqa (%rsp),%ymm0
  4006e3:       c5 fd 7f 84 24 00 02 00 00      vmovdqa %ymm0,0x200(%rsp)
  4006ec:       c5 fd 6f 44 24 20               vmovdqa 0x20(%rsp),%ymm0
  4006f2:       c5 fd 7f 84 24 20 02 00 00      vmovdqa %ymm0,0x220(%rsp)
  4006fb:       c5 fd 6f 44 24 40               vmovdqa 0x40(%rsp),%ymm0
  400701:       c5 fd 7f 84 24 40 02 00 00      vmovdqa %ymm0,0x240(%rsp)
  40070a:       c5 fd 6f 44 24 60               vmovdqa 0x60(%rsp),%ymm0
  400710:       c5 fd 7f 84 24 60 02 00 00      vmovdqa %ymm0,0x260(%rsp)
  400719:       c5 fd 6f 84 24 80 00 00 00      vmovdqa 0x80(%rsp),%ymm0
  400722:       c5 fd 7f 84 24 80 02 00 00      vmovdqa %ymm0,0x280(%rsp)
  40072b:       c5 fd 6f 84 24 a0 00 00 00      vmovdqa 0xa0(%rsp),%ymm0
  400734:       c5 fd 7f 84 24 a0 02 00 00      vmovdqa %ymm0,0x2a0(%rsp)
  40073d:       c5 fd 6f 84 24 c0 00 00 00      vmovdqa 0xc0(%rsp),%ymm0
  400746:       c5 fd 7f 84 24 c0 02 00 00      vmovdqa %ymm0,0x2c0(%rsp)
  40074f:       c5 fd 6f 84 24 e0 00 00 00      vmovdqa 0xe0(%rsp),%ymm0
  400758:       c5 fd 7f 84 24 e0 02 00 00      vmovdqa %ymm0,0x2e0(%rsp)
  400761:       0f 1f 80 00 00 00 00            nopl   0x0(%rax)
  400768:       80 3c 04 00                     cmpb   $0x0,(%rsp,%rax,1)
  40076c:       0f b6 8c 04 00 02 00 00         movzbl 0x200(%rsp,%rax,1),%ecx
  400774:       ba 01 00 00 00                  mov    $0x1,%edx
  400779:       75 08                           jne    400783 <_Z4Mainv+0x163>
  40077b:       0f b6 94 04 00 01 00 00         movzbl 0x100(%rsp,%rax,1),%edx
  400783:       38 d1                           cmp    %dl,%cl
  400785:       0f 85 b2 00 00 00               jne    40083d <_Z4Mainv+0x21d>
  40078b:       48 83 c0 01                     add    $0x1,%rax
  40078f:       48 3d 00 01 00 00               cmp    $0x100,%rax
  400795:       75 d1                           jne    400768 <_Z4Mainv+0x148>
  400797:       c5 fd 6f 8c 24 00 02 00 00      vmovdqa 0x200(%rsp),%ymm1
  4007a0:       31 c0                           xor    %eax,%eax
  4007a2:       c4 e2 7d 17 c9                  vptest %ymm1,%ymm1
  4007a7:       0f 94 c0                        sete   %al
  4007aa:       0f 85 88 00 00 00               jne    400838 <_Z4Mainv+0x218>
  4007b0:       c5 fd 6f 8c 24 20 02 00 00      vmovdqa 0x220(%rsp),%ymm1
  4007b9:       31 c0                           xor    %eax,%eax
  4007bb:       c4 e2 7d 17 c9                  vptest %ymm1,%ymm1
  4007c0:       0f 94 c0                        sete   %al
  4007c3:       75 73                           jne    400838 <_Z4Mainv+0x218>
  4007c5:       c5 fd 6f 8c 24 40 02 00 00      vmovdqa 0x240(%rsp),%ymm1
  4007ce:       31 c0                           xor    %eax,%eax
  4007d0:       c4 e2 7d 17 c9                  vptest %ymm1,%ymm1
  4007d5:       0f 94 c0                        sete   %al
  4007d8:       75 5e                           jne    400838 <_Z4Mainv+0x218>
  4007da:       c5 fd 6f 8c 24 60 02 00 00      vmovdqa 0x260(%rsp),%ymm1
  4007e3:       31 c0                           xor    %eax,%eax
  4007e5:       c4 e2 7d 17 c9                  vptest %ymm1,%ymm1
  4007ea:       0f 94 c0                        sete   %al
  4007ed:       75 49                           jne    400838 <_Z4Mainv+0x218>
  4007ef:       c5 fd 6f 8c 24 80 02 00 00      vmovdqa 0x280(%rsp),%ymm1
  4007f8:       31 c0                           xor    %eax,%eax
  4007fa:       c4 e2 7d 17 c9                  vptest %ymm1,%ymm1
  4007ff:       0f 94 c0                        sete   %al
  400802:       75 34                           jne    400838 <_Z4Mainv+0x218>
  400804:       c5 fd 6f 8c 24 a0 02 00 00      vmovdqa 0x2a0(%rsp),%ymm1
  40080d:       31 c0                           xor    %eax,%eax
  40080f:       c4 e2 7d 17 c9                  vptest %ymm1,%ymm1
  400814:       0f 94 c0                        sete   %al
  400817:       75 1f                           jne    400838 <_Z4Mainv+0x218>
  400819:       c5 fd 6f 8c 24 c0 02 00 00      vmovdqa 0x2c0(%rsp),%ymm1
  400822:       31 c0                           xor    %eax,%eax
  400824:       c4 e2 7d 17 c9                  vptest %ymm1,%ymm1
  400829:       0f 94 c0                        sete   %al
  40082c:       75 0a                           jne    400838 <_Z4Mainv+0x218>
  40082e:       31 c0                           xor    %eax,%eax
  400830:       c4 e2 7d 17 c0                  vptest %ymm0,%ymm0
  400835:       0f 94 c0                        sete   %al
  400838:       c5 f8 77                        vzeroupper
  40083b:       c9                              leaveq
  40083c:       c3                              retq
  40083d:       b9 20 09 40 00                  mov    $0x400920,%ecx
  400842:       ba 26 00 00 00                  mov    $0x26,%edx
  400847:       be e9 08 40 00                  mov    $0x4008e9,%esi
  40084c:       bf f8 08 40 00                  mov    $0x4008f8,%edi
  400851:       c5 f8 77                        vzeroupper
  400854:       e8 97 fc ff ff                  callq  4004f0 <__assert_fail@plt>
  400859:       0f 1f 80 00 00 00 00            nopl   0x0(%rax)

GCC 5:

0000000000400630 <_Z4Mainv>:
  400630:       4c 8d 54 24 08                  lea    0x8(%rsp),%r10
  400635:       48 83 e4 e0                     and    $0xffffffffffffffe0,%rsp
  400639:       b8 20 00 00 00                  mov    $0x20,%eax
  40063e:       c5 f9 ef c0                     vpxor  %xmm0,%xmm0,%xmm0
  400642:       ba 25 08 40 00                  mov    $0x400825,%edx
  400647:       41 ff 72 f8                     pushq  -0x8(%r10)
  40064b:       55                              push   %rbp
  40064c:       48 89 e5                        mov    %rsp,%rbp
  40064f:       41 52                           push   %r10
  400651:       48 81 ec 08 03 00 00            sub    $0x308,%rsp
  400658:       c5 fd 7f 85 50 fd ff ff         vmovdqa %ymm0,-0x2b0(%rbp)
  400660:       c5 fd 7f 85 30 fd ff ff         vmovdqa %ymm0,-0x2d0(%rbp)
  400668:       c5 fd 7f 85 10 fd ff ff         vmovdqa %ymm0,-0x2f0(%rbp)
  400670:       c5 fd 7f 85 f0 fc ff ff         vmovdqa %ymm0,-0x310(%rbp)
  400678:       c5 fd 7f 85 d0 fd ff ff         vmovdqa %ymm0,-0x230(%rbp)
  400680:       c5 fd 7f 85 b0 fd ff ff         vmovdqa %ymm0,-0x250(%rbp)
  400688:       c5 fd 7f 85 90 fd ff ff         vmovdqa %ymm0,-0x270(%rbp)
  400690:       c5 fd 7f 85 70 fd ff ff         vmovdqa %ymm0,-0x290(%rbp)
  400698:       0f 1f 84 00 00 00 00 00         nopl   0x0(%rax,%rax,1)
  4006a0:       48 83 c2 01                     add    $0x1,%rdx
  4006a4:       c6 84 05 f0 fc ff ff 01         movb   $0x1,-0x310(%rbp,%rax,1)
  4006ac:       0f b6 42 ff                     movzbl -0x1(%rdx),%eax
  4006b0:       84 c0                           test   %al,%al
  4006b2:       75 ec                           jne    4006a0 <_Z4Mainv+0x70>
  4006b4:       c5 f9 ef c0                     vpxor  %xmm0,%xmm0,%xmm0
  4006b8:       31 c0                           xor    %eax,%eax
  4006ba:       c5 fd 7f 85 50 fe ff ff         vmovdqa %ymm0,-0x1b0(%rbp)
  4006c2:       c5 fd 7f 85 30 fe ff ff         vmovdqa %ymm0,-0x1d0(%rbp)
  4006ca:       c5 fd 7f 85 10 fe ff ff         vmovdqa %ymm0,-0x1f0(%rbp)
  4006d2:       c5 fd 7f 85 f0 fd ff ff         vmovdqa %ymm0,-0x210(%rbp)
  4006da:       c5 fd 7f 85 d0 fe ff ff         vmovdqa %ymm0,-0x130(%rbp)
  4006e2:       c5 fd 7f 85 b0 fe ff ff         vmovdqa %ymm0,-0x150(%rbp)
  4006ea:       c5 fd 7f 85 90 fe ff ff         vmovdqa %ymm0,-0x170(%rbp)
  4006f2:       c5 fd 7f 85 70 fe ff ff         vmovdqa %ymm0,-0x190(%rbp)
  4006fa:       c5 fd 7f 85 f0 fe ff ff         vmovdqa %ymm0,-0x110(%rbp)
  400702:       c5 fd 7f 85 10 ff ff ff         vmovdqa %ymm0,-0xf0(%rbp)
  40070a:       c5 fd 7f 85 30 ff ff ff         vmovdqa %ymm0,-0xd0(%rbp)
  400712:       c5 fd 7f 85 50 ff ff ff         vmovdqa %ymm0,-0xb0(%rbp)
  40071a:       c5 fd 7f 85 70 ff ff ff         vmovdqa %ymm0,-0x90(%rbp)
  400722:       c5 fd 7f 45 90                  vmovdqa %ymm0,-0x70(%rbp)
  400727:       c5 fd 7f 45 b0                  vmovdqa %ymm0,-0x50(%rbp)
  40072c:       c5 fd 7f 45 d0                  vmovdqa %ymm0,-0x30(%rbp)
  400731:       0f 1f 80 00 00 00 00            nopl   0x0(%rax)
  400738:       0f b6 94 05 f0 fc ff ff         movzbl -0x310(%rbp,%rax,1),%edx
  400740:       0f b6 8c 05 f0 fe ff ff         movzbl -0x110(%rbp,%rax,1),%ecx
  400748:       84 d2                           test   %dl,%dl
  40074a:       75 08                           jne    400754 <_Z4Mainv+0x124>
  40074c:       0f b6 94 05 f0 fd ff ff         movzbl -0x210(%rbp,%rax,1),%edx
  400754:       38 d1                           cmp    %dl,%cl
  400756:       75 2c                           jne    400784 <_Z4Mainv+0x154>
  400758:       48 83 c0 01                     add    $0x1,%rax
  40075c:       48 3d 00 01 00 00               cmp    $0x100,%rax
  400762:       75 d4                           jne    400738 <_Z4Mainv+0x108>
  400764:       c5 f9 ef c0                     vpxor  %xmm0,%xmm0,%xmm0
  400768:       31 c0                           xor    %eax,%eax
  40076a:       c4 e2 7d 17 c0                  vptest %ymm0,%ymm0
  40076f:       0f 94 c0                        sete   %al
  400772:       c5 f8 77                        vzeroupper
  400775:       48 81 c4 08 03 00 00            add    $0x308,%rsp
  40077c:       41 5a                           pop    %r10
  40077e:       5d                              pop    %rbp
  40077f:       49 8d 62 f8                     lea    -0x8(%r10),%rsp
  400783:       c3                              retq
  400784:       b9 60 08 40 00                  mov    $0x400860,%ecx
  400789:       ba 26 00 00 00                  mov    $0x26,%edx
  40078e:       be 29 08 40 00                  mov    $0x400829,%esi
  400793:       bf 38 08 40 00                  mov    $0x400838,%edi
  400798:       c5 f8 77                        vzeroupper
  40079b:       e8 50 fd ff ff                  callq  4004f0 <__assert_fail@plt>


来源: stackexchange

问:
Error in opening zip file in Android Studio
I was developing an app and then i just updated my android studio which failed due to some reasons. I tried updating again but it still failed then i re-installed android studio still the same error occurs. It was working perfectly all right before updation.My log is as below

31-03-2017 16:59  Platform and Plugin Updates: The following components
  are ready to update: Android Emulator, Android Support Repository,
  Google Repository, Intel x86 Emulator Accelerator (HAXM installer),
  Android SDK Platform-Tools, Android SDK Tools

17:01 Gradle sync started

17:01 Gradle sync failed: Cause: error in opening zip file            Consult
  IDE log for more details (Help | Show Log)

17:11 Gradle sync started

17:11 Gradle sync failed: Cause: error in opening zip file            Consult
  IDE log for more details (Help | Show Log)

17:35 FileNotFoundException:
  C:\Users\Shubham\AppData\Local\Temp\idea.updater.files7337844724625856855\temp5508043076486539057.tmp\lib\gles_angle11\libGLESv2.dll
  (The process cannot access the file because it is being used by
  another process)

18:13 Executing tasks: [clean, :app:generateDebugSources]

18:13 Gradle build finished with 1 error(s) in 382ms

答:
Delete the .gradle directories from both your home directory and from your project's root directory and try building again.

Right click on app select show in explorer to get projects directory.

or you can try deleting .gradle and build directories too in project's root directory.

ContentLicense: CC BY-SA 3.0


问:
How to pass arguments to an included file?
I'm trying to make the whole  section its own include file. One drawback is the title and description and keyword will be the same; I can't figure out how to pass arguments to the include file.

So here is the code:

index.php

```<code><?php include("header.php?header=aaaaaaaaaaaaaaaaaaaaa"); ?>

<body>
.....
..
.
</code>```

header.php

```<code><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<link rel="shortcut icon" href="favicon.ico">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="Keywords" content=" <?php $_GET["header"]?> " >
<meta name="Description" content=" <?php $_GET["header"]?> " >
<title> <?php $_GET["header"]?> </title>
<link rel="stylesheet" type="text/css" href="reset.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
</head>
</code>```

Obviously this doesn't work; how can I pass arguments to an included file?

答:
index.php:

```<code><?php
$my_header = 'aaaaaaaaaaaaaaaaaaaa';
include 'header.php';
?>
</code>```

and header.php

```<code><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="shortcut icon" href="favicon.ico" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="Keywords" content=" <?php echo $my_header ?> " />
<meta name="Description" content=" <?php echo $my_header ?> " />
<title> <?php echo $my_header ?> </title>
<link rel="stylesheet" type="text/css" href="reset.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
</head>
</code>```

It's not an ideal solution, but I understand it's your first steps in php.

PS. Your Doctype doesn't match the code. I've adjusted your header html to be XHTML.

ContentLicense: CC BY-SA 2.5

Body:
I'm trying to make the whole  section its own include file. One drawback is the title and description and keyword will be the same; I can't figure out how to pass arguments to the include file.

So here is the code:

index.php

<?php include("header.php?header=aaaaaaaaaaaaaaaaaaaaa"); ?>

.....
..
.

header.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<link rel="shortcut icon" href="favicon.ico">

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="Keywords" content=" <?php $_GET["header"]?> " >
<meta name="Description" content=" <?php $_GET["header"]?> " >
<title> <?php $_GET["header"]?> </title>
<link rel="stylesheet" type="text/css" href="reset.css" />

Obviously this doesn't work; how can I pass arguments to an included file?

Body:
index.php:

<?php
$my_header = 'aaaaaaaaaaaaaaaaaaaa';
include 'header.php';
?>

and header.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="shortcut icon" href="favicon.ico" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="Keywords" content=" <?php echo $my_header ?> " />
<meta name="Description" content=" <?php echo $my_header ?> " />
<title> <?php echo $my_header ?> </title>
<link rel="stylesheet" type="text/css" href="reset.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
</head>

It's not an ideal solution, but I understand it's your first steps in php.

PS. Your Doctype doesn't match the code. I've adjusted your header html to be XHTML.


问:
Splitting large html file in several files
I want to preface the following by saying that I am pretty novice at html coding.

I am currently building a relatively large database (2000 entries) in excel and I want to make that database available on my website. What I started doing is converting the excel data to html data, and then using the DataTables jQuery plugin to convert it into a nice searchable html table. Here is what my code looks like:

```<code><html>
<head>

<link rel="stylesheet" type="text/css" href="DataTables-1.10.13/datatables.min.css"/>
<script type="text/javascript" src="https://cdn.datatables.net/v/dt/jq-2.2.4/dt-1.10.13/fh-3.1.2/datatables.min.js"></script>

<style>
  some style options
</style>

<script type="text/javascript" charset="utf-8">
  $(document).ready(function() {
    $('#booklist').dataTable({
    });
  });
</script>
</head>

<body>
<table id="booklist" class="display">
 Table data here
</table>
</body>
</html>
</code>```

I am still updating periodically the database, and having to copy and paste the new table data in the document every time is annoying, especially since it represents around 10000 lines.

I was wondering if there is a way to keep the table data in a separate file, say b.html, and importing it in such a way as it would be interpreted the same way as simply pasting the content of it directly where "Table data here" appears in my original code.

I tried using jQuery .load() function, but could not get it to work. Is it problematic that I am using CSS formatting?

Let me know what you think is the best solution to my problem.

Thank you!

答:
You can use <link> element with rel attribute set to import, get data using .import property of link element, which returns a document

```<code><link rel="import" type="text/html" href="b.html" />
</code>```

<link id="data"
      rel="import"
      type="text/html"
      href='data:text/html,{"abc":123, "def":[4,5,6]}' />

```

Body:
I want to preface the following by saying that I am pretty novice at html coding.

I am currently building a relatively large database (2000 entries) in excel and I want to make that database available on my website. What I started doing is converting the excel data to html data, and then using the DataTables jQuery plugin to convert it into a nice searchable html table. Here is what my code looks like:

<link rel="stylesheet" type="text/css" href="DataTables-1.10.13/datatables.min.css"/>

 Table data here

I am still updating periodically the database, and having to copy and paste the new table data in the document every time is annoying, especially since it represents around 10000 lines.

I was wondering if there is a way to keep the table data in a separate file, say b.html, and importing it in such a way as it would be interpreted the same way as simply pasting the content of it directly where "Table data here" appears in my original code.

I tried using jQuery .load() function, but could not get it to work. Is it problematic that I am using CSS formatting?

Let me know what you think is the best solution to my problem.

Thank you!

Body:
You can use <link> element with rel attribute set to import, get data using .import property of link element, which returns a document

<link rel="import" type="text/html" href="b.html" />

<head>
<link id="data"
      rel="import"
      type="text/html"
      href='data:text/html,{"abc":123, "def":[4,5,6]}' />
</head>
<body>
  <script>
    const data = document.getElementById("data");
    let entries = JSON.parse(data.import.body.textContent);

    console.log(entries);
    /*
    $(document).ready(function() {
      $('#booklist').dataTable({
        // populate `.dataTable()` with selected `entries`
      })
    });
    */

  </script>
</body>


问:
Simple breadcrum logo in jsx of react binding
```<code>{breadcrumbs.map((obj,i) =>
    <p> {i} > 1 ? "<span className="seperator">|</span>" : <span className="bold">{obj}</span> </p>
)}
</code>```

I want to make breadcrumbs from an array but failed using above code. breadcrumbs is just an array ['books','javascript'] and my expected output will be

Books -> javascript and so on, it should be working if I have more than 2 item in the array.

答:
I am not sure in the syntax, as I'm not a React user, but the base logic is bad. If you doing a breadcrumb, you should put separators between the entries except the last one. Based on HJ Cross's answer, here is the correct code you looking for:

```<code>var arry = ['books','javascript', 'reactJS'];
ReactDOM.render(
  <div>
    {arry.map((obj,i) =>
      <p key={i}><span className="bold">{obj}</span>{
        i < arry.length - 1
          ?  <span className="seperator">-></span>
          : <span className="none"></span>
      }</p>
    )}
  </div>,
  document.getElementById('container')
);
</code>```

Body:
{breadcrumbs.map((obj,i) =>

 {i} > 1 ? "|" : {obj}

)}

I want to make breadcrumbs from an array but failed using above code. breadcrumbs is just an array ['books','javascript'] and my expected output will be

Books -> javascript and so on, it should be working if I have more than 2 item in the array.

Body:
I am not sure in the syntax, as I'm not a React user, but the base logic is bad. If you doing a breadcrumb, you should put separators between the entries except the last one. Based on HJ Cross's answer, here is the correct code you looking for:

var arry = ['books','javascript', 'reactJS'];
ReactDOM.render(
  <div>
    {arry.map((obj,i) =>
      <p key={i}><span className="bold">{obj}</span>{
        i < arry.length - 1
          ?  <span className="seperator">-&gt;</span>
          : <span className="none"></span>
      }</p>
    )}
  </div>,
  document.getElementById('container')
);


问:
Batch File to zip files - apply to sub directories
I'm looking to get a batch file to apply to all sub directories.

I have a number of folders. Each folder will contain file pairs

xxx1.mp3 and xxx1.cdg,

xxx2.mp3 and xxx2.cdg,

etc.

I have a 7zip batch file that will look for file pairs and create a single zip file xxx1.zip, xxx2.zip and delete the (now) redundant cdg/mp3 files.

However, this will only work if the bat file is run in each individual folder. What I'm really looking for is a switch to add to the bat file that if I run in the root directory, will run through all sub directories also.

The code I currently run is:

```<code>FOR  %F IN (*.cdg) DO "C:\Program Files\7-Zip\7Z.exe" a "%~nF.zip" "%~nF.cdg" "%~nF.mp3" -sdel
</code>```

Any help?

答:
```<code>FOR /R %%F IN (*.cdg) DO IF EXIST "%%~dpnF.mp3" pushd "%%~dpF"&ECHO("C:\Program Files\7-Zip\7Z.exe" a "%%~nF.zip" "%%~nF.cdg" "%%~nF.mp3" -sdel&POPD
</code>```

Note that this is a batch line - to execute from the prompt, reduce each %% in metavariable to % (but it's a whole lot easier to put it into a batch by cut-and-paste;saves all those typos...)

The required commands are merely ECHOed for testing purposes. After you've verified that the commands are correct, delete the string ECHO( which appears before your command to actually execute the commands.

Using for /r will iterate through the filenames matching the supplied mask (it's possible to also add a starting directory - see for /?|more from the prompt.)

Since we know the selected full filename exists, first check that the paired file exists, then switch to the required directory, archive, and switch back.

Body:
I'm looking to get a batch file to apply to all sub directories.

I have a number of folders. Each folder will contain file pairs

xxx1.mp3 and xxx1.cdg,

xxx2.mp3 and xxx2.cdg,

etc.

I have a 7zip batch file that will look for file pairs and create a single zip file xxx1.zip, xxx2.zip and delete the (now) redundant cdg/mp3 files.

However, this will only work if the bat file is run in each individual folder. What I'm really looking for is a switch to add to the bat file that if I run in the root directory, will run through all sub directories also.

The code I currently run is:

FOR  %F IN (*.cdg) DO "C:\Program Files\7-Zip\7Z.exe" a "%~nF.zip" "%~nF.cdg" "%~nF.mp3" -sdel

Any help?

Body:
FOR /R %%F IN (*.cdg) DO IF EXIST "%%~dpnF.mp3" pushd "%%~dpF"&ECHO("C:\Program Files\7-Zip\7Z.exe" a "%%~nF.zip" "%%~nF.cdg" "%%~nF.mp3" -sdel&POPD

Note that this is a batch line - to execute from the prompt, reduce each %% in metavariable to % (but it's a whole lot easier to put it into a batch by cut-and-paste;saves all those typos...)

The required commands are merely ECHOed for testing purposes. After you've verified that the commands are correct, delete the string ECHO( which appears before your command to actually execute the commands.

Using for /r will iterate through the filenames matching the supplied mask (it's possible to also add a starting directory - see for /?|more from the prompt.)

Since we know the selected full filename exists, first check that the paired file exists, then switch to the required directory, archive, and switch back.


问:
How to assign a package to a variable in Go?
First of all, the word "variable" might be wrong in the question but I assume the detailed question explains why I'm using the word "variable".

I have two packages with different names but the exact same function(s).

Depending on the input of the user I want to use the function of a package. But instead of switching over the packages I would like to assign the package to a new function with a generic name, how to do this? And if it's not possible, why?

```<code>// foo/bar.go

package foo

func Test() {
    fmt.Println("hola from bar")
}
</code>```

```<code>// baz/bar.go

package baz

func Test() {
    fmt.Println("hola from baz")
}
</code>```

```<code>// main.go

package main

import (
    "foo"
    "baz"
)

func main() {

    thePackage := flag.String("package", "foo", "a package")

    if thePackage == "foo" {
        howToSetThis := foo // How to do this?
    } else {
        howToSetThis := baz // How to do this?
    }

    howToSetThis.Test() // execs Println from one of the two bar.go files

}
</code>```

In JavaScript I would do something like (simplified):

```<code>function foo(){
  console.log("hola from foo")
}

function baz(){
  console.log("hola from baz")
}

if(somethingInput == "foo"){
  var howToSetThis = foo;
} else {
  var howToSetThis = baz;
}

howToSetThis();
</code>```

答:
At compile time import is practically if not the first directive to get parsed.  That means whatever package name is present in the import directive will be the one used as reference in parsing everything else.

Hence you can't use a dynamic language structure like what you did in Javascript.  Cerise's answer is correct.

Body:
First of all, the word "variable" might be wrong in the question but I assume the detailed question explains why I'm using the word "variable".

I have two packages with different names but the exact same function(s).

Depending on the input of the user I want to use the function of a package. But instead of switching over the packages I would like to assign the package to a new function with a generic name, how to do this? And if it's not possible, why?

// foo/bar.go

package foo

func Test() {
    fmt.Println("hola from bar")
}

// baz/bar.go

package baz

func Test() {
    fmt.Println("hola from baz")
}

// main.go

package main

import (
    "foo"
    "baz"
)

func main() {

    thePackage := flag.String("package", "foo", "a package")

    if thePackage == "foo" {
        howToSetThis := foo // How to do this?
    } else {
        howToSetThis := baz // How to do this?
    }

    howToSetThis.Test() // execs Println from one of the two bar.go files

}

In JavaScript I would do something like (simplified):

function foo(){
  console.log("hola from foo")
}

function baz(){
  console.log("hola from baz")
}

if(somethingInput == "foo"){
  var howToSetThis = foo;
} else {
  var howToSetThis = baz;
}

howToSetThis();


问:
Using a generator resulting in insufficient memory error
I have the following generator in python. It takes in samples which is an array which consists of x rows where each row looks something like this

```<code>['some\\path\\center.jpg', 'some\\path\\left.jpg', 'some\\path\\right.jpg', 'someNumber']

def generator(samples, batch_size):
num_samples = len(samples)
while 1: # Loop forever so the generator never terminates
    shuffle(samples)
    for offset in range(0, num_samples, batch_size):
        batch_samples = samples[offset:offset+batch_size]

        for batch_sample in batch_samples:

            source_path = np.random.choice([batch_sample[0], batch_sample[1], batch_sample[2]])
            filename = source_path.split(os.sep)[-1]
            current_path = 'data20/IMG/' + filename
            current_image = cv2.imread(current_path)
            current_angle = float(batch_sample[3])

            if source_path == line[1]:
                current_angle += 0.2

            elif source_path == line[2]:
                current_angle -= 0.2

            images.append(current_image)
            angles.append(current_angle)

        # trim image to only see section with road
        X_train = np.array(images)
        y_train = np.array(angles)
        yield (X_train, y_train)
</code>```

Then I have some CNN where I train the network with the generator with the given function

```<code>model.fit_generator(train_generator, samples_per_epoch=len(train_samples), validation_data=validation_generator, nb_val_samples=len(validation_samples), nb_epoch=5)
</code>```

My Question: How come the time rises during training, so that it takes longer and longer.. leading to insufficient memory for a batch size of lets say 32??

答:
As Dref360 mentioned, I do not clear image and angle inside my generator. The main Problem was that i put

```<code>images = []
angles = []
</code>```

outside of my generator, which resulted in both growing each cycle, where they should have been inside my generator. Below is the working code:

```<code>['some\\path\\center.jpg', 'some\\path\\left.jpg', 'some\\path\\right.jpg', 'someNumber']

def generator(samples, batch_size):
num_samples = len(samples)
while 1: # Loop forever so the generator never terminates
    shuffle(samples)
    for offset in range(0, num_samples, batch_size):
        batch_samples = samples[offset:offset+batch_size]

        images = []
        angles = []
        for batch_sample in batch_samples:

            source_path = np.random.choice([batch_sample[0], batch_sample[1], batch_sample[2]])
            filename = source_path.split(os.sep)[-1]
            current_path = 'data20/IMG/' + filename
            current_image = cv2.imread(current_path)
            current_angle = float(batch_sample[3])

            if source_path == line[1]:
                current_angle += 0.2

            elif source_path == line[2]:
                current_angle -= 0.2

            images.append(current_image)
            angles.append(current_angle)

        # trim image to only see section with road
        X_train = np.array(images)
        y_train = np.array(angles)
        yield (X_train, y_train)
</code>```

Big thanks to Dref360 :D

Body:
I have the following generator in python. It takes in samples which is an array which consists of x rows where each row looks something like this

['some\\path\\center.jpg', 'some\\path\\left.jpg', 'some\\path\\right.jpg', 'someNumber']

def generator(samples, batch_size):
num_samples = len(samples)
while 1: # Loop forever so the generator never terminates
    shuffle(samples)
    for offset in range(0, num_samples, batch_size):
        batch_samples = samples[offset:offset+batch_size]

        for batch_sample in batch_samples:

            source_path = np.random.choice([batch_sample[0], batch_sample[1], batch_sample[2]])
            filename = source_path.split(os.sep)[-1]
            current_path = 'data20/IMG/' + filename
            current_image = cv2.imread(current_path)
            current_angle = float(batch_sample[3])

            if source_path == line[1]:
                current_angle += 0.2

            elif source_path == line[2]:
                current_angle -= 0.2

            images.append(current_image)
            angles.append(current_angle)

        # trim image to only see section with road
        X_train = np.array(images)
        y_train = np.array(angles)
        yield (X_train, y_train)

Then I have some CNN where I train the network with the generator with the given function

model.fit_generator(train_generator, samples_per_epoch=len(train_samples), validation_data=validation_generator, nb_val_samples=len(validation_samples), nb_epoch=5)

My Question: How come the time rises during training, so that it takes longer and longer.. leading to insufficient memory for a batch size of lets say 32??

Body:
As Dref360 mentioned, I do not clear image and angle inside my generator. The main Problem was that i put

images = []
angles = []

outside of my generator, which resulted in both growing each cycle, where they should have been inside my generator. Below is the working code:

['some\\path\\center.jpg', 'some\\path\\left.jpg', 'some\\path\\right.jpg', 'someNumber']

def generator(samples, batch_size):
num_samples = len(samples)
while 1: # Loop forever so the generator never terminates
    shuffle(samples)
    for offset in range(0, num_samples, batch_size):
        batch_samples = samples[offset:offset+batch_size]

        images = []
        angles = []
        for batch_sample in batch_samples:

            source_path = np.random.choice([batch_sample[0], batch_sample[1], batch_sample[2]])
            filename = source_path.split(os.sep)[-1]
            current_path = 'data20/IMG/' + filename
            current_image = cv2.imread(current_path)
            current_angle = float(batch_sample[3])

            if source_path == line[1]:
                current_angle += 0.2

            elif source_path == line[2]:
                current_angle -= 0.2

            images.append(current_image)
            angles.append(current_angle)

        # trim image to only see section with road
        X_train = np.array(images)
        y_train = np.array(angles)
        yield (X_train, y_train)

Big thanks to Dref360 :D


问:
You may have an infinite update loop in a component render function
I'm new to VueJS, I've got warning from Vue,

```<code>[Vue warn]: You may have an infinite update loop in a component render function.
</code>```

When i use V-for variable in V-bind:style, here is an example :
in template :

```<code><div v-for="item in model.items" v-bind:class="test(item.result)">
{{item.id}}
</div>
</code>```

in script :

```<code>data() {
    return {
        accept: false,
        not_accept: false,
    };
},
methods: {
    test(result) {
        if (result == 'accept') {
            this.accept = true;
            this.not_accept = false;
        } else if (result == 'Not accept') {
            this.accept = false;
            this.not_accept = true;
        } else {
            console.log(result);
        }

        return {
            success: this.accept,
            danger: this.not_accept,
        };
    },
},
</code>```

答:
@Decade is right about the problem. Here is the exact problem:

You are in render method rendering the list of item using some state value

NOTE: render method is triggered whenever any state changes

Then you are trying to bind the class based on a result of function test this function is flawed as it is again trying to mutate the state, thus causing the render - test - render cycle.

You can solve this problem by making your test function not mutate the state instead, like so:

```<code>methods: {
    test(result) {
        let accept;
        if (result == 'accept') {
            accept = true;
        } else if (result == 'Not accept') {
            accept = false;
        } else {
            console.log(result);
        }

        return {
            success: accept,
            danger: !accept,
        };
    },
}
</code>```

I hope that helped!

Body:
I'm new to VueJS, I've got warning from Vue,

[Vue warn]: You may have an infinite update loop in a component render function.

When i use V-for variable in V-bind:style, here is an example :
in template :

{{item.id}}

in script :

data() {
    return {
        accept: false,
        not_accept: false,
    };
},
methods: {
    test(result) {
        if (result == 'accept') {
            this.accept = true;
            this.not_accept = false;
        } else if (result == 'Not accept') {
            this.accept = false;
            this.not_accept = true;
        } else {
            console.log(result);
        }

        return {
            success: this.accept,
            danger: this.not_accept,
        };
    },
},

Body:
@Decade is right about the problem. Here is the exact problem:

You are in render method rendering the list of item using some state value

NOTE: render method is triggered whenever any state changes

Then you are trying to bind the class based on a result of function test this function is flawed as it is again trying to mutate the state, thus causing the render - test - render cycle.

You can solve this problem by making your test function not mutate the state instead, like so:

methods: {
    test(result) {
        let accept;
        if (result == 'accept') {
            accept = true;
        } else if (result == 'Not accept') {
            accept = false;
        } else {
            console.log(result);
        }

        return {
            success: accept,
            danger: !accept,
        };
    },
}

I hope that helped!


问:
How do I change the Hibernate logging level?
How can I change the Hibernate logging level programmatically?</p>

答:
Use Log4j functionality:</p>

```<code>import org.apache.log4j.Logger;
import org.apache.log4j.Level;

Logger.getLogger("org.hibernate").setLevel(Level.<what you want>);
</code>```

Body:
Use Log4j functionality:

import org.apache.log4j.Logger;
import org.apache.log4j.Level;

Logger.getLogger("org.hibernate").setLevel(Level.<what you want>);


问:
how to access 6 different functions within for loop in C?
I am writing a code in C. I have to calculate some coefficients named as:

```<code>k1, k2, k3, k4
</code>```

I have 6 different functions named as:

```<code>func1, func2, func3, .....func6
</code>```

Very inefficient way is to write a code like this:

```<code>/* find k1 for all 6 functions */

/* k[0][0] is k1 for func1 */
/* k[0][1] is k1 for func2 */
   ......
   ......
/* k[0][5] is k1 for func6 */

/* h is some constant */

            k[0][0] = h*func1()
            k[0][1] = h*func2()
            k[0][2] = h*func3()
            k[0][3] = h*func4()
            k[0][4] = h*func5()
            k[0][5] = h*func6()
</code>```

Similarly I have to find out k2 for all 6 functions.

Again very inefficient way would be :

```<code>        k[1][0] = h*func1()
        k[1][1] = h*func2()
        k[1][2] = h*func3()
        k[1][3] = h*func4()
        k[1][4] = h*func5()
        k[1][5] = h*func6()
</code>```

And similar things for remaining k3 & k4 would be:

```<code> /* find K3 for all 6 functions */
   .............
   .............
 /* find K4 for all 6 functions */
   .............
   .............
</code>```

I want to avoid all this.

I want a way so that I can call 6 functions for each coefficient k within a for loop. Something like this:

```<code>for(i=0; i<=3; i++)
  {
     for(j=0; j<=5; j++)
       {
          k[i][j] =  h*func[...]
          /* where func[...] means some way for calling 6 functions */
       }
  }
</code>```

May be some array of functions ??

Any help will be highly appreciated.

Thanks.

答:
If all the 6 functions have the same prototype, I assume they have - for example receives void and returns int, then you can use an array of function pointers:

```<code>typedef int (*FUNCTION_PTR)(void);

FUNCTION_PTR funcs[6] = { func1, func2, ... };

for(i = 0; i <= 3; i++)
{
    for(j = 0; j <= 5; j++)
    {
        k[i][j] = h * func[j]();
    }
}
</code>```

Body:
I am writing a code in C. I have to calculate some coefficients named as:

k1, k2, k3, k4

I have 6 different functions named as:

func1, func2, func3, .....func6

Very inefficient way is to write a code like this:

/* find k1 for all 6 functions */

/* k[0][0] is k1 for func1 */
/* k[0][1] is k1 for func2 */
   ......
   ......
/* k[0][5] is k1 for func6 */

/* h is some constant */

            k[0][0] = h*func1()
            k[0][1] = h*func2()
            k[0][2] = h*func3()
            k[0][3] = h*func4()
            k[0][4] = h*func5()
            k[0][5] = h*func6()

Similarly I have to find out k2 for all 6 functions.

Again very inefficient way would be :

        k[1][0] = h*func1()
        k[1][1] = h*func2()
        k[1][2] = h*func3()
        k[1][3] = h*func4()
        k[1][4] = h*func5()
        k[1][5] = h*func6()

And similar things for remaining k3 & k4 would be:

 /* find K3 for all 6 functions */
   .............
   .............
 /* find K4 for all 6 functions */
   .............
   .............

I want to avoid all this.

I want a way so that I can call 6 functions for each coefficient k within a for loop. Something like this:

for(i=0; i<=3; i++)
  {
     for(j=0; j<=5; j++)
       {
          k[i][j] =  h*func[...]
          /* where func[...] means some way for calling 6 functions */
       }
  }

May be some array of functions ??

Any help will be highly appreciated.

Thanks.

Body:
If all the 6 functions have the same prototype, I assume they have - for example receives void and returns int, then you can use an array of function pointers:

typedef int (*FUNCTION_PTR)(void);

FUNCTION_PTR funcs[6] = { func1, func2, ... };

for(i = 0; i <= 3; i++)
{
    for(j = 0; j <= 5; j++)
    {
        k[i][j] = h * func[j]();
    }
}


问:
How to show regular expression validation's message after button click only?
Below is my html code. I have a email textbox and there is a login button. I have added a required field validator and regular expression validator for email textbox.

The problem is that when I type some thing in the email textbox browser's auto suggestion shows some list of emails. When I select any of those emails by using down arrow key and enter key it shows the error message for regular expression validation even though email is in proper format.

```<code><asp:RequiredFieldValidator ID="reqValUserName" runat="server"
    ErrorMessage="Email is required!"
    ControlToValidate="txtUserName"
    ValidationGroup="validateCredential"
    Display="Dynamic">
</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="regValUserName" runat="server"
    ErrorMessage="Incorrect format!"
    ControlToValidate="txtUserName"
    ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
    ValidationGroup="validateCredential"
    Display="Static">
</asp:RegularExpressionValidator>

     <asp:TextBox ID="txtUserName" runat="server"
           TabIndex="1" CssClass="inputCredential" MaxLength="60"
           AccessKey="E"
           ValidationGroup="validateCredential">
     </asp:TextBox>

     <asp:Button ID="btnLogin" runat="server" CssClass="btnPrimary"
           Text="Login" onclick="btnLogin_Click"
           ValidationGroup="validateCredential"/>
</code>```

In this image as you see if I select the email from the suggestion and press enter it is showing the wrong email validation message.

Can anyone please let me know, how to stop this kind of message display?

If there is any clarification needed regarding the question then please add it as a comment.

答: Just see the properties of the validator there you will find 'Display' property under Appearance section, set it to dynamic and VOLA!!</p>

Body:
Below is my html code. I have a email textbox and there is a login button. I have added a required field validator and regular expression validator for email textbox.

The problem is that when I type some thing in the email textbox browser's auto suggestion shows some list of emails. When I select any of those emails by using down arrow key and enter key it shows the error message for regular expression validation even though email is in proper format.

<asp:RequiredFieldValidator ID="reqValUserName" runat="server"
    ErrorMessage="Email is required!"
    ControlToValidate="txtUserName"
    ValidationGroup="validateCredential"
    Display="Dynamic">
</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="regValUserName" runat="server"
    ErrorMessage="Incorrect format!"
    ControlToValidate="txtUserName"
    ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
    ValidationGroup="validateCredential"
    Display="Static">
</asp:RegularExpressionValidator>

     <asp:TextBox ID="txtUserName" runat="server"
           TabIndex="1" CssClass="inputCredential" MaxLength="60"
           AccessKey="E"
           ValidationGroup="validateCredential">
     </asp:TextBox>

     <asp:Button ID="btnLogin" runat="server" CssClass="btnPrimary"
           Text="Login" onclick="btnLogin_Click"
           ValidationGroup="validateCredential"/>

In this image as you see if I select the email from the suggestion and press enter it is showing the wrong email validation message.

Can anyone please let me know, how to stop this kind of message display?

If there is any clarification needed regarding the question then please add it as a comment.


问:
Missing } in XML Expression
I am trying to change our site to load a Header through jquery using the .load() function but to do so I need to set the Title of the page.

From another StackFlow question it was suggested to do something as simple as

```<code>$(document).ready(function() {
    document.title ='Name Changed to Protect the Innocent';
});
</code>```

When i do this I get the firebug error
Missing } in XML Expression for that line in the script

I am sure there is probably an easy solution but it is certainly escaping me.

答:
I've just tested this out here, please see if you have created your html document in the same way. Code as below.</p>

```<code>    <html>
    <head>
        <title>Old Title</title>
        <script type="text/javascript" src="jquery-1.4.2.js"></script>

    </head>
    <body>

        <script type="text/javascript">
            $(document).ready(function() {
                document.title ='Name Changed to Protect the Innocent';
            });
        </script>
    </body>
   </html>
</code>```

Title: Missing } in XML Expression

Body:
I am trying to change our site to load a Header through jquery using the .load() function but to do so I need to set the Title of the page.

From another StackFlow question it was suggested to do something as simple as

$(document).ready(function() {
    document.title ='Name Changed to Protect the Innocent';
});

When i do this I get the firebug error
Missing } in XML Expression for that line in the script

I am sure there is probably an easy solution but it is certainly escaping me.

Body:
I've just tested this out here, please see if you have created your html document in the same way. Code as below.

    <html>
    <head>
        <title>Old Title</title>
        <script type="text/javascript" src="jquery-1.4.2.js"></script>

    </head>
    <body>

        <script type="text/javascript">
            $(document).ready(function() {
                document.title ='Name Changed to Protect the Innocent';
            });
        </script>
    </body>
   </html>


问:
JavaScript tag with rocket property
In the site: pro emoji keyboard online at http://www.emojiselector.com, I saw in source code, something as follows:

```<code><script data-rocketsrc="assets/web/assets/jquery/jquery.min.js" type="text/rocketscript"></script>
<script data-rocketsrc="assets/tether/tether.min.js" type="text/rocketscript"></script>
</code>```

What does this mean? data-rocketsrc, text/rocketscript??? I know for traditional tag in html is src and text/javascript. Is this another languages or another standards? I saw in code of JS, nothing is different!

答:
Rocket Loader is a general-purpose asynchronous JavaScript loader coupled with a lightweight virtual browser which can safely run any JavaScript code after window.onload.

Turning on Rocket Loader will almost always immediately improve a web page's window.onload time (assuming there is JavaScript on the page).

Title: JavaScript tag with rocket property

Body:
In the site: pro emoji keyboard online at http://www.emojiselector.com, I saw in source code, something as follows:

What does this mean? data-rocketsrc, text/rocketscript??? I know for traditional tag in html is src and text/javascript. Is this another languages or another standards? I saw in code of JS, nothing is different!


问:
Drawing a sphere in a room opengl
I have the code for a room provided to me, I need to add a sphere in the room. It goes like this:

```<code>PushMatrix();
       //draw floor,walls,ceilings
       PushMatrix();
       //draw some boxes on front wall
       PopMatrix();

       PushMatrix();
       //drawing sphere;
        glLoadIdentity();
        glColor3f(1, 0, 0);
        glTranslatef(0, ypos, 0);
        glutSolidSphere(2, 20, 20);
       PopMatrix();

 PopMatrix();
</code>```

But all the walls etc turn red (and no sphere) when I do this. Why does that happen even after pushing another matrix?

答:
Calling glColor*() sets the current color. This color doesn't change before you call glColor*() again. In other words glPushMatrix() and glPopMatrix() has no effect on the current color.

Thus if you in //draw some boxes on front wall don't call glColor*(). Then due to you setting the color to red by calling glColor3f(1, 0, 0) then everything is going to be red from that point on.

Considering:

```<code>glMatrixMode(GL_PROJECTION);
gluPerspective(40, 1, 1, 40);
glMatrixMode(GL_MODELVIEW);
</code>```

Then:

```<code>glPushMatrix();
glTranslatef(0, 0, -10);
glColor3f(1, 0, 0);
glutSolidSphere(2, 20, 20);
glPopMatrix();
</code>```

By doing the above you should see a sphere.

Thus if you before didn't see the sphere at all. Then it's probably due to ypos being outside your view. If you were referring to the whole screen being red, then I'm assuming ypos to be around 0, which means that it would be filling the whole screen (Again assuming you don't translate the view in any other way).

Title: Drawing a sphere in a room opengl

Body:
I have the code for a room provided to me, I need to add a sphere in the room. It goes like this:

PushMatrix();
       //draw floor,walls,ceilings
       PushMatrix();
       //draw some boxes on front wall
       PopMatrix();

       PushMatrix();
       //drawing sphere;
        glLoadIdentity();
        glColor3f(1, 0, 0);
        glTranslatef(0, ypos, 0);
        glutSolidSphere(2, 20, 20);
       PopMatrix();

 PopMatrix();

But all the walls etc turn red (and no sphere) when I do this. Why does that happen even after pushing another matrix?

Body:
Calling glColor*() sets the current color. This color doesn't change before you call glColor*() again. In other words glPushMatrix() and glPopMatrix() has no effect on the current color.

Thus if you in //draw some boxes on front wall don't call glColor*(). Then due to you setting the color to red by calling glColor3f(1, 0, 0) then everything is going to be red from that point on.

Considering:

glMatrixMode(GL_PROJECTION);
gluPerspective(40, 1, 1, 40);
glMatrixMode(GL_MODELVIEW);

Then:

glPushMatrix();
glTranslatef(0, 0, -10);
glColor3f(1, 0, 0);
glutSolidSphere(2, 20, 20);
glPopMatrix();

By doing the above you should see a sphere.

Thus if you before didn't see the sphere at all. Then it's probably due to ypos being outside your view. If you were referring to the whole screen being red, then I'm assuming ypos to be around 0, which means that it would be filling the whole screen (Again assuming you don't translate the view in any other way).


问:
How do you change the loading image in visual composer on wordpress
I have visual composer running in wordpress.  When media grids load, there is a loading graphic.  My client hates the default graphic and wants me to create a custom one.  I can not find where this is controlled in the code, nor can I even figure out what the name of the graphic is to swop it out.

the page is:  http://ninawilliamsinteriors.com/index.php/portfolio/rooms/living_rooms/

Any help would greatly be appreciated.

答:
Is this the one: http://ninawilliamsinteriors.com/wp-content/uploads/2017/03/loadingspinner150.gif

You could upload a different image with the same file name in the same folder and replace this one. This should make the change. There is probably a cleaner solutions via the admin panel though. Try to find it first.

I managed to see this URL using the inspect feature of Google Chrome in the Network tab. There is a list with the loaded assets there you can use in the future.

If this is not the one you are talking about, I see something else showing under it. It looks like gray circles to me. Might be made entirely with CSS and without an image.


答:
Write it like this:

var breadcrumb = ['food','hotdogt', 'a', 'b', 'c'];

var App = () => {
   return(

          {
             breadcrumb.map((obj,i) => {
                return
                            {obj}
                           {i != breadcrumb.length -1 ?  ->  : null}

             })
          }

   )
}

ReactDOM.render(<App/>, document.getElementById('app'))```
<pre class="snippet-code-css lang-css prettyprint-override"><code>.bold {
  font-weight: bold;
}

.seperator {
  color: blue;
}</code>```

```

Title: Simple breadcrum logo in jsx of react binding

Body:
{breadcrumbs.map((obj,i) =>

 {i} > 1 ? "|" : {obj}

)}

I want to make breadcrumbs from an array but failed using above code. breadcrumbs is just an array ['books','javascript'] and my expected output will be

Books -> javascript and so on, it should be working if I have more than 2 item in the array.

Body:
Write it like this:

var breadcrumb = ['food','hotdogt', 'a', 'b', 'c'];

var App = () => {
   return(
       <div>
          {
             breadcrumb.map((obj,i) => {
                return <span key={obj}>
                           <span className="bold"> {obj} </span>
                           {i != breadcrumb.length -1 ? <span className="seperator"> -> </span> : null}
                       </span>
             })
          }
       </div>
   )
}

ReactDOM.render(<App/>, document.getElementById('app'))

.bold {
  font-weight: bold;
}

.seperator {
  color: blue;
}

<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>

<div id='app'/>


问:
Apache: Virtual Host and URL Rewriting inside httpd.conf for Kohana Framework
I'm using the Kohana Framework 3.x. My Webserver is Apache and I use Virtual Hosts, because I manage more than one websites with my Server.

My httpd.conf looks like this:

```<code>  <VirtualHost *:80>
 ServerName www.myPage1.com
 ServerAlias myPage1.com
 DocumentRoot /var/www/myPage1
</VirtualHost>
<VirtualHost *:80>
 ServerName www.myPage2.com
 ServerAlias myPage2.de
 DocumentRoot /var/www/myPage2
</VirtualHost>
</code>```

In Kohana every http request needs to go to the index.php first. Because I dont like these ugly URLs that all starts with index.php (for example www.myPage1.com/index.php/item/detail/itemId) I used the following .htaccess file which worked perfectly

```<code># Turn on URL rewriting
RewriteEngine On

# Installation directory
RewriteBase /

# Protect hidden files from being viewed
<Files .*>
    Order Deny,Allow
    Deny From All
</Files>

# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]
</code>```

I would now like to not use a .htaccess file anymore and instead put all the rewrite logic into my httpd.conf file. The following gives me a "400 Bad Request"

```<code><VirtualHost *:80>
 RewriteEngine On
 <Files .*>
  Order Deny,Allow
  Deny From All
 </Files>
 RewriteRule ^(?:aplication|modules|system)\b.* index.php/$0 [L]
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule .* index.php/$0 [PT]

 ServerName www.myPage2.com
 ServerAlias myPage2.com
 DocumentRoot /var/www/myPage2
</VirtualHost>
</code>```

What am I doing wrong? Help would be appreciated!

答: You don't have a RewriteBase in your httpd.conf. And what's wrong with the .htaccess?</p>

Body:
I'm using the Kohana Framework 3.x. My Webserver is Apache and I use Virtual Hosts, because I manage more than one websites with my Server.

My httpd.conf looks like this:

  <VirtualHost *:80>
 ServerName www.myPage1.com
 ServerAlias myPage1.com
 DocumentRoot /var/www/myPage1
</VirtualHost>
<VirtualHost *:80>
 ServerName www.myPage2.com
 ServerAlias myPage2.de
 DocumentRoot /var/www/myPage2
</VirtualHost>

In Kohana every http request needs to go to the index.php first. Because I dont like these ugly URLs that all starts with index.php (for example www.myPage1.com/index.php/item/detail/itemId) I used the following .htaccess file which worked perfectly

# Turn on URL rewriting
RewriteEngine On

# Installation directory
RewriteBase /

# Protect hidden files from being viewed
<Files .*>
    Order Deny,Allow
    Deny From All
</Files>

# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]

I would now like to not use a .htaccess file anymore and instead put all the rewrite logic into my httpd.conf file. The following gives me a "400 Bad Request"

<VirtualHost *:80>
 RewriteEngine On
 <Files .*>
  Order Deny,Allow
  Deny From All
 </Files>
 RewriteRule ^(?:aplication|modules|system)\b.* index.php/$0 [L]
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule .* index.php/$0 [PT]

 ServerName www.myPage2.com
 ServerAlias myPage2.com
 DocumentRoot /var/www/myPage2
</VirtualHost>

What am I doing wrong? Help would be appreciated!


问:
Should I modify zipkin service libraries to pass generic feature flags?
We're looking to implement Zipkin in our stack.  As I look into Zipkin it makes sense to me to extend the Zipkin system to handle generic flags as well.

Observations:

Any implementation of Zipkin needs to capture "B3" tagged values (headers in HTTP) and propagate them to requests further down the stack.

Some values are mutated

Some values are just propagated (Sampled, Debug)

Conclusion:

Extending Zipkin with the option to propagate (X-)B3-Flag- Key/Value pairs make sense.

This enables A/B testing and Blue/Green Deploy.

These techniques often need to compare timings to ensure that timings are similar or improved unless noted by the service development team.

答:
The TL;DR; is that B3 propagation was initially designed for fixed size data: carrying data ancillary to tracing isn't in scope, and for this reason any solution that extends B3 in such a fashion wouldn't be compatible with existing code.

So, that means any solution like this will be an extension which means custom handling in the instrumented apps which are the things passing headers around. The server won't care as it never sees these headers anyway.

Ways people usually integrate other things like flags with zipkin is to add a tag aka binary annotation including its value (usually in the root span). This would allow you to query or retrieve these offline, but it doesn't address in-flight lookups from applications.

Let's say that instead of using an intermediary like linkerd, or a platform-specific propagated context, we want to dispatch the responsibility to the tracing layer. Firstly, what sort of data could work alright? The easiest is something set-once (like zipkin's trace id). Anything set and propagated without mutating it is the least mechanics. Next in difficulty is appending new entries mid-stream, and most difficult is mutating/merging entries.

Let's assume this is for inbound flags which never change through the request/trace tree. We see a header when processing trace data, we store it and forward it downstream. If this value doesn't need to be read by the tracing system, it is easiest, as it is largely a transport/propagation concern. For example, maybe other middleware read that header and it is only a "side job" we are adding to the tracer to remember certain things to pass along. If this was done in a single header, it would be less code than a pattern in each of the places this would be to added. It would be even less code if the flags could be encoded in a number, however unrealistic that may be.

There are libraries with apis to manipulate the propagated context manually, for example, "baggage" from brownsys and OpenTracing (of which some libraries support zipkin). The former aims to be a generic layer for any instrumentation (ex monitoring, chargeback, tracing etc) and the latter is specific to tracing. OpenTracing has defines abstract types like injector and extractor which could be customized to carry other fields. However, you still would need a concrete implementation (which knows your header format etc) in order to do this. Unless you want applications to read this data, it would need to be a secret detail of that implementation (specifically the trace context).

Certain zipkin-specific libraries like Spring Cloud Sleuth and Brave have means to customize how headers are parsed, to support variants of B3 or new or site-specific trace formats. Not all support this at the moment, but I would expect this type of feature to become more common. This means you may need to do some surgery in order to support all platforms you may need to support.

So long story short is that there are some libraries which are pluggable with regards to propagation, and those will be easiest to modify to support this use case. Some code will be needed regardless as B3 doesn't currently define an expression like this.


问:
Splitting start and end date in python to separate years
I want to adapt the code here: Given a date range how can we break it up into N contiguous sub-intervals? to split a range of dates as follows:

Starting date is '2015-03-20' and end date is '2017-03-12'. I want to split it into 3 parts. One for each of the 3 years, so that I get a list like this:

```<code>[['2015-03-20', '2015-12-31'], ['2016-01-01', '2016-12-31'], ['2017-01-01', '2017-03-12']]
</code>```

Any pythonic way to do this?

Body:
I want to adapt the code here: Given a date range how can we break it up into N contiguous sub-intervals? to split a range of dates as follows:

Starting date is '2015-03-20' and end date is '2017-03-12'. I want to split it into 3 parts. One for each of the 3 years, so that I get a list like this:

[['2015-03-20', '2015-12-31'], ['2016-01-01', '2016-12-31'], ['2017-01-01', '2017-03-12']]

Any pythonic way to do this?

Body:
If I don't misunderstand your meaning, you can just get the middle years and append it to the string like   -12-31 or -01-01.

start_date = '2015-03-20'
end_date = '2018-03-12'

def split_date(s,e):
    return [[s,s[:4]+"-12-31"]]+ [['%s-01-01'%(str(i)), '%s-12-31'%(str(i))] for i in range(int(s[:4])+1,int(e[:4]))]+[[e[:4] + "-01-01", e]]

print(split_date(start_date,end_date))

Result:

[['2015-03-20', '2015-12-31'], ['2016-01-01', '2016-12-31'], ['2017-01-01', '2017-12-31'], ['2018-01-01', '2018-03-12']]


问:
SQLSTATE[28000] [1045] Access denied for user 'root'@'localhost' (using password: NO)
I have uploaded my project on my hosting ..But when i tried to access form url I got the following Error

```<code>QueryException in Connection.php line 647:
SQLSTATE[28000] [1045] Access denied for user 'root'@'localhost' (using password: NO)
</code>```

I have changed the following credentials of .env

```<code>DB_DATABASE=cpanel_database
DB_USERNAME=cpanel_db_name
DB_PASSWORD=cpanel_db_password
</code>```

What could be the error for getting the Above Error?

答:
Just make sure your database credentials are correct.
Might be chance that configurations run from cache. once clear is by login in server via ssh or remove config.php file from bootstrap/cache/ folder.

Good luck.

Body:
I have uploaded my project on my hosting ..But when i tried to access form url I got the following Error

QueryException in Connection.php line 647:
SQLSTATE[28000] [1045] Access denied for user 'root'@'localhost' (using password: NO)

I have changed the following credentials of .env

DB_DATABASE=cpanel_database
DB_USERNAME=cpanel_db_name
DB_PASSWORD=cpanel_db_password

What could be the error for getting the Above Error?


问:
Spring Integration as embedded alternative to standalone ESB
Does anybody has an experience with Spring Integration project as embedded ESB?

I'm highly interesting in such use cases as:

Reading files from directory on schedule basis

Getting data from JDBC data source

Modularity and possibility to start/stop/redeploy module on the fly (e.g. one module can scan directory on schedule basis, another call query from jdbc  data source etc.)

repeat/retry policy

UPDATE:

I found answers on all my questions except "Getting data from JDBC data source". Is it technically possible?

答: The Spring Integration JDBC adapters are available in 2.0, and we just released GA last week. Here's the relevant section from the reference manual: http://static.springsource.org/spring-integration/docs/latest-ga/reference/htmlsingle/#jdbc</p>

LastEditorDisplayName: John Topley


问:
How to create image or pdf from html having css filters?
I want to create an image or pdf from a html. The html consist of images with css filters like sepia, gray-scale etc. So it would be better if anyone have worked on that.

```<code><img class="dj_rot" src="/940/images/photos.png" style="filter: sepia(1);">
<img class="dj_rot" src="/940/images/photos.png" style="filter: grayscale(1);">
</code>```

Thanks
Deepak

答: Have you tried taking a screenshot of the HTML? To take a screenshot you should hit command+shift+4. The number 3 takes a screenshot of the entire screen, while the number 4 allows you to select what it will take a screenshot of.</p>

Body:
I want to create an image or pdf from a html. The html consist of images with css filters like sepia, gray-scale etc. So it would be better if anyone have worked on that.

Thanks
Deepak