[CLN-list] Overriding read_number_bad_syntax and read_number_junk

Ron Garret ron at flownet.com
Wed Mar 16 17:24:29 CET 2005


On Mar 15, 2005, at 2:55 PM, Richard B. Kreckel wrote:

> On Tue, 15 Mar 2005, Ron Garret wrote:
>> I'm using cln inside a little Lisp interpreter, which uses cln's input
>> routines to parse numbers.  I'm resurrecting this project after about 
>> a
>> three-year hiatus, and something that worked back then is no longer
>> working.  The default behavior of cln's parser when it encounters bad
>> syntax is to call read_number_bad_syntax which calls cl_abort which
>> calls exit(0).  This is obviously not what I want.  Back in the day, I
>> was able to override this behavior by simply defining my own version 
>> of
>> read_number_bad_syntax and read_number_junk in my own code like so:
>>
>> namespace cln {
>>    void read_number_bad_syntax(const char * string, const char *
>> string_limit) {
>>      throw 0;
>>    }
>>    void read_number_junk (const char * string_rest, const char * 
>> string,
>>                           const char* string_limit) {
>>      throw 0;
>>    }
>> }
>>
>> But this no longer works and I don't know why.  My guess is that it's 
>> a
>> change in the C++ compiler.  Back then it was gcc-2.95 or something
>> like that on Linux, and now I'm using 3.3 on OS X.
>>
>> Obviously I can fix this by hacking the cln source code, but I'd 
>> rather
>> not do that because I don't want people to have to recompile cln (or
>> keep multiple copies of cln around) to be able to use my code.  Is
>> there another way for users to override the behavior of
>> read_number_bad_syntax?  And does anyone know why the technique I used
>> successfully before no longer works?
>
> Could you please define what exactly "no longer works" means?

Whenever the reader tries to process an atom that is not a valid number 
the process exits rather than throwing an exception which the reader 
can catch to turn the atom into a symbol.

>   Also, it
> will be helpful for people who might want to help you if you provide a
> self-contained example.
>

#include <cln/cln.h>
#include <iostream>

using namespace cln;
using namespace std;

namespace cln {
   void read_number_bad_syntax(const char * string, const char *
                               string_limit) {
     throw 0;
   }
   void read_number_junk (const char * string_rest, const char * string,
                          const char* string_limit) {
     throw 0;
   }
}

int main(int argc, char *argv[]) {
   cout << "Checking " << argv[1] << "\n";
   try {
     cl_N n(argv[1]);
     cout << argv[1] << " is a valid number.\n";
   } catch(...) {
     cout << argv[1] << " is not a valid number.\n";
   }
   cout << "This should be printed in either case.\n";
}






More information about the CLN-list mailing list