void shufb(int128 *r, const unsigned char *l)
{
  int128 t;
  unsigned char *cr;
  unsigned char *ct;

  copy2(&t,r);
  cr = (unsigned char *)r;
  ct = (unsigned char *)&t;
  cr[0] = ct[l[0]];
  cr[1] = ct[l[1]];
  cr[2] = ct[l[2]];
  cr[3] = ct[l[3]];
  cr[4] = ct[l[4]];
  cr[5] = ct[l[5]];
  cr[6] = ct[l[6]];
  cr[7] = ct[l[7]];
  cr[8] = ct[l[8]];
  cr[9] = ct[l[9]];
  cr[10] = ct[l[10]];
  cr[11] = ct[l[11]];
  cr[12] = ct[l[12]];
  cr[13] = ct[l[13]];
  cr[14] = ct[l[14]];
  cr[15] = ct[l[15]];
}
Exemple #2
0
    // 跟copy的区别在于,不是针对CSGTreeOld
    CSGTreeNode* copy2(const CSGTreeNode* thiz, CSGTreeNode** leafList)
	{
		if (!thiz) return nullptr;

		CSGTreeNode* pRes = new CSGTreeNode(*thiz);

        if (thiz->pMesh) leafList[thiz->pMesh->id()] = pRes;

        pRes->pLeft = copy2(thiz->pLeft, leafList);
		pRes->pRight = copy2(thiz->pRight, leafList);

        if (pRes->pLeft) pRes->pLeft->Parent = pRes;
		if (pRes->pRight) pRes->pRight->Parent = pRes;

		return pRes;
	}
Exemple #3
0
int main()
{
	char X[MONTHS][15];
	char Y[MONTHS][15];
	int i,j;
	char **Z;
	char **ret;
	strcpy(X[0],"January");strcpy(X[1],"February");strcpy(X[2],"March");
	strcpy(X[3],"April");strcpy(X[4],"May"); strcpy(X[5],"June");
	strcpy(X[6],"July");strcpy(X[7],"August");strcpy(X[8],"September");
	strcpy(X[9],"October");strcpy(X[10],"November");strcpy(X[11],"December");

	copy1(X,Y);
	ret=copy2(X);
	copy3(X,&Z);
	printf("Output of copy1 --> Array Y\n");
	for(i=0;i<MONTHS;i++)
			printf("%s\n",Y[i]);
	printf("\n\n\n");

	printf("Output of copy2 --> ret\n");
	for(i=0;i<MONTHS;i++)
			printf("%s\n",ret[i]);
	printf("\n\n\n");

	printf("Output of copy3 --> Z\n");
	for(i=0;i<MONTHS;i++)
			printf("%s\n",Z[i]);
	printf("\n\n\n");

	return 0;
}
void shufd(int128 *r, const int128 *x, const unsigned int c)
{
  int128 t;
  uint32 *tp = (uint32 *)&t;
  const uint32 *xp = (const uint32 *)x;
  tp[0] = xp[c&3];
  tp[1] = xp[(c>>2)&3];
  tp[2] = xp[(c>>4)&3];
  tp[3] = xp[(c>>6)&3];
  copy2(r,&t);
}
main() {
    char string1[10], string3[10];
    char  *string2 = "Hello", string4[10]="Good Bye";
    
    copy1(string1,string2);
    printf("String1 : %s\n",string1);
    
    copy2(string3,string4);
    printf("String3 : %s\n",string3);
    
    *string3 = 'Z';
    printf("String3 : %s\n",string3);
}
Exemple #6
0
static int upheap(CHEAP *heap, int k)
{
    GB_VARIANT_VALUE x;
    int r = 0;

    copy1(heap, k, &x);
    while (k && compare1(heap, &x, parent(k)) < 0) {
        copy(heap, parent(k), k);
        k = parent(k);
        r++;
    }
    copy2(heap, &x, k);
    return r;
}
Exemple #7
0
int main ( void )
{
	char string1[ 10 ]; /* create array string1 */
	char *string2 = "Hello"; /* create a pointer to a string */
	char string3[ 10 ]; /* create array string3 */
	char string4[] = "Good Bye"; /* create a pointer to a string */

	copy1( string1, string2 );
	printf( "string1 = %s\n", string1 );

	copy2( string3, string4 );
	printf ("string3 = %s\n", string3 );
	return 0; /*indicate successful termination */
} /* end main */
Exemple #8
0
int main () {
	char s1 [16];                        //char-string array
	char *s2 = "Now is the time";		//pointer
	char s3[25];
	char s4[] = " for all good programmers";

	copy1(s1, s2);

	printf("s1:  %s\n", s1);

	copy2(s3, s4);

	printf("s3:  %s\n", s3);

	return 0;
}
Exemple #9
0
int main(void) {

	char string1[10];
	char *string2 = "Hello";
	char string3[10];
	char *string4 = "Good bye";

	copy1(string1, string2);
	printf("string1 = %s\n", string1);

	copy2(string3, string4);
	printf("string3 = %s\n", string3);

	system("pause");
	return 0;
}
void
run_assign_and_copy_constructor_test(const char *test_name) {
    REMARK("Testing assignment and copy construction for %s\n", test_name);

    // test initializer with exemplar
    T initializer0;
    test_helper<T>::init(initializer0);
    T initializer7;
    test_helper<T>::set(initializer7,7);
    tbb::enumerable_thread_specific<T> create1(initializer7);
    (void) create1.local();  // create an initialized value
    ASSERT(7 == test_helper<T>::get(create1.local()), NULL);

    // test copy construction with exemplar initializer
    create1.clear();
    tbb::enumerable_thread_specific<T> copy1(create1);
    (void) copy1.local();
    ASSERT(7 == test_helper<T>::get(copy1.local()), NULL);

    // test copy assignment with exemplar initializer
    create1.clear();
    tbb::enumerable_thread_specific<T> assign1(initializer0);
    assign1 = create1;
    (void) assign1.local();
    ASSERT(7 == test_helper<T>::get(assign1.local()), NULL);

    // test creation with finit function
    FunctorFinit<T,7> my_finit7(SecretTag);
    tbb::enumerable_thread_specific<T> create2(my_finit7);
    (void) create2.local();
    ASSERT(7 == test_helper<T>::get(create2.local()), NULL);

    // test copy construction with function initializer
    create2.clear();
    tbb::enumerable_thread_specific<T> copy2(create2);
    (void) copy2.local();
    ASSERT(7 == test_helper<T>::get(copy2.local()), NULL);

    // test copy assignment with function initializer
    create2.clear();
    FunctorFinit<T,0> my_finit(SecretTag);
    tbb::enumerable_thread_specific<T> assign2(my_finit);
    assign2 = create2;
    (void) assign2.local();
    ASSERT(7 == test_helper<T>::get(assign2.local()), NULL);
}
Exemple #11
0
void add(double *A1, double *A2, double *B1, double *B2, int n, double *outA,
         double *outB) {
  double *A = A1, *B = A1 + 2 * n * n, *C = A1 + n, *D = A1 + 2 * n * n + n,
         *E = B1, *F = B1 + n, *G = A2, *H = A2 + 2 * n * n, *I_ = A2 + n,
         *J = A2 + 2 * n * n + n, *K = B2, *L = B2 + n, *oA = outA,
         *oB = outA + 3 * n * n, *oC = outA + 2 * 3 * n * n, *oD = outA + n,
         *oE = outA + 3 * n * n + n, *oF = outA + 2 * 3 * n * n + n,
         *oG = outA + 2 * n, *oH = outA + 3 * n * n + 2 * n,
         *oI = outA + 2 * 3 * n * n + 2 * n, *oK = outB, *oL = outB + n,
         *oM = outB + 2 * n;

  /*
    oA = D+G
    oB = C
    oC = H
    oD = B
    oE = A
    oF = 0
    oG = I
    oH = 0
    oI = I

    oK = F + K
    oL = E
    oM = L
  */

  copy2(oA, D, n, 3 * n, 2 * n);
  add2(oA, G, n, 3 * n, 2 * n);

  copy2(oB, C, n, 3 * n, 2 * n);
  copy2(oC, H, n, 3 * n, 2 * n);
  copy2(oD, B, n, 3 * n, 2 * n);
  copy2(oE, A, n, 3 * n, 2 * n);
  zero2(oF, n, 3 * n);
  copy2(oG, I_, n, 3 * n, 2 * n);
  zero2(oH, n, 3 * n);
  copy2(oI, J, n, 3 * n, 2 * n);

  memcpy(oK, F, n * sizeof(double));
  for (int i = 0; i < n; i++)
    oK[i] += K[i];

  memcpy(oL, E, n * sizeof(double));
  memcpy(oM, L, n * sizeof(double));
}
void
RunAssignmentAndCopyConstructorTest(const char *test_name) {
    REMARK("Testing assignment and copy construction for %s\n", test_name);

    // test creation with finit function (combine returns finit return value if no threads have created locals)
    FunctorAddFinit7<T> my_finit7_decl;
    tbb::combinable<T> create2(my_finit7_decl);
    ASSERT(7 == create2.combine(my_combine<T>), NULL);

    // test copy construction with function initializer
    tbb::combinable<T> copy2(create2);
    ASSERT(7 == copy2.combine(my_combine<T>), NULL);

    // test copy assignment with function initializer
    FunctorAddFinit<T> my_finit_decl;
    tbb::combinable<T> assign2(my_finit_decl);
    assign2 = create2;
    ASSERT(7 == assign2.combine(my_combine<T>), NULL);
}
TEST(RadixSortRand, RadixSortTest) {
    static constexpr size_t n = 1 << 20;
    U32Vector vct(n);
    for (size_t i = 0; i < n; ++i) {
        vct[i] = rand();
    }
    U32Vector copy1(vct);
    U32Vector copy2(vct);
    {
        Timer t("radix");
        radixSort(copy1);
    }
    {
        Timer t("std::sort");
        sort(copy2.begin(), copy2.end());
    }
    for (size_t i = 1; i < n; ++i) {
        EXPECT_LE(copy1[i - 1], copy1[i]);
    }
}
Exemple #14
0
int main84()
{
	char str1[] = "Hello";
	char *str1_p = "China";
	char *str1_p2;
	str1_p2 = "Hello";

	printf("%d\n", sizeof(str1));//最后自动加'\0'

	char c1[10], c2[10];
	copy1(str1, c1);
	copy2(str1_p, c2);

	printf("%s\n", c1);
	printf("%s\n", c2);

	str1[0] = 'X';
	//str1_p[0] = 'X'; //错误,指针指向的是常量
	return 0;
}
Exemple #15
0
static int downheap(CHEAP *heap, int k)
{
    int count = GB.Count(heap->h), r = 0;
    GB_VARIANT_VALUE x;

    copy1(heap, k, &x);
    while (k <= parent(count - 1)) {
        int j, l = j = left(k), r = right(k);

        if (r < count && compare(heap, l, r) > 0)
            j = r;
        if (compare1(heap, &x, j) <= 0)
            break;
        copy(heap, j, k);
        k = j;
        r++;
    }
    copy2(heap, &x, k);
    return r;
}
Exemple #16
0
int main()
{
	Sorcerer robert("Robert", "the Magnificent");
	Victim jim("Jimmy");
	Peon joe("Joe");
	std::cout << robert << jim << joe;
	robert.polymorph(jim);
	robert.polymorph(joe);
	std::cout << std::endl;

	Perifalk henri("Henri");
	std::cout << henri;
	robert.polymorph(henri);
	std::cout << std::endl;

	Peon copy(joe);
	Peon copy2("Franck");
	copy2 = copy;
	std::cout << std::endl;

	return 0;
}
Exemple #17
0
 void expand(uintt a=0){
     
     if (test[EXPAND]){
         erint "expanding";
     }
     if (a==0){
         assert(s() == c());
         assert(c() < s() * 2 || (c() == s() && c() == uintt(0)));
         if (test[EXPAND]){
            cout << "c() set from " << c();
         }
         c() = (s() == uintt(0) ? 1 : s()*2);
         if (test[EXPAND]){
             erint " to", c();
         }
     }
     else {
         assert(a > s());
         assert(a > c());
         if (test[EXPAND]){
             cout << "c() set from " << c();
         }
         c() = a;
         if (test[EXPAND]){
             erint " to value of a,", c();
         }
         //s() = max(s()*s(), a);
     }
     T *bar = new T[c()];
     copy2(bar, t(), t()+s());
     delete [] t();
     t() = bar;
     if (test[EXPAND]){
         erint "done expanding";
     }
 }
Exemple #18
0
TEST(WTF_HashSet, CopyCapacityIsNotOnBoundary)
{
    // Starting at 4 because the minimum size is 8.
    // With a size of 8, a medium load can be up to 3.3333->3.
    // Adding 1 to 3 would reach max load.
    // While correct, that's not really what we care about here.
    for (unsigned size = 4; size < 100; ++size) {
        HashSet<unsigned> source;
        for (unsigned i = 1; i < size + 1; ++i)
            source.add(i);

        HashSet<unsigned> copy1(source);
        HashSet<unsigned> copy2(source);
        HashSet<unsigned> copy3(source);

        EXPECT_EQ(size, copy1.size());
        EXPECT_EQ(size, copy2.size());
        EXPECT_EQ(size, copy3.size());
        for (unsigned i = 1; i < size + 1; ++i) {
            EXPECT_TRUE(copy1.contains(i));
            EXPECT_TRUE(copy2.contains(i));
            EXPECT_TRUE(copy3.contains(i));
        }
        EXPECT_FALSE(copy1.contains(size + 2));
        EXPECT_FALSE(copy2.contains(size + 2));
        EXPECT_FALSE(copy3.contains(size + 2));

        EXPECT_TRUE(copy2.remove(1));
        EXPECT_EQ(copy1.capacity(), copy2.capacity());
        EXPECT_FALSE(copy2.contains(1));

        EXPECT_TRUE(copy3.add(size + 2).isNewEntry);
        EXPECT_EQ(copy1.capacity(), copy3.capacity());
        EXPECT_TRUE(copy3.contains(size + 2));
    }
}
Exemple #19
0
 Term *copy() { return copy2(); }
