Esempio n. 1
0
MODULE check_if_answer_is_complete (THREAD *thread)
{
    Bool
        complete;
    tcb = thread-> tcb;                 /*  Point to thread's context        */

    complete = rdns_check_answer_size (tcb-> query, (dbyte)tcb-> readsize);
    if (complete == FALSE)
        raise_exception (read_more_event);
}
Esempio n. 2
0
void helper_boundl(CPUX86State *env, target_ulong a0, int v)
{
    int low, high;

    low = cpu_ldl_data(env, a0);
    high = cpu_ldl_data(env, a0 + 4);
    if (v < low || v > high) {
        raise_exception(env, EXCP05_BOUND);
    }
}
Esempio n. 3
0
const InputEventDefinition&
ControllerDescription::get_definition(int id) const
{
  std::map<int, InputEventDefinition>::const_iterator i = id_to_event.find(id);
  if (i == id_to_event.end())
  {
    raise_exception(std::runtime_error, "Unknown event id");
  }
  return i->second;
}
Esempio n. 4
0
/**
 * Called by Java's Socket::getLongSockopt(int option).
 */
JNIEXPORT jlong JNICALL Java_org_zeromq_ZMQ_00024Socket_getLongSockopt (JNIEnv *env,
                                                                        jobject obj,
                                                                        jint option)
{
    switch (option) {
#if ZMQ_VERSION >= ZMQ_MAKE_VERSION(2,1,0)
    case ZMQ_TYPE:
    case ZMQ_FD:
    case ZMQ_EVENTS:
    case ZMQ_LINGER:
#endif
    case ZMQ_HWM:
    case ZMQ_SWAP:
    case ZMQ_AFFINITY:
    case ZMQ_RATE:
    case ZMQ_RECOVERY_IVL:
    case ZMQ_MCAST_LOOP:
    case ZMQ_SNDBUF:
    case ZMQ_RCVBUF:
    case ZMQ_RCVMORE:
        {
            void *s = get_socket (env, obj, 1);
            jlong ret = 0;
            int rc = 0;
            int err = 0;

            uint64_t optval = 0;
            size_t optvallen = sizeof(optval);
            rc = zmq_getsockopt (s, option, &optval, &optvallen);
            err = zmq_errno();
            ret = (jlong) optval;

            if (rc != 0) {
                raise_exception (env, err);
                return 0L;
            }
            return ret;
        }
    default:
        raise_exception (env, EINVAL);
        return 0L;
    }
}
Esempio n. 5
0
    /** @brief Checks whether an OpenCL error has occured.
    *
    *  Do not use this function directly, use the macro CL_ERROR_CHECK instead.
    */
    static void checkError(cl_int err, const std::string & file, const std::string & func, int line)
    {
        if (err != CL_SUCCESS)
        {
#ifdef VIENNACL_DEBUG_ALL
            std::cerr << "ViennaCL: Error " << err  << " in function " << func << " ( "<< file << ":" << line << " ) " << std::endl;
#endif
            raise_exception(err);
        }
    } //checkError()
PyObject * AerospikeScan_Results(AerospikeScan * self, PyObject * args, PyObject * kwds)
{
	PyObject * py_policy = NULL;
	as_policy_scan scan_policy;
	as_policy_scan * scan_policy_p = NULL;

	static char * kwlist[] = {"policy", NULL};

	if ( PyArg_ParseTupleAndKeywords(args, kwds, "|O:results", kwlist, &py_policy) == false ) {
		return NULL;
	}

	as_error err;
	as_error_init(&err);

	if (!self || !self->client->as) {
		as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object");
		goto CLEANUP;
	}
	if (!self->client->is_conn_16) {
		as_error_update(&err, AEROSPIKE_ERR_CLUSTER, "No connection to aerospike cluster");
		goto CLEANUP;
	}

	// Convert python policy object to as_policy_scan
	pyobject_to_policy_scan(&err, py_policy, &scan_policy, &scan_policy_p,
			&self->client->as->config.policies.scan);
	if ( err.code != AEROSPIKE_OK ) {
		as_error_update(&err, err.code, NULL);
		goto CLEANUP;
	}

	PyObject * py_results = NULL;
	py_results = PyList_New(0);

	PyThreadState * _save = PyEval_SaveThread();

	aerospike_scan_foreach(self->client->as, &err, scan_policy_p, &self->scan, each_result, py_results);

	PyEval_RestoreThread(_save);


CLEANUP:

	if ( err.code != AEROSPIKE_OK ) {
		PyObject * py_err = NULL;
		error_to_pyobject(&err, &py_err);
		PyObject *exception_type = raise_exception(&err);
		PyErr_SetObject(exception_type, py_err);
		Py_DECREF(py_err);
		return NULL;
	}

	return py_results;
}
Esempio n. 7
0
std::vector<std::string>
ArchiveManager::get_filenames(const std::string& zip_filename, 
                              const ArchiveLoader** loader_out) const
{
  auto loader = find_loader_by_filename(zip_filename);
  if (!loader)
  {
    raise_exception(std::runtime_error, "failed to find loader for archive file: " << zip_filename);
  }
  else
  {
    try
    {
      if (loader_out) { *loader_out = loader; }
      return loader->get_filenames(zip_filename);
    }
    catch(const std::exception& err)
    {
      auto new_loader = find_loader_by_magic(zip_filename);
      
      if (!new_loader || new_loader == loader)
      {
        throw;
        return std::vector<std::string>();
      }
      else
      {
        loader = new_loader;
        if (!loader)
        {
          raise_exception(std::runtime_error, "failed to find loader for archive file: " << zip_filename);
        }
        else
        {
          log_warning << err.what() << std::endl;
          if (loader_out) { *loader_out = loader; }
          return loader->get_filenames(zip_filename);
        }
      }
    }
  }
}
Esempio n. 8
0
void
System::create_dir(std::string directory)
{
#ifndef WIN32
  log_info("System::create_dir: %1%", directory);
  
  if (!exist(directory))
  {
    if (mkdir(directory.c_str(), S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP) != 0)
    {
      raise_exception(std::runtime_error, "System::create_dir: " << directory << ": " << strerror(errno));
    }
    else
    {
      log_info("Successfully created: %1%", directory);
    }
  }
#else
  if (!CreateDirectory(directory.c_str(), 0))
  {
    DWORD dwError = GetLastError();
    if (dwError == ERROR_ALREADY_EXISTS)
    {
    }
    else if (dwError == ERROR_PATH_NOT_FOUND)
    {
      raise_exception(std::runtime_error, 
                      "CreateDirectory: " << directory <<
                      ": One or more intermediate directories do not exist; this function will only create the final directory in the path.");
    }
    else
    {
      raise_exception(std::runtime_error, 
                      "CreateDirectory: " << directory << ": failed with error " << StringUtil::to_string(dwError));
    }
  }
  else
  {
    log_info("Successfully created: %1%", directory);
  }
#endif
}
Esempio n. 9
0
 /** @brief Checks whether an OpenCL error has occured.
 *
 *  Do not use this function directly, use the macro CL_ERROR_CHECK instead.
 */
 static void checkError(cl_int err,
                        const std::string & file,
                        const std::string & func,
                        int line)
 {
   if (err != CL_SUCCESS)
   {
     std::cerr << "OpenCL: Error " << err  << " in function " << func << " ( "<< file << ":" << line << " ) " << std::endl;
     raise_exception(err);
   }
 } //checkError()
