-
Notifications
You must be signed in to change notification settings - Fork 8
/
starlark.c
600 lines (535 loc) Β· 20.7 KB
/
starlark.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
#include "starlark.h"
/* Declarations for object methods written in Go */
void ConfigureStarlark(int allowSet, int allowGlobalReassign, int allowRecursion);
int Starlark_init(Starlark *self, PyObject *args, PyObject *kwds);
Starlark *Starlark_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
void Starlark_dealloc(Starlark *self);
PyObject *Starlark_eval(Starlark *self, PyObject *args);
PyObject *Starlark_exec(Starlark *self, PyObject *args);
PyObject *Starlark_global_names(Starlark *self, PyObject *_);
PyObject *Starlark_get_global(Starlark *self, PyObject *args, PyObject **kwargs);
PyObject *Starlark_set_globals(Starlark *self, PyObject *args, PyObject **kwargs);
PyObject *Starlark_pop_global(Starlark *self, PyObject *args, PyObject **kwargs);
PyObject *Starlark_get_print(Starlark *self, void *closure);
int Starlark_set_print(Starlark *self, PyObject *value, void *closure);
PyObject *Starlark_tp_iter(Starlark *self);
/* Exceptions - the module init function will fill these in */
PyObject *StarlarkError;
PyObject *SyntaxError;
PyObject *EvalError;
PyObject *ResolveError;
PyObject *ResolveErrorItem;
PyObject *ConversionToPythonFailed;
PyObject *ConversionToStarlarkFailed;
/* Wrapper for setting Starlark configuration options */
static char *configure_keywords[] = {
"allow_set", "allow_global_reassign", "allow_recursion", NULL /* Sentinel */
};
PyObject *configure_starlark(PyObject *self, PyObject *args, PyObject *kwargs)
{
/* ConfigureStarlark interprets -1 as "unspecified" */
int allow_set = -1, allow_global_reassign = -1, allow_recursion = -1;
if (PyArg_ParseTupleAndKeywords(
args,
kwargs,
"|$ppp:configure_starlark",
configure_keywords,
&allow_set,
&allow_global_reassign,
&allow_recursion
) == 0) {
return NULL;
}
ConfigureStarlark(allow_set, allow_global_reassign, allow_recursion);
Py_RETURN_NONE;
}
PyDoc_STRVAR(
configure_starlark_doc,
"configure_starlark(*, allow_set=None, allow_global_reassign=None, "
"allow_recursion=None)\n--\n\n"
"Change what features the Starlark interpreter allows. Unfortunately, "
"this manipulates global variables, and affects all Starlark interpreters "
"in your application. It is not possible to have one Starlark "
"interpreter with ``allow_set=True`` and another with ``allow_set=False`` "
"simultaneously.\n\n"
"All feature flags are initially ``False``.\n\n"
"See the `starlark-go documentation "
"<https://pkg.go.dev/go.starlark.net/resolve#pkg-variables>`_ for "
"more information.\n\n"
":param allow_set: If ``True``, allow the creation of `set "
"<https://github.com/google/starlark-go/blob/master/doc/spec.md#sets=>`_ objects "
"in Starlark.\n"
":type allow_set: typing.Optional[bool]\n"
":param allow_global_reassign: If ``True``, allow reassignment to top-level names; "
"also, allow if/for/while at top-level.\n"
":type allow_global_reassign: typing.Optional[bool]\n"
":param allow_recursion: If ``True``, allow while statements and recursive "
"functions.\n"
":type allow_recursion: typing.Optional[bool]\n"
);
/* Argument names and documentation for our methods */
static char *init_keywords[] = {"globals", "print", NULL};
PyDoc_STRVAR(
Starlark_init_doc,
"Starlark(*, globals=None, print=None)\n--\n\n"
"Create a Starlark object. A Starlark object contains a set of global variables, "
"which can be manipulated by executing Starlark code.\n\n"
":param globals: Initial set of global variables. Keys must be strings. Values can "
"be any type supported by :func:`set`.\n"
":type globals: typing.Mapping[str, typing.Any]\n"
":param print: A function to call in place of Starlark's ``print()`` function. If "
"unspecified, Starlark's ``print()`` function will be forwarded to Python's "
"built-in :py:func:`python:print`.\n"
":type print: typing.Callable[[str], typing.Any]\n"
);
static char *eval_keywords[] = {"expr", "filename", "convert", "print", NULL};
PyDoc_STRVAR(
Starlark_eval_doc,
"eval(self, expr, *, filename=None, convert=True, print=None)\n--\n\n"
"Evaluate a Starlark expression. The expression passed to ``eval`` must evaluate "
"to a value. Function definitions, variable assignments, and control structures "
"are not allowed by ``eval``. To use those, please use :meth:`exec`.\n\n"
":param expr: A string containing a Starlark expression to evaluate\n"
":type expr: str\n"
":param filename: An optional filename to use in exceptions, if evaluting the "
"expression fails.\n"
":type filename: typing.Optional[str]\n"
":param convert: If True, convert the result of the expression into a Python "
"value. If False, return a string containing the representation of the expression "
"in Starlark. Defaults to True.\n"
":type convert: bool\n"
":param print: A function to call in place of Starlark's ``print()`` function. If "
"unspecified, Starlark's ``print()`` function will be forwarded to Python's "
"built-in :py:func:`python:print`.\n"
":type print: typing.Callable[[str], typing.Any]\n"
":raises ConversionToPythonFailed: if the value is of an unsupported type for "
"conversion.\n"
":raises EvalError: if there is a Starlark evaluation error\n"
":raises ResolveError: if there is a Starlark resolution error\n"
":raises SyntaxError: if there is a Starlark syntax error\n"
":raises StarlarkError: if there is an unexpected error\n"
":rtype: typing.Any\n"
);
static char *exec_keywords[] = {"defs", "filename", "print", NULL};
PyDoc_STRVAR(
Starlark_exec_doc,
"exec(self, defs, *, filename=None, print=None)\n--\n\n"
"Execute Starlark code. All legal Starlark constructs may be used with "
"``exec``.\n\n"
"``exec`` does not return a value. To evaluate the value of a Starlark expression, "
"please use func:`eval`.\n\n"
":param defs: A string containing Starlark code to execute\n"
":type defs: str\n"
":param filename: An optional filename to use in exceptions, if evaluting the "
"expression fails.\n"
":type filename: Optional[str]\n"
":param print: A function to call in place of Starlark's ``print()`` function. If "
"unspecified, Starlark's ``print()`` function will be forwarded to Python's "
"built-in :py:func:`python:print`.\n"
":type print: typing.Callable[[str], typing.Any]\n"
":raises EvalError: if there is a Starlark evaluation error\n"
":raises ResolveError: if there is a Starlark resolution error\n"
":raises SyntaxError: if there is a Starlark syntax error\n"
":raises StarlarkError: if there is an unexpected error\n"
);
static char *get_global_keywords[] = {"name", "default", NULL};
PyDoc_STRVAR(
Starlark_get_doc,
"get(self, name, default_value = ...)\n--\n\n"
"Get the value of a Starlark global variable.\n\n"
"Conversion from most Starlark data types is supported:\n\n"
"* Starlark `None <https://pkg.go.dev/go.starlark.net/starlark#None>`_ to "
"Python :py:obj:`python:None`\n"
"* Starlark `bool <https://pkg.go.dev/go.starlark.net/starlark#Bool>`_ to "
"Python :py:obj:`python:bool`\n"
"* Starlark `bytes <https://pkg.go.dev/go.starlark.net/starlark#Bytes>`_ to "
"Python :py:obj:`python:bytes`\n"
"* Starlark `float <https://pkg.go.dev/go.starlark.net/starlark#Float>`_ to "
"Python :py:obj:`python:float`\n"
"* Starlark `int <https://pkg.go.dev/go.starlark.net/starlark#Int>`_ to "
"Python :py:obj:`python:int`\n"
"* Starlark `string <https://pkg.go.dev/go.starlark.net/starlark#String>`_ to "
"Python :py:obj:`python:str`\n"
"* Starlark `dict <https://pkg.go.dev/go.starlark.net/starlark#Dict>`_ (and "
"`IterableMapping <https://pkg.go.dev/go.starlark.net/starlark#IterableMapping>`_) "
"to Python :py:obj:`python:dict`\n"
"* Starlark `list <https://pkg.go.dev/go.starlark.net/starlark#List>`_ (and "
"`Iterable <https://pkg.go.dev/go.starlark.net/starlark#Iterable>`_) to "
"Python :py:obj:`python:list`\n"
"* Starlark `set <https://pkg.go.dev/go.starlark.net/starlark#Set>`_ to "
"Python :py:obj:`python:set`\n"
"* Starlark `tuple <https://pkg.go.dev/go.starlark.net/starlark#Tuple>`_ to "
"Python :py:obj:`python:tuple`\n\n"
"For the aggregate types (``dict``, ``list``, ``set``, and ``tuple``,) all keys "
"and/or values must also be one of the supported types.\n\n"
"Attempting to get the value of any other Starlark type will raise a "
":py:class:`ConversionToPythonFailed`.\n\n"
":param name: The name of the global variable.\n"
":type name: str\n"
":param default_value: A default value to return, if no global variable named "
"``name`` is defined.\n"
":type default_value: typing.Any\n"
":raises KeyError: if there is no global value named ``name`` defined.\n"
":raises ConversionToPythonFailed: if the value is of an unsupported type for "
"conversion.\n"
":rtype: typing.Any\n"
);
PyDoc_STRVAR(
Starlark_globals_doc,
"globals(self)\n--\n\n"
"Get the names of the currently defined global variables.\n\n"
":rtype: typing.List[str]\n"
);
PyDoc_STRVAR(
Starlark_set_doc,
"set(self, **kwargs)\n--\n\n"
"Set the value of one or more Starlark global variables.\n\n"
"For each keyword parameter specified, one global variable is set.\n\n"
"Conversion from most basic Python types is supported:\n\n"
"* Python :py:obj:`python:None` to Starlark `None "
"<https://pkg.go.dev/go.starlark.net/starlark#None>`_\n"
"* Python :py:obj:`python:bool` to Starlark `bool "
"<https://pkg.go.dev/go.starlark.net/starlark#Bool>`_\n"
"* Python :py:obj:`python:bytes` to Starlark `bytes "
"<https://pkg.go.dev/go.starlark.net/starlark#Bytes>`_\n"
"* Python :py:obj:`python:float` to Starlark `float "
"<https://pkg.go.dev/go.starlark.net/starlark#Float>`_\n"
"* Python :py:obj:`python:int` to Starlark `int "
"<https://pkg.go.dev/go.starlark.net/starlark#Int>`_\n"
"* Python :py:obj:`python:str` to Starlark `string "
"<https://pkg.go.dev/go.starlark.net/starlark#String>`_\n"
"* Python :py:obj:`python:dict` (and other objects that implement the mapping "
"protocol) to Starlark "
"`dict <https://pkg.go.dev/go.starlark.net/starlark#Dict>`_\n"
"* Python :py:obj:`python:list` (and other objects that implement the sequence "
"protocol) to Starlark "
"`list <https://pkg.go.dev/go.starlark.net/starlark#List>`_\n"
"* Python :py:obj:`python:set` to Starlark `set "
"<https://pkg.go.dev/go.starlark.net/starlark#Set>`_\n"
"* Python :py:obj:`python:tuple` to Starlark `tuple "
"<https://pkg.go.dev/go.starlark.net/starlark#Tuple>`_\n"
"* Python functions can be registered as a Starlark function directly. "
"Any exceptions raised will be rethrown as :py:class:`EvalError`.\n"
"\n"
"For the aggregate types (``dict``, ``list``, ``set``, and ``tuple``,) all keys "
"and/or values must also be one of the supported types.\n\n"
"Attempting to set a value of any other Python type will raise a "
":py:class:`ConversionToStarlarkFailed`.\n\n"
":raises ConversionToStarlarkFailed: if a value is of an unsupported type for "
"conversion.\n"
);
PyDoc_STRVAR(
Starlark_pop_doc,
"pop(self, name, default_value = ...)\n--\n\n"
"Remove a Starlark global variable, and return its value.\n\n"
"If a value of ``name`` does not exist, and no ``default_value`` has been "
"specified, raise :py:obj:`python:KeyError`. Otherwise, return "
"``default_value``.\n\n"
":param name: The name of the global variable.\n"
":type name: str\n"
":param default_value: A default value to return, if no global variable named "
"``name`` is defined.\n"
":type default_value: typing.Any\n"
":raises KeyError: if there is no global value named ``name`` defined.\n"
":raises ConversionToPythonFailed: if the value is of an unsupported type for "
"conversion.\n"
":rtype: typing.Any\n"
);
PyDoc_STRVAR(
Starlark_print_doc,
"A function to call in place of Starlark's ``print()`` function. If "
"unspecified, Starlark's ``print()`` function will be forwarded to Python's "
"built-in :py:func:`python:print`.\n\n"
":type: typing.Callable[[str], typing.Any]\n"
);
/* Container for module methods */
static PyMethodDef module_methods[] = {
{"configure_starlark",
(PyCFunction)configure_starlark,
METH_VARARGS | METH_KEYWORDS,
configure_starlark_doc},
{NULL} /* Sentinel */
};
/* Container for object methods */
static PyMethodDef StarlarkGo_methods[] = {
{"eval",
(PyCFunction)Starlark_eval,
METH_VARARGS | METH_KEYWORDS,
Starlark_eval_doc},
{"exec",
(PyCFunction)Starlark_exec,
METH_VARARGS | METH_KEYWORDS,
Starlark_exec_doc},
{"globals", (PyCFunction)Starlark_global_names, METH_NOARGS, Starlark_globals_doc},
{"get",
(PyCFunction)Starlark_get_global,
METH_VARARGS | METH_KEYWORDS,
Starlark_get_doc},
{"set",
(PyCFunction)Starlark_set_globals,
METH_VARARGS | METH_KEYWORDS,
Starlark_set_doc},
{"pop",
(PyCFunction)Starlark_pop_global,
METH_VARARGS | METH_KEYWORDS,
Starlark_pop_doc},
{NULL} /* Sentinel */
};
static PyGetSetDef Starlark_getset[] = {
{"print",
(getter)Starlark_get_print,
(setter)Starlark_set_print,
Starlark_print_doc,
NULL},
{NULL},
};
/* Python type for object */
static PyTypeObject StarlarkType = {
// clang-format off
PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "starlark_go.starlark_go.Starlark",
// clang-format on
.tp_doc = Starlark_init_doc,
.tp_basicsize = sizeof(Starlark),
.tp_itemsize = 0,
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
.tp_new = (newfunc)Starlark_new,
.tp_init = (initproc)Starlark_init,
.tp_dealloc = (destructor)Starlark_dealloc,
.tp_methods = StarlarkGo_methods,
.tp_iter = (getiterfunc)Starlark_tp_iter,
.tp_getset = Starlark_getset,
};
/* Module */
static PyModuleDef starlark_go = {
PyModuleDef_HEAD_INIT,
.m_name = "starlark_go.starlark_go",
.m_doc = "Interface to starlark-go",
.m_size = -1,
.m_methods = module_methods,
};
/* Helpers to allocate and free our object */
Starlark *starlarkAlloc(PyTypeObject *type)
{
/* Necessary because Cgo can't do function pointers */
return (Starlark *)type->tp_alloc(type, 0);
}
void starlarkFree(Starlark *self)
{
/* Necessary because Cgo can't do function pointers */
Py_TYPE(self)->tp_free((PyObject *)self);
}
/* Helpers to parse method arguments */
int parseInitArgs(
PyObject *args, PyObject *kwargs, PyObject **globals, PyObject **print
)
{
/* Necessary because Cgo can't do varargs */
/* One optional object */
return PyArg_ParseTupleAndKeywords(
args, kwargs, "|$OO:Starlark", init_keywords, globals, print
);
}
int parseEvalArgs(
PyObject *args,
PyObject *kwargs,
char **expr,
char **filename,
unsigned int *convert,
PyObject **print
)
{
/* Necessary because Cgo can't do varargs */
/* One required string, folloed by an optional string and an optional bool */
return PyArg_ParseTupleAndKeywords(
args, kwargs, "s|$spO:eval", eval_keywords, expr, filename, convert, print
);
}
int parseExecArgs(
PyObject *args, PyObject *kwargs, char **defs, char **filename, PyObject **print
)
{
/* Necessary because Cgo can't do varargs */
/* One required string, folloed by an optional string */
return PyArg_ParseTupleAndKeywords(
args, kwargs, "s|$sO:exec", exec_keywords, defs, filename, print
);
}
int parseGetGlobalArgs(
PyObject *args, PyObject *kwargs, char **name, PyObject **default_value
)
{
/* Necessary because Cgo can't do varargs */
/* One required string, full stop */
return PyArg_ParseTupleAndKeywords(
args, kwargs, "s|O:get", get_global_keywords, name, default_value
);
}
int parsePopGlobalArgs(
PyObject *args, PyObject *kwargs, char **name, PyObject **default_value
)
{
/* Necessary because Cgo can't do varargs */
/* One required string, full stop */
return PyArg_ParseTupleAndKeywords(
args, kwargs, "s|O:pop", get_global_keywords, name, default_value
);
}
/* Helpers for Cgo to build exception arguments */
PyObject *makeStarlarkErrorArgs(const char *error_msg, const char *error_type)
{
/* Necessary because Cgo can't do varargs */
return Py_BuildValue("ss", error_msg, error_type);
}
PyObject *makeSyntaxErrorArgs(
const char *error_msg,
const char *error_type,
const char *msg,
const char *filename,
const unsigned int line,
const unsigned int column
)
{
/* Necessary because Cgo can't do varargs */
/* Four strings and two unsigned integers */
return Py_BuildValue("ssssII", error_msg, error_type, msg, filename, line, column);
}
PyObject *makeEvalErrorArgs(
const char *error_msg,
const char *error_type,
const char *filename,
const unsigned int line,
const unsigned int column,
const char *function_name,
const char *backtrace
)
{
/* Necessary because Cgo can't do varargs */
/* Three strings */
return Py_BuildValue(
"sssIIss", error_msg, error_type, filename, line, column, function_name, backtrace
);
}
PyObject *makeResolveErrorItem(
const char *msg, const unsigned int line, const unsigned int column
)
{
/* Necessary because Cgo can't do varargs */
/* A string and two unsigned integers */
PyObject *args = Py_BuildValue("sII", msg, line, column);
PyObject *obj = PyObject_CallObject(ResolveErrorItem, args);
Py_DECREF(args);
return obj;
}
PyObject *makeResolveErrorArgs(
const char *error_msg, const char *error_type, PyObject *errors
)
{
/* Necessary because Cgo can't do varargs */
/* Two strings and a Python object */
return Py_BuildValue("ssO", error_msg, error_type, errors);
}
/* Other assorted helpers for Cgo */
PyObject *cgoPy_BuildString(const char *src)
{
/* Necessary because Cgo can't do varargs */
return Py_BuildValue("s", src);
}
PyObject *cgoPy_NewRef(PyObject *obj)
{
/* Necessary because Cgo can't do macros and Py_NewRef is part of
* Python's "stable API" but only since 3.10
*/
Py_INCREF(obj);
return obj;
}
int cgoPyFloat_Check(PyObject *obj)
{
/* Necessary because Cgo can't do macros */
return PyFloat_Check(obj);
}
int cgoPyLong_Check(PyObject *obj)
{
/* Necessary because Cgo can't do macros */
return PyLong_Check(obj);
}
int cgoPyUnicode_Check(PyObject *obj)
{
/* Necessary because Cgo can't do macros */
return PyUnicode_Check(obj);
}
int cgoPyBytes_Check(PyObject *obj)
{
/* Necessary because Cgo can't do macros */
return PyBytes_Check(obj);
}
int cgoPySet_Check(PyObject *obj)
{
/* Necessary because Cgo can't do macros */
return PySet_Check(obj);
}
int cgoPyTuple_Check(PyObject *obj)
{
/* Necessary because Cgo can't do macros */
return PyTuple_Check(obj);
}
int cgoPyDict_Check(PyObject *obj)
{
/* Necessary because Cgo can't do macros */
return PyDict_Check(obj);
}
int cgoPyList_Check(PyObject *obj)
{
/* Necessary because Cgo can't do macros */
return PyList_Check(obj);
}
int cgoPyFunc_Check(PyObject *obj)
{
/* Necessary because Cgo can't do macros */
return PyFunction_Check(obj);
}
int cgoPyMethod_Check(PyObject *obj)
{
/* Necessary because Cgo can't do macros */
return PyMethod_Check(obj);
}
/* Helper to fetch exception classes */
static PyObject *get_exception_class(PyObject *errors, const char *name)
{
PyObject *retval = PyObject_GetAttrString(errors, name);
if (retval == NULL)
PyErr_Format(PyExc_RuntimeError, "starlark_go.errors.%s is not defined", name);
return retval;
}
/* Module initialization */
PyMODINIT_FUNC PyInit_starlark_go(void)
{
PyObject *errors = PyImport_ImportModule("starlark_go.errors");
if (errors == NULL) return NULL;
StarlarkError = get_exception_class(errors, "StarlarkError");
if (StarlarkError == NULL) return NULL;
SyntaxError = get_exception_class(errors, "SyntaxError");
if (SyntaxError == NULL) return NULL;
EvalError = get_exception_class(errors, "EvalError");
if (EvalError == NULL) return NULL;
ResolveError = get_exception_class(errors, "ResolveError");
if (ResolveError == NULL) return NULL;
ResolveErrorItem = get_exception_class(errors, "ResolveErrorItem");
if (ResolveErrorItem == NULL) return NULL;
ConversionToPythonFailed = get_exception_class(errors, "ConversionToPythonFailed");
if (ConversionToPythonFailed == NULL) return NULL;
ConversionToStarlarkFailed =
get_exception_class(errors, "ConversionToStarlarkFailed");
if (ConversionToStarlarkFailed == NULL) return NULL;
PyObject *m;
if (PyType_Ready(&StarlarkType) < 0) return NULL;
m = PyModule_Create(&starlark_go);
if (m == NULL) return NULL;
Py_INCREF(&StarlarkType);
if (PyModule_AddObject(m, "Starlark", (PyObject *)&StarlarkType) < 0) {
Py_DECREF(&StarlarkType);
Py_DECREF(m);
return NULL;
}
return m;
}