| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,6 +3,7 @@ | |||
| 3 | 3 | ||
| 4 | 4 | typedef PyObject * identifier; | |
| 5 | 5 | typedef PyObject * string; | |
| 6 | + typedef PyObject * bytes; | ||
| 6 | 7 | typedef PyObject * object; | |
| 7 | 8 | ||
| 8 | 9 | /* It would be nice if the code generated by asdl_c.py was completely | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,4 @@ | |||
| 1 | - -- ASDL's four builtin types are identifier, int, string, object | ||
| 1 | + -- ASDL's five builtin types are identifier, int, string, bytes, object | ||
| 2 | 2 | ||
| 3 | 3 | module Python | |
| 4 | 4 | { | |
@@ -67,7 +67,7 @@ module Python | |||
| 67 | 67 | expr? starargs, expr? kwargs) | |
| 68 | 68 | | Num(object n) -- a number as a PyObject. | |
| 69 | 69 | | Str(string s) -- need to specify raw, unicode, etc? | |
| 70 | - | Bytes(string s) | ||
| 70 | + | Bytes(bytes s) | ||
| 71 | 71 | | Ellipsis | |
| 72 | 72 | -- other literals? bools? | |
| 73 | 73 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -228,7 +228,7 @@ def p_field_5(self, type_): | |||
| 228 | 228 | " field ::= Id ? " | |
| 229 | 229 | return Field(type[0], opt=True) | |
| 230 | 230 | ||
| 231 | - builtin_types = ("identifier", "string", "int", "bool", "object") | ||
| 231 | + builtin_types = ("identifier", "string", "bytes", "int", "bool", "object") | ||
| 232 | 232 | ||
| 233 | 233 | # below is a collection of classes to capture the AST of an AST :-) | |
| 234 | 234 | # not sure if any of the methods are useful yet, but I'm adding them | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -776,6 +776,7 @@ def visitModule(self, mod): | |||
| 776 | 776 | } | |
| 777 | 777 | #define ast2obj_identifier ast2obj_object | |
| 778 | 778 | #define ast2obj_string ast2obj_object | |
| 779 | + #define ast2obj_bytes ast2obj_object | ||
| 779 | 780 | ||
| 780 | 781 | static PyObject* ast2obj_int(long b) | |
| 781 | 782 | { | |
@@ -813,6 +814,15 @@ def visitModule(self, mod): | |||
| 813 | 814 | return obj2ast_object(obj, out, arena); | |
| 814 | 815 | } | |
| 815 | 816 | ||
| 817 | + static int obj2ast_bytes(PyObject* obj, PyObject** out, PyArena* arena) | ||
| 818 | + { | ||
| 819 | + if (!PyBytes_CheckExact(obj)) { | ||
| 820 | + PyErr_SetString(PyExc_TypeError, "AST bytes must be of type bytes"); | ||
| 821 | + return 1; | ||
| 822 | + } | ||
| 823 | + return obj2ast_object(obj, out, arena); | ||
| 824 | + } | ||
| 825 | + | ||
| 816 | 826 | static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) | |
| 817 | 827 | { | |
| 818 | 828 | int i; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -573,6 +573,7 @@ static PyObject* ast2obj_object(void *o) | |||
| 573 | 573 | } | |
| 574 | 574 | #define ast2obj_identifier ast2obj_object | |
| 575 | 575 | #define ast2obj_string ast2obj_object | |
| 576 | + #define ast2obj_bytes ast2obj_object | ||
| 576 | 577 | ||
| 577 | 578 | static PyObject* ast2obj_int(long b) | |
| 578 | 579 | { | |
@@ -610,6 +611,15 @@ static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena) | |||
| 610 | 611 | return obj2ast_object(obj, out, arena); | |
| 611 | 612 | } | |
| 612 | 613 | ||
| 614 | + static int obj2ast_bytes(PyObject* obj, PyObject** out, PyArena* arena) | ||
| 615 | + { | ||
| 616 | + if (!PyBytes_CheckExact(obj)) { | ||
| 617 | + PyErr_SetString(PyExc_TypeError, "AST bytes must be of type bytes"); | ||
| 618 | + return 1; | ||
| 619 | + } | ||
| 620 | + return obj2ast_object(obj, out, arena); | ||
| 621 | + } | ||
| 622 | + | ||
| 613 | 623 | static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) | |
| 614 | 624 | { | |
| 615 | 625 | int i; | |
@@ -1773,7 +1783,7 @@ Str(string s, int lineno, int col_offset, PyArena *arena) | |||
| 1773 | 1783 | } | |
| 1774 | 1784 | ||
| 1775 | 1785 | expr_ty | |
| 1776 | - Bytes(string s, int lineno, int col_offset, PyArena *arena) | ||
| 1786 | + Bytes(bytes s, int lineno, int col_offset, PyArena *arena) | ||
| 1777 | 1787 | { | |
| 1778 | 1788 | expr_ty p; | |
| 1779 | 1789 | if (!s) { | |
@@ -2804,7 +2814,7 @@ ast2obj_expr(void* _o) | |||
| 2804 | 2814 | case Bytes_kind: | |
| 2805 | 2815 | result = PyType_GenericNew(Bytes_type, NULL, NULL); | |
| 2806 | 2816 | if (!result) goto failed; | |
| 2807 | - value = ast2obj_string(o->v.Bytes.s); | ||
| 2817 | + value = ast2obj_bytes(o->v.Bytes.s); | ||
| 2808 | 2818 | if (!value) goto failed; | |
| 2809 | 2819 | if (PyObject_SetAttrString(result, "s", value) == -1) | |
| 2810 | 2820 | goto failed; | |
@@ -5509,13 +5519,13 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) | |||
| 5509 | 5519 | return 1; | |
| 5510 | 5520 | } | |
| 5511 | 5521 | if (isinstance) { | |
| 5512 | - string s; | ||
| 5522 | + bytes s; | ||
| 5513 | 5523 | ||
| 5514 | 5524 | if (PyObject_HasAttrString(obj, "s")) { | |
| 5515 | 5525 | int res; | |
| 5516 | 5526 | tmp = PyObject_GetAttrString(obj, "s"); | |
| 5517 | 5527 | if (tmp == NULL) goto failed; | |
| 5518 | - res = obj2ast_string(tmp, &s, arena); | ||
| 5528 | + res = obj2ast_bytes(tmp, &s, arena); | ||
| 5519 | 5529 | if (res != 0) goto failed; | |
| 5520 | 5530 | Py_XDECREF(tmp); | |
| 5521 | 5531 | tmp = NULL; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments