Skip to content

Commit 8afe37d

Browse files
committed
[GR-54196] Fixes for elasticsearch
PullRequest: graalpython/3339
2 parents 6710a79 + f6aa6c7 commit 8afe37d

File tree

7 files changed

+334
-32
lines changed

7 files changed

+334
-32
lines changed

graalpython/com.oracle.graal.python.cext/src/dictobject.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5528,6 +5528,10 @@ _PyObject_FreeInstanceAttributes(PyObject *self)
55285528
PyObject *
55295529
PyObject_GenericGetDict(PyObject *obj, void *context)
55305530
{
5531+
// GraalPy change: upcall for managed
5532+
if (points_to_py_handle_space(obj)) {
5533+
return GraalPyTruffleObject_GenericGetDict(obj);
5534+
}
55315535
PyObject *dict;
55325536
// GraalPy change: we don't have inlined values in managed dict
55335537
PyObject **dictptr = _PyObject_GetDictPtr(obj);

graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_object.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,6 +1595,26 @@ def __hash__(self):
15951595
cmpfunc=unhandled_error_compare
15961596
)
15971597

1598+
object_with_attributes = MyObject()
1599+
object_with_attributes.foo = 1
1600+
1601+
test_PyObject_GenericGetDict = CPyExtFunction(
1602+
lambda args: args[0].__dict__,
1603+
lambda: (
1604+
(TestObjectFunctions.object_with_attributes,),
1605+
),
1606+
code='''
1607+
static PyObject* wrap_PyObject_GenericGetDict(PyObject* obj) {
1608+
return PyObject_GenericGetDict(obj, NULL);
1609+
}
1610+
''',
1611+
arguments=["PyObject* obj"],
1612+
resultspec="O",
1613+
argspec="O",
1614+
callfunction="wrap_PyObject_GenericGetDict",
1615+
cmpfunc=unhandled_error_compare
1616+
)
1617+
15981618

15991619
class TestPickleNative:
16001620
def test_pickle_native(self):

graalpython/com.oracle.graal.python.test/src/tests/test_json.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
22
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33
#
44
# The Universal Permissive License (UPL), Version 1.0
@@ -37,6 +37,8 @@
3737
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3838
# SOFTWARE.
3939

40+
import json
41+
import os
4042
import unittest
4143

4244
BIGINT_JSON_DATA = '''
@@ -58,16 +60,13 @@
5860

5961
class JsonTest(unittest.TestCase):
6062
def test_dump(self):
61-
import json
62-
import os
6363
cwd = os.getcwd()
6464
new_file_path = os.path.join(cwd, 'myFile.json')
6565
json.dump(['a', 'b', 'c'], open(new_file_path, 'w'))
6666
assert json.load(open(new_file_path)) == ['a', 'b', 'c']
6767
os.remove(new_file_path)
6868

69-
def test_load_bigin(self):
70-
import json
69+
def test_load_bigint(self):
7170
data = json.loads(BIGINT_JSON_DATA)
7271
assert "int_values" in data
7372
int_values_ = data['int_values']
@@ -83,3 +82,9 @@ def test_load_bigin(self):
8382
1521583201347000000,
8483
10,
8584
}
85+
86+
def test_encode_surrogate(self):
87+
s = json.dumps({'foo': "\uda6a"})
88+
assert s == '{"foo": "\\uda6a"}'
89+
s = json.dumps({'foo': "\uda6a"}, ensure_ascii=False)
90+
assert s == '{"foo": "\uda6a"}'

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextObjectBuiltins.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
import com.oracle.graal.python.nodes.call.CallNode;
127127
import com.oracle.graal.python.nodes.classes.IsSubtypeNode;
128128
import com.oracle.graal.python.nodes.object.GetClassNode;
129+
import com.oracle.graal.python.nodes.object.GetOrCreateDictNode;
129130
import com.oracle.graal.python.nodes.util.CannotCastException;
130131
import com.oracle.graal.python.nodes.util.CastToJavaStringNode;
131132
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
@@ -739,4 +740,14 @@ static Object dir(Object object,
739740
return dir.execute(null, inliningTarget, object);
740741
}
741742
}
743+
744+
@CApiBuiltin(ret = PyObjectTransfer, args = {PyObject}, call = Ignored)
745+
abstract static class PyTruffleObject_GenericGetDict extends CApiUnaryBuiltinNode {
746+
@Specialization
747+
static Object getDict(Object object,
748+
@Bind("this") Node inliningTarget,
749+
@Cached GetOrCreateDictNode getDict) {
750+
return getDict.execute(inliningTarget, object);
751+
}
752+
}
742753
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/json/JSONUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -102,7 +102,7 @@ static void appendStringUncached(TruffleString ts, TruffleStringBuilderUTF32 bui
102102
appendEscapedUtf16Uncached((char) (0xDC00 + ((c - 0x10000) & 0x3FF)), builder);
103103
}
104104
} else {
105-
builder.appendCodePointUncached(c);
105+
builder.appendCodePointUncached(c, 1, true);
106106
}
107107
break;
108108
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/PCode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,6 @@ private static void setRootNodeFileName(RootNode rootNode, TruffleString filenam
225225
@TruffleBoundary
226226
public static TruffleString extractFileName(RootNode rootNode) {
227227
RootNode funcRootNode = rootNodeForExtraction(rootNode);
228-
SourceSection src = funcRootNode.getSourceSection();
229228

230229
PythonContext context = PythonContext.get(rootNode);
231230
TruffleString filename;
@@ -242,6 +241,7 @@ public static TruffleString extractFileName(RootNode rootNode) {
242241
// for compiled modules, _imp._fix_co_filename will set the filename
243242
return filename;
244243
}
244+
SourceSection src = funcRootNode.getSourceSection();
245245
String jFilename;
246246
if (src != null) {
247247
jFilename = getSourceSectionFileName(src);

0 commit comments

Comments
 (0)