コード例 #1
0
ファイル: Exception.cpp プロジェクト: 18768108070/pyv8
void CJavascriptException::PrintCallStack(py::object file)
{
  CPythonGIL python_gil;

  PyObject *out = file.is_none() ? ::PySys_GetObject((char *) "stdout") : file.ptr();

  int fd = ::PyObject_AsFileDescriptor(out);

  Message()->PrintCurrentStackTrace(m_isolate, fdopen(fd, "w+"));
}
コード例 #2
0
ファイル: physics.cpp プロジェクト: benoitryder/simulotter
static SmartPtr<TaskBasic> Physics_schedule_task(Physics& ph, TaskBasic* task, py::object time)
{
  btScalar cpp_time = -1;
  if(time.ptr() != Py_None) {
    cpp_time = py::extract<btScalar>(time);
  }
  ph.scheduleTask(task, cpp_time);
  return task;
}
コード例 #3
0
ファイル: physics.cpp プロジェクト: benoitryder/simulotter
static SmartPtr<TaskBasic> Task_init(py::object cb, py::object period)
{
  SmartPtr<TaskBasic> task;

  if(period.ptr() == Py_None) {
    task = new TaskBasic();
  } else {
    task = new TaskBasic( py::extract<btScalar>(period) );
  }

  if(PyObject_HasAttrString(cb.ptr(), "__iter__")) {
    task->setCallback(boost::bind(Physics_task_iter, task, cb, _1));
  } else if(!PyCallable_Check(cb.ptr())) {
    PyErr_SetString(PyExc_TypeError, "callback is not callable");
    throw py::error_already_set();
  } else {
    task->setCallback(boost::bind(Physics_task_cb, cb, _1));
  }
  return task;
}
コード例 #4
0
ファイル: Context.cpp プロジェクト: liqingqiya/python_package
CContext::CContext(py::object global, py::list extensions)
  : m_global(global)
{
  v8::HandleScope handle_scope(v8::Isolate::GetCurrent());

  std::auto_ptr<v8::ExtensionConfiguration> cfg;
  std::vector<std::string> ext_names;
  std::vector<const char *> ext_ptrs;

  for (Py_ssize_t i=0; i<PyList_Size(extensions.ptr()); i++)
  {
    py::extract<const std::string> extractor(::PyList_GetItem(extensions.ptr(), i));

    if (extractor.check())
    {
      ext_names.push_back(extractor());
    }
  }

  for (size_t i=0; i<ext_names.size(); i++)
  {
    ext_ptrs.push_back(ext_names[i].c_str());
  }

  if (!ext_ptrs.empty()) cfg.reset(new v8::ExtensionConfiguration(ext_ptrs.size(), &ext_ptrs[0]));

  v8::Handle<v8::Context> context = v8::Context::New(v8::Isolate::GetCurrent(), cfg.get());

  m_context.Reset(v8::Isolate::GetCurrent(), context);

  v8::Context::Scope context_scope(Handle());

  if (!global.is_none())
  {
    Handle()->Global()->Set(v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), "__proto__"), CPythonObject::Wrap(global));

    Py_DECREF(global.ptr());
  }
}
コード例 #5
0
ファイル: curand.hpp プロジェクト: DirkHaehnel/pycuda
  void py_curand_get_scramble_constants32(py::object dst, int count)
  {
    void *buf;
    PYCUDA_BUFFER_SIZE_T len;
    int n = 0;

    if (PyObject_AsWriteBuffer(dst.ptr(), &buf, &len))
      throw py::error_already_set();
    unsigned int *vectors;
    CURAND_CALL_GUARDED(curandGetScrambleConstants32, (&vectors));
// Documentation does not mention number of dimensions
// Assuming the same as in getDirectionVectors*
    while (count > 0) {
      int size = ((count > 20000) ? 20000 : count)*sizeof(unsigned int);
      memcpy((unsigned int *)buf+n*20000, vectors, size);
      count -= size/sizeof(unsigned int);
      n++;
    }
  }
コード例 #6
0
ファイル: curand.hpp プロジェクト: EelcoHoogendoorn/pycuda
  void py_curand_get_scramble_constants32(py::object dst, int count)
  {
    int n = 0;

    py_buffer_wrapper buf_wrapper;
    buf_wrapper.get(dst.ptr(), PyBUF_ANY_CONTIGUOUS | PyBUF_WRITABLE);

    void *buf = buf_wrapper.m_buf.buf;
    PYCUDA_BUFFER_SIZE_T len = buf_wrapper.m_buf.len;

    unsigned int *vectors;
    CURAND_CALL_GUARDED(curandGetScrambleConstants32, (&vectors));
// Documentation does not mention number of dimensions
// Assuming the same as in getDirectionVectors*
    while (count > 0) {
      int size = ((count > 20000) ? 20000 : count)*sizeof(unsigned int);
      memcpy((unsigned int *)buf+n*20000, vectors, size);
      count -= size/sizeof(unsigned int);
      n++;
    }
  }
コード例 #7
0
ファイル: curand.hpp プロジェクト: EelcoHoogendoorn/pycuda
  void py_curand_get_direction_vectors(
      curandDirectionVectorSet_t set, py::object dst, int count)
  {
    int n = 0;

    py_buffer_wrapper buf_wrapper;
    buf_wrapper.get(dst.ptr(), PyBUF_ANY_CONTIGUOUS | PyBUF_WRITABLE);

    void *buf = buf_wrapper.m_buf.buf;
    PYCUDA_BUFFER_SIZE_T len = buf_wrapper.m_buf.len;

    if (CURAND_DIRECTION_VECTORS_32_JOEKUO6 == set
#if CUDAPP_CUDA_VERSION >= 4000
      || CURAND_SCRAMBLED_DIRECTION_VECTORS_32_JOEKUO6 == set
#endif
    ) {
      curandDirectionVectors32_t *vectors;
      CURAND_CALL_GUARDED(curandGetDirectionVectors32, (&vectors, set));
      while (count > 0) {
        int size = ((count > 20000) ? 20000 : count)*sizeof(curandDirectionVectors32_t);
        memcpy((unsigned int *)buf+n*20000*sizeof(curandDirectionVectors32_t)/sizeof(unsigned int), vectors, size);
	count -= size/sizeof(curandDirectionVectors32_t);
        n++;
      }
    }
#if CUDAPP_CUDA_VERSION >= 4000
    if (CURAND_DIRECTION_VECTORS_64_JOEKUO6 == set
      || CURAND_SCRAMBLED_DIRECTION_VECTORS_64_JOEKUO6 == set) {
      curandDirectionVectors64_t *vectors;
      CURAND_CALL_GUARDED(curandGetDirectionVectors64, (&vectors, set));
      while (count > 0) {
        int size = ((count > 20000) ? 20000 : count)*sizeof(curandDirectionVectors64_t);
        memcpy((unsigned long long *)buf+n*20000*sizeof(curandDirectionVectors64_t)/sizeof(unsigned long long), vectors, size);
	count -= size/sizeof(curandDirectionVectors64_t);
        n++;
      }
    }
#endif
  }
コード例 #8
0
ファイル: curand.hpp プロジェクト: DirkHaehnel/pycuda
  void py_curand_get_direction_vectors(
      curandDirectionVectorSet_t set, py::object dst, int count)
  {
    void *buf;
    PYCUDA_BUFFER_SIZE_T len;
    int n = 0;

    if (PyObject_AsWriteBuffer(dst.ptr(), &buf, &len))
      throw py::error_already_set();
    if (CURAND_DIRECTION_VECTORS_32_JOEKUO6 == set
#if CUDAPP_CUDA_VERSION >= 4000
      || CURAND_SCRAMBLED_DIRECTION_VECTORS_32_JOEKUO6 == set
#endif
    ) {
      curandDirectionVectors32_t *vectors;
      CURAND_CALL_GUARDED(curandGetDirectionVectors32, (&vectors, set));
      while (count > 0) {
        int size = ((count > 20000) ? 20000 : count)*sizeof(curandDirectionVectors32_t);
        memcpy((unsigned int *)buf+n*20000*sizeof(curandDirectionVectors32_t)/sizeof(unsigned int), vectors, size);
	count -= size/sizeof(curandDirectionVectors32_t);
        n++;
      }
    }
#if CUDAPP_CUDA_VERSION >= 4000
    if (CURAND_DIRECTION_VECTORS_64_JOEKUO6 == set
      || CURAND_SCRAMBLED_DIRECTION_VECTORS_64_JOEKUO6 == set) {
      curandDirectionVectors64_t *vectors;
      CURAND_CALL_GUARDED(curandGetDirectionVectors64, (&vectors, set));
      while (count > 0) {
        int size = ((count > 20000) ? 20000 : count)*sizeof(curandDirectionVectors64_t);
        memcpy((unsigned long long *)buf+n*20000*sizeof(curandDirectionVectors64_t)/sizeof(unsigned long long), vectors, size);
	count -= size/sizeof(curandDirectionVectors64_t);
        n++;
      }
    }
#endif
  }
コード例 #9
0
ファイル: physics.cpp プロジェクト: benoitryder/simulotter
static void Physics_task_cb(py::object cb, Physics* ph)
{
  py::call<void>(cb.ptr(), py::ptr(ph));
}