Skip to content

Notes from meeting with Cinder devs

Stepan Sindelar edited this page Jun 8, 2022 · 4 revisions

Suggested new API: HPy_ssize_t HPyUnicode_CopyUTF8ToBuffer(ctx, buffer, start, nsize, handle)


Iterating things effectively?

  • iterating a dictionary (PyDict_Next)?
  • read-only view on dictionary items/keys?
HPy buffer[16];
start = 0;
while (...)
  HPy_ssize_t n = HPy_ToBuffer(ctx, start, buffer);
  start += 16;
  for (i = 0; i< min(n, 16); ++i)
     HPy_Length(ctx, buffer[i])

C compiler could optimize the inner loop nicely at least on CPython ABI.


Alternative to opaqueness:

  • pass non-opaque structs + field offsets?
struct {
    HPy the_list;
    HPy_ssize_t length;
} HPyListView;

foo(HpyContext *ctx, HPyListView self);

How to implement HPy:

  • definition of the context structure: hpy/devel/include/hpy/universal/autogen_ctx.h
  • generated from this: hpy/tools/autogen/public_api.h
  • using this configuration: hpy/tools/autogen/conf.py
  • the HPy internal autogen tools generate also the trampolines, which are part of the header files that are the same for all implementations, e.g.:
    • HPy HPyLong_FromLong(HPyContext *ctx, long l) { return ctx->ctx_Long_FromLong(ctx, l); }

Idea regarding the module state + argument clinic:

struct {
    HPy my_type1;
    int my_counter;
} MyModuleContext;

SIGNATURE(...)
foo(HPyContext *ctx, MyModuleContext *moduleCtx) {
    return HPy_New(ctx, moduleCtx->my_type1);
}

ModuleDef module = {
  //...
  cotext_size = sizeof(MyModuleContext),
};

static HPy init_my_module_impl(HPyContext *ctx) {
    HPy type_handle = HPyType_FromSpec(ctx, &module);
    // ...
    HPyModuleContext_Add(ctx, offsetof(MyModuleContext, my_type1), type_handle);
    HPy_Close(ctx, type_handle);
    // ...
}

Pointers to issues that were discussed during the meeting:


  • We need some API to check interrupts, call safepoints, etc.
Clone this wiki locally