Skip to content

Commit a5c70cd

Browse files
authored
Merge pull request #458 from DuToitSpies/dict_type_add
Add dictionary type to HPyContext
2 parents bdf7e7f + 7ceb238 commit a5c70cd

19 files changed

+68
-6
lines changed

hpy/debug/src/autogen_debug_ctx_init.h

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hpy/debug/src/debug_ctx.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ static const char *get_builtin_shape_name(HPyType_BuiltinShape shape)
328328
SHAPE_NAME(HPyType_BuiltinShape_Unicode)
329329
SHAPE_NAME(HPyType_BuiltinShape_Tuple)
330330
SHAPE_NAME(HPyType_BuiltinShape_List)
331+
SHAPE_NAME(HPyType_BuiltinShape_Dict)
331332
}
332333
return "<unknown shape>";
333334
#undef SHAPE_NAME
@@ -372,6 +373,8 @@ MAKE_debug_ctx_AsStruct(Tuple)
372373

373374
MAKE_debug_ctx_AsStruct(List)
374375

376+
MAKE_debug_ctx_AsStruct(Dict)
377+
375378
/* ~~~ debug mode implementation of HPyTracker ~~~
376379
377380
This is a bit special and it's worth explaining what is going on.

hpy/devel/include/hpy/cpython/autogen_ctx.h

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hpy/devel/include/hpy/cpython/misc.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ HPyAPI_FUNC HPyContext * _HPyGetContext(void) {
144144
ctx->h_MemoryViewType = _py2h((PyObject *)&PyMemoryView_Type);
145145
ctx->h_CapsuleType = _py2h((PyObject *)&PyCapsule_Type);
146146
ctx->h_SliceType = _py2h((PyObject *)&PySlice_Type);
147+
ctx->h_DictType = _py2h((PyObject *)&PyDict_Type);
147148
/* Reflection */
148149
ctx->h_Builtins = _py2h(PyEval_GetBuiltins());
149150
}
@@ -271,6 +272,11 @@ HPyAPI_FUNC void* _HPy_AsStruct_List(HPyContext *ctx, HPy h)
271272
return ctx_AsStruct_List(ctx, h);
272273
}
273274

275+
HPyAPI_FUNC void* _HPy_AsStruct_Dict(HPyContext *ctx, HPy h)
276+
{
277+
return ctx_AsStruct_Dict(ctx, h);
278+
}
279+
274280
HPyAPI_FUNC HPy HPy_CallTupleDict(HPyContext *ctx, HPy callable, HPy args, HPy kw)
275281
{
276282
return ctx_CallTupleDict(ctx, callable, args, kw);

hpy/devel/include/hpy/hpytype.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ typedef enum {
7373
* need to specify base class ``ctx->h_ListType``.
7474
*/
7575
HPyType_BuiltinShape_List = 6,
76+
77+
/**
78+
* The type inherits from built-in type ``dict``. If using this shape, you
79+
* need to specify base class ``ctx->h_DictType``.
80+
*/
81+
HPyType_BuiltinShape_Dict = 7,
7682
} HPyType_BuiltinShape;
7783

7884
typedef struct {
@@ -292,5 +298,6 @@ _HPyType_HELPER_X(_HPyType_HELPER_FNAME(__VA_ARGS__))(HPyContext *ctx, HPy h) \
292298
#define HPyType_BuiltinShape_Unicode_AsStruct _HPy_AsStruct_Unicode
293299
#define HPyType_BuiltinShape_Tuple_AsStruct _HPy_AsStruct_Tuple
294300
#define HPyType_BuiltinShape_List_AsStruct _HPy_AsStruct_List
301+
#define HPyType_BuiltinShape_Dict_AsStruct _HPy_AsStruct_Dict
295302

296303
#endif /* HPY_UNIVERSAL_HPYTYPE_H */

hpy/devel/include/hpy/runtime/ctx_funcs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ _HPy_HIDDEN void* ctx_AsStruct_Float(HPyContext *ctx, HPy h);
8787
_HPy_HIDDEN void* ctx_AsStruct_Unicode(HPyContext *ctx, HPy h);
8888
_HPy_HIDDEN void* ctx_AsStruct_Tuple(HPyContext *ctx, HPy h);
8989
_HPy_HIDDEN void* ctx_AsStruct_List(HPyContext *ctx, HPy h);
90+
_HPy_HIDDEN void* ctx_AsStruct_Dict(HPyContext *ctx, HPy h);
9091
_HPy_HIDDEN void* ctx_AsStruct_Slow(HPyContext *ctx, HPy h);
9192
_HPy_HIDDEN HPy ctx_Type_FromSpec(HPyContext *ctx, HPyType_Spec *hpyspec,
9293
HPyType_SpecParam *params);

hpy/devel/include/hpy/universal/autogen_ctx.h

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hpy/devel/include/hpy/universal/autogen_trampolines.h

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hpy/devel/src/runtime/ctx_type.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ FULLY_ALIGNED_SPACE(PyFloatObject)
7676
FULLY_ALIGNED_SPACE(PyUnicodeObject)
7777
FULLY_ALIGNED_SPACE(PyTupleObject)
7878
FULLY_ALIGNED_SPACE(PyListObject)
79+
FULLY_ALIGNED_SPACE(PyDictObject)
7980

8081
#define _HPy_HEAD_SIZE(HEAD) (offsetof(_HPy_FullyAlignedSpaceFor##HEAD, payload))
8182

@@ -101,6 +102,8 @@ _HPy_GetHeaderSize(HPyType_BuiltinShape shape)
101102
return _HPy_HEAD_SIZE(PyTupleObject);
102103
case HPyType_BuiltinShape_List:
103104
return _HPy_HEAD_SIZE(PyListObject);
105+
case HPyType_BuiltinShape_Dict:
106+
return _HPy_HEAD_SIZE(PyDictObject);
104107
}
105108
return -1;
106109
}
@@ -1504,6 +1507,12 @@ ctx_AsStruct_List(HPyContext *ctx, HPy h)
15041507
return _HPy_Payload(_h2py(h), HPyType_BuiltinShape_List);
15051508
}
15061509

