| 1032 | |
| 1033 | protected: |
| 1034 | Status Init(MemoryPool* pool) override { |
| 1035 | RETURN_NOT_OK((StructConverter<PyConverter, PyConverterTrait>::Init(pool))); |
| 1036 | |
| 1037 | // This implementation will check the child values before appending itself, |
| 1038 | // so no rewind is necessary |
| 1039 | this->rewind_on_overflow_ = false; |
| 1040 | |
| 1041 | // Store the field names as a PyObjects for dict matching |
| 1042 | num_fields_ = this->struct_type_->num_fields(); |
| 1043 | bytes_field_names_.reset(PyList_New(num_fields_)); |
| 1044 | unicode_field_names_.reset(PyList_New(num_fields_)); |
| 1045 | RETURN_IF_PYERROR(); |
| 1046 | |
| 1047 | for (int i = 0; i < num_fields_; i++) { |
| 1048 | const auto& field_name = this->struct_type_->field(i)->name(); |
| 1049 | PyObject* bytes = PyBytes_FromStringAndSize(field_name.c_str(), field_name.size()); |
| 1050 | PyObject* unicode = |
| 1051 | PyUnicode_FromStringAndSize(field_name.c_str(), field_name.size()); |
| 1052 | RETURN_IF_PYERROR(); |
| 1053 | PyList_SET_ITEM(bytes_field_names_.obj(), i, bytes); |
| 1054 | PyList_SET_ITEM(unicode_field_names_.obj(), i, unicode); |
| 1055 | } |
| 1056 | return Status::OK(); |
| 1057 | } |
| 1058 | |
| 1059 | Status InferInputKind(PyObject* value) { |
| 1060 | // Infer input object's type, note that heterogeneous sequences are not allowed |