Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pybison
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Taddeüs Kroes
pybison
Commits
22f2e1c4
Commit
22f2e1c4
authored
13 years ago
by
Sander Mathijs van Veen
Browse files
Options
Downloads
Patches
Plain Diff
Handle init_attr failure and added debug_refcnt macro.
parent
bc4b291c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/c/bison_callback.c
+14
-8
14 additions, 8 deletions
src/c/bison_callback.c
with
14 additions
and
8 deletions
src/c/bison_callback.c
+
14
−
8
View file @
22f2e1c4
...
...
@@ -44,9 +44,15 @@ static PyObject *py_attr_close_name;
// Construct attribute names (only the first time)
// TODO: where do we Py_DECREF(handle_name) ??
#define INIT_ATTR(variable, name) \
#define INIT_ATTR(variable, name
, failure
) \
if (unlikely(!variable)) { \
variable = PyString_FromString(name); \
if (!variable) failure; \
}
#define debug_refcnt(variable, count) { \
printf(#variable ": %d\n", Py_REFCNT(variable)); \
assert(Py_REFCNT(variable) == count); \
}
/*
...
...
@@ -80,8 +86,8 @@ PyObject* py_callback(PyObject *parser, char *target, int option, int nargs,
va_end
(
ap
);
INIT_ATTR
(
py_attr_handle_name
,
"_handle"
);
INIT_ATTR
(
py_attr_hook_handler_name
,
"hook_handler"
);
INIT_ATTR
(
py_attr_handle_name
,
"_handle"
,
return
NULL
);
INIT_ATTR
(
py_attr_hook_handler_name
,
"hook_handler"
,
return
NULL
);
// Call the handler with the arguments
PyObject
*
handle
=
PyObject_GetAttr
(
parser
,
py_attr_handle_name
);
...
...
@@ -126,11 +132,11 @@ void py_input(PyObject *parser, char *buf, int *result, int max_size)
PyObject
*
handle
,
*
arglist
,
*
res
;
char
*
bufstr
;
INIT_ATTR
(
py_attr_hook_read_after_name
,
"hook_read_after"
);
INIT_ATTR
(
py_attr_hook_read_before_name
,
"hook_read_before"
);
INIT_ATTR
(
py_attr_read_name
,
"read"
);
INIT_ATTR
(
py_attr_file_name
,
"file"
);
INIT_ATTR
(
py_attr_close_name
,
"close"
);
INIT_ATTR
(
py_attr_hook_read_after_name
,
"hook_read_after"
,
return
);
INIT_ATTR
(
py_attr_hook_read_before_name
,
"hook_read_before"
,
return
);
INIT_ATTR
(
py_attr_read_name
,
"read"
,
return
);
INIT_ATTR
(
py_attr_file_name
,
"file"
,
return
);
INIT_ATTR
(
py_attr_close_name
,
"close"
,
return
);
// Check if the "hook_READ_BEFORE" callback exists
if
(
PyObject_HasAttr
(
parser
,
py_attr_hook_read_before_name
))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment