Esempio n. 1
0
static struct object *low_do_query_phrase( Blob **blobs, int nblobs,
					   double field_c[65])
{
  struct object *res = wf_resultset_new();
  struct tofree *__f = malloc( sizeof( struct tofree ) );
  double max_c=0.0;
  ONERROR e;
  int i, j;
  __f->blobs = blobs;
  __f->nblobs = nblobs;
  __f->res = res;
  __f->tmp    = 0;
  SET_ONERROR( e, free_stuff, __f );


  for( i = 0; i<65; i++ )
    if( field_c[i] > max_c )
      max_c = field_c[i];

  if(  max_c != 0.0 )
  {
    /* Time to do the real work. :-) */
    for( i = 0; i<nblobs; i++ ) /* Forward to first element */
      wf_blob_next( blobs[i] );

    /* Main loop: Find the smallest element in the blob array. */
    while( 1 )
    {
      unsigned int min = 0x7fffffff;

      for( i = 0; i<nblobs; i++ )
	if( blobs[i]->eof )
	  goto end;
	else if( ((unsigned int)blobs[i]->docid) < min )
	  min = blobs[i]->docid;

      if( min == 0x7fffffff )
	goto end;

      for( j = 0, i = 0; i < nblobs; i++ )
	if( blobs[i]->docid != min )
	  goto next;

      handle_phrase_hit( blobs, nblobs, res, min, &field_c, max_c );

    next:
      for( i = 0; i<nblobs; i++ )
	if( blobs[i]->docid == min )
	  wf_blob_next( blobs[i] );
    }
  }
end:
  /* Free workarea and return the result. */

  UNSET_ONERROR( e );
  __f->res = 0;
  free_stuff( __f );
  return res;
}
Esempio n. 2
0
/*! @decl array(array(string)|string) tokenize(string code)
 *!
 *!   Tokenize a string of Pike tokens.
 *!
 *! @returns
 *!   Returns an array with Pike-level tokens and the remainder (a
 *!   partial token), if any.
 */
static void f_tokenize( INT32 args )
{
  struct array *res;
  struct pike_string *left_s = NULL; /* Make gcc happy. */
  struct pike_string *data;
  int left;
  ONERROR tmp;

  get_all_args("tokenize", args, "%W", &data);

  if(!data->len)
  {
    pop_n_elems(args);
    push_empty_array();
    push_empty_string();
    f_aggregate(2);
    return;
  }

  res = allocate_array_no_init( 0, 128 );
  SET_ONERROR(tmp, do_free_arrayptr, &res);
  
  switch(data->size_shift)
  {
    case 0:
      left = tokenize0(&res, STR0(data), data->len);
      left_s = make_shared_binary_string0(STR0(data)+left, data->len-left);
      break;
    case 1:
      left = tokenize1(&res, STR1(data), data->len);
      left_s = make_shared_binary_string1(STR1(data)+left, data->len-left);
      break;
    case 2:
      left = tokenize2(&res,STR2(data), data->len);
      left_s = make_shared_binary_string2(STR2(data)+left, data->len-left);
      break;
#ifdef PIKE_DEBUG
    default:
      Pike_error("Unknown shift size %d.\n", data->size_shift);
#endif
  }

  UNSET_ONERROR(tmp);
  pop_n_elems(args);
  if (!res->size) {
    free_array(res);
    push_empty_array();
  }
  else
    push_array(res);
  push_string( left_s );
  f_aggregate( 2 );
}
Esempio n. 3
0
void image_polyfill(INT32 args)
{
    struct vertex *v;
    double *buf;
    ONERROR err;

    if (!THIS->img)
        Pike_error("Image.Image->polyfill: no image\n");

    buf=xalloc(sizeof(double)*(THIS->xsize+1));
    SET_ONERROR(err, free, buf);

    v=polyfill_begin();

    while (args)
    {
        struct vertex *v_tmp;

        if (sp[-1].type!=T_ARRAY)
        {
            polyfill_free(v);
            SIMPLE_BAD_ARG_ERROR("Image.Image->polyfill", args,
                                 "array(int|float)");
        }
        if ((v_tmp=polyfill_add(&v, sp[-1].u.array, args,
                                "Image.Image->polyfill()"))) {
            v = v_tmp;
        } else {
            polyfill_free(v);
            Pike_error("Image.Image->polyfill: Bad argument %d, bad vertex\n", args);
        }
        args--;
        pop_stack();
    }

    if (!v) {
        free(buf);
        return; /* no vertices */
    }

    polyfill_some(THIS,v,buf);

    polyfill_free(v);

    UNSET_ONERROR(err);
    free(buf);

    ref_push_object(THISOBJ);
}
Esempio n. 4
0
static struct object *low_do_query_or( Blob **blobs,
					  int nblobs,
					  double field_c[65],
					  double prox_c[8],
					  int cutoff)
{
  struct object *res = wf_resultset_new();
  struct tofree *__f = malloc( sizeof( struct tofree ) );
  double max_c=0.0, max_p=0.0;
  ONERROR e;
  int i, j;
  Blob **tmp;
  tmp = calloc( nblobs, sizeof( Blob *) );

  __f->res = res;
  __f->blobs = blobs;
  __f->nblobs = nblobs;
  __f->tmp    = tmp;
  SET_ONERROR( e, free_stuff, __f );


  for( i = 0; i<65; i++ )
    if( field_c[i] > max_c )
      max_c = field_c[i];

  for( i = 0; i<8; i++ )
    if( prox_c[i] > max_p )
      max_p = prox_c[i];

  if( max_p != 0.0 && max_c != 0.0 )
  {
    /* Time to do the real work. :-) */
    for( i = 0; i<nblobs; i++ ) /* Forward to first element */
      wf_blob_next( blobs[i] );

    /* Main loop: Find the smallest element in the blob array. */
    while( 1 )
    {
      unsigned int min = 0x7fffffff;

      for( i = 0; i<nblobs; i++ )
	if( !blobs[i]->eof && ((unsigned int)blobs[i]->docid) < min )
	  min = blobs[i]->docid;

      if( min == 0x7fffffff )
	break;

      for( j = 0, i = 0; i < nblobs; i++ )
	if( blobs[i]->docid == min && !blobs[i]->eof )
	  tmp[j++] = blobs[i];

      handle_hit( tmp, j, res, min, &field_c, &prox_c, max_c, max_p, cutoff );

      for( i = 0; i<j; i++ )
	wf_blob_next( tmp[i] );
    }
  }
  /* Free workarea and return the result. */

  UNSET_ONERROR( e );
  __f->res = 0;
  free_stuff( __f );
  return res;
}
Esempio n. 5
0
/*! @decl program load_module(string module_name)
 *!
 *! Load a binary module.
 *!
 *! This function loads a module written in C or some other language
 *! into Pike. The module is initialized and any programs or constants
 *! defined will immediately be available.
 *!
 *! When a module is loaded the C function @tt{pike_module_init()@} will
 *! be called to initialize it. When Pike exits @tt{pike_module_exit()@}
 *! will be called. These two functions @b{must@} be available in the module.
 *!
 *! @note
 *!   The current working directory is normally not searched for
 *!   dynamic modules. Please use @expr{"./name.so"@} instead of just
 *!   @expr{"name.so"@} to load modules from the current directory.
 */
