pynect 0.2.5 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/binding.gyp +2 -1
- package/dist/config/project.d.ts +1 -0
- package/dist/config/project.d.ts.map +1 -1
- package/dist/config/project.js +3 -2
- package/dist/config/project.js.map +1 -1
- package/dist/core/py-runtime.d.ts +3 -0
- package/dist/core/py-runtime.d.ts.map +1 -1
- package/dist/core/py-runtime.js +20 -3
- package/dist/core/py-runtime.js.map +1 -1
- package/dist/env/project-environment.d.ts.map +1 -1
- package/dist/env/project-environment.js +1 -0
- package/dist/env/project-environment.js.map +1 -1
- package/dist/native/native-addon-loader.js +19 -5
- package/dist/native/native-addon-loader.js.map +1 -1
- package/dist/types/addon.d.ts +4 -0
- package/dist/types/addon.d.ts.map +1 -1
- package/dist/types/addon.js.map +1 -1
- package/package.json +2 -2
- package/prebuilds/darwin-arm64/pynect-prebuild.json +5 -4
- package/prebuilds/darwin-arm64/pynect_addon.node +0 -0
- package/prebuilds/darwin-x64/pynect-prebuild.json +5 -4
- package/prebuilds/darwin-x64/pynect_addon.node +0 -0
- package/prebuilds/linux-arm64/pynect-prebuild.json +5 -4
- package/prebuilds/linux-arm64/pynect_addon.node +0 -0
- package/prebuilds/linux-x64/pynect-prebuild.json +5 -4
- package/prebuilds/linux-x64/pynect_addon.node +0 -0
- package/prebuilds/win32-arm64/pynect-prebuild.json +5 -4
- package/prebuilds/win32-arm64/pynect_addon.node +0 -0
- package/prebuilds/win32-x64/pynect-prebuild.json +5 -4
- package/prebuilds/win32-x64/pynect_addon.node +0 -0
- package/scripts/build-native.js +9 -3
- package/scripts/ensure-native.js +8 -2
- package/scripts/smoke-python-boundary.js +1 -1
- package/src/native/native-addon-loader.ts +26 -7
- package/src/native/pynect_addon.cpp +8 -0
- package/src/native/python_bridge.cpp +105 -40
- package/src/native/python_bridge.h +6 -0
- package/src/native/type_converter.cpp +32 -22
|
@@ -106,14 +106,19 @@ void TypeConverter::clearRegistry() {
|
|
|
106
106
|
|
|
107
107
|
std::string TypeConverter::getTypeName(PyObject* obj) {
|
|
108
108
|
if (!obj) return "NoneType";
|
|
109
|
-
PyObject* type =
|
|
109
|
+
PyObject* type = PyObject_Type(obj);
|
|
110
|
+
if (!type) {
|
|
111
|
+
PyErr_Clear();
|
|
112
|
+
return "unknown";
|
|
113
|
+
}
|
|
114
|
+
PyRef typeRef = PyRef::steal(type);
|
|
110
115
|
PyObject* name = PyObject_GetAttrString(type, "__name__");
|
|
111
116
|
if (!name) {
|
|
112
117
|
PyErr_Clear();
|
|
113
118
|
return "unknown";
|
|
114
119
|
}
|
|
115
120
|
PyRef nameRef = PyRef::steal(name);
|
|
116
|
-
const char* str =
|
|
121
|
+
const char* str = PyUnicode_AsUTF8AndSize(name, nullptr);
|
|
117
122
|
if (!str) {
|
|
118
123
|
PyErr_Clear();
|
|
119
124
|
return "unknown";
|
|
@@ -123,7 +128,12 @@ std::string TypeConverter::getTypeName(PyObject* obj) {
|
|
|
123
128
|
|
|
124
129
|
std::string TypeConverter::getQualifiedTypeName(PyObject* obj) {
|
|
125
130
|
if (!obj) return "NoneType";
|
|
126
|
-
PyObject* type =
|
|
131
|
+
PyObject* type = PyObject_Type(obj);
|
|
132
|
+
if (!type) {
|
|
133
|
+
PyErr_Clear();
|
|
134
|
+
return "unknown";
|
|
135
|
+
}
|
|
136
|
+
PyRef typeRef = PyRef::steal(type);
|
|
127
137
|
|
|
128
138
|
// Try __module__.__qualname__ first
|
|
129
139
|
PyObject* module = PyObject_GetAttrString(type, "__module__");
|
|
@@ -132,13 +142,13 @@ std::string TypeConverter::getQualifiedTypeName(PyObject* obj) {
|
|
|
132
142
|
|
|
133
143
|
std::string result;
|
|
134
144
|
if (module && PyUnicode_Check(module)) {
|
|
135
|
-
const char* mod =
|
|
145
|
+
const char* mod = PyUnicode_AsUTF8AndSize(module, nullptr);
|
|
136
146
|
if (mod) {
|
|
137
147
|
result = std::string(mod) + ".";
|
|
138
148
|
}
|
|
139
149
|
}
|
|
140
150
|
if (qualname && PyUnicode_Check(qualname)) {
|
|
141
|
-
const char* qn =
|
|
151
|
+
const char* qn = PyUnicode_AsUTF8AndSize(qualname, nullptr);
|
|
142
152
|
if (qn) result += qn;
|
|
143
153
|
} else {
|
|
144
154
|
result += getTypeName(obj);
|
|
@@ -249,7 +259,7 @@ SerializedValue TypeConverter::pythonToSerialized(PyObject* obj, int depth) {
|
|
|
249
259
|
if (strObj) {
|
|
250
260
|
PyRef strRef = PyRef::steal(strObj);
|
|
251
261
|
result.format = SerializedFormat::JSON;
|
|
252
|
-
result.jsonData = "\"" + std::string(
|
|
262
|
+
result.jsonData = "\"" + std::string(PyUnicode_AsUTF8AndSize(strObj, nullptr)) + "\"";
|
|
253
263
|
return result;
|
|
254
264
|
}
|
|
255
265
|
}
|
|
@@ -286,7 +296,7 @@ SerializedValue TypeConverter::pythonToSerialized(PyObject* obj, int depth) {
|
|
|
286
296
|
|
|
287
297
|
// String
|
|
288
298
|
if (PyUnicode_Check(obj)) {
|
|
289
|
-
const char* str =
|
|
299
|
+
const char* str = PyUnicode_AsUTF8AndSize(obj, nullptr);
|
|
290
300
|
if (!str) {
|
|
291
301
|
PyErr_Clear();
|
|
292
302
|
result.format = SerializedFormat::JSON;
|
|
@@ -420,13 +430,13 @@ std::string TypeConverter::dictToJson(PyObject* mapping, int depth) {
|
|
|
420
430
|
// Convert key to string
|
|
421
431
|
std::string keyStr;
|
|
422
432
|
if (PyUnicode_Check(key)) {
|
|
423
|
-
const char* k =
|
|
433
|
+
const char* k = PyUnicode_AsUTF8AndSize(key, nullptr);
|
|
424
434
|
if (k) keyStr = k;
|
|
425
435
|
} else {
|
|
426
436
|
PyObject* strKey = PyObject_Str(key);
|
|
427
437
|
if (strKey) {
|
|
428
438
|
PyRef strRef = PyRef::steal(strKey);
|
|
429
|
-
const char* k =
|
|
439
|
+
const char* k = PyUnicode_AsUTF8AndSize(strKey, nullptr);
|
|
430
440
|
if (k) keyStr = k;
|
|
431
441
|
} else {
|
|
432
442
|
PyErr_Clear();
|
|
@@ -470,7 +480,7 @@ SerializedValue TypeConverter::numpyArrayToBuffer(PyObject* array) {
|
|
|
470
480
|
PyObject* dtypeName = PyObject_GetAttrString(dtypeObj, "name");
|
|
471
481
|
if (dtypeName) {
|
|
472
482
|
PyRef nameRef = PyRef::steal(dtypeName);
|
|
473
|
-
const char* name =
|
|
483
|
+
const char* name = PyUnicode_AsUTF8AndSize(dtypeName, nullptr);
|
|
474
484
|
if (name) result.metadata.dtype = name;
|
|
475
485
|
} else { PyErr_Clear(); }
|
|
476
486
|
} else { PyErr_Clear(); }
|
|
@@ -538,7 +548,7 @@ SerializedValue TypeConverter::dataFrameToBuffer(PyObject* df) {
|
|
|
538
548
|
for (Py_ssize_t i = 0; i < ncols; ++i) {
|
|
539
549
|
PyObject* col = PyList_GetItem(colList, i);
|
|
540
550
|
if (col && PyUnicode_Check(col)) {
|
|
541
|
-
const char* colName =
|
|
551
|
+
const char* colName = PyUnicode_AsUTF8AndSize(col, nullptr);
|
|
542
552
|
if (colName) result.metadata.columns.push_back(colName);
|
|
543
553
|
}
|
|
544
554
|
}
|
|
@@ -565,7 +575,7 @@ SerializedValue TypeConverter::dataFrameToBuffer(PyObject* df) {
|
|
|
565
575
|
|
|
566
576
|
if (jsonStr) {
|
|
567
577
|
PyRef jsonRef = PyRef::steal(jsonStr);
|
|
568
|
-
const char* json =
|
|
578
|
+
const char* json = PyUnicode_AsUTF8AndSize(jsonStr, nullptr);
|
|
569
579
|
if (json) {
|
|
570
580
|
result.jsonData = json;
|
|
571
581
|
result.format = SerializedFormat::PANDAS_DATAFRAME;
|
|
@@ -588,7 +598,7 @@ SerializedValue TypeConverter::seriesToBuffer(PyObject* series) {
|
|
|
588
598
|
PyObject* jsonStr = PyObject_CallNoArgs(toJson);
|
|
589
599
|
if (jsonStr) {
|
|
590
600
|
PyRef jsonRef = PyRef::steal(jsonStr);
|
|
591
|
-
const char* json =
|
|
601
|
+
const char* json = PyUnicode_AsUTF8AndSize(jsonStr, nullptr);
|
|
592
602
|
if (json) result.jsonData = json;
|
|
593
603
|
} else { PyErr_Clear(); }
|
|
594
604
|
} else { PyErr_Clear(); }
|
|
@@ -598,7 +608,7 @@ SerializedValue TypeConverter::seriesToBuffer(PyObject* series) {
|
|
|
598
608
|
if (nameObj && nameObj != Py_None) {
|
|
599
609
|
PyRef nameRef = PyRef::steal(nameObj);
|
|
600
610
|
if (PyUnicode_Check(nameObj)) {
|
|
601
|
-
const char* name =
|
|
611
|
+
const char* name = PyUnicode_AsUTF8AndSize(nameObj, nullptr);
|
|
602
612
|
if (name) result.metadata.columns.push_back(name);
|
|
603
613
|
}
|
|
604
614
|
} else if (nameObj) {
|
|
@@ -634,7 +644,7 @@ PyObject* TypeConverter::jsonToPython(const std::string& json) {
|
|
|
634
644
|
}
|
|
635
645
|
PyRef strRef = PyRef::steal(strObj);
|
|
636
646
|
|
|
637
|
-
PyObject* result =
|
|
647
|
+
PyObject* result = PyObject_CallFunctionObjArgs(loads, strObj, nullptr);
|
|
638
648
|
if (!result) {
|
|
639
649
|
PyErr_Clear();
|
|
640
650
|
Py_RETURN_NONE;
|
|
@@ -747,7 +757,7 @@ PyObject* TypeConverter::bufferToNumpyArray(
|
|
|
747
757
|
}
|
|
748
758
|
PyRef shapeListRef = PyRef::steal(shapeList);
|
|
749
759
|
|
|
750
|
-
PyObject* reshaped =
|
|
760
|
+
PyObject* reshaped = PyObject_CallFunctionObjArgs(reshape, shapeList, nullptr);
|
|
751
761
|
if (reshaped) {
|
|
752
762
|
return reshaped;
|
|
753
763
|
}
|
|
@@ -770,7 +780,7 @@ std::string TypeConverter::getRepr(PyObject* obj) {
|
|
|
770
780
|
return "<error getting repr>";
|
|
771
781
|
}
|
|
772
782
|
PyRef reprRef = PyRef::steal(repr);
|
|
773
|
-
const char* str =
|
|
783
|
+
const char* str = PyUnicode_AsUTF8AndSize(repr, nullptr);
|
|
774
784
|
if (!str) {
|
|
775
785
|
PyErr_Clear();
|
|
776
786
|
return "<encoding error>";
|
|
@@ -786,7 +796,7 @@ std::string TypeConverter::getStr(PyObject* obj) {
|
|
|
786
796
|
return "<error>";
|
|
787
797
|
}
|
|
788
798
|
PyRef strRef = PyRef::steal(str);
|
|
789
|
-
const char* cstr =
|
|
799
|
+
const char* cstr = PyUnicode_AsUTF8AndSize(str, nullptr);
|
|
790
800
|
if (!cstr) {
|
|
791
801
|
PyErr_Clear();
|
|
792
802
|
return "";
|
|
@@ -815,7 +825,7 @@ std::tuple<std::string, std::string, std::string> TypeConverter::captureExceptio
|
|
|
815
825
|
PyObject* name = PyObject_GetAttrString(excType, "__name__");
|
|
816
826
|
if (name) {
|
|
817
827
|
PyRef nameRef = PyRef::steal(name);
|
|
818
|
-
const char* n =
|
|
828
|
+
const char* n = PyUnicode_AsUTF8AndSize(name, nullptr);
|
|
819
829
|
if (n) typeName = n;
|
|
820
830
|
} else { PyErr_Clear(); }
|
|
821
831
|
}
|
|
@@ -825,7 +835,7 @@ std::tuple<std::string, std::string, std::string> TypeConverter::captureExceptio
|
|
|
825
835
|
PyObject* str = PyObject_Str(excValue);
|
|
826
836
|
if (str) {
|
|
827
837
|
PyRef strRef = PyRef::steal(str);
|
|
828
|
-
const char* s =
|
|
838
|
+
const char* s = PyUnicode_AsUTF8AndSize(str, nullptr);
|
|
829
839
|
if (s) message = s;
|
|
830
840
|
} else { PyErr_Clear(); }
|
|
831
841
|
}
|
|
@@ -838,7 +848,7 @@ std::tuple<std::string, std::string, std::string> TypeConverter::captureExceptio
|
|
|
838
848
|
PyObject* formatTb = PyObject_GetAttrString(tbModule, "format_tb");
|
|
839
849
|
if (formatTb) {
|
|
840
850
|
PyRef formatTbRef = PyRef::steal(formatTb);
|
|
841
|
-
PyObject* tbLines =
|
|
851
|
+
PyObject* tbLines = PyObject_CallFunctionObjArgs(formatTb, excTb, nullptr);
|
|
842
852
|
if (tbLines) {
|
|
843
853
|
PyRef tbLinesRef = PyRef::steal(tbLines);
|
|
844
854
|
std::ostringstream oss;
|
|
@@ -847,7 +857,7 @@ std::tuple<std::string, std::string, std::string> TypeConverter::captureExceptio
|
|
|
847
857
|
for (Py_ssize_t i = 0; i < nlines; ++i) {
|
|
848
858
|
PyObject* line = PyList_GetItem(tbLines, i);
|
|
849
859
|
if (line && PyUnicode_Check(line)) {
|
|
850
|
-
const char* l =
|
|
860
|
+
const char* l = PyUnicode_AsUTF8AndSize(line, nullptr);
|
|
851
861
|
if (l) oss << l;
|
|
852
862
|
}
|
|
853
863
|
}
|