Esempio n. 1
0
// Test boost::tie() interoperabiliy.
int test_main( int, char* [] )
{
  typedef X T ;
          
  try
  {
    TRACE( std::endl << BOOST_CURRENT_FUNCTION  );
  
    T z(0);
    T a(1);
    T b(2);
  
    optional<T> oa, ob ;
  
    // T::T( T const& x ) is used
    set_pending_dtor( ARG(T) ) ;
    set_pending_copy( ARG(T) ) ;
    boost::tie(oa,ob) = std::make_pair(a,b) ;
    check_is_not_pending_dtor( ARG(T) ) ;
    check_is_not_pending_copy( ARG(T) ) ;
    check_initialized(oa);
    check_initialized(ob);
    check_value(oa,a,z);
    check_value(ob,b,z);
    
  }
  catch ( ... )
  {
    BOOST_ERROR("Unexpected Exception caught!");
  }

  return 0;
}
Esempio n. 2
0
int edcl_read(unsigned int address, void* obuf, size_t len)
{
	check_initialized();
	if(len > edcl_platform_get_maxpacket()) {
		errno = EINVAL;
		return -1;
	}

	address = htonl(address);

	struct EdclPacket rq = {.control = edcl_control(seq++, 0, len), .address = address };
	char buf[2000];
	struct EdclPacket* rs = (struct EdclPacket*)buf;
	ssize_t n = edcl_transaction(&rq, sizeof(rq), rs, sizeof(buf));

	if(n < len + sizeof(*rs)) {
		errno = EPROTO;
		return -1;
	}

	if(rs->address != address || edcl_len(rs) != len) {
		errno = EPROTO;
		return -1;
	}

	memcpy(obuf, buf + sizeof(*rs), len);
	return 0;
}

int edcl_write(unsigned int address, const void* ibuf, size_t len) {
	char buf[2000] = {0};
	check_initialized();
	struct EdclPacket* rq = (struct EdclPacket*)buf;
	struct EdclPacket rs;

	if((len > edcl_platform_get_maxpacket()) || len > chip_config->maxpayload) {
		errno = EINVAL;
		fprintf(stderr, "payload too large: %zu \n",
			len );
		return -1;
	}


	rq->address = htonl(address);
	rq->control = edcl_control(seq++, 1, len);

	memcpy(buf + sizeof(*rq), ibuf, len);
	return edcl_transaction(rq, sizeof(*rq) + len, &rs, sizeof(rs)) > 0 ? 0 : -1;
}
Esempio n. 3
0
/*! \details This function gets the scheduling parameters from \a attr and
 * stores it in \a param.
 * \return Zero on success or -1 with errno set to:
 * - EINVAL: \a attr does not refer to an initialized thread attribute object
 */
int pthread_attr_getschedparam(const pthread_attr_t *attr /*! a pointer to the attributes structure */,
		struct sched_param *param /*! the destination for the sched param value */){
	if ( check_initialized(attr) < 0 ){
		return -1;
	}

	memcpy(param, &(attr->schedparam), sizeof(struct sched_param));
	return 0;
}
Esempio n. 4
0
/*! \details This function gets the scheduling policy from \a attr and
 * stores it in \a policy.
 * \return Zero on success or -1 with errno set to:
 * - EINVAL: \a attr does not refer to an initialized thread attribute object
 */
int pthread_attr_getschedpolicy(const pthread_attr_t *attr /*! a pointer to the attributes structure */,
		int *policy /*! the destination for the schedule policy value */){
	if ( check_initialized(attr) < 0 ){
		return -1;
	}

	*policy = PTHREAD_ATTR_GET_SCHED_POLICY(attr);
	return 0;
}
Esempio n. 5
0
/*! \details This function gets the detach state from \a attr and
 * stores it in \a detachstate.
 * \return Zero on success or -1 with errno set to:
 * - EINVAL: \a attr does not refer to an initialized thread attribute object
 */
int pthread_attr_getdetachstate(const pthread_attr_t * attr  /*! a pointer to the attributes structure */,
		int * detachstate /*! the destination for the detach state */){
	if ( check_initialized(attr) < 0 ){
		return -1;
	}

	*detachstate = PTHREAD_ATTR_GET_DETACH_STATE(attr);
	return 0;
}
Esempio n. 6
0
/*! \details This function gets the guard size from \a attr and
 * stores it in \a guardsize.
 * \return Zero on success or -1 with errno set to:
 * - EINVAL: \a attr does not refer to an initialized thread attribute object
 */
