Composite type fields names from C code

Hello everyone!
I am trying to get the name of composite type fields in version 1.11.
A long time ago I did it like this:

int nfields = jl_datatype_nfields(jtype);
fields.resize(nfields);
for (int i = 0; i < nfields; i++) {
   jl_symbol_name(jl_field_name(jtype,i));
}

But now in julia.h there is no function jl_field_name. I try to use jl_field_names

jl_svec_t *vn = jl_field_names(jtype);
for (int i = 0; i < nfields; i++) {
        jl_value_t* name = jl_svecref(vn, i);
        const char *c = jl_string_ptr(name);
}

but I get nonsense instead of names. What is the correct path in current versions?

1 Like

There is an example of string conversion of a field name here. It’s jl_symbol_name instead of jl_string_ptr.

1 Like

Right way:

jl_svec_t *field_names = jl_field_names(jtype);
for (int i = 0; i < nfields; i++) {
        jl_sym_t* name = (jl_sym_t*)jl_svecref(field_names, i);
        const char *c = jl_symbol_name(name);