Skip to content

Commit 313b50f

Browse files
committed
Fix conversion for referenced types
1 parent 8bb1749 commit 313b50f

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

libasn1compiler/asn1c_Py.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,7 @@ int asn1c_lang_Py_type_SIMPLE_TYPE(arg_t *arg) {
10031003
PY_GEN_END_FUNC();
10041004

10051005
PY_GEN_ASNTYPE_FROMPY_INLINE(name);
1006+
OUT("PY_IMPL_FROMPY_COMPAT(%s, pObj, pDst);\n", name);
10061007
OUT("PyCompatLong_Check(pObj, -1);\n");
10071008
if (asn1c_type_fits_long(arg, expr) == FL_FITS_UNSIGN) {
10081009
OUT("*pDst = (%s)PyCompatLong_AsSize_t(pObj);\n", name);
@@ -1026,8 +1027,7 @@ int asn1c_lang_Py_type_SIMPLE_TYPE(arg_t *arg) {
10261027
PY_GEN_END_FUNC();
10271028

10281029
PY_GEN_ASNTYPE_FROMPY_INLINE(name);
1029-
// we actually don't need this
1030-
// OUT("PyCompatBool_Check(pObj, -1);\n");
1030+
OUT("PY_IMPL_FROMPY_COMPAT(%s, pObj, pDst);\n", name);
10311031
OUT("*pDst = (%s_t)PyCompatBool_AsLong(pObj);\n", name);
10321032
OUT("return 0;\n");
10331033
PY_GEN_END_FUNC();
@@ -1047,6 +1047,7 @@ int asn1c_lang_Py_type_SIMPLE_TYPE(arg_t *arg) {
10471047
PY_GEN_END_FUNC();
10481048

10491049
PY_GEN_ASNTYPE_FROMPY_INLINE(name);
1050+
OUT("PY_IMPL_FROMPY_COMPAT(%s, pObj, pDst);\n", name);
10501051
OUT("return PyCompatFloat_FromObject(pObj, (void *)pDst, "
10511052
"%d);\n",
10521053
is_float32);
@@ -1078,6 +1079,7 @@ int asn1c_lang_Py_type_SIMPLE_TYPE(arg_t *arg) {
10781079
}
10791080
case ASN_BASIC_BIT_STRING: {
10801081
PY_GEN_ASNTYPE_FROMPY_INLINE(name);
1082+
OUT("PY_IMPL_FROMPY_COMPAT(%s, pObj, pDst);\n", name);
10811083
if (el_count) {
10821084
OUT("return PyCompatFlag_FromObject(pObj, &pDst->buf, "
10831085
"&pDst->size);\n");
@@ -1150,6 +1152,7 @@ int asn1c_lang_Py_type_SIMPLE_TYPE(arg_t *arg) {
11501152
case ASN_BASIC_OBJECT_IDENTIFIER: { /* for now, use special
11511153
converter*/
11521154
PY_GEN_ASNTYPE_FROMPY_INLINE(name);
1155+
OUT("PY_IMPL_FROMPY_COMPAT(%s, pObj, pDst);\n", name);
11531156
OUT("return PyCompatOID_FromUnicode(pObj, pDst);");
11541157
PY_GEN_END_FUNC();
11551158

@@ -1170,6 +1173,7 @@ int asn1c_lang_Py_type_SIMPLE_TYPE(arg_t *arg) {
11701173
}
11711174
case ASN_BASIC_RELATIVE_OID: { /* for now, use special converter*/
11721175
PY_GEN_ASNTYPE_FROMPY_INLINE(name);
1176+
OUT("PY_IMPL_FROMPY_COMPAT(%s, pObj, pDst);\n", name);
11731177
OUT("return PyCompatRelativeOID_FromUnicode(pObj, pDst);");
11741178
PY_GEN_END_FUNC();
11751179

@@ -1193,6 +1197,7 @@ int asn1c_lang_Py_type_SIMPLE_TYPE(arg_t *arg) {
11931197
case ASN_TYPE_ANY:
11941198
case ASN_BASIC_OCTET_STRING: {
11951199
PY_GEN_ASNTYPE_FROMPY_INLINE(name);
1200+
OUT("PY_IMPL_FROMPY_COMPAT(%s, pObj, pDst);\n", name);
11961201
OUT("return PyCompatBytes_ToStringAndSize(pObj, &pDst->buf, "
11971202
"&pDst->size);");
11981203
PY_GEN_END_FUNC();
@@ -1228,6 +1233,7 @@ int asn1c_lang_Py_type_SIMPLE_TYPE(arg_t *arg) {
12281233
case ASN_STRING_VideotexString:
12291234
case ASN_STRING_ObjectDescriptor: {
12301235
PY_GEN_ASNTYPE_FROMPY_INLINE(name);
1236+
OUT("PY_IMPL_FROMPY_COMPAT(%s, pObj, pDst);\n", name);
12311237
OUT("pDst->buf = (uint8_t "
12321238
"*)PyCompatUnicode_AsUTF8AndSize(pObj, "
12331239
"&pDst->size);\n");
@@ -1250,6 +1256,7 @@ int asn1c_lang_Py_type_SIMPLE_TYPE(arg_t *arg) {
12501256
case ASN_BASIC_ENUMERATED: {
12511257
basic_enumeration:
12521258
PY_GEN_ASNTYPE_FROMPY_INLINE(name);
1259+
OUT("PY_IMPL_FROMPY_COMPAT(%s, pObj, pDst);\n", name);
12531260
OUT("return PyCompatEnum_FromObject(pObj, (void *)pDst, %d);\n",
12541261
is_signed);
12551262
PY_GEN_END_FUNC();
@@ -2170,8 +2177,7 @@ static int asn1c_lang_Py_stubs_generate_init(arg_t *arg) {
21702177
type_name = PY_TYPE_MAP[v->expr_type];
21712178
if (type_name != NULL) {
21722179
OUT("%s: %s = ...,\n", memb_name, type_name);
2173-
}
2174-
else {
2180+
} else {
21752181
OUT("%s: EXT_Any = ...,\n", memb_name);
21762182
}
21772183
}

skeletons/py_application.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,18 @@ static PyObject* PyCompat_Encode(enum asn_transfer_syntax ats,
186186
} \
187187
} while (0)
188188

189+
#define PY_IMPL_FROMPY_COMPAT(typeName, obj, dst) \
190+
do { \
191+
if (PyObject_TypeCheck((obj), &PyAsn##typeName##_Type)) { \
192+
if (asn_copy(&asn_DEF_##typeName, (void**)&dst, \
193+
((PyCompatAsnObject_t*)(obj))->ob_value) < 0) { \
194+
PyErr_BadInternalCall(); \
195+
return -1; \
196+
} \
197+
return 0; \
198+
} \
199+
} while (0)
200+
189201
#define PY_IMPL_GENERIC_NEW(name, type_DEF) \
190202
static PyObject* PyAsn##name##__new(PyTypeObject* type, PyObject* args, \
191203
PyObject* kwds) { \

0 commit comments

Comments
 (0)