void f_load_module(INT32 args)
{
  extern int global_callable_flags;

  void *module;
  modfun init, exit;
  struct module_list *new_module;
  struct pike_string *module_name;

  ONERROR err;

  module_name = Pike_sp[-args].u.string;

  if((Pike_sp[-args].type != T_STRING) ||
     (module_name->size_shift) ||
     string_has_null(module_name)) {
    Pike_error("Bad argument 1 to load_module()\n");
  }

  {
    struct module_list *mp;
    for (mp = dynamic_module_list; mp; mp = mp->next)
      if (mp->name == module_name && mp->module_prog) {
	pop_n_elems(args);
	ref_push_program(mp->module_prog);
	return;
      }
  }

  /* Removing RTLD_GLOBAL breaks some PiGTK themes - Hubbe */
  /* Using RTLD_LAZY is faster, but makes it impossible to 
   * detect linking problems at runtime..
   */
  module=dlopen(module_name->str, 
                RTLD_NOW /*|RTLD_GLOBAL*/  );

  if(!module)
  {
    struct object *err_obj = low_clone (module_load_error_program);
#define LOADERR_STRUCT(OBJ) \
    ((struct module_load_error_struct *) (err_obj->storage + module_load_error_offset))

    const char *err = dlerror();
    if (err) {
      if (err[strlen (err) - 1] == '\n')
	push_string (make_shared_binary_string (err, strlen (err) - 1));
      else
	push_text (err);
    }
    else
      push_constant_text ("Unknown reason");

    add_ref (LOADERR_STRUCT (err_obj)->path = Pike_sp[-args - 1].u.string);
    add_ref (LOADERR_STRUCT (err_obj)->reason = Pike_sp[-1].u.string);

    if (Pike_sp[-args].u.string->len < 1024) {
      throw_error_object (err_obj, "load_module", Pike_sp - args - 1, args,
			  "load_module(\"%s\") failed: %s\n",
			  module_name->str, Pike_sp[-1].u.string->str);
    } else {
      throw_error_object (err_obj, "load_module", Pike_sp - args - 1, args,
			  "load_module() failed: %s\n",
			  Pike_sp[-1].u.string->str);
    }
  }

#ifdef PIKE_DEBUG
  {
    struct module_list *mp;
    for (mp = dynamic_module_list; mp; mp = mp->next)
      if (mp->module == module && mp->module_prog) {
	fprintf(stderr, "load_module(): Module loaded twice:\n"
		"Old name: %s\n"
		"New name: %s\n",
		mp->name->str, module_name->str);
	pop_n_elems(args);
	ref_push_program(mp->module_prog);
	return;
      }
  }
#endif /* PIKE_DEBUG */

  init = CAST_TO_FUN(dlsym(module, "pike_module_init"));
  if (!init) {
    init = CAST_TO_FUN(dlsym(module, "_pike_module_init"));
    if (!init) {
      dlclose(module);
      Pike_error("pike_module_init missing in dynamic module \"%S\".\n",
		 module_name);
    }
  }

  exit = CAST_TO_FUN(dlsym(module, "pike_module_exit"));
  if (!exit) {
    exit = CAST_TO_FUN(dlsym(module, "_pike_module_exit"));
    if (!exit) {
      dlclose(module);
      Pike_error("pike_module_exit missing in dynamic module \"%S\".\n",
		 module_name);
    }
  }

#if defined(__NT__) && defined(_M_IA64)
  {
    fprintf(stderr, "pike_module_init: 0x%p\n"
	    "  func: 0x%p\n"
	    "  gp:   0x%p\n",
	    init, ((void **)init)[0], ((void **)init)[1]);
    fprintf(stderr, "pike_module_exit: 0x%p\n"
	    "  func: 0x%p\n"
	    "  gp:   0x%p\n",
	    exit, ((void **)exit)[0], ((void **)exit)[1]);
  }
#endif /* __NT__ && _M_IA64 */

  new_module=ALLOC_STRUCT(module_list);
  new_module->next=dynamic_module_list;
  dynamic_module_list=new_module;
  new_module->module=module;
  copy_shared_string(new_module->name, Pike_sp[-args].u.string);
  new_module->module_prog = NULL;
  new_module->init=init;
  new_module->exit=exit;

  enter_compiler(new_module->name, 1);

  start_new_program();

  global_callable_flags|=CALLABLE_DYNAMIC;

#ifdef PIKE_DEBUG
  { struct svalue *save_sp=Pike_sp;
#endif
  SET_ONERROR(err, cleanup_compilation, NULL);
#if defined(__NT__) && defined(_M_IA64)
  fprintf(stderr, "Calling pike_module_init()...\n");
#endif /* __NT__ && _M_IA64 */
  (*(modfun)init)();
#if defined(__NT__) && defined(_M_IA64)
  fprintf(stderr, "pike_module_init() done.\n");
#endif /* __NT__ && _M_IA64 */
  UNSET_ONERROR(err);
#ifdef PIKE_DEBUG
  if(Pike_sp != save_sp)
    Pike_fatal("load_module(%s) left %ld droppings on stack!\n",
	       module_name->str,
	       PTRDIFF_T_TO_LONG(Pike_sp - save_sp));
  }
#endif

  pop_n_elems(args);
  {
    struct program *p = end_program();
    exit_compiler();
    if (p) {
      if (
#if 0
	  p->num_identifier_references
#else /* !0 */
	  1
#endif /* 0 */
	  ) {
	push_program(p);
	add_ref(new_module->module_prog = Pike_sp[-1].u.program);
      } else {
	/* No identifier references -- Disabled module. */
	free_program(p);
	push_undefined();
      }
    } else {
      /* Initialization failed. */
      new_module->exit();
      dlclose(module);
      dynamic_module_list = new_module->next;
      free_string(new_module->name);
      free(new_module);
      Pike_error("Failed to initialize dynamic module \"%S\".\n",
		 module_name);
    }
  }
}