English 中文(简体)
图像Magick + 粉碎式
原标题:Segmentation fault of ImageMagick + Python ctypes

I am using ImageMagick library with Python ctypes. I wrote a following simple code, but it crashes with segmentation fault (KERN_INVALID_ADDRESS) in Mac:

from ctypes import *
from ctypes.util import find_library

lib = CDLL(find_library( MagickWand ))
lib.MagickWandGenesis()
wand = lib.NewMagickWand()
lib.MagickReadImage(wand,  mona-lisa.jpg )
lib.DestroyMagickWand(wand)
lib.MagickWandTerminus()

该公司在北纬度和视窗两方面都运行良好,但只在麦克斯温斯角运行。 我以各种方式建立了图像模型(官方双轨制包、家装、传统<代码>/configure &&使),但每次试验都坠毁。

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x00000000009a7638
0x000000010149a8d1 in MagickReadImage ()

不仅在<代码>MagickReadImage()功能上,IsMagickWand(功能也发生故障。 我只想NewMagickWand(>回到错误的点子,或ctype in Mac Hands Pointers不正确,但我并不肯定。

这种情况有什么错误?

最佳回答

Most likely this is a 32/64 bit issue. Is the Mac version the only 64 bit process that you ve tested? Or perhaps you got lucky in the Windows and Linux versions in that they happen to return pointers of the form 0x00000000xxxxxxxx.

wand = lib.NewMagickWand()

NewMagick 谁回到了一位点子,但你没有听说过哪类人期望一位点子。 目前的回归价值为32倍的ger。 在你打电话之前添加这一条。

lib.NewMagickWand.restype = c_void_p

这说明,新南威尔士工人返回点的类型。

问题回答

我修改了以下法典:

lib.MagickReadImage(wand,  mona-lisa.jpg )

:

f2 = lib.MagickReadImage
f2.argtypes = [c_void_p, c_char_p]
f2(wand,  mona-lisa.jpg )

因此,它运作良好。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签