int pthread_attr_getguardsize(const pthread_attr_t * attr /*! a pointer to the attributes structure */,
		size_t * guardsize /*! the destination for the new guard size */){
	if ( check_initialized(attr) < 0 ){
		return -1;
	}

	*guardsize = PTHREAD_ATTR_GET_GUARDSIZE(attr);
	return 0;
}
Esempio n. 7
0
/*! \details This functions gets the stack size from \a attr and
 * stores it in \a stacksize.
 * \return Zero on success or -1 with errno set to:
 * - EINVAL: \a attr does not refer to an initialized thread attribute object
 */
int pthread_attr_getstacksize(const pthread_attr_t *attr /*! a pointer to the attributes structure */,
		size_t *stacksize /*! the destination for the new stack size */){
	if ( check_initialized(attr) < 0 ){
		return -1;
	}

	*stacksize = attr->stacksize;
	return 0;
}
Esempio n. 8
0
static  int  get_random( void )
{
    check_initialized();

#if HAVE_RANDOM
    return( (int) random() );
#else
    return( (int) rand() );
#endif /* HAVE_RANDOM */
}
Esempio n. 9
0
/*! \details This function gets the inherit sched value from \a attr and
 * stores it in \a inheritsched.
 * \return Zero on success or -1 with errno set to:
 * - EINVAL: \a attr does not refer to an initialized thread attribute object
 */
int pthread_attr_getinheritsched(const pthread_attr_t * attr /*! a pointer to the attributes structure */,
		int * inheritsched /*! the destination for the inherit sched value */){
#ifndef _POSIX_THREAD_PRIORITY_SCHEDULING
	errno = ENOSYS;
	return -1;
#else
	if ( check_initialized(attr) < 0 ){
		return -1;
	}

	*inheritsched = PTHREAD_ATTR_GET_INHERIT_SCHED(attr);
	return 0;
#endif
}
Esempio n. 10
0
/*! \details This function sets the stack size in \a attr with \a stacksize.
 * \return Zero on success or -1 with errno set to:
 * - EINVAL: \a attr does not refer to an initialized thread attribute object
 * - EINVAL: \a stacksize is too low of a value
 * - ENOMEM:  not enough memory
 */
int pthread_attr_setstacksize(pthread_attr_t *attr /*! a pointer to the attributes structure */,
		size_t stacksize /*! the new stack size value */){
	if ( check_initialized(attr) < 0 ){
		return -1;
	}

    if( stacksize >= PTHREAD_STACK_MIN ){
        attr->stacksize = stacksize;
        return 0;
    }

    errno = EINVAL;
    return -1;
}
Esempio n. 11
0
/*! \details This function gets the contention scope from \a attr and
 * stores it in \a contentionscope.
 * \return Zero on success or -1 with errno set to:
 * - EINVAL: \a attr does not refer to an initialized thread attribute object
 */
int pthread_attr_getscope(const pthread_attr_t *attr /*! a pointer to the attributes structure */,
		int *contentionscope /*! the destination for the contention scope value */){
#ifndef _POSIX_THREAD_PRIORITY_SCHEDULING
	errno = ENOTSUP;
	return -1;
#else
	if ( check_initialized(attr) < 0 ){
		return -1;
	}

	*contentionscope = PTHREAD_ATTR_GET_CONTENTION_SCOPE(attr);
	return 0;
#endif
}
Esempio n. 12
0
/*! \details This function sets the detach state in \a attr with \a detachstate.
 * \return Zero on success or -1 with errno set to:
 * - EINVAL: \a attr does not refer to an initialized thread attribute object
 * - EINVAL: \a detachstate is not a valid
 */
int pthread_attr_setdetachstate(pthread_attr_t *attr /*! a pointer to the attributes structure */,
		int detachstate /*! the new detach state (PTHREAD_CREATE_DETACHED or PTHREAD_CREATE_JOINABLE) */){
	if ( check_initialized(attr) < 0 ){
		return -1;
	}

	if ( (detachstate != PTHREAD_CREATE_DETACHED) &&
			(detachstate != PTHREAD_CREATE_JOINABLE) ){
		errno = EINVAL;
		return -1;
	}

	PTHREAD_ATTR_SET_DETACH_STATE(attr, detachstate);
	return 0;
}
Esempio n. 13
0
/**
 * Retrieve a GL function pointer given the function name.
 *
 * This function is similar to glXGetProcAddressARB(), except that:
 *
 * - It is platform-independent.
 *
 * - It may be called on any supported function, regardless of whether
 *   the function is defined in GL core or an extension, and
 *   regardless of whether desktop GL or GLES is in use.
 *
 * - Synonymous function names (e.g. glMapBuffer and glMapBufferARB)
 *   may be used interchangably; the correct function is automatically
 *   chosen based on the GL version and extension string.
 *
 * - If the requested function is not supported by the implementation,
 *   the unsupported_proc that was passed to piglit_dispatch_init() is
 *   called.
 */
piglit_dispatch_function_ptr
piglit_dispatch_resolve_function(const char *name)
{
	size_t item_size = sizeof(function_names[0]);
	size_t num_items = ARRAY_SIZE(function_names);
	const char * const *item = (const char * const *)
		bsearch(&name, function_names, num_items, item_size,
			compare_function_names);
	check_initialized();
	if (!item) {
		unsupported(name);
		return NULL;
	} else {
		size_t item_index = item - function_names;
		return function_resolvers[item_index]();
	}
}
Esempio n. 14
0
int oss_mixer_open(const char *pathname, int flags, ...)
{
	int result;

	check_initialized();
	if (native_oss)
		return open(pathname, flags);
	result = x_oss_mixer_open(pathname, flags);
	if (result >= 0) {
		open_count++;
	} else {
		if (open_count == 0) {
			dlclose(dl_handle);
			dl_handle = NULL;
		}
	}
	return result;
}
Esempio n. 15
0
/*! \details This function sets the scheduling policy in \a attr with \a policy.
 * \return Zero on success or -1 with errno set to:
 * - EINVAL: \a attr does not refer to an initialized thread attribute object
 * - EINVAL: \a policy does not refer to a valid policy.
 */
int pthread_attr_setschedpolicy(pthread_attr_t *attr /*! a pointer to the attributes structure */,
		int policy /*! the new policy value (SCHED_FIFO, SCHED_RR, or SCHED_OTHER) */){
	if ( check_initialized(attr) < 0 ){
		return -1;
	}

	switch(policy){
	case SCHED_FIFO:
	case SCHED_RR:
	case SCHED_OTHER:
		PTHREAD_ATTR_SET_SCHED_POLICY(attr, policy);
		return 0;
	default:
		errno = EINVAL;
		return -1;
	}

}
Esempio n. 16
0
JNIEXPORT jobjectArray JNICALL
Java_com_zimbra_znative_ProxyInfo_getProxyInfo(JNIEnv *env, jclass cls, jstring jurl) {
    check_initialized(env);
    CFStringRef urlstr = getCFString(env, jurl);
    CFURLRef url = CFURLCreateWithString(NULL, urlstr, NULL);
    CFDictionaryRef systemProxy = CFNetworkCopySystemProxySettings();
    CFArrayRef proxyArray = CFNetworkCopyProxiesForURL(url, systemProxy);
    CFIndex size = CFArrayGetCount(proxyArray);
    jobjectArray results = (*env)->NewObjectArray(env, (jsize) size, pi_cls, NULL);
    int i;
    for (i = 0; i < size; i++) {
        CFDictionaryRef proxy = CFArrayGetValueAtIndex(proxyArray, i);
        (*env)->SetObjectArrayElement(env, results, i, getProxyInfo(env, proxy));
    }
    CFRelease(proxyArray);
    CFRelease(systemProxy);
    CFRelease(url);
    CFRelease(urlstr);
    return results;
}
Esempio n. 17
0
/*! \details This function sets the contention scope in \a attr with \a contentionscope.
 * \return Zero on success or -1 with errno set to:
 * - EINVAL: \a attr does not refer to an initialized thread attribute object
 * - ENOTSUP:  contentionscope is not PTHREAD_SCOPE_SYSTEM or PTHREAD_SCOPE_PROCESS
 */
int pthread_attr_setscope(pthread_attr_t *attr /*! a pointer to the attributes structure */,
		int contentionscope /*! the new contention scope value */){
#ifndef _POSIX_THREAD_PRIORITY_SCHEDULING
	errno = ENOSYS;
	return -1;
#else
	if ( check_initialized(attr) < 0 ){
		return -1;
	}

	switch(contentionscope){
	case PTHREAD_SCOPE_SYSTEM:
		PTHREAD_ATTR_SET_CONTENTION_SCOPE(attr, contentionscope);
		return 0;
	case PTHREAD_SCOPE_PROCESS:
	default:
		errno = EINVAL;
		return -1;
	}
#endif
}
Esempio n. 18
0
/*! \details This function sets the inherit sched in \a attr with \a inheritsched.
 * \return Zero on success or -1 with errno set to:
 * - EINVAL: \a attr does not refer to an initialized thread attribute object
 * - EINVAL: \a inheritsched is not a valid value
 */
