Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6869361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:32:54+00:00 2026-05-27T03:32:54+00:00

so I am getting a segfault from ctypes on a 32 bit linux machine

  • 0

so I am getting a segfault from ctypes on a 32 bit linux machine that I can’t reproduce on 64 bit darwin or linux.

Here is the C:

typedef struct {
  void *ptr;
  } doodle;

doodle C_intpointerfunction(int *a)
{
  *a = 41;
  doodle foo;
  foo.ptr = a;
  return foo;
}

which is compiled with:

gcc -c intpointerlibrary.c
gcc -shared intpointerlibrary.o -o libintpointerlib.so

and here is the Python:

import numpy as N
from ctypes import *

_libintpointer = N.ctypeslib.load_library('libintpointerlib.so','.')

_libintpointer.C_intpointerfunction.restype = c_void_p
_libintpointer.C_intpointerfunction.argtypes = [POINTER(c_int)]
def P_intpointerfunction():
  lrc = c_int(0)
  print "lrc before (should be 0) = "+str(lrc.value)
  return_val = _libintpointer.C_intpointerfunction(byref(lrc))
  print "lrc after (should be 41) = "+str(lrc.value)
  return return_val

so now, when I call this function:

  rc = P_intpointerfunction()

I get a segfault. I’ve tried creating a Python class to wrap the returned struct that is created on the C side with the same results. If passing back a native ctypes type (like c_int) everything works fine.. Is this truly just a problem with 32 bit Linux, or is there something I have not considered? Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:32:54+00:00Added an answer on May 27, 2026 at 3:32 am

    Not sure why you’re setting restype = c_void_p;

    class DOODLE(Structure):
        _fields_ = [('ptr', c_void_p)]
    _libintpointer.C_intpointerfunction.restype = DOODLE
    

    works as expected for me, on Linux x86-64.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting a segfault that GDB says is coming from SDL_GL_SwapBuffers. However, I can't
I'm getting an obnoxious segfault in PHP 5.3.6 (compiled from source, Slackware 13.1 x86,
I am implementing a function to recursively reverse a linked-list, but getting seg-fault. typedef
Getting the subdomain from a URL sounds easy at first. http://www.domain.example Scan for the
Getting started with NHibernate How can I generate identity fields in nHibernate using Hilo
I suspect I am doing something dumb here but I am getting seg faults
I'm working with a c++ program that uses multiple buffers and I'm getting a
Im working on this bit of code and I keep getting a segmentation fault.
I saw many questions about getting segmentation fault in C program here in SO,
Getting contradictory messages about that, hope they're not. I cannot imagine support for it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.