Skip to content

Unable to write header field with string value #41

@theNewFlesh

Description

@theNewFlesh

When I run this:

import Imath as imath
import numpy as np
import OpenEXR

ctype = imath.Channel(imath.PixelType(imath.PixelType.HALF))

target = '/tmp/test_exr.exr'
data = {}
chans = {}
channels = list('RGBA')
for c in channels:
    chan = c.upper()
    data[chan] = np.zeros((5, 10), dtype=np.float16).tobytes()
    chans[chan] = ctype

header = OpenEXR.Header(10, 5)
header['channels'] = chans
header['foo'] = 'bar'

# ALSO-FAIL-------------------------------
# header['foo'] = 'bar'.encode('ascii')
# header['foo'] = 'bar'.encode('utf-8')

# Segmentation fault
# header['foo'] = list('bar'.encode('utf-8'))
# header['foo'] = [bytes([x]) for x in list('bar')]
# ------------------------------------------

file_ = OpenEXR.OutputFile(target, header)
file_.writePixels(data)

I get this:

XXX - unknown attribute: foo

Inside of my pytest environment I get a segmentation fault. This was not the case a few months ago, when I last ran them.

I'm guessing the problem is that PyList_Check(val) returns false when it shouldn't.
I looked at PyType_FastSubclass, which PyList_Check uses, inside /usr/include/python3.7m/object.h but it seems impenetrable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions