Opened 14 years ago

Closed 13 years ago

#304 closed defect (fixed)


Reported by: stassats Owned by: gb
Priority: minor Milestone:
Component: Runtime (threads, GC) Version: 1.2
Keywords: Cc:


c_gethostbyname on Linux is implemented using #_gethostbyname_r. But gethostbyname_r is very strange and it fails to resolve local defined hosts in /etc/hosts and it's also obsolete according to the man page. So I rewrote it using #_getaddrinfo. It seems to work, but when I replace old c_gethostbyname with it, CCL fails on rebuilding complaining about ffi-type. I'm not quite understand mechanisms of CCL's FFI and don't know how to handle this.

So I attach my version of c_gethostbyname, maybe someone could adapt it.

Attachments (1)

gethostbyname.lisp (333 bytes) - added by stassats 14 years ago.

Download all attachments as: .zip

Change History (4)

Changed 14 years ago by stassats

comment:1 Changed 14 years ago by gb

  • Status changed from new to assigned

When we create pointers, we try to identify the type of object that the pointer points to (mostly to help with debugging.) Every time a new foreign type is introduced, it's assigned a unique small integer "ordinal", and when the pointer is created, a field within the pointer object is set to the type's ordinal. Constructs that create typed pointers - like RLET - ordinarily expand into code that reference an object that represents the foreign type as a constant (via LOAD-TIME-VALUE) and access the type object's ordinal. (In general, a foreign type's ordinal can vary from session to session but will remain consistent within a session.)

Unfortunately, the system needs to be able to reference foreign type ordinals before the foreign type system is loaded (when the bootstrapping image is loading fasl files.) To work around this, it's necessary to assign "canonical" foreign-type ordinals to types that are referenced early in the bootstrapping process; the first 100 or so unsigned integers are reserved for use as "canonical foreign type ordinals."

A function named CANONICALIZE-FOREIGN-TYPE-ORDINALS - defined in ccl:lib;foreign-types.lisp - assigns canonical foreign-type ordinals to (currently) about 2 dozen foreign types.

The easiest way to bootstrap a change like the one you're making is:

1) comment out the changes to l1-sockets, for now. 2) Add a call to the local function CANONICALIZE-FOREIGN-TYPE-ORDINAL at the end of CANONICALIZE-FOREIGN-TYPE-ORDINALS. We want to be able to refer to the foreign structure type :ADDRINFO "early", so I think that that call would say:

  (canonicalize-foreign-type-ordinal '(:struct :addrinfo))

3) Rebuild the lisp.

4) Un-comment your changes to l1-sockets.lisp, and rebuild the lisp again. This time, the FFI will recognize that :ADDRINFO structures have a canonical type ordinal and will generate code that references the foreign type at runtime.

I wasn't aware that gethostbyname_r was deprecated or had other problems. I'm fairly sure that getaddrinfo is supported on Darwin and FreeBSD as well as Linux, so some functions that are currently platform-dependent could be shared.

Hope this makes sense.

comment:2 Changed 14 years ago by stassats

Thanks for the help. I have added canonicalize-foreign-type-ordinal, but rebuilded only once. Now it works.

I don't know how widespread getaddrinfo is, but we can have two c_gethostbyname functions: one with gethostbyname and one with getaddrinfo. Then we need to detect whether we have getaddrinfo, and add new feature like ":addrinfo-support". So is made in SBCL.

c_gethostbyaddr can be also rewritten with getnameinfo. However it seems to work.

comment:3 Changed 13 years ago by stassats

  • Resolution set to fixed
  • Status changed from assigned to closed
Note: See TracTickets for help on using tickets.