int cpp_main(int /*argc*/, char * /*argv*/[]) { #ifdef TEST_THREADS try{ get_array_data(); // initialises data. } catch(const std::exception& e) { std::cerr << "TSS Initialisation failed with message: " << e.what() << std::endl; return -1; } std::list<boost::shared_ptr<boost::thread> > threads; for(int i = 0; i < 5; ++i) { try{ threads.push_back(boost::shared_ptr<boost::thread>(new boost::thread(&run_tests))); } catch(const std::exception& e) { std::cerr << "<note>Thread creation failed with message: " << e.what() << "</note>" << std::endl; } } std::list<boost::shared_ptr<boost::thread> >::const_iterator a(threads.begin()), b(threads.end()); while(a != b) { (*a)->join(); ++a; } #else run_tests(); #endif return error_count; }
jarray _Z17_Jv_NewMultiArrayPN4java4lang5ClassEiPi(java_lang_Class *type, jint n_dims, jint *sizes) { assert(_ZN4java4lang5Class7isArrayEJbv(type)); java_lang_Class *eltype = type->me.element_type; jarray result; if (_ZN4java4lang5Class11isPrimitiveEJbv(eltype)) { assert(n_dims == 1); result = _Jv_NewPrimArray(eltype, sizes[0]); } else { result = _Jv_NewObjectArray(sizes[0], eltype, NULL); } if (n_dims > 1) { jarray *contents = get_array_data(jarray, result); for (jint i = 0; i < sizes[0]; ++i) { contents[i] = _Z17_Jv_NewMultiArrayPN4java4lang5ClassEiPi(eltype, n_dims-1, sizes + 1); } } return result; }
void _ZN4java4lang6String8getCharsEJviiP6JArrayIwEi( const java_lang_String *this_, jint srcBegin, jint srcEnd, jarray dstArray, jint dstBegin) { assert(srcBegin >= 0); assert(srcEnd >= srcBegin); assert(dstBegin >= 0); jint len = srcEnd - srcBegin; assert(len <= (dstArray->length - dstBegin)); jchar *dst = get_array_data(jchar, dstArray) + dstBegin; const jchar *data = get_string_begin(this_) + srcBegin; memcpy(dst, data, len * sizeof(dst[0])); }
int cpp_main(int /*argc*/, char * /*argv*/[]) { #ifdef BOOST_HAS_ICU // // We need to set the default locale used by ICU, // otherwise some of our tests using equivalence classes fail. // UErrorCode err = U_ZERO_ERROR; uloc_setDefault("en", &err); if(err != U_ZERO_ERROR) { std::cerr << "Unable to set the default ICU locale to \"en\"." << std::endl; return -1; } #endif #ifdef TEST_THREADS try{ get_array_data(); // initialises data. } catch(const std::exception& e) { std::cerr << "TSS Initialisation failed with message: " << e.what() << std::endl; return -1; } std::list<boost::shared_ptr<boost::thread> > threads; for(int i = 0; i < 5; ++i) { try{ threads.push_back(boost::shared_ptr<boost::thread>(new boost::thread(&run_tests))); } catch(const std::exception& e) { std::cerr << "<note>Thread creation failed with message: " << e.what() << "</note>" << std::endl; } } std::list<boost::shared_ptr<boost::thread> >::const_iterator a(threads.begin()), b(threads.end()); while(a != b) { (*a)->join(); ++a; } #else run_tests(); #endif return error_count; }
const int* make_array(int first, ...) { // // this function takes a variable number of arguments // and packs them into an array that we can pass through // our testing macros (ideally we would use an array literal // but these can't apparently be used as macro arguments). // #ifdef TEST_THREADS int* data = get_array_data(); #else static int data[200]; #endif va_list ap; va_start(ap, first); // // keep packing args, until we get two successive -2 values: // int terminator_count; int next_position = 1; data[0] = first; if(first == -2) terminator_count = 1; else terminator_count = 0; while(terminator_count < 2) { data[next_position] = va_arg(ap, int); if(data[next_position] == -2) ++terminator_count; else terminator_count = 0; ++next_position; } va_end(ap); return data; }
/* given a return value in OCaml land, translate it to the return_val_t C structure */ return_val_t translate_return_value(value ocaml_result) { CAMLparam1(ocaml_result); CAMLlocal5(ocaml_shape, ocaml_strides, ocaml_data, ocaml_cur, ocaml_type); CAMLlocal1(v); return_val_t ret; if (Is_long(ocaml_result)) { // In this case, we know that the return code must have been Pass, // since the other two return codes have data. ret.return_code = RET_PASS; ret.results_len = 0; } else if (Tag_val(ocaml_result) == RET_FAIL) { ret.return_code = RET_FAIL; ret.results_len = caml_string_length(Field(ocaml_result, 0)); ret.error_msg = malloc(ret.results_len + 1); strcpy(ret.error_msg, String_val(Field(ocaml_result, 0))); } else if (Tag_val(ocaml_result) == RET_SUCCESS) { ocaml_cur = Field(ocaml_result, 0); ret.return_code = RET_SUCCESS; ret.results_len = ocaml_list_length(ocaml_cur); ret.results = (ret_t*)malloc(sizeof(ret_t) * ret.results_len); int i, j; host_val h; for (i = 0; i < ret.results_len; ++i) { v = Field(ocaml_cur, 0); h = create_host_val(v); ocaml_cur = Field(ocaml_cur, 1); // returning a scalar if (value_is_scalar(h)) { ret.results[i].is_scalar = 1; ocaml_type = (scalar_type)value_type_of(h); ret.results[i].data.scalar.ret_type = get_scalar_element_type(ocaml_type); // WARNING: // Tiny Memory Leak Ahead // ----------------------- // When scalar data is returned to the host language // on the heap, it should be manually deleted by the // host frontend if (type_is_bool(ocaml_type)) { ret.results[i].data.scalar.ret_scalar_value.boolean = get_bool(h); } else if (type_is_int32(ocaml_type)) { ret.results[i].data.scalar.ret_scalar_value.int32 = get_int32(h); } else if (type_is_int64(ocaml_type)) { ret.results[i].data.scalar.ret_scalar_value.int64 = get_int64(h); } else if (type_is_float32(ocaml_type)) { ret.results[i].data.scalar.ret_scalar_value.float32 = get_float64(h); } else if (type_is_float64(ocaml_type)) { ret.results[i].data.scalar.ret_scalar_value.float64 = get_float64(h); } else { caml_failwith("Unable to return scalar of this type\n"); } } else { // Pass the type ret.results[i].is_scalar = 0; ret.results[i].data.array.ret_type = array_type_of(h); // Pass the data ret.results[i].data.array.data = get_array_data(h); // Build the shape array ocaml_shape = value_get_shape(h); int shape_len = Wosize_val(ocaml_shape); ret.results[i].data.array.shape = (int*)malloc(shape_len * sizeof(int)); ret.results[i].data.array.shape_len = shape_len; for (j = 0; j < shape_len; ++j) { ret.results[i].data.array.shape[j] = Int_val(Field(ocaml_shape, j)); } // Build the strides array ocaml_strides = value_get_strides(h); int strides_len = Wosize_val(ocaml_strides); ret.results[i].data.array.strides_len = strides_len; ret.results[i].data.array.strides = (int*)malloc(strides_len * sizeof(int)); for (j = 0; j < strides_len; ++j) { ret.results[i].data.array.strides[j] = Int_val(Field(ocaml_strides, j)); } } } } CAMLreturnT(return_val_t, ret); }