Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pybison
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
pybison
Commits
22f2e1c4
Commit
22f2e1c4
authored
Jan 27, 2012
by
Sander Mathijs van Veen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle init_attr failure and added debug_refcnt macro.
parent
bc4b291c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
8 deletions
+14
-8
src/c/bison_callback.c
src/c/bison_callback.c
+14
-8
No files found.
src/c/bison_callback.c
View file @
22f2e1c4
...
@@ -44,9 +44,15 @@ static PyObject *py_attr_close_name;
...
@@ -44,9 +44,15 @@ static PyObject *py_attr_close_name;
// Construct attribute names (only the first time)
// Construct attribute names (only the first time)
// TODO: where do we Py_DECREF(handle_name) ??
// TODO: where do we Py_DECREF(handle_name) ??
#define INIT_ATTR(variable, name) \
#define INIT_ATTR(variable, name
, failure
) \
if (unlikely(!variable)) { \
if (unlikely(!variable)) { \
variable = PyString_FromString(name); \
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,
...
@@ -80,8 +86,8 @@ PyObject* py_callback(PyObject *parser, char *target, int option, int nargs,
va_end
(
ap
);
va_end
(
ap
);
INIT_ATTR
(
py_attr_handle_name
,
"_handle"
);
INIT_ATTR
(
py_attr_handle_name
,
"_handle"
,
return
NULL
);
INIT_ATTR
(
py_attr_hook_handler_name
,
"hook_handler"
);
INIT_ATTR
(
py_attr_hook_handler_name
,
"hook_handler"
,
return
NULL
);
// Call the handler with the arguments
// Call the handler with the arguments
PyObject
*
handle
=
PyObject_GetAttr
(
parser
,
py_attr_handle_name
);
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)
...
@@ -126,11 +132,11 @@ void py_input(PyObject *parser, char *buf, int *result, int max_size)
PyObject
*
handle
,
*
arglist
,
*
res
;
PyObject
*
handle
,
*
arglist
,
*
res
;
char
*
bufstr
;
char
*
bufstr
;
INIT_ATTR
(
py_attr_hook_read_after_name
,
"hook_read_after"
);
INIT_ATTR
(
py_attr_hook_read_after_name
,
"hook_read_after"
,
return
);
INIT_ATTR
(
py_attr_hook_read_before_name
,
"hook_read_before"
);
INIT_ATTR
(
py_attr_hook_read_before_name
,
"hook_read_before"
,
return
);
INIT_ATTR
(
py_attr_read_name
,
"read"
);
INIT_ATTR
(
py_attr_read_name
,
"read"
,
return
);
INIT_ATTR
(
py_attr_file_name
,
"file"
);
INIT_ATTR
(
py_attr_file_name
,
"file"
,
return
);
INIT_ATTR
(
py_attr_close_name
,
"close"
);
INIT_ATTR
(
py_attr_close_name
,
"close"
,
return
);
// Check if the "hook_READ_BEFORE" callback exists
// Check if the "hook_READ_BEFORE" callback exists
if
(
PyObject_HasAttr
(
parser
,
py_attr_hook_read_before_name
))
if
(
PyObject_HasAttr
(
parser
,
py_attr_hook_read_before_name
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment