示例#1
0
 /* Copy constructor */
 numpy_boost(const self_type &other) throw() :
   super(NULL, std::vector<typename super::index>(NDims, 0)),
   array(NULL)
 {
   Py_INCREF(other.array);
   init_from_array(other.array);
 }
示例#2
0
 /* Assignment operator */
 void operator=(const self_type &other) throw() {
   if (other.array != array)
   {
     Py_INCREF(other.array);
     Py_XDECREF(array);
     init_from_array(other.array);
   }
 }
示例#3
0
 numpy_boost(self_type &&other) /*throw()*/ :
   super(NULL, std::vector<typename super::index>(NDims, 0)),
   array(other.array)
 {
   // Correct way would be to move super, and then just update 
   // the array member...however, boost::multi_array does not 
   // support moving yet, so, let's stay in safe grounds.
   init_from_array(other.array);
   other.array = 0;
 }
示例#4
0
 /* Copy constructor... ensure clone */
 numpy_boost(const self_type &other) throw() :
   super(NULL, std::vector<typename super::index>(NDims, 0)),
   array(NULL)
 {
   PyObject* cloned = PyArray_FromAny(
       other.array,
       NULL, // dtype = NULL, obtain from array
       0, 0, // just use whatever depth is already there
       NPY_C_CONTIGUOUS|NPY_ENSURECOPY,
       NULL );
   //Py_INCREF(other.array);
   init_from_array(cloned);
 }
示例#5
0
  /* Construct from an existing Numpy array */
  numpy_boost(PyObject* obj) throw (python_exception) :
    super(NULL, std::vector<typename super::index>(NDims, 0)),
    array(NULL)
  {
    PyArrayObject* a;

    a = (PyArrayObject*)PyArray_FromObject(
        obj, detail::numpy_type_map<T>::typenum, NDims, NDims);
    if (a == NULL) {
      throw python_exception();
    }

    init_from_array(a);
  }
示例#6
0
  /* Construct from an existing Numpy array */
  numpy_boost(PyObject* obj) throw () :
    super(NULL, std::vector<typename super::index>(NDims, 0)),
    array(NULL)
  {
    PyArrayObject* a;

    a = (PyArrayObject*)PyArray_FromObject(
        obj, detail::numpy_type_map<T>::typenum, NDims, NDims);
    if (a == NULL) {
      throw boost::python::error_already_set();
    }

    init_from_array(a);
  }
示例#7
0
文件: blacklist.c 项目: DecKen/zmap
// Initialize address constraints from whitelist and blacklist files.
// Either can be set to NULL to omit.
int blacklist_init(char *whitelist_filename, char *blacklist_filename,
		char **whitelist_entries, size_t whitelist_entries_len,
		char **blacklist_entries, size_t blacklist_entries_len)
{
	assert(!constraint);
	if (whitelist_filename && whitelist_entries) {
		log_warn("whitelist", "both a whitelist file and destination addresses "
					"were specified. The union of these two sources "
					"will be utilized.");
	}
	if (whitelist_filename || whitelist_entries) {
		// using a whitelist, so default to allowing nothing
		constraint = constraint_init(ADDR_DISALLOWED);
		log_trace("whitelist", "blacklisting 0.0.0.0/0");
		if (whitelist_filename) {
			init_from_file(whitelist_filename, "whitelist", ADDR_ALLOWED);
		}
		if (whitelist_entries) {
			init_from_array(whitelist_entries,
					whitelist_entries_len, ADDR_ALLOWED);
		}
	} else {
		// no whitelist, so default to allowing everything
		constraint = constraint_init(ADDR_ALLOWED);
	}
	if (blacklist_filename) {
		init_from_file(blacklist_filename, "blacklist", ADDR_DISALLOWED);
	}
	if (blacklist_entries) {
		init_from_array(blacklist_entries, blacklist_entries_len, ADDR_DISALLOWED);
	}
	constraint_paint_value(constraint, ADDR_ALLOWED);
	uint64_t allowed = blacklist_count_allowed();
	log_debug("blacklist", "%lu addresses allowed to be scanned (%0.0f%% of address space)", 
			  allowed, allowed*100./((long long int)1 << 32));
	return EXIT_SUCCESS;
}
示例#8
0
  explicit numpy_boost(const ExtentsList& extents) throw (python_exception) :
    super(NULL, std::vector<typename super::index>(NDims, 0)),
    array(NULL)
  {
    npy_intp shape[NDims];
    PyArrayObject* a;

    boost::detail::multi_array::copy_n(extents, NDims, shape);

    a = (PyArrayObject*)PyArray_SimpleNew(
        NDims, shape, detail::numpy_type_map<T>::typenum);
    if (a == NULL) {
      throw python_exception();
    }

    init_from_array(a);
  }
示例#9
0
  numpy_boost( numpy_from_boost_array_proxy<Array> const& prx ) throw (python_exception):
    super(NULL, std::vector<typename super::index>(NDims, 0)),
    array(NULL)
  {
        static_assert(Array::dimensionality==NDims,"IncorrectDimensions");
        npy_intp shape[NDims];
        PyArrayObject* a;

        std::copy_n(prx.source_arr.shape(), NDims, shape);

        a = (PyArrayObject*)PyArray_SimpleNew(
            NDims, shape, detail::numpy_type_map<T>::typenum);
        if (a == NULL) {
          throw python_exception();
        }
        std::copy_n( prx.source_arr.origin(), prx.source_arr.num_elements(), (T*)PyArray_DATA(a) );

        init_from_array(a);
  }