int pthread_attr_setinheritsched(pthread_attr_t *attr /*! a pointer to the attributes structure */,
		int inheritsched /*! the new inherit sched value */){
#ifndef _POSIX_THREAD_PRIORITY_SCHEDULING
	errno = ENOSYS;
	return -1;
#else
	if ( check_initialized(attr) < 0 ){
		return -1;
	}

	if ( (inheritsched == PTHREAD_INHERIT_SCHED) ||
			(inheritsched == PTHREAD_EXPLICIT_SCHED)){

		PTHREAD_ATTR_SET_INHERIT_SCHED(attr, inheritsched);
		return 0;
	} else {
		errno = EINVAL;
		return -1;
	}

#endif
}
Esempio n. 19
0
/*! \details This function sets the scheduling parameters in \a attr with \a param.
 * \return Zero on success or -1 with errno set to:
 * - EINVAL: \a attr does not refer to an initialized thread attribute object
 */
int pthread_attr_setschedparam(pthread_attr_t *attr /*! a pointer to the attributes structure */,
		const struct sched_param *param /*! the source for the sched param value */){
	int policy;

	if ( check_initialized(attr) < 0 ){
		return -1;
	}

	policy = PTHREAD_ATTR_GET_SCHED_POLICY(attr);

	if ( param->sched_priority < sched_get_priority_min(policy) ){
		errno = EINVAL;
		return -1;
	}

	if ( param->sched_priority > sched_get_priority_max(policy) ){
		errno = EINVAL;
		return -1;
	}

	memcpy(&(attr->schedparam), param, sizeof(struct sched_param));
	return 0;
}
Esempio n. 20
0
int main(int argc, char **argv) {
    if (argc < 2) {
        fprintf(stderr, "Usage: %s <command> [<args>]\n", argv[0]);
        return 2;
    }

    // TODO: If students aren't going to write this themselves, replace by clean
    // implementation using function pointers.
    if (strcmp(argv[1], "init") == 0) {

      if (check_initialized()) {
        fprintf(stderr, "ERROR: Repository is already initialized\n");
        return 1;
      }

      return beargit_init();

    } else {

        if (!check_initialized()) {
            fprintf(stderr, "ERROR: Repository is not initialized\n");
            return 1;
        }

        if (strcmp(argv[1], "add") == 0 || strcmp(argv[1], "rm") == 0) {

          if (argc < 3 || !check_filename(argv[2])) {
            fprintf(stderr, "ERROR: No or invalid filename given\n");
            return 1;
          }

          if (strcmp(argv[1], "rm") == 0) {
            return beargit_rm(argv[2]);
          } else {
            return beargit_add(argv[2]);
          }

        } else if (strcmp(argv[1], "commit") == 0) {

          if (argc < 4 || strcmp(argv[2], "-m") != 0) {
            fprintf(stderr, "ERROR: Need a commit message (-m <msg>)\n");
            return 1;
          }

          if (strlen(argv[3]) > MSG_SIZE-1) {
            fprintf(stderr, "ERROR: Message is too long!\n");
            return 1;
          }

          return beargit_commit(argv[3]);

        } else if (strcmp(argv[1], "status") == 0) {
            return beargit_status();
        } else if (strcmp(argv[1], "log") == 0) {
            return beargit_log();
        } else if (strcmp(argv[1], "branch") == 0) {
            return beargit_branch();
        } else if (strcmp(argv[1], "checkout") == 0) {
            int branch_new = 0;
            char* arg = NULL;

            for (int i = 2; i < argc; i++) {
              if (argv[i][0] == '-') {
                if (strcmp(argv[i], "-b") == 0) {
                  branch_new = 1;
                  continue;
                } else {
                  fprintf(stderr, "ERROR: Invalid argument: %s", argv[i]);
                  return 1;
                }
              }

              if (arg) {
                  fprintf(stderr, "ERROR: Too many arguments for checkout!");
                  return 1;
              }

              arg = argv[i];
            }

            return beargit_checkout(arg, branch_new);
        } else {
            fprintf(stderr, "ERROR: Unknown command \"%s\"\n", argv[1]);
            return 1;
        }
    }
}
Esempio n. 21
0
      // return cipher mode (such as CIPH_CBC_MODE, etc.)
      int cipher_mode() const
      {
	check_initialized();
	return CIPH_CBC_MODE;
      }