MCPcopy Create free account
hub / github.com/f0rr0/oliphaunt / take_output

Method take_output

src/pglite/postgres_mod.rs:2811–2855  ·  view source on GitHub ↗
(
        &self,
        store: &mut Store,
        env: &WasiFunctionEnv,
        allocator: &GuestAllocator,
    )

Source from the content-addressed store, hash-verified

2809 }
2810
2811 fn take_output(
2812 &self,
2813 store: &mut Store,
2814 env: &WasiFunctionEnv,
2815 allocator: &GuestAllocator,
2816 ) -> Result<Vec<u8>> {
2817 let len = self
2818 .output_len
2819 .call(&mut *store)
2820 .context("pgl_wasix_output_len")?;
2821 ensure!(
2822 len >= 0,
2823 "pgl_wasix_output_len returned negative length {len}"
2824 );
2825 if len == 0 {
2826 return Ok(Vec::new());
2827 }
2828 let bytes = allocator.with_allocation(store, len, |store, ptr| {
2829 let read = self
2830 .output_read
2831 .call(&mut *store, ptr, len)
2832 .context("pgl_wasix_output_read")?;
2833 ensure!(
2834 read >= 0 && read <= len,
2835 "invalid pgl_wasix_output_read length {read}"
2836 );
2837
2838 let mut bytes = vec![0u8; read as usize];
2839 let view = env
2840 .data(&*store)
2841 .try_memory_view(&*store)
2842 .context("get WASIX memory view")?;
2843 view.read(ptr as u64, &mut bytes)
2844 .with_context(|| format!("read SQL output at 0x{ptr:x}"))?;
2845 Ok(bytes)
2846 })?;
2847 ensure!(
2848 self.output_reset
2849 .call(&mut *store)
2850 .context("pgl_wasix_output_reset after read")?
2851 == 0,
2852 "pgl_wasix_output_reset after read failed"
2853 );
2854 Ok(bytes)
2855 }
2856}
2857
2858impl GuestAllocator {

Calls 2

with_allocationMethod · 0.80
readMethod · 0.80

Tested by

no test coverage detected