Ask Reuben
Do You Need Your C-Extension?
“I am having trouble with my C-Extension” … STOP! Before you go any further, do you really need your C-Extension?
Whenever I get a question on C-Extensions I turn the question around and ask “Do you need your C-Extension”? What I invariably find is that the C-Extension is being used to overcome a short-coming in Informix-4GL, and the C-Extension can be replaced with some pure Genero code that we have introduced to do what Informix-4GL did not do.
Removing the C-Extension and using code from a built-in package can simplify your build and deployment practices.
The following is a list of scenarios I see people using C-Extensions for, and the Genero functionality that has been added.
- Reading / Writing to a file – Use the base.Channel class, in particular base.Channel.openFile and its read and write methods to open a file and read or write to it.
- Interacting with File / Directories – Use the os.Path class to manipulate files and directories.
- Advanced Mathematics – Use the util.Math class to do some mathematical functions.
- Random Numbers – Included in the util.Math class is the .rand method to generate a random number.
- Security – Complex security algorithms for things like Password encryption maybe implemented in the util.Security class
These classes are actually c-libraries, if you look in $FGLDIR/lib you will see the appropriate .so, .dll, .dylib file that you are importing with statements like IMPORT util. You don’t need to worry about creating the .so, .dll, .dylib, we have done that for you, hence why using these libraries instead of your own can simplify your build and deployment practices.
There is still a time and place for C-Extension Libraries (Genero Mobile for iOS development for example), but you may find that your existing C-extension library is unnecessary. If there is code you are implementing in a C Library, please periodically review it and see if it can be replaced with Genero code, thus making your C-Extension unnecessary.