@@ -51,7 +51,7 @@ PyJsonic_JsonicType_dealloc(
5151) {
5252 jsonic_free_addr (self -> node );
5353 jsonic_free_addr (self -> from );
54- free (self -> json );
54+ Py_CLEAR (self -> json );
5555 Py_TYPE (self )-> tp_free ((PyObject * ) self );
5656}
5757
@@ -61,18 +61,16 @@ PyJsonic_JsonicType_init(
6161 PyObject * args ,
6262 PyObject * kwds
6363) {
64- char * json ;
6564 int is_root = 1 ;
66- if (!PyArg_ParseTuple (args , "s |i" , & json , & is_root )) {
65+ if (!PyArg_ParseTuple (args , "U |i" , & self -> json , & is_root )) {
6766 return NULL ;
6867 }
6968
70- self -> attr_json = PyUnicode_FromString (json );
71- self -> json = malloc (strlen (json )+ 1 );
72- strcpy (self -> json , json );
69+ Py_INCREF (self -> json );
70+ self -> json_ascii = PyBytes_AS_STRING (PyUnicode_AsEncodedString (self -> json , "utf-8" , "asdasdads" ));
7371
7472 if (is_root ) {
75- self -> node = jsonic_get_root (self -> json );
73+ self -> node = jsonic_get_root (self -> json_ascii );
7674 self -> from = NULL ;
7775 self -> json_type = self -> node -> type ;
7876 } else {
@@ -125,7 +123,7 @@ PyJsonic_JsonicType_key(
125123 }
126124
127125 jsonic_node_t * node = jsonic_object_get (
128- self -> json ,
126+ self -> json_ascii ,
129127 self -> node ,
130128 key
131129 );
@@ -139,7 +137,7 @@ PyJsonic_JsonicType_key(
139137 if (node -> type == JSONIC_NODE_TYPE_OBJECT ) {
140138 pyNode = PyObject_CallObject (
141139 (PyObject * ) & PyJsonic_JsonicType ,
142- Py_BuildValue ("(si)" , self -> json , 0 )
140+ Py_BuildValue ("(si)" , self -> json_ascii , 0 )
143141 );
144142
145143 ((PyJsonic_JsonicObject * ) pyNode )-> node = node ;
@@ -149,7 +147,7 @@ PyJsonic_JsonicType_key(
149147 } else if (node -> type == JSONIC_NODE_TYPE_ARRAY ) {
150148 pyNode = PyObject_CallObject (
151149 (PyObject * ) & PyJsonic_JsonicType ,
152- Py_BuildValue ("(si)" , self -> json , 0 )
150+ Py_BuildValue ("(si)" , self -> json_ascii , 0 )
153151 );
154152
155153 ((PyJsonic_JsonicObject * ) pyNode )-> node = node ;
@@ -181,7 +179,7 @@ PyJsonic_JsonicType_item(
181179 }
182180
183181 jsonic_node_t * node = jsonic_array_get (
184- self -> json ,
182+ self -> json_ascii ,
185183 self -> node ,
186184 index
187185 );
@@ -195,7 +193,7 @@ PyJsonic_JsonicType_item(
195193 if (node -> type == JSONIC_NODE_TYPE_OBJECT ) {
196194 pyNode = PyObject_CallObject (
197195 (PyObject * ) & PyJsonic_JsonicType ,
198- Py_BuildValue ("(s)" , self -> json )
196+ Py_BuildValue ("(s)" , self -> json_ascii )
199197 );
200198
201199 ((PyJsonic_JsonicObject * ) pyNode )-> node = node ;
@@ -204,7 +202,7 @@ PyJsonic_JsonicType_item(
204202 } else if (node -> type == JSONIC_NODE_TYPE_ARRAY ) {
205203 pyNode = PyObject_CallObject (
206204 (PyObject * ) & PyJsonic_JsonicType ,
207- Py_BuildValue ("(s)" , self -> json )
205+ Py_BuildValue ("(s)" , self -> json_ascii )
208206 );
209207
210208 ((PyJsonic_JsonicObject * ) pyNode )-> node = node ;
@@ -230,7 +228,7 @@ PyJsonic_JsonicType_len(
230228 PyObject * kwds
231229) {
232230 unsigned int length = jsonic_array_length (
233- self -> json ,
231+ self -> json_ascii ,
234232 self -> node
235233 );
236234
@@ -249,7 +247,7 @@ PyJsonic_JsonicType_iterItem(
249247 }
250248
251249 jsonic_node_t * node = jsonic_array_iter (
252- self -> json ,
250+ self -> json_ascii ,
253251 self -> node ,
254252 self -> from ,
255253 index
@@ -267,7 +265,7 @@ PyJsonic_JsonicType_iterItem(
267265 if (node -> type == JSONIC_NODE_TYPE_OBJECT ) {
268266 pyNode = PyObject_CallObject (
269267 (PyObject * ) & PyJsonic_JsonicType ,
270- Py_BuildValue ("(s)" , self -> json )
268+ Py_BuildValue ("(s)" , self -> json_ascii )
271269 );
272270
273271 ((PyJsonic_JsonicObject * ) pyNode )-> node = node ;
@@ -276,7 +274,7 @@ PyJsonic_JsonicType_iterItem(
276274 } else if (node -> type == JSONIC_NODE_TYPE_ARRAY ) {
277275 pyNode = PyObject_CallObject (
278276 (PyObject * ) & PyJsonic_JsonicType ,
279- Py_BuildValue ("(s)" , self -> json )
277+ Py_BuildValue ("(s)" , self -> json_ascii )
280278 );
281279
282280 ((PyJsonic_JsonicObject * ) pyNode )-> node = node ;
@@ -307,7 +305,7 @@ PyJsonic_JsonicType_iterKey(
307305 }
308306
309307 jsonic_node_t * node = jsonic_object_iter (
310- self -> json ,
308+ self -> json_ascii ,
311309 self -> node ,
312310 self -> from ,
313311 key
@@ -325,7 +323,7 @@ PyJsonic_JsonicType_iterKey(
325323 if (node -> type == JSONIC_NODE_TYPE_OBJECT ) {
326324 pyNode = PyObject_CallObject (
327325 (PyObject * ) & PyJsonic_JsonicType ,
328- Py_BuildValue ("(s)" , self -> json )
326+ Py_BuildValue ("(s)" , self -> json_ascii )
329327 );
330328
331329 ((PyJsonic_JsonicObject * ) pyNode )-> node = node ;
@@ -334,7 +332,7 @@ PyJsonic_JsonicType_iterKey(
334332 } else if (node -> type == JSONIC_NODE_TYPE_ARRAY ) {
335333 pyNode = PyObject_CallObject (
336334 (PyObject * ) & PyJsonic_JsonicType ,
337- Py_BuildValue ("(s)" , self -> json )
335+ Py_BuildValue ("(s)" , self -> json_ascii )
338336 );
339337
340338 ((PyJsonic_JsonicObject * ) pyNode )-> node = node ;
@@ -360,7 +358,7 @@ PyJsonic_JsonicType_reset(
360358 PyObject * kwds
361359) {
362360 self -> from = malloc (sizeof (jsonic_node_t ));
363- memcpy (self -> from , jsonic_get_root (self -> json ), sizeof (jsonic_node_t ));
361+ memcpy (self -> from , jsonic_get_root (self -> json_ascii ), sizeof (jsonic_node_t ));
364362
365363 Py_RETURN_NONE ;
366364}
0 commit comments