Exemple #20
0
// EmbeddedNuls
//------------------------------------------------------------------------------
void TestAString::EmbeddedNuls() const
{
    // Create a string with an embedded nul and check various behaviours
    AStackString<> string( "0123456789" );
    const uint32_t originalStringLen = string.GetLength();
    string[ 5 ] = 0; // insert null terminator

    // Copy construction
    {
        AString copy( string );
        TEST_ASSERT( copy.GetLength() == originalStringLen );
        TEST_ASSERT( memcmp( "01234" "\0" "6789", copy.Get(), originalStringLen ) == 0 );
    }

    // Assignment (operator =)
    {
        AString copy;
        copy = string;
        TEST_ASSERT( copy.GetLength() == originalStringLen );
        TEST_ASSERT( memcmp( "01234" "\0" "6789", copy.Get(), originalStringLen ) == 0 );
    }

    // Assignment (Assign)
    {
        AString copy;
        copy.Assign( string );
        TEST_ASSERT( copy.GetLength() == originalStringLen );
        TEST_ASSERT( memcmp( "01234" "\0" "6789", copy.Get(), originalStringLen ) == 0 );
    }

    // Assignment (Assign with iterators)
    {
        AString copy;
        copy.Assign( string.Get(), string.GetEnd() );
        TEST_ASSERT( copy.GetLength() == originalStringLen );
        TEST_ASSERT( memcmp( "01234" "\0" "6789", copy.Get(), originalStringLen ) == 0 );
    }

    // Append (operator +=)
    {
        // Append to empty
        AString copy;
        copy += string;
        TEST_ASSERT( copy.GetLength() == originalStringLen );
        TEST_ASSERT( AString::StrNCmp( string.Get(), copy.Get(), originalStringLen ) == 0 );
        TEST_ASSERT( memcmp( "01234" "\0" "6789", copy.Get(), originalStringLen ) == 0 );

        // Append to existing
        AString copy2( string );
        copy2 += string;
        TEST_ASSERT( copy2.GetLength() == ( originalStringLen * 2 ) );
        TEST_ASSERT( memcmp( "01234" "\0" "678901234" "\0" "6789", copy2.Get(), ( originalStringLen * 2 ) ) == 0 );
    }

    // Append (Append)
    {
        // Append to empty
        AString copy;
        copy.Append( string );
        TEST_ASSERT( copy.GetLength() == originalStringLen );
        TEST_ASSERT( memcmp( "01234" "\0" "6789", copy.Get(), originalStringLen ) == 0 );

        // Append to existing
        AString copy2( string );
        copy2.Append( string );
        TEST_ASSERT( copy2.GetLength() == ( originalStringLen * 2 ) );
        TEST_ASSERT( memcmp( "01234" "\0" "678901234" "\0" "6789", copy2.Get(), ( originalStringLen * 2 ) ) == 0 );
    }
}
TEST(ResourceRequestTest, CrossThreadResourceRequestData)
{
    ResourceRequest original;
    original.setURL(KURL(ParsedURLString, "http://www.example.com/test.htm"));
    original.setCachePolicy(UseProtocolCachePolicy);
    original.setTimeoutInterval(10);
    original.setFirstPartyForCookies(KURL(ParsedURLString, "http://www.example.com/first_party.htm"));
    original.setHTTPMethod(AtomicString("GET", AtomicString::ConstructFromLiteral));
    original.setHTTPHeaderField(AtomicString("Foo"), AtomicString("Bar"));
    original.setHTTPHeaderField(AtomicString("Piyo"), AtomicString("Fuga"));
    original.setPriority(ResourceLoadPriorityLow, 20);

    RefPtr<FormData> originalBody(FormData::create("Test Body"));
    original.setHTTPBody(originalBody);
    original.setAllowStoredCredentials(false);
    original.setReportUploadProgress(false);
    original.setHasUserGesture(false);
    original.setDownloadToFile(false);
    original.setSkipServiceWorker(false);
    original.setFetchRequestMode(WebURLRequest::FetchRequestModeCORS);
    original.setFetchCredentialsMode(WebURLRequest::FetchCredentialsModeSameOrigin);
    original.setRequestorID(30);
    original.setRequestorProcessID(40);
    original.setAppCacheHostID(50);
    original.setRequestContext(WebURLRequest::RequestContextAudio);
    original.setFrameType(WebURLRequest::FrameTypeNested);
    original.setHTTPReferrer(Referrer("http://www.example.com/referrer.htm", ReferrerPolicyDefault));

    EXPECT_STREQ("http://www.example.com/test.htm", original.url().string().utf8().data());
    EXPECT_EQ(UseProtocolCachePolicy, original.cachePolicy());
    EXPECT_EQ(10, original.timeoutInterval());
    EXPECT_STREQ("http://www.example.com/first_party.htm", original.firstPartyForCookies().string().utf8().data());
    EXPECT_STREQ("GET", original.httpMethod().utf8().data());
    EXPECT_STREQ("Bar", original.httpHeaderFields().get("Foo").utf8().data());
    EXPECT_STREQ("Fuga", original.httpHeaderFields().get("Piyo").utf8().data());
    EXPECT_EQ(ResourceLoadPriorityLow, original.priority());
    EXPECT_STREQ("Test Body", original.httpBody()->flattenToString().utf8().data());
    EXPECT_FALSE(original.allowStoredCredentials());
    EXPECT_FALSE(original.reportUploadProgress());
    EXPECT_FALSE(original.hasUserGesture());
    EXPECT_FALSE(original.downloadToFile());
    EXPECT_FALSE(original.skipServiceWorker());
    EXPECT_EQ(WebURLRequest::FetchRequestModeCORS, original.fetchRequestMode());
    EXPECT_EQ(WebURLRequest::FetchCredentialsModeSameOrigin, original.fetchCredentialsMode());
    EXPECT_EQ(30, original.requestorID());
    EXPECT_EQ(40, original.requestorProcessID());
    EXPECT_EQ(50, original.appCacheHostID());
    EXPECT_EQ(WebURLRequest::RequestContextAudio, original.requestContext());
    EXPECT_EQ(WebURLRequest::FrameTypeNested, original.frameType());
    EXPECT_STREQ("http://www.example.com/referrer.htm", original.httpReferrer().utf8().data());
    EXPECT_EQ(ReferrerPolicyDefault, original.referrerPolicy());

    OwnPtr<CrossThreadResourceRequestData> data1(original.copyData());
    OwnPtr<ResourceRequest> copy1(ResourceRequest::adopt(data1.release()));

    EXPECT_STREQ("http://www.example.com/test.htm", copy1->url().string().utf8().data());
    EXPECT_EQ(UseProtocolCachePolicy, copy1->cachePolicy());
    EXPECT_EQ(10, copy1->timeoutInterval());
    EXPECT_STREQ("http://www.example.com/first_party.htm", copy1->firstPartyForCookies().string().utf8().data());
    EXPECT_STREQ("GET", copy1->httpMethod().utf8().data());
    EXPECT_STREQ("Bar", copy1->httpHeaderFields().get("Foo").utf8().data());
    EXPECT_EQ(ResourceLoadPriorityLow, copy1->priority());
    EXPECT_STREQ("Test Body", copy1->httpBody()->flattenToString().utf8().data());
    EXPECT_FALSE(copy1->allowStoredCredentials());
    EXPECT_FALSE(copy1->reportUploadProgress());
    EXPECT_FALSE(copy1->hasUserGesture());
    EXPECT_FALSE(copy1->downloadToFile());
    EXPECT_FALSE(copy1->skipServiceWorker());
    EXPECT_EQ(WebURLRequest::FetchRequestModeCORS, copy1->fetchRequestMode());
    EXPECT_EQ(WebURLRequest::FetchCredentialsModeSameOrigin, copy1->fetchCredentialsMode());
    EXPECT_EQ(30, copy1->requestorID());
    EXPECT_EQ(40, copy1->requestorProcessID());
    EXPECT_EQ(50, copy1->appCacheHostID());
    EXPECT_EQ(WebURLRequest::RequestContextAudio, copy1->requestContext());
    EXPECT_EQ(WebURLRequest::FrameTypeNested, copy1->frameType());
    EXPECT_STREQ("http://www.example.com/referrer.htm", copy1->httpReferrer().utf8().data());
    EXPECT_EQ(ReferrerPolicyDefault, copy1->referrerPolicy());

    copy1->setAllowStoredCredentials(true);
    copy1->setReportUploadProgress(true);
    copy1->setHasUserGesture(true);
    copy1->setDownloadToFile(true);
    copy1->setSkipServiceWorker(true);
    copy1->setFetchRequestMode(WebURLRequest::FetchRequestModeNoCORS);
    copy1->setFetchCredentialsMode(WebURLRequest::FetchCredentialsModeInclude);

    OwnPtr<CrossThreadResourceRequestData> data2(copy1->copyData());
    OwnPtr<ResourceRequest> copy2(ResourceRequest::adopt(data2.release()));
    EXPECT_TRUE(copy2->allowStoredCredentials());
    EXPECT_TRUE(copy2->reportUploadProgress());
    EXPECT_TRUE(copy2->hasUserGesture());
    EXPECT_TRUE(copy2->downloadToFile());
    EXPECT_TRUE(copy2->skipServiceWorker());
    EXPECT_EQ(WebURLRequest::FetchRequestModeNoCORS, copy1->fetchRequestMode());
    EXPECT_EQ(WebURLRequest::FetchCredentialsModeInclude, copy1->fetchCredentialsMode());
}
void test_regex_token_iterator(boost::basic_regex<charT, traits>& r)
{
   typedef typename std::basic_string<charT>::const_iterator const_iterator;
   typedef boost::regex_token_iterator<const_iterator, charT, traits> test_iterator;
   const std::basic_string<charT>& search_text = test_info<charT>::search_text();
   boost::regex_constants::match_flag_type opts = test_info<charT>::match_options();
   const int* answer_table = test_info<charT>::answer_table();
   //
   // we start by testing sub-expression 0:
   //
   test_iterator start(search_text.begin(), search_text.end(), r, 0, opts), end;
   test_iterator copy(start);
   while(start != end)
   {
      if(start != copy)
      {
         BOOST_REGEX_TEST_ERROR("Failed iterator != comparison.", charT);
      }
      if(!(start == copy))
      {
         BOOST_REGEX_TEST_ERROR("Failed iterator == comparison.", charT);
      }
      test_sub_match(*start, search_text.begin(), answer_table, 0);
      ++start;
      ++copy;
      // move on the answer table to next set of answers;
      if(*answer_table != -2)
         while(*answer_table++ != -2){}
   }
   if(answer_table[0] >= 0)
   {
      // we should have had a match but didn't:
      BOOST_REGEX_TEST_ERROR("Expected match was not found.", charT);
   }
   //
   // and now field spitting:
   //
   test_iterator start2(search_text.begin(), search_text.end(), r, -1, opts), end2;
   test_iterator copy2(start2);
   int last_end2 = 0;
   answer_table = test_info<charT>::answer_table();
   while(start2 != end2)
   {
      if(start2 != copy2)
      {
         BOOST_REGEX_TEST_ERROR("Failed iterator != comparison.", charT);
      }
      if(!(start2 == copy2))
      {
         BOOST_REGEX_TEST_ERROR("Failed iterator == comparison.", charT);
      }
#ifdef BOOST_MSVC
#pragma warning(push)
#pragma warning(disable:4244)
#endif
      if(boost::re_detail::distance(search_text.begin(), start2->first) != last_end2)
      {
         BOOST_REGEX_TEST_ERROR(
            "Error in location of start of field split, found: " 
            << boost::re_detail::distance(search_text.begin(), start2->first)
            << ", expected: "
            << last_end2
            << ".", charT);
      }
      int expected_end = static_cast<int>(answer_table[0] < 0 ? search_text.size() : answer_table[0]);
      if(boost::re_detail::distance(search_text.begin(), start2->second) != expected_end)
      {
         BOOST_REGEX_TEST_ERROR(
            "Error in location of end2 of field split, found: "
            << boost::re_detail::distance(search_text.begin(), start2->second)
            << ", expected: "
            << expected_end
            << ".", charT);
      }
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
      last_end2 = answer_table[1];
      ++start2;
      ++copy2;
      // move on the answer table to next set of answers;
      if(*answer_table != -2)
         while(*answer_table++ != -2){}
   }
   if(answer_table[0] >= 0)
   {
      // we should have had a match but didn't:
      BOOST_REGEX_TEST_ERROR("Expected match was not found.", charT);
   }
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
   //
   // and now both field splitting and $0:
   //
   std::vector<int> subs;
   subs.push_back(-1);
   subs.push_back(0);
   start2 = test_iterator(search_text.begin(), search_text.end(), r, subs, opts);
   copy2 = start2;
   last_end2 = 0;
   answer_table = test_info<charT>::answer_table();
   while(start2 != end2)
   {
      if(start2 != copy2)
      {
         BOOST_REGEX_TEST_ERROR("Failed iterator != comparison.", charT);
      }
      if(!(start2 == copy2))
      {
         BOOST_REGEX_TEST_ERROR("Failed iterator == comparison.", charT);
      }
#ifdef BOOST_MSVC
#pragma warning(push)
#pragma warning(disable:4244)
#endif
      if(boost::re_detail::distance(search_text.begin(), start2->first) != last_end2)
      {
         BOOST_REGEX_TEST_ERROR(
            "Error in location of start of field split, found: " 
            << boost::re_detail::distance(search_text.begin(), start2->first)
            << ", expected: "
            << last_end2
            << ".", charT);
      }
      int expected_end = static_cast<int>(answer_table[0] < 0 ? search_text.size() : answer_table[0]);
      if(boost::re_detail::distance(search_text.begin(), start2->second) != expected_end)
      {
         BOOST_REGEX_TEST_ERROR(
            "Error in location of end2 of field split, found: "
            << boost::re_detail::distance(search_text.begin(), start2->second)
            << ", expected: "
            << expected_end
            << ".", charT);
      }
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
      last_end2 = answer_table[1];
      ++start2;
      ++copy2;
      if((start2 == end2) && (answer_table[0] >= 0))
      {
         BOOST_REGEX_TEST_ERROR(
            "Expected $0 match not found", charT);
      }
      if(start2 != end2)
      {
         test_sub_match(*start2, search_text.begin(), answer_table, 0);
         ++start2;
         ++copy2;
      }
      // move on the answer table to next set of answers;
      if(*answer_table != -2)
         while(*answer_table++ != -2){}
   }
   if(answer_table[0] >= 0)
   {
      // we should have had a match but didn't:
      BOOST_REGEX_TEST_ERROR("Expected match was not found.", charT);
   }
#endif
}
Exemple #23
0
int crypto_stream_aes128ctr_afternm(unsigned char *out, unsigned long long len, const unsigned char *nonce, const unsigned char *c)
{

  int128 xmm0;
  int128 xmm1;
  int128 xmm2;
  int128 xmm3;
  int128 xmm4;
  int128 xmm5;
  int128 xmm6;
  int128 xmm7;

  int128 xmm8;
  int128 xmm9;
  int128 xmm10;
  int128 xmm11;
  int128 xmm12;
  int128 xmm13;
  int128 xmm14;
  int128 xmm15;

  int128 nonce_stack;
  unsigned long long lensav;
  unsigned char bl[128];
  unsigned char *blp;
  unsigned char *np;
  unsigned char b;

  uint32 tmp;

  /* Copy nonce on the stack */
  copy2(&nonce_stack, (const int128 *) (nonce + 0));
  np = (unsigned char *)&nonce_stack;

    enc_block:

    xmm0 = *(int128 *) (np + 0);
    copy2(&xmm1, &xmm0);
    shufb(&xmm1, SWAP32);
    copy2(&xmm2, &xmm1);
    copy2(&xmm3, &xmm1);
    copy2(&xmm4, &xmm1);
    copy2(&xmm5, &xmm1);
    copy2(&xmm6, &xmm1);
    copy2(&xmm7, &xmm1);

    add_uint32_big(&xmm1, 1);
    add_uint32_big(&xmm2, 2);
    add_uint32_big(&xmm3, 3);
    add_uint32_big(&xmm4, 4);
    add_uint32_big(&xmm5, 5);
    add_uint32_big(&xmm6, 6);
    add_uint32_big(&xmm7, 7);

    shufb(&xmm0, M0);
    shufb(&xmm1, M0SWAP);
    shufb(&xmm2, M0SWAP);
    shufb(&xmm3, M0SWAP);
    shufb(&xmm4, M0SWAP);
    shufb(&xmm5, M0SWAP);
    shufb(&xmm6, M0SWAP);
    shufb(&xmm7, M0SWAP);

    bitslice(xmm7, xmm6, xmm5, xmm4, xmm3, xmm2, xmm1, xmm0, xmm8)

    aesround( 1, xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15,c)
    aesround( 2, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7,c)
    aesround( 3, xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15,c)
    aesround( 4, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7,c)
    aesround( 5, xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15,c)
    aesround( 6, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7,c)
    aesround( 7, xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15,c)
    aesround( 8, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7,c)
    aesround( 9, xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15,c)
    lastround(xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7,c)

    bitslice(xmm13, xmm10, xmm15, xmm11, xmm14, xmm12, xmm9, xmm8, xmm0)

    if(len < 128) goto partial;
    if(len == 128) goto full;

    tmp = LOAD32_BE(np + 12);
    tmp += 8;
    STORE32_BE(np + 12, tmp);

    *(int128 *) (out + 0) = xmm8;
    *(int128 *) (out + 16) = xmm9;
    *(int128 *) (out + 32) = xmm12;
    *(int128 *) (out + 48) = xmm14;
    *(int128 *) (out + 64) = xmm11;
    *(int128 *) (out + 80) = xmm15;
    *(int128 *) (out + 96) = xmm10;
    *(int128 *) (out + 112) = xmm13;

    len -= 128;
    out += 128;

    goto enc_block;

    partial:

    lensav = len;
    len >>= 4;

    tmp = LOAD32_BE(np + 12);
    tmp += len;
    STORE32_BE(np + 12, tmp);

    blp = bl;
    *(int128 *)(blp + 0) = xmm8;
    *(int128 *)(blp + 16) = xmm9;
    *(int128 *)(blp + 32) = xmm12;
    *(int128 *)(blp + 48) = xmm14;
    *(int128 *)(blp + 64) = xmm11;
    *(int128 *)(blp + 80) = xmm15;
    *(int128 *)(blp + 96) = xmm10;
    *(int128 *)(blp + 112) = xmm13;

    bytes:

    if(lensav == 0) goto end;

    b = blp[0]; /* clang false positive */
    *(unsigned char *)(out + 0) = b;

    blp += 1;
    out +=1;
    lensav -= 1;

    goto bytes;

    full:

    tmp = LOAD32_BE(np + 12);
    tmp += 8;
    STORE32_BE(np + 12, tmp);

    *(int128 *) (out + 0) = xmm8;
    *(int128 *) (out + 16) = xmm9;
    *(int128 *) (out + 32) = xmm12;
    *(int128 *) (out + 48) = xmm14;
    *(int128 *) (out + 64) = xmm11;
    *(int128 *) (out + 80) = xmm15;
    *(int128 *) (out + 96) = xmm10;
    *(int128 *) (out + 112) = xmm13;

    end:
    return 0;

}
TEST(ResourceRequestTest, CrossThreadResourceRequestData) {
  ResourceRequest original;
  original.setURL(KURL(ParsedURLString, "http://www.example.com/test.htm"));
  original.setCachePolicy(WebCachePolicy::UseProtocolCachePolicy);
  original.setTimeoutInterval(10);
  original.setFirstPartyForCookies(
      KURL(ParsedURLString, "http://www.example.com/first_party.htm"));
  original.setRequestorOrigin(SecurityOrigin::create(
      KURL(ParsedURLString, "http://www.example.com/first_party.htm")));
  original.setHTTPMethod(HTTPNames::GET);
  original.setHTTPHeaderField(AtomicString("Foo"), AtomicString("Bar"));
  original.setHTTPHeaderField(AtomicString("Piyo"), AtomicString("Fuga"));
  original.setPriority(ResourceLoadPriorityLow, 20);

  RefPtr<EncodedFormData> originalBody(EncodedFormData::create("Test Body"));
  original.setHTTPBody(originalBody);
  original.setAllowStoredCredentials(false);
  original.setReportUploadProgress(false);
  original.setHasUserGesture(false);
  original.setDownloadToFile(false);
  original.setSkipServiceWorker(WebURLRequest::SkipServiceWorker::None);
  original.setFetchRequestMode(WebURLRequest::FetchRequestModeCORS);
  original.setFetchCredentialsMode(
      WebURLRequest::FetchCredentialsModeSameOrigin);
  original.setRequestorID(30);
  original.setRequestorProcessID(40);
  original.setAppCacheHostID(50);
  original.setRequestContext(WebURLRequest::RequestContextAudio);
  original.setFrameType(WebURLRequest::FrameTypeNested);
  original.setHTTPReferrer(
      Referrer("http://www.example.com/referrer.htm", ReferrerPolicyDefault));

  EXPECT_STREQ("http://www.example.com/test.htm",
               original.url().getString().utf8().data());
  EXPECT_EQ(WebCachePolicy::UseProtocolCachePolicy, original.getCachePolicy());
  EXPECT_EQ(10, original.timeoutInterval());
  EXPECT_STREQ("http://www.example.com/first_party.htm",
               original.firstPartyForCookies().getString().utf8().data());
  EXPECT_STREQ("www.example.com",
               original.requestorOrigin()->host().utf8().data());
  EXPECT_STREQ("GET", original.httpMethod().utf8().data());
  EXPECT_STREQ("Bar", original.httpHeaderFields().get("Foo").utf8().data());
  EXPECT_STREQ("Fuga", original.httpHeaderFields().get("Piyo").utf8().data());
  EXPECT_EQ(ResourceLoadPriorityLow, original.priority());
  EXPECT_STREQ("Test Body",
               original.httpBody()->flattenToString().utf8().data());
  EXPECT_FALSE(original.allowStoredCredentials());
  EXPECT_FALSE(original.reportUploadProgress());
  EXPECT_FALSE(original.hasUserGesture());
  EXPECT_FALSE(original.downloadToFile());
  EXPECT_EQ(WebURLRequest::SkipServiceWorker::None,
            original.skipServiceWorker());
  EXPECT_EQ(WebURLRequest::FetchRequestModeCORS, original.fetchRequestMode());
  EXPECT_EQ(WebURLRequest::FetchCredentialsModeSameOrigin,
            original.fetchCredentialsMode());
  EXPECT_EQ(30, original.requestorID());
  EXPECT_EQ(40, original.requestorProcessID());
  EXPECT_EQ(50, original.appCacheHostID());
  EXPECT_EQ(WebURLRequest::RequestContextAudio, original.requestContext());
  EXPECT_EQ(WebURLRequest::FrameTypeNested, original.frameType());
  EXPECT_STREQ("http://www.example.com/referrer.htm",
               original.httpReferrer().utf8().data());
  EXPECT_EQ(ReferrerPolicyDefault, original.getReferrerPolicy());

  std::unique_ptr<CrossThreadResourceRequestData> data1(original.copyData());
  ResourceRequest copy1(data1.get());

  EXPECT_STREQ("http://www.example.com/test.htm",
               copy1.url().getString().utf8().data());
  EXPECT_EQ(WebCachePolicy::UseProtocolCachePolicy, copy1.getCachePolicy());
  EXPECT_EQ(10, copy1.timeoutInterval());
  EXPECT_STREQ("http://www.example.com/first_party.htm",
               copy1.firstPartyForCookies().getString().utf8().data());
  EXPECT_STREQ("www.example.com",
               copy1.requestorOrigin()->host().utf8().data());
  EXPECT_STREQ("GET", copy1.httpMethod().utf8().data());
  EXPECT_STREQ("Bar", copy1.httpHeaderFields().get("Foo").utf8().data());
  EXPECT_EQ(ResourceLoadPriorityLow, copy1.priority());
  EXPECT_STREQ("Test Body", copy1.httpBody()->flattenToString().utf8().data());
  EXPECT_FALSE(copy1.allowStoredCredentials());
  EXPECT_FALSE(copy1.reportUploadProgress());
  EXPECT_FALSE(copy1.hasUserGesture());
  EXPECT_FALSE(copy1.downloadToFile());
  EXPECT_EQ(WebURLRequest::SkipServiceWorker::None, copy1.skipServiceWorker());
  EXPECT_EQ(WebURLRequest::FetchRequestModeCORS, copy1.fetchRequestMode());
  EXPECT_EQ(WebURLRequest::FetchCredentialsModeSameOrigin,
            copy1.fetchCredentialsMode());
  EXPECT_EQ(30, copy1.requestorID());
  EXPECT_EQ(40, copy1.requestorProcessID());
  EXPECT_EQ(50, copy1.appCacheHostID());
  EXPECT_EQ(WebURLRequest::RequestContextAudio, copy1.requestContext());
  EXPECT_EQ(WebURLRequest::FrameTypeNested, copy1.frameType());
  EXPECT_STREQ("http://www.example.com/referrer.htm",
               copy1.httpReferrer().utf8().data());
  EXPECT_EQ(ReferrerPolicyDefault, copy1.getReferrerPolicy());

  copy1.setAllowStoredCredentials(true);
  copy1.setReportUploadProgress(true);
  copy1.setHasUserGesture(true);
  copy1.setDownloadToFile(true);
  copy1.setSkipServiceWorker(WebURLRequest::SkipServiceWorker::All);
  copy1.setFetchRequestMode(WebURLRequest::FetchRequestModeNoCORS);
  copy1.setFetchCredentialsMode(WebURLRequest::FetchCredentialsModeInclude);

  std::unique_ptr<CrossThreadResourceRequestData> data2(copy1.copyData());
  ResourceRequest copy2(data2.get());
  EXPECT_TRUE(copy2.allowStoredCredentials());
  EXPECT_TRUE(copy2.reportUploadProgress());
  EXPECT_TRUE(copy2.hasUserGesture());
  EXPECT_TRUE(copy2.downloadToFile());
  EXPECT_EQ(WebURLRequest::SkipServiceWorker::All, copy2.skipServiceWorker());
  EXPECT_EQ(WebURLRequest::FetchRequestModeNoCORS, copy1.fetchRequestMode());
  EXPECT_EQ(WebURLRequest::FetchCredentialsModeInclude,
            copy1.fetchCredentialsMode());
}
Exemple #25
0
    void doClassification(Octree* pOctree, CSGTree<RegularMesh>* pCSG,
        std::vector<RegularMesh*>& meshList, RegularMesh* result,
        MyVertex::Index seedId)
    {
        uint32_t nMesh = meshList.size();
        CSGTreeOld* tree = pCSG->auxiliary();
        CSGTreeNode** curTreeLeaves = new CSGTreeNode*[nMesh];

        SSeed tmpSeed;
        MyVertex& seedV = xvertex(seedId);
        tmpSeed.edgeId = *seedV.edges.begin();
        MyEdge& seedE = xedge(tmpSeed.edgeId);

        tmpSeed.eIndicators.reset(new FullIndicatorVector(nMesh));
        calcEdgeIndicatorByExtremity(seedId, tmpSeed, 
            *reinterpret_cast<FullIndicatorVector*>(tmpSeed.eIndicators.get()), nMesh);

        MeshId curMeshId;
        std::queue<IPolygon*> faceQueue;
        std::queue<SSeed> intraQueue, interQueue;
        bool added, inverse;
        std::pair<uint32_t, uint32_t> inversePair;
        Relation relation;
        TestTree dummyForest;
        std::vector<Relation> relTab(nMesh);
        std::vector<MyEdge::Index> edges;

        interQueue.push(tmpSeed);
        tmpSeed.pFace->mark = SEEDED0;
        assert(tmpSeed.pFace->isValid());
        while (!interQueue.empty())
        {
            SSeed curSeed = interQueue.front();
            interQueue.pop();

            if (curSeed.pFace->mark == VISITED)
                continue;

            assert(intraQueue.empty());
            curSeed.pFace->mark = SEEDED1;
            intraQueue.push(curSeed);

            curMeshId = curSeed.pFace->meshId();
            inverse = meshList[curMeshId]->inverse();
            if (inverse)
                inversePair.first = result->faces().size();

            bool seedFlag = true;
            while (!intraQueue.empty())
            {
                curSeed = intraQueue.front();
                intraQueue.pop();

                if (curSeed.pFace->mark == VISITED)
                    continue;

                CSGTreeNode* tree0 = copy2(tree->pRoot, curTreeLeaves);

                calcFaceIndicator(curSeed, relTab, seedFlag?false:true);
                if (seedFlag) seedFlag = false; // only for debug use

                relation = ParsingCSGTree(meshList[curMeshId], relTab.data(), 
                    nMesh, tree0, curTreeLeaves, dummyForest);
                assert(relation != REL_NOT_AVAILABLE || relation != REL_UNKNOWN);

                added = (relation == REL_SAME); 
                faceQueue.push(curSeed.pFace);
                while (!faceQueue.empty())
                {
                    IPolygon* curFace = faceQueue.front();
                    faceQueue.pop();
                    if (curFace->mark == VISITED)
                        continue;

                    curFace->mark = VISITED;
                    if (added)
                        result->faces().push_back(curFace);

                    edges.clear();
                    curFace->getEdges(edges);
                    assert(edges.size() == curFace->degree());

                    // flood filling, bfs
                    for (int i = 0; i < curFace->degree(); i++)
                    {
                        MyEdge& curEdge = xedge(edges[i]);
                        MyEdge::FaceIterator fItr(curEdge);
                        if (curEdge.neighbor)
                        {
                            // 但因为共面的存在,有些neigh可能记录的相邻,但不在相邻面当中,这没关系!
                            //assert(curEdge.faceCount() >= 4); // 如果这是一个相交而成的边,那么一定会有超过4个polygon在周围
                            for (; fItr; ++fItr)
                            {
                                if (!fItr.face())
                                {
                                    XLOG_ERROR << "Edge with less than two neighboring faces.";
                                    continue;
                                }

                                if (!fItr.face()->isValid()) continue;

                                tmpSeed.edgeId = edges[i];
                                tmpSeed.pFace = fItr.face();

                                for (int i = 0; i < nMesh; i++)
                                {
                                    Indicator tmpInd = REL_NOT_AVAILABLE;
                                    switch (relTab[i])
                                    {
                                    case REL_SAME:
                                    case REL_OPPOSITE:
                                        tmpInd = REL_ON_BOUNDARY;
                                        break;
                                    default:
                                        tmpInd = relTab[i];
                                        break;
                                    }
                                    tmpSeed.eIndicators->at(i) = tmpInd;
                                }

                                for (NeighborInfo& nInfo : *curEdge.neighbor)
                                    tmpSeed.eIndicators->at(nInfo.neighborMeshId) = REL_ON_BOUNDARY;

                                if (fItr.face()->meshId() == curMeshId)
                                {
                                    if (fItr.face()->mark < SEEDED1)
                                    {
                                        tmpSeed.pFace->mark = SEEDED1;
                                        intraQueue.push(tmpSeed);
                                    }
                                }
                                else
                                {
                                    if (fItr.face()->mark < SEEDED0)
                                    {
                                        tmpSeed.pFace->mark = SEEDED0;
                                        interQueue.push(tmpSeed);
                                    }
                                }
                            }
                        }
                        else
                        {
                            for (; fItr; ++fItr)
                            {
                                if (!fItr.face())
                                {
                                    XLOG_ERROR << "Edge with less than two neighboring faces.";
                                    continue;
                                }
                                if (!fItr.face()->isValid() || fItr.face()->meshId() != curMeshId) continue;
                                if (fItr.face()->mark < SEEDED2)
                                {
                                    faceQueue.push(fItr.face());
                                    fItr.face()->mark = SEEDED2;
                                }
                            }
                        }
                    }
                }
                //break;
            }
            if (inverse)
            {
                inversePair.second = result->faces().size();
                result->inverseMap.push_back(inversePair);
            }
            //break;
        }
        SAFE_DELETE_ARRAY(curTreeLeaves);
    }