~ubuntu-branches/ubuntu/lucid/luatex/lucid

« back to all changes in this revision

Viewing changes to src/libs/lua51/lcoco.h

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Preining
  • Date: 2007-12-10 10:24:34 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20071210102434-9w9ljypghznwb4dy
Tags: 0.20.1-1
* new upstreams, add the announcements with changes to the debian dir
* call build.sh.linux with bash, not with sh, otherwise building breaks
  (thanks to Pascal de Bruijn <pmjdebruijn@gmail.com> from Ubuntu for
  letting us know) [np]
* update libpoppler patch
* change the texdoclua patch to use the new os.tmpdir with a template of
  /tmp/luatex.XXXXXX
* bump standards version to 3.7.3, no changes necessary
* convert copyright file to utf-8

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
** Lua/Coco glue.
 
3
** Copyright (C) 2004-2007 Mike Pall. See copyright notice in lcoco.c
 
4
*/
 
5
 
 
6
#ifndef lcoco_h
 
7
#define lcoco_h
 
8
 
 
9
#define LUACOCO_VERSION         "Coco 1.1.3"
 
10
#define LUACOCO_VERSION_NUM     10103
 
11
 
 
12
/* Exported C API to add a C stack to a coroutine. */
 
13
LUA_API lua_State *lua_newcthread(lua_State *L, int cstacksize);
 
14
 
 
15
/* Internal support routines. */
 
16
LUAI_FUNC void luaCOCO_free(lua_State *L);
 
17
LUAI_FUNC int luaCOCO_resume(lua_State *L, int nargs);
 
18
LUAI_FUNC int luaCOCO_yield(lua_State *L);
 
19
LUAI_FUNC int luaCOCO_cstacksize(int cstacksize);
 
20
 
 
21
/* Forward declaration. */
 
22
typedef struct coco_State coco_State;
 
23
 
 
24
/* These are redefined below. */
 
25
#undef LUAI_EXTRASPACE
 
26
#undef luai_userstateopen
 
27
/* luai_userstateclose unused */
 
28
#undef luai_userstatethread
 
29
#undef luai_userstatefree
 
30
#undef luai_userstateresume
 
31
#undef luai_userstateyield
 
32
 
 
33
/* Use Windows Fibers (Win98+). */
 
34
#if defined(_WIN32)
 
35
 
 
36
/* Fibers allocate their own stack. The whole Coco state is in front of L. */
 
37
struct coco_State {
 
38
  void *fib;                    /* Own fiber (if any). */
 
39
  void *back;                   /* Fiber to switch back to. */
 
40
  int nargs;                    /* Number of arguments to pass. */
 
41
  int dummy_align;
 
42
};
 
43
 
 
44
#define L2COCO(L)               (&((coco_State *)(L))[-1])
 
45
#define LHASCOCO(L)             (L2COCO(L)->fib)
 
46
#define LUAI_EXTRASPACE         sizeof(coco_State)
 
47
#define luai_userstateopen(L)   L2COCO(L)->fib = NULL
 
48
#define luai_userstatethread(L,L1)      L2COCO(L1)->fib = NULL
 
49
#define COCO_USE_FIBERS
 
50
 
 
51
#else /* !defined(_WIN32) */
 
52
 
 
53
/* The Coco state depends on the context switch method used. See lcoco.c. */
 
54
/* It's stored at the end of the stack. Only need a pointer in front of L. */
 
55
#define L2COCO(L)               (((coco_State **)(L))[-1])
 
56
#define LHASCOCO(L)             (L2COCO(L))
 
57
/* This wastes some space on 32 bit systems, but gets better alignment. */
 
58
#define LUAI_EXTRASPACE         sizeof(LUAI_USER_ALIGNMENT_T)
 
59
#define luai_userstateopen(L)   L2COCO(L) = NULL
 
60
#define luai_userstatethread(L,L1)      L2COCO(L1) = NULL
 
61
 
 
62
#endif /* !defined(_WIN32) */
 
63
 
 
64
#define luai_userstatefree(L)   if (LHASCOCO(L)) luaCOCO_free(L)
 
65
#define luai_userstateresume(L, nargs) \
 
66
  if (LHASCOCO(L)) return luaCOCO_resume(L, nargs)
 
67
#define luai_userstateyield(L, nresults) \
 
68
  do { if (LHASCOCO(L)) { \
 
69
    L->base = L->top - (nresults);  /* Protect stack slots below. */ \
 
70
    return luaCOCO_yield(L); } } while (0)
 
71
 
 
72
#endif