1510+
_HPy_HIDDEN void*
1511+
ctx_AsStruct_Dict(HPyContext *ctx, HPy h)
1512+
{
1513+
return _HPy_Payload(_h2py(h), HPyType_BuiltinShape_Dict);
1514+
}
1515+
15071516
_HPy_HIDDEN void*
15081517
ctx_AsStruct_Slow(HPyContext *ctx, HPy h)
15091518
{

hpy/tools/autogen/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
'_HPy_AsStruct_Unicode': None,
5353
'_HPy_AsStruct_Tuple': None,
5454
'_HPy_AsStruct_List': None,
55+
'_HPy_AsStruct_Dict': None,
5556
'_HPy_AsStruct_Legacy': None,
5657
'_HPyType_GetBuiltinShape': None,
5758
'_HPy_CallRealFunctionFromTrampoline': None,

hpy/tools/autogen/debug.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class autogen_debug_wrappers(AutoGenFile):
7474
'_HPy_AsStruct_Unicode',
7575
'_HPy_AsStruct_Tuple',
7676
'_HPy_AsStruct_List',
77+
'_HPy_AsStruct_Dict',
7778
'HPyTracker_New',
7879
'HPyTracker_Add',
7980
'HPyTracker_ForgetAll',

hpy/tools/autogen/parse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import pycparser
77
from pycparser import c_ast
88
from pycparser.c_generator import CGenerator
9-
from distutils.sysconfig import get_config_var
9+
from sysconfig import get_config_var
1010
from .conf import SPECIAL_CASES, RETURN_CONSTANT
1111

1212
PUBLIC_API_H = py.path.local(__file__).dirpath('public_api.h')

hpy/tools/autogen/public_api.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ HPy_ID(239) HPy h_BytesType; /* built-in 'bytes' */
101101
HPy_ID(240) HPy h_MemoryViewType; /* built-in 'memoryview' */
102102
HPy_ID(241) HPy h_CapsuleType; /* built-in 'capsule' */
103103
HPy_ID(242) HPy h_SliceType; /* built-in 'slice' */
104+
HPy_ID(263) HPy h_DictType; /* built-in 'dict' */
104105

105106
/* Reflection */
106107
HPy_ID(243) HPy h_Builtins; /* dict of builtins */
@@ -539,6 +540,8 @@ HPy_ID(232)
539540
void* _HPy_AsStruct_Tuple(HPyContext *ctx, HPy h);
540541
HPy_ID(233)
541542
void* _HPy_AsStruct_List(HPyContext *ctx, HPy h);
543+
HPy_ID(264)
544+
void* _HPy_AsStruct_Dict(HPyContext *ctx, HPy h);
542545
HPy_ID(234)
543546
HPyType_BuiltinShape _HPyType_GetBuiltinShape(HPyContext *ctx, HPy h_type);
544547

hpy/trace/src/autogen_trace_ctx_init.h

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hpy/trace/src/autogen_trace_func_table.c

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hpy/trace/src/autogen_trace_wrappers.c

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hpy/universal/src/autogen_ctx_def.h

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hpy/universal/src/hpymodule.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,7 @@ static void init_universal_ctx(HPyContext *ctx)
676676
ctx->h_MemoryViewType = _py2h((PyObject *)&PyMemoryView_Type);
677677
ctx->h_CapsuleType = _py2h((PyObject *)&PyCapsule_Type);
678678
ctx->h_SliceType = _py2h((PyObject *)&PySlice_Type);
679+
ctx->h_DictType = _py2h((PyObject *)&PyDict_Type);
679680
/* Reflection */
680681
ctx->h_Builtins = _py2h(PyEval_GetBuiltins());
681682
}

test/test_00_basic.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ def test_builtin_handles(self):
262262
case 20: h = ctx->h_MemoryViewType; break;
263263
case 21: h = ctx->h_SliceType; break;
264264
case 22: h = ctx->h_Builtins; break;
265+
case 23: h = ctx->h_DictType; break;
265266
case 2048: h = ctx->h_CapsuleType; break;
266267
default:
267268
HPyErr_SetString(ctx, ctx->h_ValueError, "invalid choice");
@@ -278,7 +279,7 @@ def test_builtin_handles(self):
278279
'<NULL>', None, False, True, ValueError, TypeError, IndexError,
279280
SystemError, object, type, bool, int, float, str, tuple, list,
280281
NotImplemented, Ellipsis, complex, bytes, memoryview, slice,
281-
builtins.__dict__
282+
builtins.__dict__, dict
282283
)
283284
for i, obj in enumerate(builtin_objs):
284285
if i == 0:

0 commit comments

Comments
 (0)