Esempio n. 10
0
UdevSubsystem::UdevSubsystem() :
  m_udev(),
  m_monitor(),
  m_process_match_cb()
{
  m_udev = udev_new();
  if (!m_udev)
  {
    raise_exception(std::runtime_error, "udev init failure");
  }
}
Esempio n. 11
0
void helper_rdpmc(CPUX86State *env)
{
    if ((env->cr[4] & CR4_PCE_MASK) && ((env->hflags & HF_CPL_MASK) != 0)) {
        raise_exception(env, EXCP0D_GPF);
    }
    cpu_svm_check_intercept_param(env, SVM_EXIT_RDPMC, 0);

    /* currently unimplemented */
    qemu_log_mask(LOG_UNIMP, "x86: unimplemented rdpmc\n");
    raise_exception_err(env, EXCP06_ILLOP, 0);
}
Esempio n. 12
0
PingusSoundReal::PingusSoundReal() :
  music_sample(0),
  m_music_volume(1.0f),
  m_sound_volume(1.0f),
  m_master_volume(1.0f)
{
  log_info("Initializing SDL audio");

  if (SDL_Init(SDL_INIT_AUDIO) == -1)
  {
    raise_exception(std::runtime_error, "Unable to initialize SDL: " << SDL_GetError());
  }

  log_info("Initializing SDL_Mixer");

  if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 4096) == -1)
  {
    raise_exception(std::runtime_error, "Unable to initialize SDL_Mixer: " << Mix_GetError());
  }
}
Esempio n. 13
0
static void mce_irq_ipi(void *info)
{
	int cpu = smp_processor_id();
	struct mce *m = this_cpu_ptr(&injectm);

	if (cpumask_test_cpu(cpu, mce_inject_cpumask) &&
			m->inject_flags & MCJ_EXCEPTION) {
		cpumask_clear_cpu(cpu, mce_inject_cpumask);
		raise_exception(m, NULL);
	}
}
PyObject *EntryIterator_iternext(PyObject *self)
{
  EntryIterator *entryIterator = reinterpret_cast<EntryIterator *>(self);

  bool notAtEnd;
  Py_BEGIN_ALLOW_THREADS
  try {
    notAtEnd = entryIterator->iter->hasNext();
  } catch (ac::IterationInterrupted &e) {
    Py_BLOCK_THREADS
    PyErr_SetNone(PyExc_GeneratorExit);
    return NULL;
  } catch (std::runtime_error &e) {
    Py_BLOCK_THREADS
    raise_exception(e.what());
    return NULL;
  }
  Py_END_ALLOW_THREADS

  if (notAtEnd) {
    ac::Entry e;

    Py_BEGIN_ALLOW_THREADS
    try {
      e = entryIterator->iter->next(*entryIterator->reader->reader);
    } catch (ac::IterationInterrupted &e) {
      Py_BLOCK_THREADS
      // XXX - throw a specific exception here
      PyErr_SetNone(PyExc_GeneratorExit);
      return NULL;
    } catch (std::runtime_error &e) {
      Py_BLOCK_THREADS
      raise_exception(e.what());
      return NULL;
    }
    Py_END_ALLOW_THREADS

    PyObject *entry = Entry_new(e);

    return entry;
  } else {
Esempio n. 15
0
std::string
Filesystem::get_magic(const std::string& filename)
{
  char buf[512];
  std::ifstream in(filename, std::ios::binary);
  if (!in)
  {
    raise_exception(std::runtime_error, filename << ": " << strerror(errno));
  }
  else
  {
    if (!in.read(buf, sizeof(buf)))
    {
      raise_exception(std::runtime_error, filename << ": " << strerror(errno));
    }
    else
    {
      return std::string(buf, in.gcount());
    }
  }
}
Esempio n. 16
0
void
ControllerSlotConfig::set_current_config(int num)
{
  if (num >= 0 && num < static_cast<int>(m_config.size()))
  {  
    m_current_config = num;
  }
  else
  {
    raise_exception(std::runtime_error, "argument out of range");
  }
}
Esempio n. 17
0
Button2AxisModifier*
Button2AxisModifier::from_string(const std::vector<std::string>& args)
{
  if (args.size() != 3)
  {
    raise_exception(std::runtime_error, "BUTTON:BUTTON:AXIS required as argument");
  }
  else
  {
    return new Button2AxisModifier(args[0], args[1], args[2]);
  }
}
Esempio n. 18
0
 /** Returns the id of the given name, throws on lookup failure */
 int get(const T& name) const
 {
   typename std::map<T, int>::const_iterator it = m_name2int.find(name);
   if (it == m_name2int.end())
   {
     raise_exception(std::runtime_error, "lookup failure for: '" << name << "'");
   }
   else
   {
     return it->second;
   }
 }
Esempio n. 19
0
USBSubsystem::USBSubsystem() :
  m_usb_gsource()
{
  int ret = libusb_init(NULL);
  if (ret != LIBUSB_SUCCESS)
  {
    raise_exception(std::runtime_error, "libusb_init() failed: " << usb_strerror(ret));
  }

  m_usb_gsource.reset(new USBGSource);
  m_usb_gsource->attach(NULL);
}
Esempio n. 20
0
SplitAxisModifier*
SplitAxisModifier::from_string(const std::vector<std::string>& args)
{
  if (args.size() != 3)
  {
    raise_exception(std::runtime_error, "SplitAxisModifier requires three arguments");
  }
  else
  {
    return new SplitAxisModifier(args[0], args[1], args[2]);
  }
}
Esempio n. 21
0
Options
Options::from_file(const Pathname& filename)
{
  FileReader reader = FileReader::parse(filename);

  if (reader.get_name() != "pingus-config")
  {
    raise_exception(std::runtime_error, "Error: " << filename << ": not a (pingus-config) file");
  }

  return from_file_reader(reader);
}
Esempio n. 22
0
int main(void) {
	if (setjmp(j) == 0) {
		printf("''setjmp'' is initializing ''j''\n");
		raise_exception();
		printf("this line should never appear\n");
	}
	else{
		printf("''setjmp'' was just jumped into\n");
		/* this code is the exception handler */
	}
	return 0;
}
Esempio n. 23
0
void HELPER(ill)(CPULM32State *env)
{
#ifndef CONFIG_USER_ONLY
    CPUState *cs = CPU(lm32_env_get_cpu(env));
    fprintf(stderr, "VM paused due to illegal instruction. "
            "Connect a debugger or switch to the monitor console "
            "to find out more.\n");
    qemu_system_vmstop_request(RUN_STATE_PAUSED);
    cs->halted = 1;
    raise_exception(env, EXCP_HALTED);
#endif
}
Esempio n. 24
0
/**
 * Called by Java's Socket::getBytesSockopt(int option).
 */
JNIEXPORT jbyteArray JNICALL Java_org_zeromq_ZMQ_00024Socket_getBytesSockopt (JNIEnv *env,
                                                                              jobject obj,
                                                                              jint option)
{
    switch (option) {
    case ZMQ_IDENTITY:
#if ZMQ_VERSION >= ZMQ_MAKE_VERSION(3,2,0)
    case ZMQ_LAST_ENDPOINT:
#endif
#if ZMQ_VERSION >= ZMQ_MAKE_VERSION(4,0,0)
    case ZMQ_PLAIN_USERNAME:
    case ZMQ_PLAIN_PASSWORD:
#endif
        {
            void *s = get_socket (env, obj);

            // Warning: hard-coded limit here.
            char optval[1024];
            size_t optvallen = 1024;
            int rc = zmq_getsockopt (s, option, optval, &optvallen);
            int err = zmq_errno();
            if (rc != 0) {
                raise_exception (env, err);
                return env->NewByteArray (0);
            }

            jbyteArray array = env->NewByteArray (optvallen);
            if (array == NULL) {
                raise_exception (env, EINVAL);
                return env->NewByteArray(0);
            }

            env->SetByteArrayRegion (array, 0, optvallen, (jbyte*) optval);
            return array;
        }
    default:
        raise_exception (env, EINVAL);
        return env->NewByteArray(0);
    }
}
Esempio n. 25
0
/**
 * Issue a read on the socket.
 */
static zmq_msg_t* do_read(JNIEnv *env, jobject obj, zmq_msg_t *message, int flags)
{
    void *s = get_socket (env, obj, 1);

    int rc = zmq_msg_init (message);
    int err = zmq_errno();
    if (rc != 0) {
        raise_exception (env, err);
        return NULL;
    }

#if ZMQ_VERSION >= ZMQ_MAKE_VERSION(3,0,0)
    rc = zmq_recvmsg (s, message, flags);
#else
    rc = zmq_recv (s, message, flags);
#endif
    err = zmq_errno();
    if (rc < 0 && err == EAGAIN) {
        rc = zmq_msg_close (message);
        err = zmq_errno();
        if (rc != 0) {
            raise_exception (env, err);
            return NULL;
        }
        return NULL;
    }

    if (rc < 0) {
        raise_exception (env, err);
        rc = zmq_msg_close (message);
        err = zmq_errno();
        if (rc != 0) {
            raise_exception (env, err);
            return NULL;
        }
        return NULL;
    }
    
    return message;
}
Esempio n. 26
0
unsigned int
GenericLevelObj::get_attributes(std::string obj_type)
{
  if (obj_type == "groundpiece")
    return HAS_GPTYPE | HAS_SPRITE | CAN_ROTATE;
  else if (obj_type == "hotspot")
    return HAS_SPEED | HAS_PARALLAX | HAS_SPRITE | CAN_ROTATE;
  else if (obj_type == "liquid")
    return HAS_SPEED | HAS_REPEAT | HAS_SPRITE;
  else if (obj_type == "surface-background")
    return HAS_COLOR | HAS_STRETCH | HAS_PARA | HAS_SCROLL | HAS_SPRITE;
  else if (obj_type == "solidcolor-background")
    return HAS_COLOR | HAS_SPRITE_FAKE;
  else if (obj_type == "starfield-background")
    return HAS_STARFIELD | HAS_SPRITE_FAKE;
  else if (obj_type == "entrance")
    return HAS_DIRECTION | HAS_RELEASE_RATE | HAS_OWNER | HAS_SPRITE_FAKE;
  else if (obj_type == "exit")
    return HAS_OWNER | HAS_SPRITE;
  else if (obj_type == "spike")
    return HAS_SPRITE_FAKE;
  else if (obj_type == "snow-generator" || obj_type == "snow")
    return HAS_SPRITE_FAKE;
  else if (obj_type == "rain-generator" || obj_type == "rain")
    return HAS_SPRITE_FAKE;
  else if (obj_type == "smasher")
    return HAS_SPRITE_FAKE;
  else if (obj_type == "laser_exit")
    return HAS_SPRITE_FAKE;
  else if (obj_type == "hammer")
    return HAS_SPRITE_FAKE;
  else if (obj_type == "teleporter")
    return HAS_SPRITE_FAKE | HAS_TARGET_ID;
  else if (obj_type == "teleporter-target")
    return HAS_SPRITE_FAKE | HAS_ID;
  else if (obj_type == "fake_exit")
    return HAS_SPRITE_FAKE;
  else if (obj_type == "guillotine")
    return HAS_SPRITE_FAKE;
  else if (obj_type == "iceblock")
    return HAS_SPRITE_FAKE | HAS_REPEAT;
  else if (obj_type == "conveyorbelt")
    return HAS_SPRITE_FAKE | HAS_REPEAT | HAS_SPEED;
  else if (obj_type == "switchdoor-door")
    return HAS_SPRITE_FAKE | HAS_ID | HAS_HEIGHT;
  else if (obj_type == "switchdoor-switch")
    return HAS_SPRITE_FAKE | HAS_TARGET_ID;
  else
  {
    raise_exception(std::runtime_error, "unknown object type: '" << obj_type << "'");
  }
}
Esempio n. 27
0
MODULE load_ddns_services_list (THREAD *thread)
{
    char
        *filename;

    filename = CONFIG ("ddns:filename");
    services = NULL;

    switch (xml_load_file (&services, "PATH", filename, FALSE))
      {
        case XML_FILEERROR:
            sendfmt (&operq, "ERROR",
                "xiddns: cannot read '%s': %s", filename, xml_error ());
            raise_exception (exception_event);
            break;
        case XML_LOADERROR:
            sendfmt (&operq, "ERROR",
                "xiddns: error in '%s': %s", filename, xml_error ());
            raise_exception (exception_event);
            break;
      }
}
Esempio n. 28
0
static int mce_raise_notify(unsigned int cmd, struct pt_regs *regs)
{
	int cpu = smp_processor_id();
	struct mce *m = &__get_cpu_var(injectm);
	if (!cpumask_test_cpu(cpu, mce_inject_cpumask))
		return NMI_DONE;
	cpumask_clear_cpu(cpu, mce_inject_cpumask);
	if (m->inject_flags & MCJ_EXCEPTION)
		raise_exception(m, regs);
	else if (m->status)
		raise_poll(m);
	return NMI_HANDLED;
}
Esempio n. 29
0
void
Environment::add_namespace_alias(const std::string& name, NamespacePtr ns)
{
  Namespaces::iterator it = m_namespaces.find(name);
  if (it != m_namespaces.end())
  {
    raise_exception(std::runtime_error, "name conflict for symbol: " << name);
  }
  else
  {
    m_namespaces[name] = ns;
  }
}
Esempio n. 30
0
/**
 * Called by Java's Socket::setBytesSockopt(int option, byte[] value).
 */
JNIEXPORT void JNICALL Java_org_zeromq_ZMQ_00024Socket_setBytesSockopt (JNIEnv *env,
                                                                        jobject obj,
                                                                        jint option,
                                                                        jbyteArray value)
{
    switch (option) {
#if (ZMQ_VERSION_MAJOR <= 3)
    case ZMQ_IDENTITY:
#endif
    case ZMQ_SUBSCRIBE:
    case ZMQ_UNSUBSCRIBE:
        {
            if (value == NULL) {
                raise_exception (env, EINVAL);
                return;
            }

            void *s = get_socket (env, obj, 1);

            jbyte *optval = env->GetByteArrayElements (value, NULL);
            if (! optval) {
                raise_exception (env, EINVAL);
                return;
            }
            size_t optvallen = env->GetArrayLength (value);
            int rc = zmq_setsockopt (s, option, optval, optvallen);
            int err = zmq_errno();
            env->ReleaseByteArrayElements (value, optval, 0);
            if (rc != 0) {
                raise_exception (env, err);
            }

            return;
        }
    default:
        raise_exception (env, EINVAL);
        return;
    }
}