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 6382511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:31:54+00:00 2026-05-25T02:31:54+00:00

I’m working on trying to get a ruby extension written in c, working with

  • 0

I’m working on trying to get a ruby extension written in c, working with ruby 1.9.2 on Mac OSX. I keep getting a segfault caused by a 64-bit pointer returned from a function being truncated to a 32-bit value and trying to access low memory.

Here’s what I’ve figured out about it. VALUE is a long, defined in the ruby source code, and the code won’t compile unless sizeof(long) is 8 bytes.

In file_b.c:

VALUE
rb_helper_function_foo(VALUE file)
{
  VALUE blah;

  ...

  //Using gdb, blah right here is a 64bit address, ex: 0x1 009d 62a0
  return blah;
}

In file_a.c

VALUE
func_do_stuff(int argc, VALUE *argv, VALUE obj)
{
  VALUE filename, file_path;

  ...

  // But here, the size of what is returned is 4 bytes
  // file_path has a size of 8 bytes though
  file_path = rb_helper_function_foo(filename);

  //This statement will segfault :-(
  if(!RTEST(file_path))
  {
    ...
  }
  ...
}

At the end of the function call, the return value has the correct address, but only the lower 4 bytes get returned: 0x009d52a0 instead of 0x1009d52a0. Accessing the low memory address is causing a segfault.

In the assembly code that gets called during the return, there’s this instruction

movslq %eax, %r12

which only copies the lower 4 bytes, but I need all 8 bytes of %rax to be copied.

I’m on ruby 1.9.2-p290 (though it did the same with p180), Mac OSX 10.6.8, using xcode 4.0.1 (with gcc 4.2.1), but I also tried upgrading to gcc 4.6.1. It has also previously tried xcode 3.2.

Thanks for any help you can give me.

  • 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-25T02:31:54+00:00Added an answer on May 25, 2026 at 2:31 am

    Maybe this is as simple as rb_helper_function_foo not being declared in the file_a.c compilation unit– so the compiler is assuming it returns int instead of VALUE?

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.