void EXPRESSdestroy( Express model ) { if( model->u.express->basename ) { sc_free( model->u.express->basename ); } if( model->u.express->filename ) { sc_free( model->u.express->filename ); } sc_free( model->u.express ); SCOPEdestroy( model ); }
void queue_dispose(queue *q) { int i; if (q == NULL) { return; } for (i = 0; i < q->cache_size; i++) { sc_free(q->cache[i]); } sc_free(q->cache); sc_free(q); }
object* dequeue(queue *q) { int sz; queue_node *p; object *obj = NULL; if (q == NULL) { return NULL; } if (!queue_isempty(q)) { p = q->head; q->head = q->head->next; if (q->head == NULL) { q->rear = NULL; } obj = p->elem; sz = q->cache_size; if (sz < QUEUE_CACHE_SIZE) { /* cache this node */ q->cache[sz++] = p; q->cache_size = sz; } else { sc_free(p); } } return obj; }
void sc_free_arraytex(sc_arraytex_t *arr) { int i; if (!arr) return; for (i = 0; i < arr->textures->size; i++) sc_free(arr->textures->items[i]); if (arr->buffers) { for (i = 0; i < arr->mipmap_levels; i++) sc_free_strbuf(arr->buffers[i]); sc_free(arr->buffers); } sc_free_list(arr->textures); sc_free_texture(arr->texture); sc_free(arr); }
sc_texture_t * sc_texture_from_resource(const char *filename, int mipmaps) { char *path = sc_path_to_resource("textures", filename); sc_texture_t *rv; SDL_Surface *surface = IMG_Load(path); if (!surface) { sc_set_error(SC_ENOENT, path, 0, "Unable to load texture"); sc_free(path); return NULL; } rv = sc_texture_from_surface(surface, mipmaps); if (!rv) sc_augment_error_context(filename, 0); sc_free(path); SDL_FreeSurface(surface); return rv; }
void sc_free_texture(sc_texture_t *texture) { if (!texture) return; assert(!texture->shared); if (texture->id) glDeleteTextures(1, &texture->id); sc_free(texture); }
/* * res_sync_resources() * * Bring resources into line with the game; called on undo, restart, * restore, and so on. */ void res_sync_resources (sc_gameref_t game) { assert (gs_is_game_valid (game)); /* Deal with any latched sound stop first. */ if (game->stop_sound) { if (game->sound_active) { if_update_sound ("", 0, 0, FALSE); game->sound_active = FALSE; res_clear_resource (&game->playing_sound); } game->stop_sound = FALSE; } /* Look for a change of sound, and pass to interface on change. */ if (!res_compare_resource (&game->playing_sound, &game->requested_sound)) { const sc_char *name; sc_char *clean_name; sc_bool is_looping; /* If the sound name ends '##', this is a looping sound. */ name = game->requested_sound.name; is_looping = !strcmp (name + strlen (name) - 2, "##"); clean_name = sc_malloc (strlen (name) + 1); strcpy (clean_name, name); if (is_looping) clean_name[strlen (clean_name) - 2] = NUL; if_update_sound (clean_name, game->requested_sound.offset, game->requested_sound.length, is_looping); game->playing_sound = game->requested_sound; game->sound_active = TRUE; sc_free (clean_name); } /* Look for a change of graphic, and pass to interface on change. */ if (!res_compare_resource (&game->displayed_graphic, &game->requested_graphic)) { if_update_graphic (game->requested_graphic.name, game->requested_graphic.offset, game->requested_graphic.length); game->displayed_graphic = game->requested_graphic; } }
const sc_texture_t * sc_arraytex_add_from_resource(sc_arraytex_t *arr, const char *filename) { char *path; const sc_texture_t *rv; SDL_Surface *surface; ASSERT_NOT_FINALIZED(arr); path = sc_path_to_resource("textures", filename); surface = IMG_Load(path); if (!surface) { sc_free(path); sc_set_error(SC_EGRAPHIC, path, 0, "Unable to load texture. " "Tried to feed texture array"); return NULL; } rv = sc_arraytex_add_from_surface(arr, surface); if (!rv) sc_augment_error_context(filename, 0); sc_free(path); SDL_FreeSurface(surface); return rv; }
void * sc_realloc (int package, void *ptr, size_t size) { if (ptr == NULL) { return sc_malloc (package, size); } else if (size == 0) { sc_free (package, ptr); return NULL; } else { void *ret; ret = realloc (ptr, size); SC_CHECK_ABORT (ret != NULL, "Reallocation"); return ret; } }
queue *queue_new(void) { queue *q; queue_node **cache; q = sc_malloc(sizeof(queue)); if (q == NULL) { return NULL; } cache = sc_malloc(sizeof(queue_node*) * QUEUE_CACHE_SIZE); if (cache == NULL) { sc_free(q); return NULL; } q->cache = cache; q->cache_size = 0; q->head = q->rear = NULL; return q; }
/* * Create a configuration for one of the special services */ struct service_config *sc_make_special( const char *service_name, const builtin_s *bp, int instances ) { struct service_config *scp ; const char *func = "sc_make" ; if ( ( scp = sc_alloc( service_name ) ) == NULL ) return( NULL ) ; SC_ID(scp) = new_string( SC_NAME(scp) ) ; if ( SC_ID(scp) == NULL ) { out_of_memory( func ) ; /* * Since we're returning instead of exiting, it's probably a good idea to * free scp */ sc_free( scp ); return( NULL ) ; } SC_SPECIFY( scp, A_ID ) ; /* * All special services are internal */ M_SET( SC_TYPE(scp), ST_SPECIAL ) ; M_SET( SC_TYPE(scp), ST_INTERNAL ) ; SC_BUILTIN(scp) = bp ; SC_SPECIFY( scp, A_TYPE ) ; M_SET( SC_XFLAGS(scp), SF_NORETRY ) ; SC_SPECIFY( scp, A_FLAGS ) ; SC_INSTANCES(scp) = instances ; SC_SPECIFY( scp, A_INSTANCES ) ; SC_WAIT(scp) = NO ; SC_SPECIFY( scp, A_WAIT ) ; return( scp ) ; }
void * sc_realloc (int package, void *ptr, size_t size) { if (ptr == NULL) { return sc_malloc (package, size); } else if (size == 0) { sc_free (package, ptr); return NULL; } else { void *ret; #ifdef SC_ALLOC_ALIGN size_t sptr; size_t shift; size_t aligned; sptr = (size_t) ptr; ptr = (void *) ((size_t *) ptr)[-1]; SC_ASSERT (ptr != NULL && sptr >= (size_t) ptr + sizeof (size_t)); shift = sptr - (size_t) ptr; size += sc_page_bytes; #endif ret = realloc (ptr, size); SC_CHECK_ABORT (ret != NULL, "Reallocation"); #ifdef SC_ALLOC_ALIGN aligned = (size_t) ret + shift; SC_ASSERT (aligned >= (size_t) ret + sizeof (size_t)); SC_ASSERT (aligned <= (size_t) ret + sc_page_bytes); SC_ASSERT (((size_t *) aligned)[-1] == (size_t) ptr); ((size_t *) aligned)[-1] = (size_t) ret; ret = (void *) aligned; #endif return ret; } }
/* for windows, rewrite backslashes in paths * that will be written to generated code */ const char * path2str_fn( const char * fileMacro ) { static char * result = 0; static size_t rlen = 0; char * p; if( rlen < strlen( fileMacro ) ) { if( result ) { sc_free( result ); } rlen = strlen( fileMacro ); result = ( char * )sc_malloc( rlen * sizeof( char ) + 1 ); } strcpy( result, fileMacro ); p = result; while( *p ) { if( *p == '\\' ) { *p = '/'; } p++; } return result; }
/** * Like format_for_stringout above, but splits the static string up * into numerous small ones that are appended to a std::string named * 'str'. It is assumed that this string already exists and is empty. * * This version takes a file pointer and eliminates use of the temp buffer. */ void format_for_std_stringout( FILE * f, char * orig_buf ) { const char * optr = orig_buf; char * s_end = "\\n\" );\n"; char * s_begin = " str.append( \""; fprintf( f, "%s", s_begin ); while( *optr ) { if( *optr == '\n' ) { if( * ( optr + 1 ) == '\n' ) { /* skip blank lines */ optr++; continue; } fprintf( f, "%s", s_end ); fprintf( f, "%s", s_begin ); } else if( *optr == '\\' ) { fprintf( f, "\\\\" ); } else { fprintf( f, "%c", *optr ); } optr++; } fprintf( f, "%s", s_end ); sc_free( orig_buf ); }
int main() { struct sraf* sra = sc_allocate("dummy.sraf"); /* make an image with 4 squares: red, green, blue, r+g */ const uint64_t nx = 64; const uint64_t ny = 64; uint8_t* data = malloc(nx * ny * sizeof(uint8_t) * 4); for(size_t y=0; y < ny; ++y) { for(size_t x=0; x < nx; ++x) { if(x < 32 && y < 32) { data[y*(nx*4) + x*4 + 0] = 255; data[y*(nx*4) + x*4 + 1] = 0; data[y*(nx*4) + x*4 + 2] = 0; } else if(x >= 32 && y < 32) { data[y*(nx*4) + x*4 + 0] = 0; data[y*(nx*4) + x*4 + 1] = 128; data[y*(nx*4) + x*4 + 2] = 0; } else if(x < 32 && y >= 32) { data[y*(nx*4) + x*4 + 0] = 0; data[y*(nx*4) + x*4 + 1] = 0; data[y*(nx*4) + x*4 + 2] = 192; } else { data[y*(nx*4) + x*4 + 0] = 64; data[y*(nx*4) + x*4 + 1] = 64; data[y*(nx*4) + x*4 + 2] = 0; } data[y*(nx*4) + x*4 + 3] = 255; } } sc_add_image(sra, data, nx,ny, 0.0f,0.0f,0.0f); sc_free(sra); return 0; }
void * sc_realloc (int package, void *ptr, size_t size) { if (ptr == NULL) { return sc_malloc (package, size); } else if (size == 0) { sc_free (package, ptr); return NULL; } else { void *ret; #if defined SC_ENABLE_MEMALIGN ret = sc_realloc_aligned (ptr, SC_MEMALIGN_BYTES, size); #else ret = realloc (ptr, size); SC_CHECK_ABORTF (ret != NULL, "Reallocation (realloc size %lli)", (long long int) size); #endif return ret; } }
void charcache_dispose(void) { sc_free(char_cache); char_cache = NULL; }
/* * res_handle_resource() * * General helper for handling graphics and sound resources. Supplied with a * partial key to the node containing resources, it identifies what resource * is appropriate, and sets this as the requested resource in the game, for * later use on sync'ing, using the handler appropriate for the game version. * * The partial format is something like "sis" (the bit to follow I<- or S<- * in prop_get), and the partial key is guaranteed to contain at least * strlen(partial_format) elements. */ void res_handle_resource (sc_gameref_t game, const sc_char *partial_format, const sc_vartype_t vt_partial[]) { const sc_prop_setref_t bundle = gs_get_bundle (game); sc_vartype_t vt_key[2], *vt_full; sc_int partial_length, resource_start_offset; sc_bool embedded; sc_char *format; assert (gs_is_game_valid (game)); assert (partial_format && vt_partial); /* * Check for resources. If this game doesn't use any, exit now to avoid the * overhead of pointless lookups and allocations. */ if (!(res_has_sound (game) || res_has_graphics (game))) return; /* * Get the global offset for all resources. For version 3.9 games this * should be zero. For version 4.0 games, it's the start of resource data * in the TAF file where resources are embedded. */ vt_key[0].string = "ResourceOffset"; resource_start_offset = prop_get_integer (bundle, "I<-s", vt_key); /* * Get the flag that indicated embedded resources. For version 3.9 games * this should be false. If not set, offset and length are forced to zero * for interface functions. */ vt_key[0].string = "Globals"; vt_key[1].string = "Embedded"; embedded = prop_get_boolean (bundle, "B<-ss", vt_key); /* * Allocate a format for use with properties calls, five characters longer * than the partial passed in. Build a key one element larger than the * partial supplied, and copy over all supplied elements. */ partial_length = strlen (partial_format); format = sc_malloc (partial_length + 5); vt_full = sc_malloc ((partial_length + 1) * sizeof (vt_partial[0])); memcpy (vt_full, vt_partial, partial_length * sizeof (vt_partial[0])); /* Search for sound resources, and offer if found. */ if (res_has_sound (game)) { const sc_char *soundfile; sc_int soundoffset, soundlen; /* Get soundfile property from the node supplied. */ vt_full[partial_length].string = "SoundFile"; strcpy (format, "S<-"); strcat (format, partial_format); strcat (format, "s"); soundfile = prop_get_string (bundle, format, vt_full); /* If a sound is defined, handle it. */ if (!sc_strempty (soundfile)) { if (embedded) { /* Retrieve offset and length. */ vt_full[partial_length].string = "SoundOffset"; strcpy (format, "I<-"); strcat (format, partial_format); strcat (format, "s"); soundoffset = prop_get_integer (bundle, format, vt_full) + resource_start_offset; vt_full[partial_length].string = "SoundLen"; strcpy (format, "I<-"); strcat (format, partial_format); strcat (format, "s"); soundlen = prop_get_integer (bundle, format, vt_full); } else { /* Coerce offset and length to zero. */ soundoffset = 0; soundlen = 0; } /* * If the sound is the special "##", latch stop, otherwise note * details to play on sync. */ if (!strcmp (soundfile, "##")) { game->stop_sound = TRUE; res_clear_resource (&game->requested_sound); } else { res_set_resource (&game->requested_sound, soundfile, soundoffset, soundlen); } } } /* Now do the same thing for graphics resources. */ if (res_has_graphics (game)) { const sc_char *graphicfile; sc_int graphicoffset, graphiclen; /* Get graphicfile property from the node supplied. */ vt_full[partial_length].string = "GraphicFile"; strcpy (format, "S<-"); strcat (format, partial_format); strcat (format, "s"); graphicfile = prop_get_string (bundle, format, vt_full); /* If a graphic is defined, handle it. */ if (!sc_strempty (graphicfile)) { if (embedded) { /* Retrieve offset and length. */ vt_full[partial_length].string = "GraphicOffset"; strcpy (format, "I<-"); strcat (format, partial_format); strcat (format, "s"); graphicoffset = prop_get_integer (bundle, format, vt_full) + resource_start_offset; vt_full[partial_length].string = "GraphicLen"; strcpy (format, "I<-"); strcat (format, partial_format); strcat (format, "s"); graphiclen = prop_get_integer (bundle, format, vt_full); } else { /* Coerce offset and length to zero. */ graphicoffset = 0; graphiclen = 0; } /* Graphics resource retrieved, note to show on sync. */ res_set_resource (&game->requested_graphic, graphicfile, graphicoffset, graphiclen); } } /* Free allocated memory. */ sc_free (format); sc_free (vt_full); }
void sc_dbg_free(void* ptr, const char* tag, int line) { fprintf(stderr, "sc_dbg_free [%s:%d]: %p\n", tag, line, ptr); sc_free(ptr); }
void World_Cleanup(World *world, bool unload_plugins) { if (!world) return; if (scsynth::asioThreadStarted()){ scsynth::stopAsioThread(); } if(unload_plugins) deinitialize_library(); HiddenWorld *hw = world->hw; if (hw && world->mRealTime) hw->mAudioDriver->Stop(); world->mRunning = false; if (world->mTopGroup) Group_DeleteAll(world->mTopGroup); reinterpret_cast<SC_Lock*>(world->mDriverLock)->lock(); if (hw) { sc_free(hw->mWireBufSpace); delete hw->mAudioDriver; hw->mAudioDriver = 0; } delete reinterpret_cast<SC_Lock*>(world->mNRTLock); reinterpret_cast<SC_Lock*>(world->mDriverLock)->unlock(); delete reinterpret_cast<SC_Lock*>(world->mDriverLock); World_Free(world, world->mTopGroup); for (uint32 i=0; i<world->mNumSndBufs; ++i) { SndBuf *nrtbuf = world->mSndBufsNonRealTimeMirror + i; SndBuf * rtbuf = world->mSndBufs + i; if (nrtbuf->data) free_alig(nrtbuf->data); if (rtbuf->data && rtbuf->data != nrtbuf->data) free_alig(rtbuf->data); #ifndef NO_LIBSNDFILE if (nrtbuf->sndfile) sf_close(nrtbuf->sndfile); if (rtbuf->sndfile && rtbuf->sndfile != nrtbuf->sndfile) sf_close(rtbuf->sndfile); #endif } free_alig(world->mSndBufsNonRealTimeMirror); free_alig(world->mSndBufs); free_alig(world->mControlBusTouched); free_alig(world->mAudioBusTouched); if (hw->mShmem) { delete hw->mShmem; } else free_alig(world->mControlBus); free_alig(world->mAudioBus); delete [] world->mRGen; if (hw) { #ifndef NO_LIBSNDFILE if (hw->mNRTInputFile) sf_close(hw->mNRTInputFile); if (hw->mNRTOutputFile) sf_close(hw->mNRTOutputFile); if (hw->mNRTCmdFile) fclose(hw->mNRTCmdFile); #endif delete hw->mUsers; delete hw->mAvailableClientIDs; delete hw->mClientIDdict; delete hw->mNodeLib; delete hw->mGraphDefLib; delete hw->mQuitProgram; delete hw->mAllocPool; free_alig(hw); } free_alig(world); }
static void EXPRESS_PATHfree( void ) { LISTdo( EXPRESS_path, dir, Dir * ) sc_free( dir ); LISTod LISTfree( EXPRESS_path ); }
SC_DLLEXPORT_C void World_Cleanup(World *world) { if (!world) return; HiddenWorld *hw = world->hw; if (hw && world->mRealTime) hw->mAudioDriver->Stop(); world->mRunning = false; if (world->mTopGroup) Group_DeleteAll(world->mTopGroup); world->mDriverLock->Lock(); // never unlock.. if (hw) { sc_free(hw->mWireBufSpace); delete hw->mAudioDriver; hw->mAudioDriver = 0; } delete world->mNRTLock; delete world->mDriverLock; World_Free(world, world->mTopGroup); for (uint32 i=0; i<world->mNumSndBufs; ++i) { SndBuf *nrtbuf = world->mSndBufsNonRealTimeMirror + i; SndBuf * rtbuf = world->mSndBufs + i; if (nrtbuf->data) free(nrtbuf->data); if (rtbuf->data && rtbuf->data != nrtbuf->data) free(rtbuf->data); #ifndef NO_LIBSNDFILE if (nrtbuf->sndfile) sf_close(nrtbuf->sndfile); if (rtbuf->sndfile && rtbuf->sndfile != nrtbuf->sndfile) sf_close(rtbuf->sndfile); #endif } free(world->mSndBufsNonRealTimeMirror); free(world->mSndBufs); free(world->mControlBusTouched); free(world->mAudioBusTouched); if (hw->mShmem) { delete hw->mShmem; } else free(world->mControlBus); free(world->mAudioBus); delete [] world->mRGen; if (hw) { #ifndef NO_LIBSNDFILE if (hw->mNRTInputFile) sf_close(hw->mNRTInputFile); if (hw->mNRTOutputFile) sf_close(hw->mNRTOutputFile); if (hw->mNRTCmdFile) fclose(hw->mNRTCmdFile); #endif free(hw->mUsers); delete hw->mNodeLib; delete hw->mGraphDefLib; delete hw->mQuitProgram; delete hw->mAllocPool; free(hw); } free(world); }
int sc_arraytex_finalize(sc_arraytex_t *arr) { sc_texture_t *texture; char *data; int i; int use_mipmaps = arr->flags & SC_ARRAYTEX_MIPMAPS; ASSERT_NOT_FINALIZED(arr); assert(arr->slices > 0); texture = sc_xalloc(sc_texture_t); glGenTextures(1, &texture->id); glBindTexture(TARGET, texture->id); /* use ansitropic filtering if possible */ sc_filter_ansitropic(TARGET); glTexParameteri(TARGET, GL_TEXTURE_MIN_FILTER, use_mipmaps ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR); glTexParameteri(TARGET, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(TARGET, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(TARGET, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); /* base level */ data = sc_free_strbuf_and_get_contents(arr->buffers[0], NULL); glTexImage3D(TARGET, 0, GL_RGBA8, arr->width, arr->height, arr->slices, 0, arr->format, GL_UNSIGNED_BYTE, data); sc_free(data); /* mipmap levels if given */ if (use_mipmaps) { /* we haven't any mipmaps generated, let the graphics device do that for us. Currently this is the case if we are using nearest neighbor mipmaps which we have to generate on the CPU. */ if (arr->mipmap_levels == 1) { glGenerateMipmap(TARGET); /* otherwise upload the manually generated ones now */ } else { size_t w = arr->width; size_t h = arr->height; for (i = 1; i < arr->mipmap_levels; i++) { if (w > 1) w /= 2; if (h > 1) h /= 2; data = sc_free_strbuf_and_get_contents(arr->buffers[i], NULL); glTexImage3D(TARGET, i, GL_RGBA8, w, h, arr->slices, 0, arr->format, GL_UNSIGNED_BYTE, data); sc_free(data); } } } sc_free(arr->buffers); arr->buffers = NULL; texture->stored_width = arr->width; texture->stored_height = arr->height; texture->off_x = 0; texture->off_y = 0; texture->width = arr->width; texture->height = arr->height; texture->target = TARGET; texture->shared = 0; texture->index = -1; arr->texture = texture; return 1; }
/* * Get a service entry. Steps: * * 1. Parse entry attributes * 2. Determine service id * 3. Insert entry in table */ static void get_service_entry( int fd, pset_h sconfs, const char *name, struct service_config *defaults ) { struct service_config *scp ; const char *func = "get_service_entry" ; scp = sc_alloc( name ) ; if ( scp == NULL ) { skip_entry( fd ) ; return ; } /* Now fill in default attributes if given. */ if ( SC_SPECIFIED( defaults, A_LOG_ON_SUCCESS ) && ! SC_IS_PRESENT( scp, A_LOG_ON_SUCCESS) ) fill_attribute( A_LOG_ON_SUCCESS, scp, defaults ) ; if ( SC_SPECIFIED( defaults, A_LOG_ON_FAILURE ) && ! SC_IS_PRESENT( scp, A_LOG_ON_FAILURE ) ) fill_attribute( A_LOG_ON_FAILURE, scp, defaults ) ; if ( SC_SPECIFIED( defaults, A_ONLY_FROM ) && ! SC_IS_PRESENT( scp, A_ONLY_FROM ) ) fill_attribute( A_ONLY_FROM, scp, defaults ) ; if ( SC_SPECIFIED( defaults, A_NO_ACCESS ) && ! SC_IS_PRESENT( scp, A_NO_ACCESS ) ) fill_attribute( A_NO_ACCESS, scp, defaults ) ; if ( SC_SPECIFIED( defaults, A_PASSENV ) && ! SC_IS_PRESENT( scp, A_PASSENV ) ) fill_attribute( A_PASSENV, scp, defaults ) ; if ( SC_SPECIFIED( defaults, A_ACCESS_TIMES ) && ! SC_IS_PRESENT( scp, A_ACCESS_TIMES ) ) fill_attribute( A_ACCESS_TIMES, scp, defaults ) ; if ( SC_SPECIFIED( defaults, A_BANNER ) && ! SC_IS_PRESENT( scp, A_BANNER ) ) fill_attribute( A_BANNER, scp, defaults ) ; if ( SC_SPECIFIED( defaults, A_BANNER_SUCCESS ) && ! SC_IS_PRESENT( scp, A_BANNER_SUCCESS ) ) fill_attribute( A_BANNER_SUCCESS, scp, defaults ) ; if ( SC_SPECIFIED( defaults, A_BANNER_FAIL ) && ! SC_IS_PRESENT( scp, A_BANNER_FAIL ) ) fill_attribute( A_BANNER_FAIL, scp, defaults ) ; if ( parse_entry( SERVICE_ENTRY, fd, scp ) == FAILED ) { sc_free( scp ) ; skip_entry( fd ) ; return ; } /* * If no service id was specified, set it equal to the service name */ if ( ! SC_SPECIFIED( scp, A_ID ) ) { if ( (SC_ID(scp) = new_string( SC_NAME(scp) )) ) SC_PRESENT( scp, A_ID ) ; else { out_of_memory( func ) ; sc_free( scp ) ; return ; } } if ( ! (pset_add( sconfs, scp )) ) { out_of_memory( func ) ; sc_free( scp ) ; return ; } }
// cleanup static void sc_destroy(void *buffer) { sc_t *info = (sc_t*)fuse_get_context()->private_data; sc_free(info); }
sc_texture_t * sc_texture_from_surface(SDL_Surface *img, int mipmaps) { GLenum format; GLuint tex; SDL_Surface *stored_img = NULL; sc_texture_t *texture = sc_xalloc(sc_texture_t); texture->width = img->w; texture->height = img->h; texture->stored_width = power_of_two_if_needed(img->w); texture->stored_height = power_of_two_if_needed(img->h); texture->target = GL_TEXTURE_2D; texture->shared = 0; stored_img = sc_prepare_surface_for_upload(img, &format); if (!stored_img) return NULL; /* if stored size differ we have to blit the image to a new surface with the requested size before uploading */ if (texture->stored_width != texture->width || texture->stored_height != texture->height) { if (!upscale_surface(&stored_img, texture->stored_width, texture->stored_height)) { sc_free(texture); texture = NULL; goto bailout; } } /* upload texture to graphics device */ glGenTextures(1, &tex); glBindTexture(texture->target, tex); sc_filter_ansitropic(texture->target); glTexParameteri(texture->target, GL_TEXTURE_MIN_FILTER, mipmaps ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR); glTexParameteri(texture->target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(texture->target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(texture->target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexImage2D(texture->target, 0, GL_RGBA8, texture->stored_width, texture->stored_height, 0, format, GL_UNSIGNED_BYTE, stored_img->pixels); /* build a bunch of mipmaps */ if (mipmaps) glGenerateMipmap(texture->target); texture->id = tex; texture->index = -1; texture->off_x = 0; texture->off_y = 0; texture->width = img->w; texture->height = img->h; bailout: SDL_FreeSurface(stored_img); glBindTexture(texture->target, 0); return texture; }
void sc_release(config_object_t *c) { sc_free(c); free(c); }
void svc_free( struct service *sp ) { sc_free( SVC_CONF(sp) ) ; CLEAR( *sp ) ; FREE_SVC( sp ) ; }
static int get_next_inet_entry( int fd, pset_h sconfs, struct service_config *defaults) { char *p; str_h strp; char *line = next_line(fd); struct service_config *scp; unsigned u, i; const char *func = "get_next_inet_entry"; char *name = NULL, *rpcvers = NULL, *rpcproto = NULL; char *group, *proto, *stype; const struct name_value *nvp; struct protoent *pep ; struct passwd *pw ; struct group *grp ; const char *dot = "."; const char *slash = "/"; pset_h args; if( line == CHAR_NULL ) return -2; strp = str_parse( line, " \t", STR_RETURN_ERROR, INT_NULL ) ; if( strp == NULL ) { parsemsg( LOG_CRIT, func, "inetd.conf - str_parse failed" ) ; return( -1 ) ; } if( (args = pset_create(10,10)) == NULL ) { out_of_memory(func); return -1; } /* Break the line into components, based on spaces */ while( (p = str_component( strp )) ) { if( pset_add(args, p) == NULL ) { parsemsg( LOG_CRIT, func, ES_NOMEM ); pset_destroy(args); return -1; } } str_endparse( strp ); /* get the service name */ name = new_string((char *)pset_pointer( args, 0 )); if( name == NULL ) { parsemsg( LOG_ERR, func, "inetd.conf - Invalid service name" ); pset_destroy(args); return -1; } /* Check to find the '/' for specifying RPC version numbers */ if( (rpcvers = strstr(name, slash)) != NULL ) { *rpcvers = '\0'; rpcvers++; } scp = sc_alloc( name ); if( scp == NULL ) { pset_destroy(args); free( name ); return -1; } /* * sc_alloc makes its own copy of name. At this point, sc_alloc worked * so we will free our copy to avoid leaks. */ free( name ); /* Replicate inetd behavior in this regard. Also makes sure the * service actually works on system where setgroups(0,NULL) doesn't * work. */ SC_GROUPS(scp) = YES; SC_SPECIFY( scp, A_GROUPS ); /* Get the socket type (stream dgram) */ stype = (char *)pset_pointer(args, 1); if( stype == NULL ) { parsemsg( LOG_ERR, func, "inetd.conf - Invalid socket type" ); pset_destroy(args); sc_free(scp); return -1; } nvp = nv_find_value( socket_types, stype ); if( nvp == NULL ) { parsemsg( LOG_ERR, func, "inetd.conf - Bad socket type: %s", p); pset_destroy(args); sc_free(scp); return -1; } SC_SOCKET_TYPE(scp) = nvp->value; /* Get the protocol type */ proto = (char *)pset_pointer(args,2); if( strstr(proto, "rpc") != NULL ) { int rpcmin, rpcmax; struct rpc_data *rdp = SC_RPCDATA( scp ) ; if( rpcvers == NULL ) { pset_destroy(args); sc_free(scp); return -1; /* uh oh */ } p = strchr(rpcvers, '-'); if( p && parse_int(rpcvers, 10, '-', &rpcmin) == 0 ) { if( parse_base10(p + 1, &rpcmax) || rpcmin > rpcmax ) { pset_destroy(args); sc_free(scp); return -1; } } else { if( parse_base10(rpcvers, &rpcmin) ) { pset_destroy(args); sc_free(scp); return -1; } rpcmax = rpcmin; } /* now have min and max rpc versions */ rdp->rd_min_version = rpcmin; rdp->rd_max_version = rpcmax; rpcproto = strstr(proto, slash); if( rpcproto == NULL ) { parsemsg( LOG_ERR, func, "inetd.conf - bad rpc version numbers" ); pset_destroy(args); sc_free(scp); return -1; } *rpcproto = '\0'; rpcproto++; proto = rpcproto; /* Set the RPC type field */ nvp = nv_find_value( service_types, "RPC" ); if ( nvp == NULL ) { parsemsg( LOG_WARNING, func, "inetd.conf - Bad foo %s", name ) ; pset_destroy(args); sc_free(scp); return -1; } M_SET(SC_TYPE(scp), nvp->value); } if ( ( pep = getprotobyname( proto ) ) == NULL ) { parsemsg( LOG_ERR, func, "inetd.conf - Protocol %s not in /etc/protocols", proto ) ; pset_destroy(args); sc_free(scp); return -1; } SC_PROTONAME(scp) = new_string( proto ) ; if ( SC_PROTONAME(scp) == NULL ) { out_of_memory( func ) ; pset_destroy(args); sc_free(scp); return -1; } SC_PROTOVAL(scp) = pep->p_proto; SC_SPECIFY(scp, A_PROTOCOL); /* Get the wait attribute */ p = (char *)pset_pointer(args, 3); if ( p == NULL ) { parsemsg( LOG_ERR, func, "inetd.conf - No value specified for wait" ); sc_free(scp); return -1; } if ( EQ( p, "wait" ) ) SC_WAIT(scp) = YES ; else if ( EQ( p, "nowait" ) ) SC_WAIT(scp) = NO ; else parsemsg( LOG_ERR, func, "inetd.conf - Bad value for wait: %s", p ) ; /* Get the user to run as */ p = (char *)pset_pointer(args, 4); if ( p == NULL ) { parsemsg( LOG_ERR, func, "inetd.conf - No value specified for user" ); sc_free(scp); return -1; } if( (group = strstr(p, dot)) ) { *group = '\0'; group++; grp = (struct group *)getgrnam( (char *)group ) ; if ( grp == NULL ) { parsemsg( LOG_ERR, func, "inetd.conf - Unknown group: %s", group ) ; pset_destroy(args); sc_free(scp); return -1; } SC_GID(scp) = ((struct group *)grp)->gr_gid; SC_SPECIFY( scp, A_GROUP ); } pw = getpwnam( p ); if ( pw == NULL ) { parsemsg( LOG_ERR, func, "inetd.conf - Unknown user: %s", p ) ; pset_destroy(args); sc_free(scp); return -1; } str_fill( pw->pw_passwd, ' ' ); SC_UID(scp) = pw->pw_uid; SC_USER_GID(scp) = pw->pw_gid; /* Get server name, or flag as internal */ p = (char *)pset_pointer(args, 5); if ( p == NULL ) { parsemsg( LOG_ERR, func, "inetd.conf - No value specified for user" ); sc_free(scp); return -1; } if( EQ( p, "internal" ) ) { nvp = nv_find_value( service_types, "INTERNAL" ); if ( nvp == NULL ) { parsemsg( LOG_WARNING, func, "inetd.conf - Bad foo %s", name ) ; pset_destroy(args); sc_free(scp); return -1; } M_SET(SC_TYPE(scp), nvp->value); if( EQ( SC_NAME(scp), "time" ) ) { if( EQ( proto, "stream" ) ) SC_ID(scp) = new_string("time-stream"); else SC_ID(scp) = new_string("time-dgram"); } if( EQ( SC_NAME(scp), "daytime" ) ) { if( EQ( proto, "stream" ) ) SC_ID(scp) = new_string("daytime-stream"); else SC_ID(scp) = new_string("daytime-dgram"); } if( EQ( SC_NAME(scp), "chargen" ) ) { if( EQ( proto, "stream" ) ) SC_ID(scp) = new_string("chargen-stream"); else SC_ID(scp) = new_string("chargen-dgram"); } if( EQ( SC_NAME(scp), "echo" ) ) { if( EQ( proto, "stream" ) ) SC_ID(scp) = new_string("echo-stream"); else SC_ID(scp) = new_string("echo-dgram"); } if( EQ( SC_NAME(scp), "discard" ) ) { parsemsg(LOG_WARNING, func, "inetd.conf - service discard not supported"); pset_destroy(args); sc_free(scp); return -1; } } else { SC_SERVER(scp) = new_string( p ); if ( SC_SERVER(scp) == NULL ) { out_of_memory( func ) ; pset_destroy(args); sc_free(scp); return -1; } SC_SPECIFY( scp, A_SERVER); /* Get argv */ SC_SERVER_ARGV(scp) = (char **)argv_alloc(pset_count(args)+1); for( u = 0; u < pset_count(args)-6 ; u++ ) { p = new_string((char *)pset_pointer(args, u+6)); if( p == NULL ) { for ( i = 1 ; i < u ; i++ ) free( SC_SERVER_ARGV(scp)[i] ); free( SC_SERVER_ARGV(scp) ); pset_destroy(args); sc_free(scp); return -1; } SC_SERVER_ARGV(scp)[u] = p; } /* Set the reuse flag, as this is the default for inetd */ nvp = nv_find_value( service_flags, "REUSE" ); if ( nvp == NULL ) { parsemsg( LOG_WARNING, func, "inetd.conf - Bad foo %s", name ) ; pset_destroy(args); sc_free(scp); return -1; } M_SET(SC_XFLAGS(scp), nvp->value); /* Set the NOLIBWRAP flag, since inetd doesn't have libwrap built in */ nvp = nv_find_value( service_flags, "NOLIBWRAP" ); if ( nvp == NULL ) { parsemsg( LOG_WARNING, func, "inetd.conf - Bad foo %s", name ) ; pset_destroy(args); sc_free(scp); return -1; } M_SET(SC_XFLAGS(scp), nvp->value); /* Set the NAMEINARGS flag, as that's the default for inetd */ nvp = nv_find_value( service_flags, "NAMEINARGS" ); if ( nvp == NULL ) { parsemsg( LOG_WARNING, func, "inetd.conf - Bad foo %s", name ) ; pset_destroy(args); sc_free(scp); return (-1); } M_SET(SC_XFLAGS(scp), nvp->value); SC_SPECIFY( scp, A_SERVER_ARGS ); if ( (SC_ID(scp) = new_string( SC_NAME(scp) )) ) SC_PRESENT( scp, A_ID ) ; else { out_of_memory( func ) ; pset_destroy(args); sc_free(scp); return -1; } } SC_SPECIFY( scp, A_PROTOCOL ); SC_SPECIFY( scp, A_USER ); SC_SPECIFY( scp, A_SOCKET_TYPE ); SC_SPECIFY( scp, A_WAIT ); if( ! pset_add(sconfs, scp) ) { out_of_memory( func ); pset_destroy(args); sc_free(scp); return -1; } pset_destroy(args); parsemsg( LOG_DEBUG, func, "added service %s", SC_NAME(scp)); return 0; }