|
9 | 9 | #ifdef STACKLESS |
10 | 10 | #include "core/stackless_impl.h" |
11 | 11 |
|
| 12 | +/* |
| 13 | + * Convert C-bitfield |
| 14 | + */ |
| 15 | +Py_LOCAL_INLINE(PyTaskletFlagStruc) |
| 16 | +tasklet_flags_from_integer(int flags) { |
| 17 | +#if defined(SLP_USE_NATIVE_BITFIELD_LAYOUT) && SLP_USE_NATIVE_BITFIELD_LAYOUT |
| 18 | + PyTaskletFlagStruc f; |
| 19 | + Py_MEMCPY(&f, &flags, sizeof(f)); |
| 20 | +#else |
| 21 | + /* the portable way */ |
| 22 | + PyTaskletFlagStruc f = {0, }; |
| 23 | + SLP_SET_BITFIELD(SLP_TASKLET_FLAGS, f, flags, blocked); |
| 24 | + SLP_SET_BITFIELD(SLP_TASKLET_FLAGS, f, flags, atomic); |
| 25 | + SLP_SET_BITFIELD(SLP_TASKLET_FLAGS, f, flags, ignore_nesting); |
| 26 | + SLP_SET_BITFIELD(SLP_TASKLET_FLAGS, f, flags, autoschedule); |
| 27 | + SLP_SET_BITFIELD(SLP_TASKLET_FLAGS, f, flags, block_trap); |
| 28 | + SLP_SET_BITFIELD(SLP_TASKLET_FLAGS, f, flags, is_zombie); |
| 29 | + SLP_SET_BITFIELD(SLP_TASKLET_FLAGS, f, flags, pending_irq); |
| 30 | +#endif |
| 31 | + (void) Py_BUILD_ASSERT_EXPR(sizeof(f) == sizeof(flags)); |
| 32 | + return f; |
| 33 | +} |
| 34 | + |
| 35 | +Py_LOCAL_INLINE(int) |
| 36 | +tasklet_flags_as_integer(PyTaskletFlagStruc flags) { |
| 37 | + int f; |
| 38 | + (void) Py_BUILD_ASSERT_EXPR(sizeof(f) == sizeof(flags)); |
| 39 | +#if defined(SLP_USE_NATIVE_BITFIELD_LAYOUT) && SLP_USE_NATIVE_BITFIELD_LAYOUT |
| 40 | + Py_MEMCPY(&f, &flags, sizeof(f)); |
| 41 | +#else |
| 42 | + /* the portable way */ |
| 43 | + f = SLP_GET_BITFIELD(SLP_TASKLET_FLAGS, flags, blocked) | |
| 44 | + SLP_GET_BITFIELD(SLP_TASKLET_FLAGS, flags, atomic) | |
| 45 | + SLP_GET_BITFIELD(SLP_TASKLET_FLAGS, flags, ignore_nesting) | |
| 46 | + SLP_GET_BITFIELD(SLP_TASKLET_FLAGS, flags, autoschedule) | |
| 47 | + SLP_GET_BITFIELD(SLP_TASKLET_FLAGS, flags, block_trap) | |
| 48 | + SLP_GET_BITFIELD(SLP_TASKLET_FLAGS, flags, is_zombie) | |
| 49 | + SLP_GET_BITFIELD(SLP_TASKLET_FLAGS, flags, pending_irq); |
| 50 | +#endif |
| 51 | + return f; |
| 52 | +} |
| 53 | + |
12 | 54 | void |
13 | 55 | slp_current_insert(PyTaskletObject *task) |
14 | 56 | { |
@@ -366,7 +408,7 @@ tasklet_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
366 | 408 | t = (PyTaskletObject *) type->tp_alloc(type, 0); |
367 | 409 | if (t == NULL) |
368 | 410 | return NULL; |
369 | | - *(int*)&t->flags = 0; |
| 411 | + memset(&t->flags, 0, sizeof(t->flags)); |
370 | 412 | t->recursion_depth = 0; |
371 | 413 | t->next = NULL; |
372 | 414 | t->prev = NULL; |
@@ -460,7 +502,7 @@ tasklet_reduce(PyTaskletObject * t) |
460 | 502 | assert(t->cstate != NULL); |
461 | 503 | tup = Py_BuildValue("(O()(" TASKLET_TUPLEFMT "))", |
462 | 504 | Py_TYPE(t), |
463 | | - t->flags, |
| 505 | + tasklet_flags_as_integer(t->flags), |
464 | 506 | t->tempval, |
465 | 507 | t->cstate->nesting_level, |
466 | 508 | lis |
@@ -513,7 +555,7 @@ tasklet_setstate(PyObject *self, PyObject *args) |
513 | 555 | * channel would have set it. |
514 | 556 | */ |
515 | 557 | j = t->flags.blocked; |
516 | | - *(int *)&t->flags = flags; |
| 558 | + t->flags = tasklet_flags_from_integer(flags); |
517 | 559 | if (t->next == NULL) { |
518 | 560 | t->flags.blocked = 0; |
519 | 561 | } else { |
|
0 commit comments