Re: Blank Window (Tile Engine)

new topic     » goto parent     » topic index » view thread      » older message » newer message

As Irv pointed out there is absolutely a distinction between NULL and a pointer to an empty string. The latter has a value while the former does not. Unfortunately some C libraries will double-check if strings are NULL or empty but just as many will accept an empty string as a valid string (because it is) and the resulting behavior may be different or altogether broken. Typically, C string parameter that can accept NULL should be specified as an object parameter in the Euphoria wrapper, so that it can accept NULL when necessary and treat empty strings separately.

I'm working on baking C_STRING (and C_WSTRING) into std/ffi.e so we can avoid a bunch of repetitive boilerplate code like this:

constant _wrapper_func = define_c_func( lib, "wrapper_func", {C_POINTER,C_POINTER}, C_POINTER ) 
 
public function wrapper_func( object required_string, object optional_string=NULL ) 
    if sequence( required_string ) then 
        required_string = allocate_string( required_string, TRUE ) 
    end if 
    if sequence( optional_string ) then 
        optional_string = allocate_string( optional_string, TRUE ) 
    end if 
    return c_func( _wrapper_func, {required_string,optional_string} ) 
end function 

And instead just pass the values and let c_func() handle the allocate/free as necessary:

constant _wrapper_func = define_c_func( lib, "wrapper_func", {C_STRING,C_STRING}, C_POINTER ) 
 
public function wrapper_func( object required_string, object optional_string=NULL ) 
    return c_func( _wrapper_func, {required_string,optional_string} ) 
end function 

However, this feature will gladly ignore any atom it receives and pass it along verbatim, which will respect NULL as NULL and also so you can allocate your own strings and pass them along. This would be useful for pre-allocating strings, such as preloading resources from a file or to avoid the overhead of repetitive memory allocation. I will be notating all of this in my documentation for std/ffi.e as well as adding a "mini-guide" to the docs for tips on wrapping C libraries and structures. The guide is mostly going to be written by way of collecting these recent conversations into a more concise format.

-Greg

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu