<html>
    <head>
      <base href="https://bugs.freedesktop.org/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Priority</th>
          <td>medium
          </td>
        </tr>

        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - get_text_layout introspection mismatch"
   href="https://bugs.freedesktop.org/show_bug.cgi?id=77790">77790</a>
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>poppler-bugs@lists.freedesktop.org
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>get_text_layout introspection mismatch
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>marcus.brinkmann@ruhr-uni-bochum.de
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Other
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>glib frontend
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>poppler
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Hi,

$ cat girtest.js
const pop = imports.gi.Poppler;
const doc = pop.Document.new_from_file("file:///path/to/test.pdf", '')
const page=doc.get_page(0)
log(page.get_text_layout())

$ gjs girtest.js
Segmentation fault (core dumped)

Backtrace follows below.  What actually happens is that gir expects
get_text_layout to return an array of PopplerRectangle* (an array of pointers
to allocated PopplerRectangle objects), while it actually returns an array of
PopplerRectangle (one continuous malloc region with all rectangles
side-by-side).

The confusion occurs naturally in C, as the type "Foo*" can be a pointer to a
single Foo object, or an array of Foo objects.

>From a cursory glance at gir, it seems the actual data layout currently
implemented is not supported by gir, and that the PopplerRectangles have to be
allocated separately.  This would be an API change.

If one tries to trick gir and change the header file to a PopplerRectangle*
(instead of the **), one gets:

$ gjs girtest.js

(gjs:20441): Gjs-WARNING **: JS ERROR: Error: Unsupported type array for (out
caller-allocates)
@girtest.js:4

JS_EvaluateScript() failed

Here is the backtrace:

(gdb) bt
#0  __memcpy_sse2_unaligned () at
../sysdeps/x86_64/multiarch/memcpy-sse2-unaligned.S:37
#1  0x00007ffff69393a7 in g_slice_copy (mem_size=32,
mem_block=0x40519322d0e56042) at gslice.c:1056
#2  0x00007ffff6c166d3 in g_boxed_copy (boxed_type=8036912,
src_boxed=0x40519322d0e56042) at gboxed.c:352
#3  0x00007ffff7d9cf54 in gjs_boxed_from_c_struct (context=0x636ff0,
info=<optimized out>, gboxed=0x40519322d0e56042, flags=<optimized out>) at
gi/boxed.cpp:1236
#4  0x00007ffff7d99d43 in gjs_value_from_g_argument
(context=context@entry=0x636ff0, value_p=value_p@entry=0x7fffffffc500,
type_info=type_info@entry=0x72aa30,
    arg=arg@entry=0x7fffffffc510, copy_structs=copy_structs@entry=1) at
gi/arg.cpp:2642
#5  0x00007ffff7d9a1fb in gjs_array_from_carray_internal
(context=context@entry=0x636ff0, value_p=value_p@entry=0x7fffffffc5c8,
param_info=param_info@entry=0x72aa30,
    length=length@entry=483, array=<optimized out>) at gi/arg.cpp:2143
#6  0x00007ffff7d9a695 in gjs_value_from_explicit_array (context=0x636ff0,
value_p=0x7fffffffc5c8, type_info=<optimized out>, arg=0x7fffffffc618,
length=483)
    at gi/arg.cpp:2195
#7  0x00007ffff7d9fe03 in gjs_invoke_c_function
(context=context@entry=0x636ff0, function=function@entry=0x6d0de0,
obj=obj@entry=0x7fffee735cd0, js_argc=js_argc@entry=0,
    js_argv=js_argv@entry=0x68e508, js_rval=js_rval@entry=0x7fffffffc970,
r_value=r_value@entry=0x0) at gi/function.cpp:1140</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>