本文整理汇总了C++中caml_alloc_tuple函数的典型用法代码示例。如果您正苦于以下问题:C++ caml_alloc_tuple函数的具体用法?C++ caml_alloc_tuple怎么用?C++ caml_alloc_tuple使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了caml_alloc_tuple函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mk_src_info
value mk_src_info(source_info_t *src_info) {
CAMLparam0();
CAMLlocal3(ocaml_src_info, file, some_none);
if (src_info != NULL) {
if (src_info->filename) {
//printf("Src info filename: %s\n", src_info->filename);
file = caml_copy_string(src_info->filename);
//int len = strlen(src_info->filename);
//file = caml_alloc_string(len);
//memcpy(String_val(file),src_info->filename , len);
some_none = caml_alloc_tuple(1);
Store_field(some_none, 0, file);
} else {
some_none = Val_int(0);
}
ocaml_src_info = caml_alloc_tuple(3);
Store_field(ocaml_src_info, 0, some_none);
Store_field(ocaml_src_info, 1, Val_int(src_info->line));
Store_field(ocaml_src_info, 2, Val_int(src_info->col));
} else {
ocaml_src_info = caml_alloc_tuple(3);
Store_field(ocaml_src_info, 0, Val_int(0));
Store_field(ocaml_src_info, 1, Val_int(0));
Store_field(ocaml_src_info, 2, Val_int(0));
}
CAMLreturn(ocaml_src_info);
}
示例2: Val_physinfo
static value Val_physinfo(libxl_physinfo *c_val)
{
CAMLparam0();
CAMLlocal2(v, hwcap);
int i;
hwcap = caml_alloc_tuple(8);
for (i = 0; i < 8; i++)
Store_field(hwcap, i, caml_copy_int32(c_val->hw_cap[i]));
v = caml_alloc_tuple(11);
Store_field(v, 0, Val_int(c_val->threads_per_core));
Store_field(v, 1, Val_int(c_val->cores_per_socket));
Store_field(v, 2, Val_int(c_val->max_cpu_id));
Store_field(v, 3, Val_int(c_val->nr_cpus));
Store_field(v, 4, Val_int(c_val->cpu_khz));
Store_field(v, 5, caml_copy_int64(c_val->total_pages));
Store_field(v, 6, caml_copy_int64(c_val->free_pages));
Store_field(v, 7, caml_copy_int64(c_val->scrub_pages));
Store_field(v, 8, Val_int(c_val->nr_nodes));
Store_field(v, 9, hwcap);
Store_field(v, 10, caml_copy_int32(c_val->phys_cap));
CAMLreturn(v);
}
示例3: caml_gc_get
CAMLprim value caml_gc_get(value v)
{
CAMLparam0 (); /* v is ignored */
CAMLlocal1 (res);
res = caml_alloc_tuple (7);
#ifndef NATIVE_CODE
Store_field (res, 5, Val_long (caml_max_stack_size)); /* l */
#else
Store_field (res, 5, Val_long (0));
#endif
CAMLreturn (res);
#if 0
CAMLparam0 (); /* v is ignored */
CAMLlocal1 (res);
res = caml_alloc_tuple (7);
Store_field (res, 0, Val_long (Wsize_bsize (Caml_state->minor_heap_size))); /* s */
Store_field (res, 1, Val_long (caml_major_heap_increment)); /* i */
Store_field (res, 2, Val_long (caml_percent_free)); /* o */
Store_field (res, 3, Val_long (caml_params->verb_gc)); /* v */
Store_field (res, 4, Val_long (caml_percent_max)); /* O */
#ifndef NATIVE_CODE
Store_field (res, 5, Val_long (caml_max_stack_size)); /* l */
#else
Store_field (res, 5, Val_long (0));
#endif
Store_field (res, 6, Val_long (caml_allocation_policy)); /* a */
Store_field (res, 7, Val_long (caml_major_window)); /* w */
CAMLreturn (res);
#endif
}
示例4: ocaml_gstreamer_message_parse_tag
CAMLprim value ocaml_gstreamer_message_parse_tag(value _msg)
{
CAMLparam1(_msg);
CAMLlocal4(v,s,t,ans);
GstMessage *msg = Message_val(_msg);
GstTagList *tags = NULL;
const GValue *val;
const gchar *tag;
int taglen;
int i, j, n;
caml_release_runtime_system();
gst_message_parse_tag(msg, &tags);
taglen = gst_tag_list_n_tags(tags);
caml_acquire_runtime_system();
ans = caml_alloc_tuple(taglen);
for(i = 0; i < taglen; i++)
{
t = caml_alloc_tuple(2);
// Tag name
tag = gst_tag_list_nth_tag_name(tags, i);
Store_field(t, 0, caml_copy_string(tag));
// Tag fields
n = gst_tag_list_get_tag_size(tags, tag);
v = caml_alloc_tuple(n);
for (j = 0; j < n; j++)
{
val = gst_tag_list_get_value_index(tags, tag, j);
if (G_VALUE_HOLDS_STRING(val)) {
s = caml_copy_string(g_value_get_string(val));
}
else if (GST_VALUE_HOLDS_DATE_TIME(val)) {
GstDateTime *dt = g_value_get_boxed(val);
gchar *dt_str = gst_date_time_to_iso8601_string(dt);
s = caml_copy_string(dt_str);
g_free(dt_str);
}
else {
//TODO: better typed handling of non-string values?
char *vc = g_strdup_value_contents(val);
s = caml_copy_string(vc);
free(vc);
}
Store_field(v, j, s);
}
Store_field(t, 1, v);
Store_field(ans, i, t);
}
gst_tag_list_unref(tags);
CAMLreturn(ans);
}
示例5: caml_gc_quick_stat
CAMLprim value caml_gc_quick_stat(value v)
{
CAMLparam0 ();
CAMLlocal1 (res);
/* get a copy of these before allocating anything... */
double minwords = caml_stat_minor_words
+ (double) Wsize_bsize (caml_young_end - caml_young_ptr);
double prowords = caml_stat_promoted_words;
double majwords = caml_stat_major_words + (double) caml_allocated_words;
intnat mincoll = caml_stat_minor_collections;
intnat majcoll = caml_stat_major_collections;
intnat heap_words = caml_stat_heap_size / sizeof (value);
intnat top_heap_words = caml_stat_top_heap_size / sizeof (value);
intnat cpct = caml_stat_compactions;
intnat heap_chunks = caml_stat_heap_chunks;
res = caml_alloc_tuple (15);
Store_field (res, 0, caml_copy_double (minwords));
Store_field (res, 1, caml_copy_double (prowords));
Store_field (res, 2, caml_copy_double (majwords));
Store_field (res, 3, Val_long (mincoll));
Store_field (res, 4, Val_long (majcoll));
Store_field (res, 5, Val_long (heap_words));
Store_field (res, 6, Val_long (heap_chunks));
Store_field (res, 7, Val_long (0));
Store_field (res, 8, Val_long (0));
Store_field (res, 9, Val_long (0));
Store_field (res, 10, Val_long (0));
Store_field (res, 11, Val_long (0));
Store_field (res, 12, Val_long (0));
Store_field (res, 13, Val_long (cpct));
Store_field (res, 14, Val_long (top_heap_words));
CAMLreturn (res);
}
示例6: tun_opendev
CAMLprim value
tun_opendev(value devname, value kind, value pi, value persist, value user, value group)
{
CAMLparam5(devname, kind, pi, persist, user);
CAMLxparam1(group);
CAMLlocal2(res, dev_caml);
char dev[IFNAMSIZ];
int fd;
#if defined (__APPLE__) && defined (__MACH__)
if (caml_string_length(devname) < 4)
caml_failwith("On MacOSX, you need to specify the name of the device, e.g. tap0");
#endif
memset(dev, 0, sizeof dev);
memcpy(dev, String_val(devname), caml_string_length(devname));
// All errors are already checked by tun_alloc, returned fd is valid
// otherwise it would have crashed before
fd = tun_alloc(dev, Int_val(kind), Bool_val(pi), Bool_val(persist), Int_val(user), Int_val(group));
res = caml_alloc_tuple(2);
dev_caml = caml_copy_string(dev);
Store_field(res, 0, Val_int(fd));
Store_field(res, 1, dev_caml);
CAMLreturn(res);
}
示例7: stub_get_blktap3_stats
CAMLprim value stub_get_blktap3_stats(value filename)
{
CAMLparam1(filename);
CAMLlocal1(stats);
FILE *c_fd;
struct stats c_stats;
c_fd = fopen(String_val(filename), "rb");
if (!c_fd) uerror("fopen", Nothing);
if (fread(&c_stats, sizeof(struct stats), 1, c_fd) < 1) uerror("fread", Nothing);
stats = caml_alloc_tuple(10);
Store_field(stats, 0, caml_copy_int64((int64_t) c_stats.read_reqs_submitted));
Store_field(stats, 1, caml_copy_int64((int64_t) c_stats.read_reqs_completed));
Store_field(stats, 2, caml_copy_int64((int64_t) c_stats.read_sectors));
Store_field(stats, 3, caml_copy_int64((int64_t) c_stats.read_total_ticks));
Store_field(stats, 4, caml_copy_int64((int64_t) c_stats.write_reqs_submitted));
Store_field(stats, 5, caml_copy_int64((int64_t) c_stats.write_reqs_completed));
Store_field(stats, 6, caml_copy_int64((int64_t) c_stats.write_sectors));
Store_field(stats, 7, caml_copy_int64((int64_t) c_stats.write_total_ticks));
Store_field(stats, 8, caml_copy_int64((int64_t) c_stats.io_errors));
if ((c_stats.flags) & BT3_LOW_MEMORY_MODE)
Store_field(stats, 9, Val_true);
else
Store_field(stats, 9, Val_false);
fclose(c_fd);
CAMLreturn(stats);
}
示例8: stub_gnttab_map_fresh
CAMLprim value stub_gnttab_map_fresh(
value xgh,
value reference,
value domid,
value writable
)
{
CAMLparam4(xgh, reference, domid, writable);
CAMLlocal2(pair, contents);
void *map =
xc_gnttab_map_grant_ref(_G(xgh), Int_val(domid), Int_val(reference),
Bool_val(writable)?PROT_READ | PROT_WRITE:PROT_READ);
if(map==NULL) {
caml_failwith("Failed to map grant ref");
}
contents = caml_ba_alloc_dims(XC_GNTTAB_BIGARRAY, 1,
map, 1 << XC_PAGE_SHIFT);
pair = caml_alloc_tuple(2);
Store_field(pair, 0, contents); /* grant_handle */
Store_field(pair, 1, contents); /* Io_page.t */
CAMLreturn(pair);
}
示例9: check_mems_taint
bool check_mems_taint( memorylog_entry* memlog, unsigned int cnt )
{
CAMLparam0();
CAMLlocal4( addrs, ret, v, tupl );
static value *proc_check_mems_taint = NULL;
if ( !proc_check_mems_taint ) {
proc_check_mems_taint = caml_named_value( "check_mems_taint" );
}
addrs = Val_emptylist;
for ( unsigned int i = 0; i < cnt; i ++ ) {
tupl = caml_alloc_tuple( 2 );
Store_field( tupl, 0, caml_copy_nativeint( memlog[i].addr ) );
Store_field( tupl, 1, Val_int( memlog[i].size * 8 ) );
v = caml_alloc_small( 2, 0 );
Field( v, 0 ) = tupl;
Field( v, 1 ) = addrs;
addrs = v;
}
ret = caml_callback( *proc_check_mems_taint, addrs );
CAMLreturnT( bool, Bool_val( ret ) );
}
示例10: stub_inotify_convert
value stub_inotify_convert(value buf)
{
CAMLparam1(buf);
CAMLlocal3(event, l, tmpl);
struct inotify_event ev;
int i;
l = Val_emptylist;
tmpl = Val_emptylist;
memcpy(&ev, String_val(buf), sizeof(struct inotify_event));
for (i = 0; inotify_return_table[i]; i++) {
if (!(ev.mask & inotify_return_table[i]))
continue;
tmpl = caml_alloc_small(2, Tag_cons);
Field(tmpl, 0) = Val_int(i);
Field(tmpl, 1) = l;
l = tmpl;
}
event = caml_alloc_tuple(4);
Store_field(event, 0, Val_int(ev.wd));
Store_field(event, 1, l);
Store_field(event, 2, caml_copy_int32(ev.cookie));
Store_field(event, 3, Val_int(ev.len));
CAMLreturn(event);
}
示例11: simulation_get_pose3d_stub
value simulation_get_pose3d_stub(value sim_val, value name_val)
{
CAMLparam2(sim_val, name_val);
CAMLlocal1(result);
playerc_simulation_t *sim = Simulation_val(sim_val);
char *name = String_val(name_val);
double x, y, z;
double roll, pitch, yaw;
double time;
DPRINTF("getting sim %p pose3d: name - %s\n", sim, name);
if(playerc_simulation_get_pose3d(sim, name, &x, &y, &z, &roll, &pitch, &yaw, &time))
exception_playerc_error();
DPRINTF("set sim %p pose3d: name - %s x = %f y = %f z = %f roll = %f pitch = %f yaw = %f time = %f\n",
sim, name, x, y, z, roll, pitch, yaw, time);
result = caml_alloc_tuple(7);
Store_field(result, 0, copy_double(x));
Store_field(result, 1, copy_double(y));
Store_field(result, 2, copy_double(z));
Store_field(result, 3, copy_double(roll));
Store_field(result, 4, copy_double(pitch));
Store_field(result, 5, copy_double(yaw));
Store_field(result, 6, copy_double(time));
CAMLreturn(result);
}
示例12: stub_launch_activate_socket
CAMLprim value stub_launch_activate_socket(value name) {
CAMLparam1(name);
CAMLlocal1(result);
const char *c_name = caml_strdup(String_val(name));
int *listening_fds = NULL;
size_t n_listening_fds = 0;
int err;
caml_release_runtime_system();
err = launch_activate_socket(c_name, &listening_fds, &n_listening_fds);
caml_acquire_runtime_system();
caml_stat_free((void*)c_name);
switch (err) {
case 0:
result = caml_alloc_tuple(n_listening_fds);
for (int i = 0; i < n_listening_fds; i++) {
Store_field(result, i, Val_int(*(listening_fds + i)));
}
break;
default:
unix_error(err, "launch_activate_socket", name);
break;
}
CAMLreturn(result);
}
示例13: caml_natdynlink_open
CAMLprim value caml_natdynlink_open(value filename, value global)
{
CAMLparam2 (filename, global);
CAMLlocal3 (res, handle, header);
void *sym;
void *dlhandle;
char *p;
/* TODO: dlclose in case of error... */
p = caml_strdup(String_val(filename));
caml_enter_blocking_section();
dlhandle = caml_dlopen(String_val(filename), 1, Int_val(global));
caml_leave_blocking_section();
caml_stat_free(p);
if (NULL == dlhandle)
caml_failwith(caml_dlerror());
sym = caml_dlsym(dlhandle, "caml_plugin_header");
if (NULL == sym)
caml_failwith("not an OCaml plugin");
handle = Val_handle(dlhandle);
header = caml_input_value_from_malloc(sym, 0);
res = caml_alloc_tuple(2);
Init_field(res, 0, handle);
Init_field(res, 1, header);
CAMLreturn(res);
}
示例14: get_capabilities
CAMLprim value get_capabilities() {
CAMLparam0();
CAMLlocal1(out_val);
out_val = caml_alloc_tuple(5);
#if defined(WIN32) || defined (__CYGWIN__)
int info[4];
int max_eax;
__cpuid(info, 0);
max_eax = info[0];
if(max_eax >= 1) {
__cpuid(info, 1);
} else {
info[0] = 0;
info[1] = 0;
info[2] = 0;
info[3] = 0;
}
Store_field(out_val, 0, Val_bool(info[3] & (1 << 25)));
Store_field(out_val, 1, Val_bool(info[3] & (1 << 26)));
Store_field(out_val, 2, Val_bool(info[2] & (1 << 0)));
Store_field(out_val, 3, Val_bool(info[2] & (1 << 9)));
Store_field(out_val, 4, Val_bool(info[2] & (1 << 19)));
#else
// Don't use SSE stuff - other OSes may be on any random architecture
Store_field(out_val, 0, Val_bool(0));
Store_field(out_val, 1, Val_bool(0));
Store_field(out_val, 2, Val_bool(0));
Store_field(out_val, 3, Val_bool(0));
Store_field(out_val, 4, Val_bool(0));
#endif
CAMLreturn(out_val);
}
示例15: get_section_data_internal
value get_section_data_internal( bhp _p )
{
CAMLparam0();
CAMLlocal4( data, v, str, tupl );
bh* p = (bh*) _p;
struct bfd* abfd = p->bfdp;
asection *sect;
bfd_size_type datasize = 0;
data = Val_emptylist;
if ( p->is_from_file ) {
for ( sect = abfd->sections; sect != NULL; sect = sect->next ) {
datasize = bfd_get_section_size( sect );
str = caml_alloc_string( datasize );
bfd_get_section_contents( abfd, sect,
(bfd_byte*)String_val(str),
0, datasize );
tupl = caml_alloc_tuple( 3 );
Store_field( tupl, 0, str );
Store_field( tupl, 1, caml_copy_int64( sect->vma ) );
Store_field( tupl, 2, caml_copy_int64( sect->vma + datasize ) );
v = caml_alloc_small( 2, 0 );
Field( v, 0 ) = tupl;
Field( v, 1 ) = data;
data = v;
}
}
CAMLreturn( data );
}