Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't set unspecified in configure_starlark #35

Merged
merged 1 commit into from
Apr 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions starlark.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#include "starlark.h"

/* Declarations for object methods written in Go */
void ConfigureStarlark(unsigned int allowSet, unsigned int allowGlobalReassign,
unsigned int allowRecursion);

void ConfigureStarlark(int allowSet, int allowGlobalReassign,
int allowRecursion);
Starlark *Starlark_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
void Starlark_dealloc(Starlark *self);
PyObject *Starlark_eval(Starlark *self, PyObject *args);
Expand All @@ -22,7 +21,8 @@ static char *configure_keywords[] = {"allow_set", "allow_global_reassign",
"allow_recursion", NULL};

PyObject *configure_starlark(PyObject *self, PyObject *args, PyObject *kwargs) {
unsigned int allow_set = 0, allow_global_reassign = 0, allow_recursion = 0;
/* ConfigureStarlark interprets -1 as "unspecified" */
int allow_set = -1, allow_global_reassign = -1, allow_recursion = -1;

if (PyArg_ParseTupleAndKeywords(args, kwargs, "|$ppp", configure_keywords,
&allow_set, &allow_global_reassign,
Expand Down
24 changes: 14 additions & 10 deletions starlark.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,27 @@ func init() {
}

//export ConfigureStarlark
func ConfigureStarlark(allowSet C.uint, allowGlobalReassign C.uint, allowRecursion C.uint) {
if allowSet > 0 {
resolve.AllowSet = true
} else {
func ConfigureStarlark(allowSet C.int, allowGlobalReassign C.int, allowRecursion C.int) {
// Ignore input values other than 0 or 1 and leave current value in place
switch allowSet {
case 0:
resolve.AllowSet = false
case 1:
resolve.AllowSet = true
}

if allowGlobalReassign > 0 {
resolve.AllowGlobalReassign = true
} else {
switch allowGlobalReassign {
case 0:
resolve.AllowGlobalReassign = false
case 1:
resolve.AllowGlobalReassign = true
}

if allowRecursion > 0 {
resolve.AllowRecursion = true
} else {
switch allowRecursion {
case 0:
resolve.AllowRecursion = false
case 1:
resolve.AllowRecursion = true
}
}

Expand Down