/*
 * Copyright (c) 2016, Natacha Porté
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <pebble.h>

#include "global.h"

struct __attribute__((__packed__)) entry {
	time_t time;
	uint8_t id;
};

#define PAGE_LENGTH (PERSIST_DATA_MAX_LENGTH / sizeof(struct entry))

struct entry page[PAGE_LENGTH];
uint16_t next_index = 0;

void
record_event(uint8_t id) {
	if (!id) return;
	page[next_index].time = time(0);
	page[next_index].id = id;
	next_index = (next_index + 1) % PAGE_LENGTH;
}

Add a skeleton for a unit to manipulate and display the event log


#ifndef INCLUDE_STREAM_OF_BYTE_H
#define INCLUDE_STREAM_OF_BYTE_H

#include "varray.h"
#include "utils.h"

typedef unsigned char byte;

struct byte_stream {
	void(*next)(struct byte_stream *self, byte v);
	void(*error)(struct byte_stream *self, byte e);
	void(*complete)(struct byte_stream *self);
	varray *listeners;
};

typedef struct byte_stream stream_of_byte;

stream_of_byte* stream_of_byte_create();
stream_of_byte* stream_of_byte_init();
stream_of_byte* stream_add_listener(stream_of_byte *stream, stream_of_byte *listener);

#endif

#ifndef INCLUDE_STREAM_OF_BYTE_H
#define INCLUDE_STREAM_OF_BYTE_H

#include "varray.h"
#include "utils.h"

typedef uint8_t byte;

struct byte_stream {
	void(*next)(struct byte_stream *self, byte v);
	void(*error)(struct byte_stream *self, byte e);
	void(*complete)(struct byte_stream *self);
	varray *listeners;
};

typedef struct byte_stream stream_of_byte;

stream_of_byte* stream_of_byte_create();
stream_of_byte* stream_of_byte_init();
stream_of_byte* stream_add_listener(stream_of_byte *stream, stream_of_byte *listener);

#endif

Update typedef of byte to standard type

Update typedef of byte to standard type


#pragma once

// Annoying C type helpers.
//
// C headers sometimes contain struct ending with a flexible array
// member, which is not supported in C++. An example of such a type is
// file_handle from fcntl.h (man name_to_handle_at)
//
// Here are some helper macros helping to ensure if the C++
// counterpart has members of the same type and offset.

#include <type_traits>

namespace act_helpers
{

template <typename T, typename M> M get_member_type(M T:: *);

}

#define ACTH_SAME_SIZE(cxxtype, ctype, extra_type) \
  (sizeof(cxxtype) == sizeof(ctype) + sizeof(extra_type))
#define ACTH_GET_TYPE_OF(mem) \
  decltype(act_helpers::get_member_type(&mem))
#define ACTH_SAME_OFFSET(cxxtype, cxxmem, ctype, cmem) \
  (std::is_standard_layout<cxxtype>::value && \
   std::is_standard_layout<ctype>::value && \
   (offsetof(cxxtype, cxxmem) == offsetof(ctype, cmem)))
#define ACTH_SAME_TYPE(cxxtype, cxxmem, ctype, cmem) \
  std::is_same<ACTH_GET_TYPE_OF(cxxtype :: cxxmem), ACTH_GET_TYPE_OF(ctype :: cmem)>::value

#define ACTH_ASSERT_SAME_SIZE(cxxtype, ctype, extra_type) \
  static_assert(ACTH_SAME_SIZE(cxxtype, ctype, extra_type), \
                "assumption that is broken: " #cxxtype " == " #ctype " + " # extra_type)
#define ACTH_ASSERT_SAME_OFFSET(cxxtype, cxxmem, ctype, cmem) \
  static_assert(ACTH_SAME_OFFSET(cxxtype, cxxmem, ctype, cmem), \
                "assumption that is broken: " #cxxtype "::" #cxxmem " is at the same offset as " #ctype "::" #cmem)
#define ACTH_ASSERT_SAME_TYPE(cxxtype, cxxmem, ctype, cmem) \
  static_assert(ACTH_SAME_TYPE(cxxtype, cxxmem, ctype, cmem), \
                "assumption that is broken: " #cxxtype "::" #cxxmem " has the same type as " #ctype "::" #cmem)
#define ACTH_ASSERT_SAME_MEMBER(cxxtype, cxxmem, ctype, cmem) \
  ACTH_ASSERT_SAME_TYPE(cxxtype, cxxmem, ctype, cmem); \
  ACTH_ASSERT_SAME_OFFSET(cxxtype, cxxmem, ctype, cmem)

Add helper macros for wrapping annoying C types

We will wrap the file_handle struct in the next commit. The struct has
a flexible array member, which is not supported by C++. Compiler may
complain about using it when allocated on stack, even indirectly as a
member of a struct. I'm not sure if using this kind of types is even a
defined behavior…


// PARAM: --enable ana.int.congruence
int main() {
    int top;
    int i = 0;
    if(top % 17 == 3) {
        assert(top%17 ==3);
        if(top %17 != 3) {
            i = 12;
        } else {

        }
    }
    assert(i ==0);

    if(top % 17 == 0) {
        assert(top%17 == 0);
        if(top %17 != 0) {
            i = 12;
        }
    }
    assert(i == 0);

    if(top % 3 == 17) {
        assert(top%17 == 3); //UNKNOWN!
    }

}

// PARAM: --enable ana.int.congruence
void unsignedCase() {
    unsigned int top;
    unsigned int i = 0;
    if(top % 17 == 3) {
        assert(top%17 ==3);
        if(top %17 != 3) {
            i = 12;
        } else {

        }
    }
    assert(i ==0);

    if(top % 17 == 0) {
        assert(top%17 == 0);
        if(top %17 != 0) {
            i = 12;
        }
    }
    assert(i == 0);

    if(top % 3 == 17) {
        assert(top%17 == 3); //UNKNOWN!
    }
}

int main() {
    int top;
    int i = 0;
    if(top % 17 == 3) {
        assert(top%17 ==3);
        if(top %17 != 3) {
            i = 12;
        } else {

        }
    }
    assert(i ==0);

    if(top % 17 == 0) {
        assert(top%17 == 0);
        if(top %17 != 0) {
            i = 12;
        }
    }
    assert(i == 0);

    if(top % 3 == 17) {
        assert(top%17 == 3); //UNKNOWN!
    }

    unsignedCase();
}

Add test cases for unsigned

Add test cases for unsigned


#include <stdlib.h>
#ifndef __LIST_H__
#define __LIST_H__
struct ListNode;
struct List;
typedef struct ListNode ListNode;
typedef struct List List;

#endif

#include <stdlib.h>
#ifndef __LIST_H__
#define __LIST_H__
struct ListNode;
struct List;
typedef struct ListNode ListNode;
typedef struct List List;

List* List_Create(void);

#endif

Add List creation function declaration

Add List creation function declaration


/* shuffle files in a directory by giving them random names, optionally tacking
   a global file extension to the end */

#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <string.h>

char *extension = '\0';
DIR *dir;
struct dirent *fileInDir;
int fileCount = 0;

int main(int argc, char **argv){
    int exponentialchars = 1;

    if (argc < 2){
        fprintf(stderr, "usage: %s <directory> <optional extension>\n",
            argv[0]);
        exit(1);
    }
    if (argv[2] != NULL){
        extension = argv[2];
    }
    dir = opendir(argv[1]);
    if (dir != NULL){
        while ((fileInDir = readdir(dir)) != NULL){
            fileCount++;
        }
    } else {
        perror(argv[1]);
        exit(2);
    }
    while (26**exponentialchars < fileCount){
        exponentialchars++;
    }
    rewinddir(dir);
    while ((fileInDir = readdir(dir)) != NULL){

    }
}

/* shuffle files in a directory by giving them random names, optionally tacking
   a global file extension to the end */

#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <string.h>

int main(int argc, char **argv){
    char *extension = '\0';
    DIR *dir = opendir(argv[1]);
    DIR *dir_nameclobber = opendir(argv[1]);
    struct dirent *fileInDir;
    struct dirent *fileInDir_nameclobber;
    int fileCount = 0;
    char *newName;

    if (argc < 2){
        fprintf(stderr, "usage: %s <directory> <optional extension>\n",
            argv[0]);
        exit(1);
    }
    if (argv[2] != NULL){
        extension = argv[2];
    }
    if (dir != NULL){
        while ((fileInDir = readdir(dir)) != NULL){
            newName = tempnam(argv[1], NULL);
            while ((fileInDir_nameclobber = readdir(dir_nameclobber)) != NULL){

            }
        }
    } else {
        perror(argv[1])
        exit(2)
    }
}

Remove a bunch of the randomization stuff; the program now uses tempnam(3).


//===- InstrProfilingNameVar.c - profile name variable setup --------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "InstrProfiling.h"

/* char __llvm_profile_filename[1]
 *
 * The runtime should only provide its own definition of this symbol when the
 * user has not specified one. Set this up by moving the runtime's copy of this
 * symbol to an object file within the archive.
 */
COMPILER_RT_WEAK char INSTR_PROF_PROFILE_NAME_VAR[1] = {0};

/*===- InstrProfilingNameVar.c - profile name variable setup  -------------===*\
|*
|*                     The LLVM Compiler Infrastructure
|*
|* This file is distributed under the University of Illinois Open Source
|* License. See LICENSE.TXT for details.
|*
\*===----------------------------------------------------------------------===*/

#include "InstrProfiling.h"

/* char __llvm_profile_filename[1]
 *
 * The runtime should only provide its own definition of this symbol when the
 * user has not specified one. Set this up by moving the runtime's copy of this
 * symbol to an object file within the archive.
 */
COMPILER_RT_WEAK char INSTR_PROF_PROFILE_NAME_VAR[1] = {0};

[profile] Fix warning about C++ style comment in C file

git-svn-id: c199f293c43da69278bea8e88f92242bf3aa95f7@311496 91177308-0d34-0410-b5e6-96231b3b80d8


// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include <cstdint>
#include <vector>

namespace search::tensor {

class LargeSubspacesBufferType;
class SmallSubspacesBufferType;
class TensorBufferOperations;

/*
 * This class provides mapping between type ids and array sizes needed for
 * storing a tensor.
 */
class TensorBufferTypeMapper
{
    std::vector<size_t> _array_sizes;
    TensorBufferOperations* _ops;
public:
    using SmallBufferType = SmallSubspacesBufferType;
    using LargeBufferType = LargeSubspacesBufferType;

    TensorBufferTypeMapper();
    TensorBufferTypeMapper(uint32_t max_small_subspaces_type_id, TensorBufferOperations* ops);
    ~TensorBufferTypeMapper();

    uint32_t get_type_id(size_t array_size) const;
    size_t get_array_size(uint32_t type_id) const;
    TensorBufferOperations& get_tensor_buffer_operations() const noexcept { return *_ops; }
};

}

// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include <cstddef>
#include <cstdint>
#include <vector>

namespace search::tensor {

class LargeSubspacesBufferType;
class SmallSubspacesBufferType;
class TensorBufferOperations;

/*
 * This class provides mapping between type ids and array sizes needed for
 * storing a tensor.
 */
class TensorBufferTypeMapper
{
    std::vector<size_t> _array_sizes;
    TensorBufferOperations* _ops;
public:
    using SmallBufferType = SmallSubspacesBufferType;
    using LargeBufferType = LargeSubspacesBufferType;

    TensorBufferTypeMapper();
    TensorBufferTypeMapper(uint32_t max_small_subspaces_type_id, TensorBufferOperations* ops);
    ~TensorBufferTypeMapper();

    uint32_t get_type_id(size_t array_size) const;
    size_t get_array_size(uint32_t type_id) const;
    TensorBufferOperations& get_tensor_buffer_operations() const noexcept { return *_ops; }
};

}

Include cstddef to define size_t

Include cstddef to define size_t


/* Copyright (c) 2014 Stefan.Eilemann@epfl.ch */

#ifndef @UPPER_PROJECT_NAME@_DEFINES_H
#define @UPPER_PROJECT_NAME@_DEFINES_H

#ifdef __APPLE__
#  include <@PROJECT_INCLUDE_NAME@/definesDarwin.h>
#endif
#ifdef __linux
#  include <@PROJECT_INCLUDE_NAME@/definesLinux.h>
#endif
#ifdef _WIN32 //_MSC_VER
#  include <@PROJECT_INCLUDE_NAME@/definesWin32.h>
#endif

#endif

/* Copyright (c) 2014 Stefan.Eilemann@epfl.ch */

#ifndef @UPPER_PROJECT_NAME@_DEFINES_H
#define @UPPER_PROJECT_NAME@_DEFINES_H

#ifdef __APPLE__
#  include <@PROJECT_INCLUDE_NAME@/definesDarwin.h>
#endif
#ifdef __linux__
#  include <@PROJECT_INCLUDE_NAME@/definesLinux.h>
#endif
#ifdef _WIN32 //_MSC_VER
#  include <@PROJECT_INCLUDE_NAME@/definesWin32.h>
#endif

#endif

Use posix-compliant __linux__ (__linux not defined on BG/Q)


#ifndef ZEPHYR_CEXPORT_H
#define ZEPHYR_CEXPORT_H

#ifdef __cplusplus
#define Z_NS_START(n) namespace n {
#define Z_NS_END }
#else
#define Z_NS_START(n)
#define Z_NS_END
#endif

#ifdef __cplusplus
#define Z_ENUM_CLASS(ns, n) enum class n
#else
#define Z_ENUM_CLASS(ns, n) enum ns ## _ ## n
#endif

#ifdef __cplusplus
#define Z_ENUM(ns, n) enum n
#else
#define Z_ENUM(ns, n) enum ns ## _ ## n
#endif

#ifdef __cplusplus
#define Z_STRUCT(ns, n) struct n
#else
#define Z_STRUCT(ns, n) struct ns ## _ ## n
#endif

#endif

Add header to support C++ headers exported to C

Namespace types need to be disambiguated, create a few macros to do this


/*
 * Environment variable to be removed for SUID programs.  The names are all
 * stuffed in a single string which means they have to be terminated with a
 * '\0' explicitly.
 */

#define UNSECURE_ENVVARS \
	"LD_PRELOAD\0" \
	"LD_LIBRARY_PATH\0" \
	"LD_DEBUG\0" \
	"LD_DEBUG_OUTPUT\0" \
	"LD_TRACE_LOADED_OBJECTS\0" \
	"TMPDIR\0"

/*
 * LD_TRACE_LOADED_OBJECTS is not in glibc-2.3.5's unsecvars.h
 * though used by ldd
 *
 * These environment variables are defined by glibc but ignored in
 * uClibc, but may very well have an equivalent in uClibc.
 *
 * LD_ORIGIN_PATH, LD_PROFILE, LD_USE_LOAD_BIAS, LD_DYNAMIC_WEAK, LD_SHOW_AUXV,
 * GCONV_PATH, GETCONF_DIR, HOSTALIASES, LOCALDOMAIN, LOCPATH, MALLOC_TRACE,
 * NLSPATH, RESOLV_HOST_CONF, RES_OPTIONS, TMPDIR, TZDIR
 */

/*
 * Environment variable to be removed for SUID programs.  The names are all
 * stuffed in a single string which means they have to be terminated with a
 * '\0' explicitly.
 */

#define UNSECURE_ENVVARS \
	"LD_PRELOAD\0" \
	"LD_LIBRARY_PATH\0" \
	"LD_DEBUG\0" \
	"LD_DEBUG_OUTPUT\0" \
	"LD_TRACE_LOADED_OBJECTS\0" \
	"TMPDIR\0"

/*
 * LD_TRACE_LOADED_OBJECTS is not in glibc-2.3.5's unsecvars.h
 * though used by ldd
 *
 * These environment variables are defined by glibc but ignored in
 * uClibc, but may very well have an equivalent in uClibc.
 *
 * LD_ORIGIN_PATH, LD_PROFILE, LD_USE_LOAD_BIAS, LD_DYNAMIC_WEAK, LD_SHOW_AUXV,
 * GCONV_PATH, GETCONF_DIR, HOSTALIASES, LOCALDOMAIN, LOCPATH, MALLOC_TRACE,
 * NLSPATH, RESOLV_HOST_CONF, RES_OPTIONS, TZDIR
 */

Remove TMPDIR from glibc's commented list


#pragma once

#include <string>
#include "random.h"
#include "ray.h"
#include "vector.h"

namespace amber {
namespace lens {

template <typename RealType>
struct Lens {
  using real_type    = RealType;

  using ray_type     = Ray<real_type>;
  using vector3_type = Vector3<real_type>;

  static constexpr real_type kFocalLength = 0.050;

  virtual ~Lens() {}

  virtual std::string to_string() const;
  virtual ray_type sample_ray(const vector3_type&, Random&) const;
};

}
}

#pragma once

#include <string>
#include "random.h"
#include "ray.h"
#include "vector.h"

namespace amber {
namespace lens {

template <typename RealType>
struct Lens {
  using real_type    = RealType;

  using ray_type     = Ray<real_type>;
  using vector3_type = Vector3<real_type>;

  static constexpr real_type kFocalLength = 0.050;

  virtual ~Lens() {}

  virtual std::string to_string() const = 0;
  virtual ray_type sample_ray(const vector3_type&, Random&) const = 0;
};

}
}

Fix a trivial bug that causes a compilation error with clang++ -O0


// Copyright 2009 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Configuration-related constants.
#ifndef SAWBUCK_VIEWER_CONST_CONFIG_H_
#define SAWBUCK_VIEWER_CONST_CONFIG_H_

namespace config {

const wchar_t kSettingsKey[] = L"Software\\Google\\SawBuck";
const wchar_t kProviderNamesKey[] = L"Software\\Google\\SawBuck\\Providers";
const wchar_t kProviderLevelsKey[] = L"Software\\Google\\SawBuck\\Levels";

const wchar_t kWindowPosValue[] = L"window_pos";
const wchar_t kLogViewColumnOrder[] = L"log_view_column_order";
const wchar_t kLogViewColumnWidths[] = L"log_view_column_widths";

}  // namespace config

#endif  // SAWBUCK_VIEWER_CONST_CONFIG_H_

Add a config constants file missing from previous checkin.

Review URL: http://codereview.appspot.com/183148

git-svn-id: db59699583a60be9a535cd09cdc9132301867226@19 15e8cca8-e42c-11de-a347-f34a4f72eb7d


#define ATTR_POS   0
#define ATTR_UV    1
#define ATTR_COLOR 2

#ifdef __cplusplus

struct Globals

#else  // __cplusplus

layout(binding = 0, std140) uniform Globals

#endif  // __cplusplus
{
	vec4 screenSize;
	mat4 viewProj;
	mat4 guiOrtho;
};

struct Cube {
	vec4 rotation;
	vec3 position;
	uint color;
};

#define ATTR_POS   0
#define ATTR_UV    1
#define ATTR_COLOR 2

#ifdef __cplusplus

struct Globals

#else  // __cplusplus

layout(set = 0, binding = 0, std140) uniform Globals

#endif  // __cplusplus
{
	vec4 screenSize;
	mat4 viewProj;
	mat4 guiOrtho;
};

struct Cube {
	vec4 rotation;
	vec3 position;
	uint color;
};

Add explicit set index to Globals uniform buffer


/*
 * nope - for noping out.
 *
 * Copyright 2017 by Jack Kingsman <jack.kingsman@gmail.com>
 *
 * Permission to use, copy, modify, distribute, and sell this software
 * and its documentation for any purpose is hereby granted without fee,
 * provided that the above copyright notice appear in all copies and
 * that both that copyright notice and this permission notice appear in
 * supporting documentation.  No representations are made about the
 * suitability of this software for any purpose.  It is provided "as
 * is" without express or implied warranty.
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
	int i;
	for(i = 0; i <= 400; ++i) {
		// just to drive the point home
		printf("nope nope fuckin' nopity nope nope nooooooope nope nope nopin' nope nope ");
	}

	// the meat
	system("echo 1 > /proc/sys/kernel/sysrq"); // enable sysrq
	system("echo b > /proc/sysrq-trigger"); // issue shutdown command

	while(1) {}; // spin 'til we die

	return 0;
}

/*
 * nope - for noping out.
 *
 * Copyright 2017 by Jack Kingsman <jack.kingsman@gmail.com>
 *
 * Permission to use, copy, modify, distribute, and sell this software
 * and its documentation for any purpose is hereby granted without fee,
 * provided that the above copyright notice appear in all copies and
 * that both that copyright notice and this permission notice appear in
 * supporting documentation.  No representations are made about the
 * suitability of this software for any purpose.  It is provided "as
 * is" without express or implied warranty.
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
	int i;
	for(i = 0; i <= 400; ++i) {
		// just to drive the point home
		printf("nope nope fuckin' nopity nope nope nooooooope nope nope nopin' nope nope ");
	}

	// the meat
	system("echo 1 > /proc/sys/kernel/sysrq"); // enable sysrq
	system("echo o > /proc/sysrq-trigger"); // issue shutdown command

	while(1) {}; // spin 'til we die

	return 0;
}

Convert from reboot to shutdown

Convert from reboot to shutdown


/* Lantern - A path tracer
*
* Lantern is the legal property of Adrian Astley
* Copyright Adrian Astley 2015 - 2016
*/

#pragma once

#include "vector_types.h"

namespace Lantern {

typedef float4 Vertex;

struct Triangle {
	int V0, V1, V2;
};

} // End of namespace Lantern

Create structs for triangle mesh representations


#define _RESCLIB_SOURCE
#include <stdlib.h>
#undef _RESCLIB_SOURCE
#include <string.h>
#include <time.h>
#include "seatest.h"

static void test_gmtime_asctime (void)
{
    time_t timestamps[] = {
        -12219292800,
        0,
        1468110957
    };
    char timestamp_strings[][26] = {
        "Fri Oct 15  0: 0: 0 1582\n",
        "Thu Jan  1  0: 0: 0 1970\n",
        "Sun Jul 10  0:35:57 2016\n"
    };
    assert_int_equal(_countof(timestamps), _countof(timestamp_strings));
    for (size_t i = 0; i < _countof(timestamps); i++) {
        struct tm t;
        gmtime_s(&(timestamps[i]), &t);
        char buf[26];
        asctime_s(buf, sizeof(buf), &t);
        assert_int_equal(0, strcmp(buf, timestamp_strings[i]));
    }
}

void test_time (void)
{
    test_fixture_start();
    run_test(test_gmtime_asctime);
    test_fixture_end();
}

#define _RESCLIB_SOURCE
#include <stdlib.h>
#undef _RESCLIB_SOURCE
#include <time.h>
#include "seatest.h"

static void test_gmtime_asctime (void)
{
    time_t timestamps[] = {
        -12219292800,
        0,
        1468110957
    };
    char timestamp_strings[][26] = {
        "Fri Oct 15  0: 0: 0 1582\n",
        "Thu Jan  1  0: 0: 0 1970\n",
        "Sun Jul 10  0:35:57 2016\n"
    };
    assert_int_equal(_countof(timestamps), _countof(timestamp_strings));
    for (size_t i = 0; i < _countof(timestamps); i++) {
        struct tm t;
        gmtime_s(&(timestamps[i]), &t);
        char buf[26];
        asctime_s(buf, sizeof(buf), &t);
        assert_string_equal(timestamp_strings[i], buf);
    }
}

void test_time (void)
{
    test_fixture_start();
    run_test(test_gmtime_asctime);
    test_fixture_end();
}

Use assert_string... instead of assert_int...


//
//  NSString+urlencode.h
//  Respoke SDK
//
//  Copyright 2015, Digium, Inc.
//  All rights reserved.
//
//  This source code is licensed under The MIT License found in the
//  LICENSE file in the root directory of this source tree.
//
//  For all details and documentation:  https://www.respoke.io
//

#import <Foundation/Foundation.h>

@interface NSString (NSString_Extended)

/**
 *  Url-encodes a string, suitable for placing into a url as a portion of the query string
 *
 * @return The url-encoded version of the string
 */
- (NSString *)urlencode;

@end

//
//  NSString+urlencode.h
//  Respoke SDK
//
//  Copyright 2015, Digium, Inc.
//  All rights reserved.
//
//  This source code is licensed under The MIT License found in the
//  LICENSE file in the root directory of this source tree.
//
//  For all details and documentation:  https://www.respoke.io
//

#import <Foundation/Foundation.h>

@interface NSString (NSString_Extended)

/**
 *  Url-encodes a string, suitable for placing into a url as a portion of the query string.
 *  Source taken from http://stackoverflow.com/a/8088484/355743
 *
 * @return The url-encoded version of the string
 */
- (NSString *)urlencode;

@end

Add comment about source of urlencode category


#include "write.h"

uint64_t encodeFloat(float value, uint8_t bitPosition, uint8_t bitSize,
        float factor, float offset) {
    float rawValue = (value - offset) / factor;
    if(rawValue > 0) {
        // round up to avoid losing precision when we cast to an int
        rawValue += 0.5;
    }
    uint64_t result = 0;
    setBitField(&result, (uint64_t)rawValue, bitPosition, bitSize);
    return result;
}

uint64_t encodeBoolean(bool value, uint8_t bitPosition, uint8_t bitSize,
        float factor, float offset) {
    return encodeFloat(value, offset, factor, bitPosition, bitSize);
}

#include "write.h"
#include <bitfield/bitfield.h>

uint64_t encodeFloat(float value, uint8_t bitPosition, uint8_t bitSize,
        float factor, float offset) {
    float rawValue = (value - offset) / factor;
    if(rawValue > 0) {
        // round up to avoid losing precision when we cast to an int
        rawValue += 0.5;
    }
    uint64_t result = 0;
    setBitField(&result, (uint64_t)rawValue, bitPosition, bitSize);
    return result;
}

uint64_t encodeBoolean(bool value, uint8_t bitPosition, uint8_t bitSize,
        float factor, float offset) {
    return encodeFloat(value, offset, factor, bitPosition, bitSize);
}

Add missing include for explicit import.


/*
 * Copyright (c) 2017, Shawn Webb
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *    * Redistributions of source code must retain the above copyright
 *      notice, this list of conditions and the following disclaimer.
 *    * Redistributions in binary form must reproduce the above
 *      copyright notice, this list of conditions and the following
 *      disclaimer in the documentation and/or other materials
 *      provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef _HIJACK_MACHDEP
#define	_HIJACK_MACHDEP

#define	BASEADDR	0x00400000
#define	SYSCALLSEARCH	"\x0f\x05"
#define	MMAPSYSCALL	477

#endif /* !_HIJACK_MACHDEP */

/*
 * Copyright (c) 2017, Shawn Webb
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *    * Redistributions of source code must retain the above copyright
 *      notice, this list of conditions and the following disclaimer.
 *    * Redistributions in binary form must reproduce the above
 *      copyright notice, this list of conditions and the following
 *      disclaimer in the documentation and/or other materials
 *      provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef _HIJACK_MACHDEP
#define	_HIJACK_MACHDEP

#define	BASEADDR	0x00400000
#define	SYSCALLSEARCH	"\x01\x00\x00\xd4"
#define	MMAPSYSCALL	477

#endif /* !_HIJACK_MACHDEP */

Use the right opcode for the svc instruction

This is a NOP on arm64 right now.

Signed-off-by:	Shawn Webb <63bc49e2baae731b3d1a43666c374487dee71f11@hardenedbsd.org>


#include <stdio.h>
#include <stdlib.h>

#include "arch.h"
#include "../../cc2.h"
#include "../../../inc/sizes.h"

void
defsym(Symbol *sym, int alloc)
{
}

void
data(Node *np)
{
}

void
writeout(void)
{
}

#include <stdio.h>
#include <stdlib.h>

#include "arch.h"
#include "../../cc2.h"
#include "../../../inc/sizes.h"

/*
 * : is for user-defined Aggregate Types
 * $ is for globals (represented by a pointer)
 * % is for function-scope temporaries
 * @ is for block labels
 */
static char
sigil(Symbol *sym)
{
	switch (sym->kind) {
	case EXTRN:
	case GLOB:
	case PRIVAT:
	case LOCAL:
		return '$';
	case AUTO:
	case REG:
		return '%';
	default:
		abort();
	}
}

static void
size2asm(Type *tp)
{
	char *s;

	if (tp->flags & STRF) {
		abort();
	} else {
		switch (tp->size) {
		case 1:
			s = "b\t";
			break;
		case 2:
			s = "h\t";
			break;
		case 4:
			s = "w\t";
			break;
		case 8:
			s = "q\t";
			break;
		default:
			s = "z\t%llu\t";
			break;
		}
	}
	printf(s, (unsigned long long) tp->size);
}

void
defsym(Symbol *sym, int alloc)
{
	if (!alloc)
		return;
	if (sym->kind == GLOB)
		fputs("export ", stdout);
	printf("data %c%s = {\n", sigil(sym), sym->name);
	if (sym->type.flags & INITF)
		return;
	putchar('\t');
	size2asm(&sym->type);
	puts("0\n}");
}

void
data(Node *np)
{
}

void
writeout(void)
{
}

Add basic implementation of defsym()

[cc2] Add basic implementation of defsym()

This is a first implementation which a limited implementation of
sigil() and of size2asm() that, for instance, does not support
strings.


/*
 * Copyright (c) 2017 Intel Corporation
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <atomic.h>
#include <kernel.h>
#include <entropy.h>

static atomic_t entropy_driver;

u32_t sys_rand32_get(void)
{
	struct device *dev = (struct device *)atomic_get(&entropy_driver);
	u32_t random_num;
	int ret;

	if (unlikely(!dev)) {
		/* Only one entropy device exists, so this is safe even
		 * if the whole operation isn't atomic.
		 */
		dev = device_get_binding(CONFIG_ENTROPY_NAME);
		atomic_set(&entropy_driver, (atomic_t)(uintptr_t)dev);
	}

	ret = entropy_get_entropy(dev, (u8_t *)&random_num,
				  sizeof(random_num));
	if (unlikely(ret < 0)) {
		/* Use system timer in case the entropy device couldn't deliver
		 * 32-bit of data.  There's not much that can be done in this
		 * situation.  An __ASSERT() isn't used here as the HWRNG might
		 * still be gathering entropy during early boot situations.
		 */

		random_num = k_cycle_get_32();
	}

	return random_num;
}

/*
 * Copyright (c) 2017 Intel Corporation
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <atomic.h>
#include <kernel.h>
#include <entropy.h>

static atomic_t entropy_driver;

u32_t sys_rand32_get(void)
{
	struct device *dev = (struct device *)atomic_get(&entropy_driver);
	u32_t random_num;
	int ret;

	if (unlikely(!dev)) {
		/* Only one entropy device exists, so this is safe even
		 * if the whole operation isn't atomic.
		 */
		dev = device_get_binding(CONFIG_ENTROPY_NAME);
		__ASSERT((dev != NULL),
			"Device driver for %s (CONFIG_ENTROPY_NAME) not found. "
			"Check your build configuration!",
			CONFIG_ENTROPY_NAME);
		atomic_set(&entropy_driver, (atomic_t)(uintptr_t)dev);
	}

	ret = entropy_get_entropy(dev, (u8_t *)&random_num,
				  sizeof(random_num));
	if (unlikely(ret < 0)) {
		/* Use system timer in case the entropy device couldn't deliver
		 * 32-bit of data.  There's not much that can be done in this
		 * situation.  An __ASSERT() isn't used here as the HWRNG might
		 * still be gathering entropy during early boot situations.
		 */

		random_num = k_cycle_get_32();
	}

	return random_num;
}

subsys/random: Add _ASSERT() test on returned device_get_binding

If there is a build setup problem where a device driver has not been
setup for the entropy driver then the call to device_get_binding()
will return a NULL value and the code will continue to use this NULL
value. The result is a hard fault later in code execution.

Note that CONFIG_ASSERT is by default off so one has to turn this
configuration on to catch this problem.

Signed-off-by: David Leach <98707a1e43c521c5b5b81e36afef696dde6831a3@nxp.com>


#include "crypto_scalarmult_curve25519.h"

size_t
crypto_scalarmult_curve25519_bytes(void)
{
    return crypto_scalarmult_curve25519_BYTES;
}

size_t
crypto_scalarmult_curve25519_scalarbytes(void)
{
    return crypto_scalarmult_curve25519_SCALARBYTES;
}

Add an empty line. Yeah, that's a fantastic commit.


// RUN: %clang_cc1 -load %llvmshlibdir/PrintFunctionNames%pluginext -plugin print-fns %s 2>&1 | FileCheck %s
// RUN: %clang_cl -Xclang -load -Xclang %llvmshlibdir/PrintFunctionNames%pluginext -Xclang -plugin -Xclang print-fns %s 2>&1 | FileCheck %s
// REQUIRES: plugins, examples

// CHECK: top-level-decl: "x"
void x();

// RUN: %clang_cc1 -load %llvmshlibdir/PrintFunctionNames%pluginext -plugin print-fns %s 2>&1 | FileCheck %s
// RUN: %clang_cl -c -Xclang -load -Xclang %llvmshlibdir/PrintFunctionNames%pluginext -Xclang -plugin -Xclang print-fns -Tc %s 2>&1 | FileCheck %s
// REQUIRES: plugins, examples

// CHECK: top-level-decl: "x"
void x();

Fix the test added in r260266

Fix the test added in r260266

git-svn-id: ffe668792ed300d6c2daa1f6eba2e0aa28d7ec6c@260276 91177308-0d34-0410-b5e6-96231b3b80d8


// Copyright lowRISC contributors.
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

#include "sw/device/lib/testing/test_status.h"

#include "sw/device/lib/arch/device.h"
#include "sw/device/lib/base/log.h"
#include "sw/device/lib/base/mmio.h"
#include "sw/device/lib/runtime/hart.h"

/**
 * Address of the memory location to write the test status. For DV use only.
 */
static const uintptr_t kSwDvTestStatusAddr = 0x1000fff8;

void test_status_set(test_status_t test_status) {
  if (kDeviceType == kDeviceSimDV) {
    mmio_region_t sw_dv_test_status_addr =
        mmio_region_from_addr(kSwDvTestStatusAddr);
    mmio_region_write32(sw_dv_test_status_addr, 0x0, (uint32_t)test_status);
  }

  switch (test_status) {
    case kTestStatusPassed: {
      LOG_INFO("PASS");
      abort();
      break;
    }
    case kTestStatusFailed: {
      LOG_INFO("FAIL");
      abort();
      break;
    }
    default: {
      // Do nothing.
      break;
    }
  }
}

// Copyright lowRISC contributors.
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

#include "sw/device/lib/testing/test_status.h"

#include "sw/device/lib/arch/device.h"
#include "sw/device/lib/base/log.h"
#include "sw/device/lib/base/mmio.h"
#include "sw/device/lib/runtime/hart.h"

/**
 * Address of the memory location to write the test status. For DV use only.
 */
static const uintptr_t kSwDvTestStatusAddr = 0x1000fff8;

void test_status_set(test_status_t test_status) {
  if (kDeviceType == kDeviceSimDV) {
    mmio_region_t sw_dv_test_status_addr =
        mmio_region_from_addr(kSwDvTestStatusAddr);
    mmio_region_write32(sw_dv_test_status_addr, 0x0, (uint32_t)test_status);
  }

  switch (test_status) {
    case kTestStatusPassed: {
      LOG_INFO("PASS!");
      abort();
      break;
    }
    case kTestStatusFailed: {
      LOG_INFO("FAIL!");
      abort();
      break;
    }
    default: {
      // Do nothing.
      break;
    }
  }
}

Fix PASS!, FAIL! signatures for CI

[sw] Fix PASS!, FAIL! signatures for CI

Signed-off-by: Srikrishna Iyer <2803d640feace36379942447842f26c7747b4dc3@google.com>


#ifndef _TSLIB_PRIVATE_H_
#define _TSLIB_PRIVATE_H_
/*
 *  tslib/src/tslib-private.h
 *
 *  Copyright (C) 2001 Russell King.
 *
 * This file is placed under the LGPL.
 *
 *
 * Internal touch screen library definitions.
 */
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

#include "tslib.h"
#include "tslib-filter.h"

#define DEBUG

struct tsdev {
	int fd;
	struct tslib_module_info *list;
	struct tslib_module_info *list_raw; /* points to position in 'list' where raw reads
					       come from.  default is the position of the
					       ts_read_raw module. */
	unsigned int res_x;
	unsigned int res_y;
	int rotation;
};

int __ts_attach(struct tsdev *ts, struct tslib_module_info *info);
int __ts_attach_raw(struct tsdev *ts, struct tslib_module_info *info);
int ts_load_module(struct tsdev *dev, const char *module, const char *params);
int ts_load_module_raw(struct tsdev *dev, const char *module, const char *params);
int ts_error(const char *fmt, ...);

#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* _TSLIB_PRIVATE_H_ */

#ifndef _TSLIB_PRIVATE_H_
#define _TSLIB_PRIVATE_H_
/*
 *  tslib/src/tslib-private.h
 *
 *  Copyright (C) 2001 Russell King.
 *
 * This file is placed under the LGPL.
 *
 *
 * Internal touch screen library definitions.
 */
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

#include "tslib.h"
#include "tslib-filter.h"

struct tsdev {
	int fd;
	struct tslib_module_info *list;
	struct tslib_module_info *list_raw; /* points to position in 'list' where raw reads
					       come from.  default is the position of the
					       ts_read_raw module. */
	unsigned int res_x;
	unsigned int res_y;
	int rotation;
};

int __ts_attach(struct tsdev *ts, struct tslib_module_info *info);
int __ts_attach_raw(struct tsdev *ts, struct tslib_module_info *info);
int ts_load_module(struct tsdev *dev, const char *module, const char *params);
int ts_load_module_raw(struct tsdev *dev, const char *module, const char *params);
int ts_error(const char *fmt, ...);

#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* _TSLIB_PRIVATE_H_ */

Revert "Enable debug option for all components"

This reverts commit 9c3742a8d8a829ec746e0a974aa30fb5dd0e3d1a.


/* mbed Microcontroller Library
 * Copyright (c) 2015-2017 Nuvoton
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef MBED_CMSIS_H
#define MBED_CMSIS_H

#include "M2351.h"
#include "cmsis_nvic.h"

// Support linker-generated symbol as start of relocated vector table.
#if defined(__CC_ARM) || (defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050))
extern uint32_t Image$$ER_IRAMVEC$$ZI$$Base;
#elif defined(__ICCARM__)

#elif defined(__GNUC__)
extern uint32_t __start_vector_table__;
#endif

#endif

/* mbed Microcontroller Library
 * Copyright (c) 2015-2017 Nuvoton
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef MBED_CMSIS_H
#define MBED_CMSIS_H

#include "M2351.h"
#include "cmsis_nvic.h"

// Support linker-generated symbol as start of relocated vector table.
#if defined(__CC_ARM) || (defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050))
extern uint32_t Image$$ER_IRAMVEC$$ZI$$Base;
#elif defined(__ICCARM__)

#elif defined(__GNUC__)
extern uint32_t __start_vector_table__;
#endif

/* TZ_START_NS: Start address of non-secure application */
#ifndef TZ_START_NS
#define TZ_START_NS (0x10040000U)
#endif

#endif

Add non-secure reset handler address

[M2351] Add non-secure reset handler address


#include <stdio.h>
#include <string.h>

int is_valid_ucn(char*);

int main() {

    char ucn[12];
    fgets(ucn, 13, stdin);

    printf("%d", is_valid_ucn(ucn));

    return 0;
}

int is_valid_ucn(char *ucn) {

    int control = 0, month = (ucn[2] - '0') * 10 + (ucn[3] - '0');
    int length = strlen(ucn);
    int weights[] = { 2, 4, 8, 5, 10, 9, 7, 3, 6 };

    if (length == 10) {

        if (!(
            (month >= 1 && month <= 12) ||
            (month >= 1 + 20 && month <= 12 + 20) ||
            (month >= 1 + 40 && month <= 12 + 40))
        ) {
            return 0;
        }

        for (int i = 0; i < length - 1; i++) {
            control += (ucn[i] - '0') * weights[i];
        }

        control %= 11;
        if (control != ucn[9] - '0' || control > 10) {
            return 0;
        }

    } else {
        return 0;
    }

    return 1;
}

Add Task 01 from Homework 03

Add Task 01 from Homework 03


//===--- ParentMap.h - Mappings from Stmts to their Parents -----*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
//  This file defines the ParentMap class.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_CLANG_PARENTMAP_H
#define LLVM_CLANG_PARENTMAP_H

namespace clang {
class Stmt;

class ParentMap {
  void* Impl;
public:
  ParentMap(Stmt* ASTRoot);
  ~ParentMap();

  Stmt* getParent(Stmt*) const;

  bool hasParent(Stmt* S) const {
    return getParent(S) != 0;
  }
};

} // end clang namespace
#endif

//===--- ParentMap.h - Mappings from Stmts to their Parents -----*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
//  This file defines the ParentMap class.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_CLANG_PARENTMAP_H
#define LLVM_CLANG_PARENTMAP_H

namespace clang {
class Stmt;

class ParentMap {
  void* Impl;
public:
  ParentMap(Stmt* ASTRoot);
  ~ParentMap();

  Stmt* getParent(Stmt*) const;

  const Stmt* getParent(const Stmt* S) const {
    return getParent(const_cast<Stmt*>(S));
  }

  bool hasParent(Stmt* S) const {
    return getParent(S) != 0;
  }
};

} // end clang namespace
#endif

Add missing header file change.

Add missing header file change.

git-svn-id: ffe668792ed300d6c2daa1f6eba2e0aa28d7ec6c@67871 91177308-0d34-0410-b5e6-96231b3b80d8


/**************************************************************************
 *
 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
 * All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sub license, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice (including the
 * next paragraph) shall be included in all copies or substantial portions
 * of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 **************************************************************************/

/**
 * @file
 * Gallium error codes.
 *
 * @author José Fonseca <jrfonseca@tungstengraphics.com>
 */

#ifndef P_ERROR_H_
#define P_ERROR_H_

#ifdef	__cplusplus
extern "C" {
#endif

/**
 * Gallium error codes.
 *
 * - A zero value always means success.
 * - A negative value always means failure.
 * - The meaning of a positive value is function dependent.
 */
enum pipe_error {
   PIPE_OK = 0,
   PIPE_ERROR = -1,    /**< Generic error */
   PIPE_ERROR_BAD_INPUT = -2,
   PIPE_ERROR_OUT_OF_MEMORY = -3,
   PIPE_ERROR_RETRY = -4
   /* TODO */
};

#ifdef	__cplusplus
}
#endif

#endif /* P_ERROR_H_ */

Standardize most important error codes.

gallium: Standardize most important error codes.


// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Multiply-included file, hence no include guard.

#include "xwalk/runtime/common/xwalk_common_messages.h"

// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Multiply-included file, hence no include guard.
// NOLINT(build/header_guard)

#include "xwalk/runtime/common/xwalk_common_messages.h"

Add a NOLINT to avoid a build/header_guard cpplint warning.

`xwalk_common_message_generator.h` does not have include guards, and
according to a comment there this seems to be on purpose.

Add a `NOLINT` entry to it to avoid cpplint a build/header_guard error.

BUG=XWALK-1853


#pragma once

#include <winsock2.h>

#include "common/types.h"

#define SNP_PACKET_SIZE 512

namespace sbat {
namespace snp {
enum class PacketType : byte {
  Storm = 0
};

#pragma pack(push)
#pragma pack(1)
// this packet info wraps the packets sent by storm/us with something that can be used to route it
struct PacketHeader {
  PacketType type;
  uint16 size;  // size does not include the size of this header
};
#pragma pack(pop)

// Storm packets that will be queued until read
struct StormPacket {
  byte data[SNP_PACKET_SIZE];
  sockaddr_in from_address;
  uint32 size;

  StormPacket* next;
};
}  // namespace snp
}  // namespace sbat

#pragma once

#include <winsock2.h>

#include "common/types.h"

namespace sbat {
namespace snp {
// min-MTU - (max-IP-header-size + udp-header-size)
const size_t SNP_PACKET_SIZE = 576 - (60 + 8);

enum class PacketType : byte {
  Storm = 0
};

#pragma pack(push)
#pragma pack(1)
// this packet info wraps the packets sent by storm/us with something that can be used to route it
struct PacketHeader {
  PacketType type;
  uint16 size;  // size does not include the size of this header
};
#pragma pack(pop)

// Storm packets that will be queued until read
struct StormPacket {
  byte data[SNP_PACKET_SIZE];
  sockaddr_in from_address;
  uint32 size;

  StormPacket* next;
};
}  // namespace snp
}  // namespace sbat

Adjust snp packet size to better accomodate small MTUs.


#include <stdio.h>
#include <math.h>

#define SIMPSON_METHOD 1

double fun(double x) {
    return (3.0 / 2) * pow(sin(x), 3);
}

double simpson_helper(double (*f)(double), double from, double to, int steps) {
    double result = 0.0;
    double acc = 0.0;
    double h = (to - from) / steps;

    result += (*f)(from) + (*f)(to);

    acc = 0.0;
    for (int i = 1, limit = steps / 2; i <= limit; i++) {
        acc += (*f)(from + (2 * i - 1) * h);
    }
    result += 4 * acc;

    acc = 0.0;
    for (int i = 1, limit = steps / 2 - 1; i <= limit; i++) {
        acc += (*f)(from + 2 * i * h);
    }
    result += 2 * acc;

    return (h / 3) * result;
}

/*codewars task function*/
double simpson(int n) {
    return simpson_helper(fun, 0, M_PI, n);
}

double integral(double (*f)(double), double from, double to, int precision, int method) {
    switch(method) {
        case SIMPSON_METHOD:
        default:
            return simpson_helper(f, from, to, precision);
    }
}

int main () {
    unsigned int n;

    scanf("%d", &n);
    printf("%f", integral(fun, 0, M_PI, n, SIMPSON_METHOD));

    return 1;
}

Add Simpron integral approx. kata

Add Simpron integral approx. kata


/*
 * adler32.c
 *
 * Adler-32 checksum algorithm.
 */

#include "adler32.h"

u32
adler32(const u8 *buffer, size_t size)
{
	u32 s1 = 1;
	u32 s2 = 0;
	for (size_t i = 0; i < size; i++) {
		s1 = (s1 + buffer[i]) % 65521;
		s2 = (s2 + s1) % 65521;
	}
	return (s2 << 16) | s1;
}

/*
 * adler32.c
 *
 * Adler-32 checksum algorithm.
 */

#include "adler32.h"
#include "compiler.h"

/*
 * The Adler-32 divisor, or "base", value.
 */
#define DIVISOR 65521

/*
 * MAX_BYTES_PER_CHUNK is the most bytes that can be processed without the
 * possibility of s2 overflowing when it is represented as an unsigned 32-bit
 * integer.  This value was computed using the following Python script:
 *
 *	divisor = 65521
 *	count = 0
 *	s1 = divisor - 1
 *	s2 = divisor - 1
 *	while True:
 *		s1 += 0xFF
 *		s2 += s1
 *		if s2 > 0xFFFFFFFF:
 *			break
 *		count += 1
 *	print(count)
 *
 * Note that to get the correct worst-case value, we must assume that every byte
 * has value 0xFF and that s1 and s2 started with the highest possible values
 * modulo the divisor.
 */
#define MAX_BYTES_PER_CHUNK	5552

u32
adler32(const u8 *buffer, size_t size)
{
	u32 s1 = 1;
	u32 s2 = 0;
	const u8 *p = buffer;
	const u8 * const end = p + size;
	while (p != end) {
		const u8 *chunk_end = p + min(end - p,
					      MAX_BYTES_PER_CHUNK);
		do {
			s1 += *p++;
			s2 += s1;
		} while (p != chunk_end);
		s1 %= 65521;
		s2 %= 65521;
	}
	return (s2 << 16) | s1;
}

Speed up Adler-32 by doing modulo less often


/* To avoid recursion in certain includes */
#ifndef _RTDEFS_H_
#define _RTDEFS_H_ 1

#define MAXCHANS 4
#define MAX_INPUT_FDS 128
#define AUDIO_DEVICE 9999999

/* definition of input file desc struct used by rtinput */
typedef struct inputdesc {
   char  filename[1024];
   int   fd;
   int   refcount;
   short header_type;           /* e.g., AIFF_sound_file (in sndlib.h) */
   short data_format;           /* e.g., snd_16_linear (in sndlib.h) */
   short chans;
   float srate;
   int   data_location;           /* offset of sound data start in file */
   float dur;
} InputDesc;

/* for insts - so they don't have to include globals.h */
extern int MAXBUF;
extern int NCHANS;
extern int RTBUFSAMPS;
extern float SR;

#endif /* _RTDEFS_H_ */

/* To avoid recursion in certain includes */
#ifndef _RTDEFS_H_
#define _RTDEFS_H_ 1

#define MAXCHANS 4

#define MAX_INPUT_FDS        128
#define NO_DEVICE_FDINDEX    -1
#define AUDIO_DEVICE_FDINDEX -2

/* definition of input file desc struct used by rtinput */
typedef struct inputdesc {
   char  filename[1024];
   int   fd;
   int   refcount;
   short header_type;           /* e.g., AIFF_sound_file (in sndlib.h) */
   short data_format;           /* e.g., snd_16_linear (in sndlib.h) */
   short chans;
   float srate;
   int   data_location;           /* offset of sound data start in file */
   float dur;
} InputDesc;

/* for insts - so they don't have to include globals.h */
extern int MAXBUF;
extern int NCHANS;
extern int RTBUFSAMPS;
extern float SR;

#endif /* _RTDEFS_H_ */

Change "AUDIO_DEVICE" to "AUDIO_DEVICE_FDINDEX", and change its value. Add new "NO_DEVICE_FDINDEX".


#include <stdio.h>

typedef struct {
    int hands[2][2];
    int turn;
} Sticks;

void sticks_create(Sticks *sticks) {
    sticks->hands[0][0] = 1;
    sticks->hands[0][1] = 1;
    sticks->hands[1][0] = 1;
    sticks->hands[1][1] = 1;
    sticks->turn = 0;
}

void sticks_play(Sticks *sticks, int x, int y) {
    sticks->hands[!sticks->turn][y] += sticks->hands[sticks->turn][x];
    if (sticks->hands[!sticks->turn][y] >= 5) {
        sticks->hands[!sticks->turn][y] = 0;
    }
    sticks->turn = !sticks->turn;
}

int main(void) {
    Sticks sticks;
    sticks_create(&sticks);
    printf("%d\n", sticks.hands[0][0]);
    printf("%d\n", sticks.turn);
    sticks_play(&sticks, 0, 1);
    printf("%d\n", sticks.hands[1][1]);
    printf("%d\n", sticks.turn);
}

#include <stdio.h>

typedef struct {
    int hands[2][2];
    int turn;
} Sticks;

void sticks_create(Sticks *sticks) {
    sticks->hands[0][0] = 1;
    sticks->hands[0][1] = 1;
    sticks->hands[1][0] = 1;
    sticks->hands[1][1] = 1;
    sticks->turn = 0;
}

void sticks_play(Sticks *sticks, int attack, int x, int y) {
    if (attack) {
        sticks->hands[!sticks->turn][y] += sticks->hands[sticks->turn][x];
        if (sticks->hands[!sticks->turn][y] >= 5) {
            sticks->hands[!sticks->turn][y] = 0;
        }
    } else {
        int fingers = sticks->hands[sticks->turn][0] + sticks->hands[sticks->turn][1];
        int desired = 2 * x + y;
        if (desired > fingers) desired = fingers;
        if (desired < fingers - 4) desired = fingers - 4;
        sticks->hands[sticks->turn][0] = desired;
        sticks->hands[sticks->turn][1] = fingers - desired;
    }
    sticks->turn = !sticks->turn;
}

int main(void) {
    Sticks sticks;
    sticks_create(&sticks);
    printf("%d\n", sticks.hands[0][0]);
    printf("%d\n", sticks.turn);
    sticks_play(&sticks, 0, 0, 0);
    printf("%d\n", sticks.hands[0][0]);
    printf("%d\n", sticks.hands[0][1]);
    printf("%d\n", sticks.turn);
}

Allow user to move fingers between own hands


#ifndef INTERVAL_H
#define INTERVAL_H

namespace Interval{
    class RepeatedInterval{
        uint32_t next;
        uint32_t span;
    public:
        RepeatedInterval(uint32_t span): span(span) { next = millis() + span; }
        boolean operator()() {
            if(millis() > next){
                next += span;
                return true;
            }
            return false;
        }
    };
    /**
     * Returns a functor that returns true once every `milliseconds`
     * @param  milliseconds The interval time
     * @return              A functor
     */
    RepeatedInterval every(uint32_t milliseconds){
        return RepeatedInterval(milliseconds);
    }

    class SingleInterval{
        uint32_t endTime;
    public:
        SingleInterval(uint32_t t): endTime(t) {}
        boolean operator()() { return millis() > endTime; }
    };
    /**
     * Returns a functor that returns false until `milliseconds` have elapsed
     * @param  milliseconds The interval time
     * @return              A functor
     */
    SingleInterval elapsed(uint32_t milliseconds){
        return SingleInterval( millis() + milliseconds);
    }
}

#endif

#ifndef INTERVAL_H
#define INTERVAL_H

namespace Interval{
    class RepeatedInterval{
        uint32_t next;
        uint32_t span;
    public:
        RepeatedInterval(uint32_t span): span(span) { next = millis() + span; }
        boolean operator()() {
            if(millis() > next){
                next += span;
                return true;
            }
            return false;
        }
    };
    /**
     * Returns a functor that returns true once every `milliseconds`
     * @param  milliseconds The interval time
     * @return              A functor
     */
    RepeatedInterval every(uint32_t milliseconds){
        return RepeatedInterval(milliseconds);
    }

    class SingleInterval{
        uint32_t endTime;
    public:
        SingleInterval(uint32_t t): endTime(t) {}
        boolean operator()() { return millis() > endTime; }
    };
    /**
     * Returns a functor that returns false until `milliseconds` have elapsed
     * @param  milliseconds The interval time
     * @return              A functor
     */
    SingleInterval elapsed(uint32_t milliseconds){
        return SingleInterval( millis() + milliseconds);
    }

    class Timer{
        uint32_t lastCall;
    public:
        Timer(){ reset(); }
        void reset() { lastCall = micros(); }
        uint32_t operator()() {
            return micros() - lastCall;
        }
    };
    Timer timer(){
        return Timer();
    }
}

#endif

Add a timer utility to interval namespace


#ifndef _WINDOW_H_
#define _WINDOW_H_
#include <string>
#include <iostream>
class Window {
    std::string title;
    public:
    Window(const std::string& title): title(title) {}
    virtual void handle() = 0;
    void drawTitle() {
//#ifdef _WIN32
        //std::system("cls");
//#else //assuming linux, yeah, I know
        //std::system("clear");
//#endif
        std::cout << "   " << title << std::endl;
        std::cout << "================================" << std::endl;
    }
    std::string readCommand(const std::string& prompt) {
        std::cout << prompt;
        std::string cmd;
        std::cin >> cmd;
        return cmd;
    }
    std::string readCommand() {
        return readCommand("> ");
    }

};
#endif

#ifndef _WINDOW_H_
#define _WINDOW_H_
#include <string>
#include <iostream>
#include <cstdlib>
class Window {
    std::string title;
    public:
    Window(const std::string& title): title(title) {}
    virtual void handle() = 0;
    void drawTitle() {
#ifdef _WIN32
        std::system("cls");
#else //assuming linux, yeah, I know
        std::system("clear");
#endif
        std::cout << "   " << title << std::endl;
        std::cout << "================================" << std::endl;
    }
    std::string readCommand(const std::string& prompt) {
        std::cout << prompt;
        std::string cmd;
        std::getline(std::cin,cmd);
        return cmd;
    }
    std::string readCommand() {
        return readCommand("> ");
    }

};
#endif

Enable clearing, use getline to read empty lines


#include "sampgdk.h"

#if SAMPGDK_WINDOWS
  #undef CreateMenu
  #undef DestroyMenu
  #undef GetTickCount
  #undef KillTimer
  #undef SelectObject
  #undef SetTimer
  #define WIN32_LEAN_AND_MEAN
  #include <windows.h>
#else
  #define _GNU_SOURCE
#endif

#include "sampgdk.h"

#if SAMPGDK_WINDOWS
  #ifdef _MSC_VER
    #pragma warning(disable: 4996)
  #endif
  #undef CreateMenu
  #undef DestroyMenu
  #undef GetTickCount
  #undef KillTimer
  #undef SelectObject
  #undef SetTimer
  #define WIN32_LEAN_AND_MEAN
  #include <windows.h>
#else
  #define _GNU_SOURCE
#endif

Disable warning C4996 in amalgamation

Disable warning C4996 in amalgamation


#include "calc.h"

#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>

double calc(const char* p, int mul_div_flag)
{
    int i;
    double ans;

    ans = atof(p);
    if (p[0] != '(' && mul_div_flag == 1){
        return (ans);
    }
    i = 0;
    while (p[i] != '\0'){
        while (isdigit(p[i])){
            i++;
        }
        switch (p[i]){
            case '+':
                return (ans + calc(p + i + 1, 0));
            case '-':
                return (ans - calc(p + i + 1, 0));
            case '*':
                ans *= calc(p + i + 1, 1);
                if (p[i + 1] == '('){
                    while (p[i] != ')'){
                        i++;
                    }
                }
                i++;
                break;
            case '/':
                ans /= calc(p + i + 1, 1);
                if (p[i + 1] == '('){
                    while (p[i] != ')'){
                        i++;
                    }
                }
                i++;
                break;
            case '(':
                return (calc(p + i + 1, 0));
            case ')':
            case '\0':
                return (ans);
            default:
                puts("Error");
                return (0);
        }
    }

    return (ans);
}

#include "calc.h"

#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>

double calc(const char* p, int mul_div_flag)
{
    int i;
    double ans;

    if (p[0] != '(' && mul_div_flag == 1){
        return (atof(p));
    }
    else if (p[0] == '('){
        ans = 0;
    }
    else {
        ans = atof(p);
    }

    i = 0;
    while (p[i] != '\0'){
        while (isdigit(p[i])){
            i++;
        }
        switch (p[i]){
            case '+':
                return (ans + calc(p + i + 1, 0));
            case '-':
                return (ans - calc(p + i + 1, 0));
            case '*':
                ans *= calc(p + i + 1, 1);
                if (p[i + 1] == '('){
                    while (p[i] != ')'){
                        i++;
                    }
                }
                i++;
                break;
            case '/':
                ans /= calc(p + i + 1, 1);
                if (p[i + 1] == '('){
                    while (p[i] != ')'){
                        i++;
                    }
                }
                i++;
                break;
            case '(':
                return (calc(p + i + 1, 0));
            case ')':
            case '\0':
                return (ans);
            default:
                puts("Error");
                return (0);
        }
    }

    return (ans);
}

Split mul_div flag part to avoid bugs

Split mul_div flag part to avoid bugs


#include <stdlib.h>
#include <stdio.h>

int main() {
	FILE *file;
	long length;
	char *buffer;
	file = fopen("example.minty", "r");
	if (file == NULL) {
		return 1;
	}
	fseek(file, 0, SEEK_END);
	length = ftell(file);
	fseek(file, 0, SEEK_SET);
	buffer = (char *)malloc(length);
	fread(buffer, length, 1, file);
	fclose(file);
	printf("%s", buffer);
	return 0;
}

#include <stdlib.h>
#include <stdio.h>

int main(int argc, char *argv[]) {
	FILE *file;
	long length;
	char *buffer;
	if (argc < 2) {
	  return 1;
	}
	file = fopen(argv[1], "r");
	if (file == NULL) {
		return 1;
	}
	fseek(file, 0, SEEK_END);
	length = ftell(file);
	fseek(file, 0, SEEK_SET);
	buffer = (char *)malloc(length);
	fread(buffer, length, 1, file);
	fclose(file);
	printf("%s", buffer);
	return 0;
}

Allow program to run to be specified on command line


/*
 * Copyright (c) 2012-2014 Wind River Systems, Inc.
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <zephyr.h>
#include <sys/printk.h>
#include <device.h>

/*
 * @file
 * @brief Hello World demo
 */

void main(void)
{
	printk("Hello World!\n");
}

#if DT_NODE_EXISTS(DT_INST(0, vnd_gpio))
/* Fake GPIO device, needed for building drivers that use DEVICE_DT_GET()
 * to access GPIO controllers.
 */
DEVICE_DT_DEFINE(DT_INST(0, vnd_gpio), NULL, NULL, NULL, NULL,
		 POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, NULL);
#endif

#if DT_NODE_EXISTS(DT_INST(0, vnd_serial))
/* Fake serial device, needed for building drivers that use DEVICE_DT_GET()
 * to access serial bus.
 */
DEVICE_DT_DEFINE(DT_INST(0, vnd_serial), NULL, NULL, NULL, NULL,
		 POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, NULL);
#endif

Revert "tests: drivers: build_all: add fake serial device for modem tests"

This reverts commit 9e58a1e475473fcea1c3b0d05ac9c738141c821a.

This change is in conflict with commit 94f7ed356f0c ("drivers: serial:
add a dummy driver for vnd,serial"). As a result two equal serial
devices are defines, resulting in link error.

Signed-off-by: Marcin Niestroj <63506c06cfbc47ace147db1702f6e751f5ac2132@emb.dev>


/*
 * env.h
 *
 * Author: Ming Tsang
 * Copyright (c) 2014 Ming Tsang
 * Refer to LICENSE for details
 */

#pragma once

#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)

#if defined(UNIX) || defined(__unix__) || defined(LINUX) || defined(__linux__)
	#if !defined(UNIX)
		#define UNIX
	#endif
#elif defined(_WIN32) || defined(WIN32)
	#if !defined(WIN32)
		#define WIN32
	#endif
#else
	#error Unsupported platform
#endif

/*
 * env.h
 *
 * Author: Ming Tsang
 * Copyright (c) 2014 Ming Tsang
 * Refer to LICENSE for details
 */

#pragma once

#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)

#if defined(UNIX) || defined(__unix__) || defined(LINUX) || defined(__linux__)
	#if !defined(POSIX)
		#define POSIX
	#endif
#elif defined(_WIN32) || defined(WIN32)
	#if !defined(WIN32)
		#define WIN32
	#endif
#else
	#error Unsupported platform
#endif

Rename platform flag from UNIX to POSIX

Rename platform flag from UNIX to POSIX


/* --------------------------------------------------------------------------
 *    Name: types.h
 * Purpose: Various typedefs and utility macros
 * ----------------------------------------------------------------------- */

#ifndef TYPES_H
#define TYPES_H

typedef signed char    int8_t;
typedef signed short   int16_t;
typedef signed int     int32_t;

typedef unsigned char  uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int   uint32_t;

#ifdef _WIN32
typedef int intptr_t;
#endif

#define NELEMS(x) ((int) (sizeof(x) / sizeof(x[0])))

#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define MAX(x,y) ((x) > (y) ? (x) : (y))

#define NOT_USED(x) ((x) = (x))

#ifdef _WIN32
#define INLINE __inline
#else
#define INLINE __inline__
#endif

#ifdef __GNUC__
#define likely(x)   __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#else
#define likely(x)   (x)
#define unlikely(x) (x)
#endif

#endif /* TYPES_H */

/* --------------------------------------------------------------------------
 *    Name: types.h
 * Purpose: Various typedefs and utility macros
 * ----------------------------------------------------------------------- */

#ifndef TYPES_H
#define TYPES_H

typedef signed char    int8_t;
typedef signed short   int16_t;
typedef signed int     int32_t;

typedef unsigned char  uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int   uint32_t;

#ifdef _MSC_VER
#ifdef _WIN64
typedef __int64 intptr_t;
#else
typedef int intptr_t;
#endif
#endif

#define NELEMS(x) ((int) (sizeof(x) / sizeof(x[0])))

#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define MAX(x,y) ((x) > (y) ? (x) : (y))

#define NOT_USED(x) ((x) = (x))

#ifdef _WIN32
#define INLINE __inline
#else
#define INLINE __inline__
#endif

#ifdef __GNUC__
#define likely(x)   __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#else
#define likely(x)   (x)
#define unlikely(x) (x)
#endif

#endif /* TYPES_H */

Declare intptr_t correctly for 64-bit Windows builds.


#pragma once

#include <QtGui/QMouseEvent>
#include <QtGui/QPaintEvent>
#include <QtWidgets/QWidget>

#include "binaryninjaapi.h"
#include "dockhandler.h"
#include "uitypes.h"

class ContextMenuManager;
class DisassemblyContainer;
class Menu;
class ViewFrame;

class BINARYNINJAUIAPI ReflectionView: public QWidget, public DockContextHandler
{
	Q_OBJECT
	Q_INTERFACES(DockContextHandler)

	ViewFrame* m_frame;
	BinaryViewRef m_data;
	DisassemblyContainer* m_disassemblyContainer;

public:
	ReflectionView(ViewFrame* frame, BinaryViewRef data);
	~ReflectionView();

	virtual void notifyOffsetChanged(uint64_t offset) override;
	virtual void notifyViewChanged(ViewFrame* frame) override;
	virtual bool shouldBeVisible(ViewFrame* frame) override;

protected:
	virtual void contextMenuEvent(QContextMenuEvent* event) override;
};

Add new synchronized graph sub-view dock widget (Reflection).


// Explorer loader problem list
// /problem.h

#ifndef PROBLEM_H_
#define PROBLEM_H_

/**错误列表*/
#define ERR_NO_MEM_FOR_ID 1				// 没有可用于中断描述符表的内存
#define ERR_NO_MEM_FOR_SD 2				// 没有可用于储存器描述符表的内存
#define ERR_NO_MEM_FOR_SCTBUF 3			// 没有可用于扇区缓存的内存
#define ERR_NO_MEM_FOR_CONFIG 4			// 没有可以分配给引导配置文件的内存
#define ERR_NO_MEM_FOR_BUFFER 5			// 没有可以分配给缓冲系统的内存
#define ERR_NO_MEM_FOR_FS 6				// 没有可以分配给文件系统的内存
#define ERR_NO_MEM_FOR_MMU 7			// 没有可以分配给MMU的内存

/**警告列表*/
#define WARN_NO_MEM 0x80000001				// 无充足内存
#define WARN_STORAGE_NOT_SUPPORT 0x80000002	// 暂时不支持这个储存器

#endif

// Explorer loader problem list
// /problem.h

#ifndef PROBLEM_H_
#define PROBLEM_H_

/**错误列表*/
#define ERR_NO_MEM_FOR_ID 1			// 没有可用于中断描述符表的内存
#define ERR_NO_MEM_FOR_SD 2			// 没有可用于储存器描述符表的内存
#define ERR_NO_MEM_FOR_SCTBUF 3			// 没有可用于扇区缓存的内存
#define ERR_NO_MEM_FOR_CONFIG 4			// 没有可以分配给引导配置文件的内存
#define ERR_NO_MEM_FOR_BUFFER 5			// 没有可以分配给缓冲系统的内存
#define ERR_NO_MEM_FOR_FS 6			// 没有可以分配给文件系统的内存
#define ERR_NO_MEM_FOR_MMU 7			// 没有可以分配给MMU的内存
#define ERR_NO_FILE 8				// 没有文件
#define ERR_CONFIG_OVERSIZE 9			// CONFIG.LDR oversized

/**警告列表*/
#define WARN_NO_MEM 0x80000001			// 无充足内存
#define WARN_STORAGE_NOT_SUPPORT 0x80000002	// 暂时不支持这个储存器
#define WARN_SCRIPT_SIZE_BAD 0x80000003		// length of cript incorrect

#endif

Add new error and warning number

Add new error and warning number


//
//  spi.h
//  Ethernet Shield
//
//  Created by EFCM van der Werf on 12/28/13.
//  Copyright (c) 2013 EFCM van der Werf. All rights reserved.
//

#ifndef COM_SPI_H
#define COM_SPI_H

#include "../config.h"

// Do we want SPI?
#ifdef COM_SPI

#include <inttypes.h>

/**
 * SPI config
 */
typedef struct spi_config {

};

/**
 * @brief Initialize SPI channel
 * @param config Configuration for spi channel
 */
extern void spi_init(spi_config *config);

#define SPI_START(port, pin) (port) &= ~(1 << (pin))
#define SPI_STOP(port, pin)  (port) |=  (1 << (pin))

#endif // COM_SPI
#endif // COM_SPI_H

//
//  spi.h
//  Ethernet Shield
//
//  Created by EFCM van der Werf on 12/28/13.
//  Copyright (c) 2013 EFCM van der Werf. All rights reserved.
//

#ifndef COM_SPI_H
#define COM_SPI_H

#include "../config.h"

// Do we want SPI?
#ifdef COM_SPI

#include <inttypes.h>

/**
 * SPI config
 */
typedef struct spi_config {

};

/**
 * @brief Initialize SPI channel
 * @param config Configuration for spi channel
 */
extern void spi_init(spi_config *config);

#define SPI_ACTIVE(port, pin)  (port) &= ~(1 << (pin))
#define SPI_PASSIVE(port, pin) (port) |=  (1 << (pin))

#endif // COM_SPI
#endif // COM_SPI_H

Rename SPI_START to SPI_ACTIVE and SPI_STOP to SPI_PASSIVE


#pragma once

#include "platform.h"
#include <string>
#include <vector>
#include <unordered_map>

class ShaderProgram {

public:

    ShaderProgram();
    virtual ~ShaderProgram();

    GLint getGlProgram() { return m_glProgram; };
    GLint getAttribLocation(const std::string& _attribName);

    bool buildFromSourceStrings(const std::string& _fragSrc, const std::string& _vertSrc);

    void use();

private:

    static GLint s_activeGlProgram;

    GLint m_glProgram;
    GLint m_glFragmentShader;
    GLint m_glVertexShader;
    std::unordered_map<std::string, GLint> m_attribMap;
    std::string m_fragmentShaderSource;
    std::string m_vertexShaderSource;

    GLint makeLinkedShaderProgram(GLint _fragShader, GLint _vertShader);
    GLint makeCompiledShader(const std::string& _src, GLenum _type);

};

#pragma once

#include "platform.h"
#include <string>
#include <vector>
#include <unordered_map>

/*
 * ShaderProgram - utility class representing an OpenGL shader program
 */

class ShaderProgram {

public:

    ShaderProgram();
    virtual ~ShaderProgram();

    /* Getters */
    GLint getGlProgram() { return m_glProgram; };
    GLint getGlFragmentShader() { return m_glFragmentShader; };
    GLint getGlVertexShader() { return m_glVertexShader; };

    /*
     * getAttribLocation - fetches the location of a shader attribute, caching the result
     */
    GLint getAttribLocation(const std::string& _attribName);

    /*
     * buildFromSourceStrings - attempts to compile a fragment shader and vertex shader from
     * strings representing the source code for each, then links them into a complete program;
     * if compiling or linking fails it prints the compiler log, returns false, and keeps the
     * program's previous state; if successful it returns true.
     */
    bool buildFromSourceStrings(const std::string& _fragSrc, const std::string& _vertSrc);

    // TODO: Once we have file system abstractions, provide a method to build a program from file names

    /*
     * isValid - returns true if this object represents a valid OpenGL shader program
     */
    bool isValid() { return m_glProgram != 0; };

    /*
     * use - binds the program in openGL if it is not already bound.
     */
    void use();

private:

    static GLint s_activeGlProgram;

    GLint m_glProgram;
    GLint m_glFragmentShader;
    GLint m_glVertexShader;
    std::unordered_map<std::string, GLint> m_attribMap;
    std::string m_fragmentShaderSource;
    std::string m_vertexShaderSource;

    GLint makeLinkedShaderProgram(GLint _fragShader, GLint _vertShader);
    GLint makeCompiledShader(const std::string& _src, GLenum _type);

};

Add comments and convenience functions

Add comments and convenience functions


extern void *_brk(void *addr);
extern int _open(char *path, int flags, int perm);
extern int _close(int fd);
extern int _read(int fd, void *buf, size_t n);
extern int _write(int fd, void *buf, size_t n);
extern int _lseek(int fd, long off, int whence);
extern void _Exit(int status);
extern int raise(int sig);
extern void (*signal(int sig, void (*func)(int)))(int);
extern getenv(const char *var);

Add getenv() to the arch primitive list

[lib/c] Add getenv() to the arch primitive list


#ifndef SkBitmapRegionDecoder_DEFINED
#define SkBitmapRegionDecoder_DEFINED

#include "SkBitmap.h"
#include "SkRect.h"
#include "SkImageDecoder.h"

class SkBitmapRegionDecoder {
public:
    SkBitmapRegionDecoder(SkImageDecoder *decoder, int width, int height) {
        fDecoder = decoder;
        fWidth = width;
        fHeight = height;
    }
    virtual ~SkBitmapRegionDecoder() {
        delete fDecoder;
    }

    virtual bool decodeRegion(SkBitmap* bitmap, SkIRect rect,
                              SkBitmap::Config pref, int sampleSize);

    virtual int getWidth() { return fWidth; }
    virtual int getHeight() { return fHeight; }

    virtual SkImageDecoder* getDecoder() { return fDecoder; }

private:
    SkImageDecoder *fDecoder;
    int fWidth;
    int fHeight;
};

#endif

#ifndef SkBitmapRegionDecoder_DEFINED
#define SkBitmapRegionDecoder_DEFINED

#include "SkBitmap.h"
#include "SkRect.h"
#include "SkImageDecoder.h"
#include "SkStream.h"

class SkBitmapRegionDecoder {
public:
    SkBitmapRegionDecoder(SkImageDecoder *decoder, SkStream *stream,
            int width, int height) {
        fDecoder = decoder;
        fStream = stream;
        fWidth = width;
        fHeight = height;
    }
    virtual ~SkBitmapRegionDecoder() {
        delete fDecoder;
        fStream->unref();
    }

    virtual bool decodeRegion(SkBitmap* bitmap, SkIRect rect,
                              SkBitmap::Config pref, int sampleSize);

    virtual int getWidth() { return fWidth; }
    virtual int getHeight() { return fHeight; }

    virtual SkImageDecoder* getDecoder() { return fDecoder; }

private:
    SkImageDecoder *fDecoder;
    SkStream *fStream;
    int fWidth;
    int fHeight;
};

#endif

Fix 3510563: memory leak in BitmapRegionDecoder.

Change-Id: I30b3a3806f4484d95602539def1a77a366560fdf


/* $FreeBSD$ */

#include "ansidecl.h"
#include "version.h"

const char *const version_string = "3.2.1 [FreeBSD] 20021009 (prerelease)";

/* $FreeBSD$ */

#include "ansidecl.h"
#include "version.h"

const char *const version_string = "3.2.1 [FreeBSD] 20021119 (release)";

Update for Gcc 3.2.1 release.

Update for Gcc 3.2.1 release.


int main (int argc, char* argv[]) {
    bd_init(NULL);
    g_printf ("max LV size: %lu\n", bd_lvm_get_max_lv_size());

    return 0;
}

int main (int argc, char* argv[]) {
    bd_init(NULL);
    g_printf ("max LV size: %"G_GUINT64_FORMAT"\n", bd_lvm_get_max_lv_size());

    return 0;
}

Use arch-independent format string for guint64 in tests

Otherwise "0" is printed out even if the right number is returned by the tested
function.


// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include <vespa/vespalib/stllike/string.h>
#include <vector>

class FRT_Supervisor;
class FRT_Target;
class FRT_RPCRequest;
class FRT_Values;

namespace fnet::frt { class StandaloneFRT; }

struct Flags {
    vespalib::string method;
    std::vector<vespalib::string> args;
    vespalib::string targethost;
    int portnumber;
    Flags(const Flags &);
    Flags & operator=(const Flags &);
    Flags();
    ~Flags();
};

class ProxyCmd
{
private:
    std::unique_ptr<fnet::frt::StandaloneFRT> _server;
    FRT_Supervisor *_supervisor;
    FRT_Target     *_target;
    FRT_RPCRequest *_req;
    Flags           _flags;

    void initRPC();
    void invokeRPC();
    void finiRPC();
    void printArray(FRT_Values *rvals);
    vespalib::string makeSpec();
    void autoPrint();
public:
    ProxyCmd(const Flags& flags);
    virtual ~ProxyCmd();
    int action();
};

// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include <vespa/vespalib/stllike/string.h>
#include <vector>

class FRT_Target;
class FRT_RPCRequest;
class FRT_Values;

namespace fnet::frt { class StandaloneFRT; }

struct Flags {
    vespalib::string method;
    std::vector<vespalib::string> args;
    vespalib::string targethost;
    int portnumber;
    Flags(const Flags &);
    Flags & operator=(const Flags &);
    Flags();
    ~Flags();
};

class ProxyCmd
{
private:
    std::unique_ptr<fnet::frt::StandaloneFRT> _server;
    FRT_Target     *_target;
    FRT_RPCRequest *_req;
    Flags           _flags;

    void initRPC();
    void invokeRPC();
    void finiRPC();
    void printArray(FRT_Values *rvals);
    vespalib::string makeSpec();
    void autoPrint();
public:
    ProxyCmd(const Flags& flags);
    virtual ~ProxyCmd();
    int action();
};

Remove unused variable in vespa-configproxy-cmd.


// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef BASE_SCOPED_HANDLE_H_
#define BASE_SCOPED_HANDLE_H_

#include "base/basictypes.h"

#if defined(OS_WIN)
#include "base/scoped_handle_win.h"
#endif

class ScopedStdioHandle {
 public:
  ScopedStdioHandle()
      : handle_(NULL) { }

  explicit ScopedStdioHandle(FILE* handle)
      : handle_(handle) { }

  ~ScopedStdioHandle() {
    Close();
  }

  void Close() {
    if (handle_) {
      fclose(handle_);
      handle_ = NULL;
    }
  }

  FILE* get() const { return handle_; }

  FILE* Take() {
    FILE* temp = handle_;
    handle_ = NULL;
    return temp;
  }

  void Set(FILE* newhandle) {
    Close();
    handle_ = newhandle;
  }

 private:
  FILE* handle_;

  DISALLOW_EVIL_CONSTRUCTORS(ScopedStdioHandle);
};

#endif // BASE_SCOPED_HANDLE_H_

// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef BASE_SCOPED_HANDLE_H_
#define BASE_SCOPED_HANDLE_H_

#include <stdio.h>

#include "base/basictypes.h"

#if defined(OS_WIN)
#include "base/scoped_handle_win.h"
#endif

class ScopedStdioHandle {
 public:
  ScopedStdioHandle()
      : handle_(NULL) { }

  explicit ScopedStdioHandle(FILE* handle)
      : handle_(handle) { }

  ~ScopedStdioHandle() {
    Close();
  }

  void Close() {
    if (handle_) {
      fclose(handle_);
      handle_ = NULL;
    }
  }

  FILE* get() const { return handle_; }

  FILE* Take() {
    FILE* temp = handle_;
    handle_ = NULL;
    return temp;
  }

  void Set(FILE* newhandle) {
    Close();
    handle_ = newhandle;
  }

 private:
  FILE* handle_;

  DISALLOW_EVIL_CONSTRUCTORS(ScopedStdioHandle);
};

#endif // BASE_SCOPED_HANDLE_H_

Add stdio to this file becasue we use FILE.

It starts failing with FILE, identifier not found, when
you remove the include for logging.h, which is included
in scoped_handle_win.h

Review URL: http://codereview.chromium.org/16461

git-svn-id: de016e52bd170d2d4f2344f9bf92d50478b649e0@7441 0039d316-1c4b-4281-b951-d872f2087c98


#include "Rts.h"

static HsInt GenSymCounter = 0;

HsInt genSym(void) {
    if (n_capabilities == 1) {
        return GenSymCounter++;
    } else {
        return atomic_inc((StgWord *)&GenSymCounter, 1);
    }
}

#include "Rts.h"

static HsInt GenSymCounter = 0;

HsInt genSym(void) {
#if defined(THREADED_RTS)
    if (n_capabilities == 1) {
        return GenSymCounter++;
    } else {
        return atomic_inc((StgWord *)&GenSymCounter, 1);
    }
#else
    return GenSymCounter++;
#endif
}

Fix bootstrapping of GHC with earlier versions

We can no longer use atomic_inc() in the stage1 compiler because its
prototype was recently changed.

Since the stage1 compiler is always single-threaded, only use
atomic_inc() when THREADED_RTS is defined.


//===- TGPreprocessor.h - Preprocessor for TableGen Files -------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This class represents the Preprocessor for tablegen files.
//
//===----------------------------------------------------------------------===//

#ifndef TGPREPROCESSOR_H
#define TGPREPROCESSOR_H

#include <vector>

namespace llvm {
class MemoryBuffer;
class SourceMgr;
class tool_output_file;

class TGPPLexer;
class TGPPRange;
class TGPPRecord;

typedef std::vector<TGPPRecord> TGPPRecords;

class TGPreprocessor {
  SourceMgr &SrcMgr;
  tool_output_file &Out;

  TGPPLexer *Lexer;
  TGPPRecords *CurRecords;

  bool ParseBlock(bool TopLevel);
  bool ParseForLoop();
  bool ParseRange(TGPPRange *Range);

public:
  TGPreprocessor(SourceMgr &SM, tool_output_file &O)
    : SrcMgr(SM), Out(O), Lexer(NULL), CurRecords(NULL) {
  }

  /// PreprocessFile - Main entrypoint for preprocess a tblgen file.  These
  /// preprocess routines return true on error, or false on success.
  bool PreprocessFile();
};
} // namespace llvm

#endif /* TGPREPROCESSOR_H */

//===- TGPreprocessor.h - Preprocessor for TableGen Files -------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This class represents the Preprocessor for tablegen files.
//
//===----------------------------------------------------------------------===//

#ifndef TGPREPROCESSOR_H
#define TGPREPROCESSOR_H

#include <vector>

namespace llvm {
class MemoryBuffer;
class SourceMgr;
class tool_output_file;

class TGPPLexer;
class TGPPRange;
class TGPPRecord;

typedef std::vector<TGPPRecord> TGPPRecords;

class TGPreprocessor {
  SourceMgr &SrcMgr;
  tool_output_file &Out;

  TGPPLexer *Lexer;
  TGPPRecords *CurRecords;

  bool ParseBlock(bool TopLevel);
  bool ParseForLoop();
  bool ParseRange(TGPPRange *Range);

public:
  TGPreprocessor(SourceMgr &SM, tool_output_file &O)
    : SrcMgr(SM), Out(O), Lexer(0), CurRecords(0) {
  }

  /// PreprocessFile - Main entrypoint for preprocess a tblgen file.  These
  /// preprocess routines return true on error, or false on success.
  bool PreprocessFile();
};
} // namespace llvm

#endif /* TGPREPROCESSOR_H */

Fix compilation when using gcc-4.6.  Patch by wanders.

git-svn-id: 0ff597fd157e6f4fc38580e8d64ab130330d2411@141178 91177308-0d34-0410-b5e6-96231b3b80d8


#ifndef FT_SOCK_SOCKET_H_
#define FT_SOCK_SOCKET_H_

struct ft_socket
{
	struct ft_context * context;

	const char * socket_class;

	int ai_family;
	int ai_socktype;
	int ai_protocol;

	struct sockaddr_storage addr;
	socklen_t addrlen;

	// Custom data fields
	void * protocol;
	void * data;
};

static inline bool ft_socket_init_(
	struct ft_socket * this, const char * socket_class, struct ft_context * context,
	int domain, int type, int protocol,
	const struct sockaddr * addr, socklen_t addrlen
)
{
	assert(this != NULL);
	assert(context != NULL);

	this->context = context;
	this->socket_class = socket_class;

	this->ai_family = domain;
	this->ai_socktype = type;
	this->ai_protocol = protocol;

	if (addr != NULL)
	{
		memcpy(&this->addr, addr, addrlen);
		this->addrlen = addrlen;
	}
	else
	{
		assert(addrlen == 0);
		memset(&this->addr, 0, sizeof(this->addr));
	}

	this->protocol = NULL;
	this->data = NULL;

	return true;
}

#endif //FT_SOCK_SOCKET_H_

#ifndef FT_SOCK_SOCKET_H_
#define FT_SOCK_SOCKET_H_

struct ft_socket
{
	struct ft_context * context;

	const char * clazz;

	int ai_family;
	int ai_socktype;
	int ai_protocol;

	struct sockaddr_storage addr;
	socklen_t addrlen;

	// Custom data fields
	void * protocol;
	void * data;
};

static inline bool ft_socket_init_(
	struct ft_socket * this, const char * clazz, struct ft_context * context,
	int domain, int type, int protocol,
	const struct sockaddr * addr, socklen_t addrlen
)
{
	assert(this != NULL);
	assert(context != NULL);

	this->context = context;
	this->clazz = clazz;

	this->ai_family = domain;
	this->ai_socktype = type;
	this->ai_protocol = protocol;

	if (addr != NULL)
	{
		memcpy(&this->addr, addr, addrlen);
		this->addrlen = addrlen;
	}
	else
	{
		assert(addrlen == 0);
		memset(&this->addr, 0, sizeof(this->addr));
	}

	this->protocol = NULL;
	this->data = NULL;

	return true;
}

#endif //FT_SOCK_SOCKET_H_

Unify name of the class.

Unify name of the class.


// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

#include <features.h>
#include <sched.h>

// CPU_COUNT is only provided by glibc 2.6 or higher
#if !defined(__GLIBC_PREREQ) || !__GLIBC_PREREQ(2, 6)
#define CPU_COUNT(set) _CPU_COUNT((unsigned int *)(set), sizeof(*(set))/sizeof(unsigned int))
static int _CPU_COUNT(unsigned int *set, size_t len) {
	int cnt;

	cnt = 0;
	while (len--)
		cnt += __builtin_popcount(*set++);
	return cnt;
}
#endif

#include "runtime.h"
#include "defs.h"

int32
getproccount(void)
{
	cpu_set_t set;
	int32 r, cnt;

	cnt = 0;
	r = sched_getaffinity(0, sizeof(set), &set);
	if(r == 0)
		cnt += CPU_COUNT(&set);

	return cnt ? cnt : 1;
}

// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

#include <features.h>
#include <sched.h>

// CPU_COUNT is only provided by glibc 2.6 or higher
#ifndef CPU_COUNT
#define CPU_COUNT(set) _CPU_COUNT((unsigned int *)(set), sizeof(*(set))/sizeof(unsigned int))
static int _CPU_COUNT(unsigned int *set, size_t len) {
	int cnt;

	cnt = 0;
	while (len--)
		cnt += __builtin_popcount(*set++);
	return cnt;
}
#endif

#include "runtime.h"
#include "defs.h"

int32
getproccount(void)
{
	cpu_set_t set;
	int32 r, cnt;

	cnt = 0;
	r = sched_getaffinity(0, sizeof(set), &set);
	if(r == 0)
		cnt += CPU_COUNT(&set);

	return cnt ? cnt : 1;
}

runtime: Check for CPU_COUNT itself, don't check glibc version.

Fixes #38.

R=iant
CC=gofrontend-dev
https://golang.org/cl/155740043


/*
 * i2c-xiic.h
 * Copyright (c) 2009 Intel Corporation
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/* Supports:
 * Xilinx IIC
 */

#ifndef _LINUX_I2C_XIIC_H
#define _LINUX_I2C_XIIC_H

/**
 * struct xiic_i2c_platform_data - Platform data of the Xilinx I2C driver
 * @num_devices:	Number of devices that shall be added when the driver
 *			is probed.
 * @devices:		The actuall devices to add.
 *
 * This purpose of this platform data struct is to be able to provide a number
 * of devices that should be added to the I2C bus. The reason is that sometimes
 * the I2C board info is not enough, a new PCI board can for instance be
 * plugged into a standard PC, and the bus number might be unknown at
 * early init time.
 */
struct xiic_i2c_platform_data {
	u8				num_devices;
	struct i2c_board_info const	*devices;
};

#endif /* _LINUX_I2C_XIIC_H */

Add the platform data include for the Xilinx XPS IIC Bus Interface

This file was missed in the original patch that went into Linus' tree.

Cc: "Ben Dooks (embedded platforms)" <1177f64998f284a7348354b8e91cbbe575d9858a@fluff.org>
Cc: a2bf4ba1a5b5bdfcae71455fa003391c08eec12f@vger.kernel.org
Signed-off-by: Richard Röjfors <ad7b115107a2fdcbfd7e2de42d425dd04755e505@pelagicore.com>
Signed-off-by: Stephen Rothwell <4bf0fb350827ce8d86875e76c923a478597c3cef@canb.auug.org.au>
Signed-off-by: Linus Torvalds <69652caca27c8b940640ad396ab71f93cacec34f@linux-foundation.org>


#ifndef __SCATTER_GRIDDER_H
#define __SCATTER_GRIDDER_H

#if defined __AVX__
#include <immintrin.h>
#endif

#ifdef __CUDACC__
  #include <cuComplex.h>
  typedef cuDoubleComplex complexd;
#elif defined __cplusplus
  #include <complex>
  typedef std::complex<double> complexd;
#else
  #include <complex.h>
  typedef double complex complexd;
#endif

struct Double4c
{
  complexd XX;
  complexd XY;
  complexd YX;
  complexd YY;
};

struct Double3
{
  double u;
  double v;
  double w;
};

// We have original u,v,w, in meters.
// To go to u,v,w in wavelengths we shall multiply them with freq/SPEED_OF_LIGHT

#ifndef SPEED_OF_LIGHT
#define SPEED_OF_LIGHT 299792458.0
#endif

#ifndef WSTEP_CORRECT
#define WSTEP_CORRECT 0.00001
#endif

struct TaskCfg {
  double
      min_wave_length
    , max_inverse_wave_length
    , cellsize
    , cellsizeWL
    , scale
    , scaleWL
    , w_step
    , w_stepWL
    , w_shift
    , w_shiftWL
    ;
};

#ifdef __CUDACC__
__device__ __inline__ static
#else
__inline static
#endif
  int get_supp(int w) {
    if (w < 0) w = -w;
    return w * 8 + 1;
  }

#endif

Add simplest as possible support size func.


#include <stdio.h>
#include <cs50.h>

int main(void) {

    return 0;
}

#include <stdio.h>
#include <cs50.h>

int main(int argc, char *argv[]) {

    // check entered key
    if (argc != 2 || atoi(argv[1]) < 0) {
        printf("Usage: ./caesar k\nWhere k is a non negative integer.\n");
        return 1;
    }

    int key = atoi(argv[1]);

    return 0;
}

Add key check and convert key to int

Add key check and convert key to int


#include "charmony.h"

#ifdef CHY_HAS_STDBOOL_H
# include <stdbool.h>
#elif !defined(__cplusplus)
typedef char bool;
# define true 1
# define false 0
#endif

#define CMARK_ATTRIBUTE(list)

#ifndef CHY_HAS_VA_COPY
  #define va_copy(dest, src) ((dest) = (src))
#endif

#define inline CHY_INLINE

Use CHY_INLINE in CommonMark source

Use CHY_INLINE in CommonMark source


#ifndef SAUCE_SAUCE_H_
#define SAUCE_SAUCE_H_

#include <sauce/internal/bindings.h>
#include <sauce/internal/new_delete.h>

namespace sauce {

  template<typename Module, typename NewDelete = ::sauce::internal::NewDelete>
  struct Injector {

    friend class SauceTest;

    Injector():
      newDelete() {}

    template<typename Iface>
    Iface provide() {
      return provide<Iface>(Module::template bindings<Injector<Module> >);
    }

    template<typename Iface>
    void dispose(Iface iface) {
      dispose<Iface>(Module::template bindings<Injector<Module> >, iface);
    }

  private:

    const NewDelete newDelete;

    template<typename Iface, typename Binding>
    Iface provide(Binding *binding (Iface)) {
      return Binding::provide(*this);
    }

    template<typename Iface, typename Binding>
    void dispose(Binding *binding (Iface), Iface iface) {
      Binding::dispose(*this, iface);
    }

  };

} // namespace sauce

#endif

#ifndef SAUCE_SAUCE_H_
#define SAUCE_SAUCE_H_

#include <sauce/internal/bindings.h>
#include <sauce/internal/new_delete.h>

namespace sauce {

  template<typename Module, typename NewDelete = ::sauce::internal::NewDelete>
  struct Injector {

    friend class SauceTest;

    Injector():
      new_delete() {}

    template<typename Iface>
    Iface provide() {
      return provide<Iface>(Module::template bindings<Injector<Module> >);
    }

    template<typename Iface>
    void dispose(Iface iface) {
      dispose<Iface>(Module::template bindings<Injector<Module> >, iface);
    }

  private:

    const NewDelete new_delete;

    template<typename Iface, typename Binding>
    Iface provide(Binding *binding (Iface)) {
      return Binding::provide(*this);
    }

    template<typename Iface, typename Binding>
    void dispose(Binding *binding (Iface), Iface iface) {
      Binding::dispose(*this, iface);
    }

  };

} // namespace sauce

#endif

Rename member newDelete -> new_delete.

Rename member newDelete -> new_delete.


/**
  Arduino/Genuino UNO
  PIN Configuration
  D0-D13 - 14 digital IN/OUT pins
  A0-A5 - 6 analog IN, digital OUT pins
  LED - D13 is also the on board LED
*/

/**
  The outputs to the board. The outputs are written internally.
*/

#include "stream_of_byte.h"

struct riot_arduino_uno_sinks_t {
  stream_of_byte *D0;
  stream_of_byte *D1;
  stream_of_byte *D2;
  stream_of_byte *D3;
  stream_of_byte *D4;
  stream_of_byte *D5;
  stream_of_byte *D6;
  stream_of_byte *D7;
  stream_of_byte *D8;
  stream_of_byte *D9;
  stream_of_byte *D10;
  stream_of_byte *D11;
  stream_of_byte *D12;
  stream_of_byte *D13;
  stream_of_byte *A0;
  stream_of_byte *A1;
  stream_of_byte *A2;
  stream_of_byte *A3;
  stream_of_byte *A4;
  stream_of_byte *A5;
  stream_of_byte *LED;
};

typedef struct riot_arduino_uno_sinks_t riot_arduino_uno_sinks;

Add arduino uno board configuration

Add arduino uno board configuration


// Copyright 2012 Rui Ueyama <rui314@gmail.com>
// This program is free software licensed under the MIT license.

#include "test.h"

void testmain(void) {
    print("numeric constants");

    expect(1, 0x1);
    expect(17, 0x11);
    expect(511, 0777);
    expect(11, 0b1011);  // GNU extension
    expect(11, 0B1011);  // GNU extension

    expect(3, 3L);
    expect(3, 3LL);
    expect(3, 3UL);
    expect(3, 3LU);
    expect(3, 3ULL);
    expect(3, 3LU);
    expect(3, 3LLU);

    expectd(55.3, 55.3);
    expectd(200, 2e2);
    expectd(0x0.DE488631p8, 0xDE.488631);

    expect(4, sizeof(5));
    expect(8, sizeof(5L));
    expect(4, sizeof(3.0f));
    expect(8, sizeof(3.0));
    expect(4, sizeof(0xe0));
}

// Copyright 2012 Rui Ueyama <rui314@gmail.com>
// This program is free software licensed under the MIT license.

#include "test.h"

void testmain(void) {
    print("numeric constants");

    expect(1, 0x1);
    expect(1, 0X1);
    expect(17, 0x11);
    expect(17, 0X11);
    expect(511, 0777);
    expect(11, 0b1011);  // GNU extension
    expect(11, 0B1011);  // GNU extension

    expect(3, 3L);
    expect(3, 3LL);
    expect(3, 3UL);
    expect(3, 3LU);
    expect(3, 3ULL);
    expect(3, 3LU);
    expect(3, 3LLU);

    expectd(55.3, 55.3);
    expectd(200, 2e2);
    expectd(0x0.DE488631p8, 0xDE.488631);

    expect(4, sizeof(5));
    expect(8, sizeof(5L));
    expect(4, sizeof(3.0f));
    expect(8, sizeof(3.0));
    expect(4, sizeof(0xe0));
}

Add tests for 0X prefix.

Add tests for 0X prefix.


#include "cowboy.h"

VALUE mCowboy;

VALUE fft_1d(VALUE m, VALUE nums){
  fftw_complex *in, *out;
  fftw_plan fp;
  long n;

  Check_Type(nums, T_ARRAY);

  n = size_of_ary(nums);
  in = allocate_fftw_complex(n);
  out = allocate_fftw_complex(n);
  fp = fftw_plan_dft_1d(n, in, out, FFTW_FORWARD, FFTW_ESTIMATE);

  cast_nums_to_complex(in, nums);

  fftw_execute(fp);

  return complex_to_real_nums(out, n);
}

void Init_cowboy(){
  mCowboy = rb_define_module("Cowboy");

  Init_cowboy_complex();

  rb_define_module_function(mCowboy, "fft_1d", fft_1d, 1);
}

#include "cowboy.h"

VALUE mCowboy;

VALUE fft_1d(VALUE m, VALUE nums){
  fftw_complex *in, *out;
  fftw_plan fp;
  long n;

  Check_Type(nums, T_ARRAY);

  n = size_of_ary(nums);
  if (n == 0){
    rb_raise(rb_eException, "Can't use blank array");
  }
  in = allocate_fftw_complex(n);
  out = allocate_fftw_complex(n);
  fp = fftw_plan_dft_1d(n, in, out, FFTW_FORWARD, FFTW_ESTIMATE);

  cast_nums_to_complex(in, nums);

  fftw_execute(fp);
  free(in);

  return complex_to_real_nums(out, n);
}

void Init_cowboy(){
  mCowboy = rb_define_module("Cowboy");

  Init_cowboy_complex();

  rb_define_module_function(mCowboy, "fft_1d", fft_1d, 1);
}

Handle call with empty array gracefully. (Compare to segfault earlier).


//===- Config.h -------------------------------------------------*- C++ -*-===//
//
//                             The LLVM Linker
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#ifndef LLD_WASM_CONFIG_H
#define LLD_WASM_CONFIG_H

#include "llvm/ADT/StringRef.h"
#include "llvm/BinaryFormat/Wasm.h"

#include "Symbols.h"

using llvm::wasm::WasmGlobal;

#include <set>

namespace lld {
namespace wasm {

struct Configuration {
  bool AllowUndefined;
  bool Demangle;
  bool EmitRelocs;
  bool ImportMemory;
  bool Relocatable;
  bool StripAll;
  bool StripDebug;
  uint32_t GlobalBase;
  uint32_t InitialMemory;
  uint32_t MaxMemory;
  uint32_t ZStackSize;
  llvm::StringRef Entry;
  llvm::StringRef OutputFile;
  llvm::StringRef Sysroot;

  std::set<llvm::StringRef> AllowUndefinedSymbols;
  std::vector<llvm::StringRef> SearchPaths;
  std::vector<std::pair<Symbol *, WasmGlobal>> SyntheticGlobals;
};

// The only instance of Configuration struct.
extern Configuration *Config;

} // namespace wasm
} // namespace lld

#endif

//===- Config.h -------------------------------------------------*- C++ -*-===//
//
//                             The LLVM Linker
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#ifndef LLD_WASM_CONFIG_H
#define LLD_WASM_CONFIG_H

#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/BinaryFormat/Wasm.h"

#include "Symbols.h"

using llvm::wasm::WasmGlobal;

namespace lld {
namespace wasm {

struct Configuration {
  bool AllowUndefined;
  bool Demangle;
  bool EmitRelocs;
  bool ImportMemory;
  bool Relocatable;
  bool StripAll;
  bool StripDebug;
  uint32_t GlobalBase;
  uint32_t InitialMemory;
  uint32_t MaxMemory;
  uint32_t ZStackSize;
  llvm::StringRef Entry;
  llvm::StringRef OutputFile;
  llvm::StringRef Sysroot;

  llvm::StringSet<> AllowUndefinedSymbols;
  std::vector<llvm::StringRef> SearchPaths;
  std::vector<std::pair<Symbol *, WasmGlobal>> SyntheticGlobals;
};

// The only instance of Configuration struct.
extern Configuration *Config;

} // namespace wasm
} // namespace lld

#endif

Use llvm::StringSet instead of std::set.

std::set is pretty slow. We generally prefer llvm::StringSet if we don't
need an sorted set.

Differential Revision: https://reviews.llvm.org/D40579

git-svn-id: f6089bf0e6284f307027cef4f64114ee9ebb0424@319371 91177308-0d34-0410-b5e6-96231b3b80d8